Skip to content

Commit

Permalink
still update lastPostTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Jul 17, 2024
1 parent e6442e3 commit 142e04a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 7 additions & 3 deletions lib/cron/fade-rate-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ export function calculateNewTimestamps(
const fades = row[1];
const fillerTimestamp = fillerTimestamps.get(hash);
if (fillerTimestamp && fillerTimestamp.blockUntilTimestamp > newPostTimestamp) {
return;
}
if (fades) {
updatedTimestamps.push({
hash,
lastPostTimestamp: newPostTimestamp,
blockUntilTimestamp: fillerTimestamp.blockUntilTimestamp,
consecutiveBlocks: fillerTimestamp.consecutiveBlocks,
});
} else if (fades) {
const blockUntilTimestamp = calculateBlockUntilTimestamp(
newPostTimestamp,
fillerTimestamp?.consecutiveBlocks,
Expand Down
18 changes: 13 additions & 5 deletions test/crons/fade-rate-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ describe('FadeRateCron test', () => {
blockUntilTimestamp: now + Math.floor(BASE_BLOCK_SECS * Math.pow(NUM_FADES_MULTIPLIER, 0)),
consecutiveBlocks: 1,
},
// still update lastPostTimestamp when blockUntilTimestamp > now
{
hash: 'filler3',
lastPostTimestamp: now,
blockUntilTimestamp: now + 1000,
consecutiveBlocks: 0,
},
{
hash: 'filler5',
lastPostTimestamp: now,
blockUntilTimestamp: now + 100,
consecutiveBlocks: 0,
},
// test exponential backoff
{
hash: 'filler7',
Expand Down Expand Up @@ -138,12 +151,7 @@ describe('FadeRateCron test', () => {
});

it('keep old blockUntilTimestamp if no new fades', () => {
expect(newTimestamps).not.toContain([['filler5', expect.anything(), expect.anything()]]);
expect(newTimestamps).not.toContain([['filler4', expect.anything(), expect.anything()]]);
});

it('ignores fillers with blockUntilTimestamp > current timestamp', () => {
expect(newTimestamps).not.toContain([['filler3', expect.anything(), expect.anything()]]);
});
});
});

0 comments on commit 142e04a

Please sign in to comment.