Skip to content

fix: last_checked_block retrieval #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

PatrickNercessian
Copy link
Contributor

@PatrickNercessian PatrickNercessian commented Jun 11, 2024

Related to #134 and #102

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix lgtm, could you please also add a test for this? You can mock ieContract so we only test the sql logic

@@ -18,4 +18,8 @@ await pgPool.query('DELETE FROM daily_reward_transfers')

await observeTransferEvents(pgPool, ieContract, provider)

// Do it a second time, without clearing the table.
// This should find 0 events, unless rewards are currently being released.
await observeTransferEvents(pgPool, ieContract, provider)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to add an automated test instead

@juliangruber juliangruber merged commit 648189b into CheckerNetwork:main Jun 13, 2024
9 of 10 checks passed
)
let queryFromBlock = rows[0].last_checked_block
let queryFromBlock = rows[0].last_checked_block + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is bug lurking here.

In the initial run against an empty database, last_checked_block will be undefined and queryFromBlock will be set to NaN.

❯ node          
Welcome to Node.js v20.14.0.
Type ".help" for more information.
> undefined + 1
NaN

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check the truthy value of the queryFromBlock directly after this, so it ends up being reset to the -1900 block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I verified that this works as you described.

> queryFromBlock = undefined + 1
NaN
> currentBlockNumber=6543
6543
> !queryFromBlock || queryFromBlock < currentBlockNumber - 1900
true
> 

It's great that the bug is not there.

It would be nice to rewrite this part to make it easier for casual readers (or novice programmers) to correctly understand how exactly the code works and how it handles different edge cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Do you prefer just a comment explaining it, or a logic change?

Comment on lines +10 to +11
const getDayAsISOString = d => d.toISOString().split('T')[0]
const today = () => getDayAsISOString(new Date())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there any particular reason for moving these two helper functions into a describe block? Can we move them back to the top where they were before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right here as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed too quickly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, merge conflicts confusion! Shall I open a PR for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

@PatrickNercessian PatrickNercessian deleted the fix-last-checked-block-retrieval branch July 1, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants