Skip to content
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

Fix inconsistent latest_block_hash #1424

Merged
merged 12 commits into from
May 15, 2024

Conversation

boundless-forest
Copy link
Collaborator

@boundless-forest boundless-forest commented May 10, 2024

We(Darwinia) have noticed that there are some unexpected cases when indexing evm logs with the third party tools, like ponder. After some investment, I found out that the root cause is the latest block hash is sometimes inconsistent when using different RPC methods. For instance, the indexing tool generally first queries the latest block number with eth_getBlockNumber(latest), which returns the client.info().best_hash in the current implementation, then it tries to fetch the block data with eth_getBlockByHash(hash), but the block data isn't sync to the kv/sql db in time, so the indexing tool misunderstands that the block doesn't have any logs. But in fact it does. Of course, the indexing tool will track the finalize tag and fetch these blocks data again and compared to the previously stored data, it would find the same block hash but with different block data information. We have found that this can be easily reproduced with the frontier sql backend. Some discussion can be found moonbeam-foundation/moonbeam#2788.

This PR changes the latest_block_hash response from the underlying substrate client best_hash to db latest_block_hash(). This only applies to the sql db now.

@boundless-forest
Copy link
Collaborator Author

boundless-forest commented May 13, 2024

@ahmadkaouk @librelois @koushiro @sorpaas Please help take a review.

client/db/src/sql/mod.rs Outdated Show resolved Hide resolved
@librelois
Copy link
Contributor

@boundless-forest the overall design seems good, but we need a migration and/or a breaking change section in this PR's description to indicate that there is a migration to run or that node operators should resync the sql backend after the upgrade

@boundless-forest
Copy link
Collaborator Author

boundless-forest commented May 15, 2024

@boundless-forest the overall design seems good, but we need a migration and/or a breaking change section in this PR's description to indicate that there is a migration to run or that node operators should resync the sql backend after the upgrade

I have deleted the broken db operation. Let's focus on fixing only one issue in this PR.

client/rpc/src/lib.rs Outdated Show resolved Hide resolved
client/db/src/kv/mod.rs Outdated Show resolved Hide resolved
@boundless-forest boundless-forest marked this pull request as draft May 15, 2024 05:23
@boundless-forest boundless-forest marked this pull request as ready for review May 15, 2024 05:37
@boundless-forest boundless-forest merged commit 17eeb7a into polkadot-evm:master May 15, 2024
4 checks passed
@boundless-forest boundless-forest deleted the bear-best-hash branch May 15, 2024 07:21
boundless-forest added a commit to darwinia-network/frontier that referenced this pull request Sep 23, 2024
* Add `best_hash` method

* Update earliest tag matched value

* Fix CI tests

* Code clean

* Fix review comments

* Update comment

* Fix compile after solving conflicts

* Remove the broken changes

* Update trait bound

* Simplify trait bound
boundless-forest added a commit to darwinia-network/frontier that referenced this pull request Sep 23, 2024
* Add `best_hash` method

* Update earliest tag matched value

* Fix CI tests

* Code clean

* Fix review comments

* Update comment

* Fix compile after solving conflicts

* Remove the broken changes

* Update trait bound

* Simplify trait bound
AurevoirXavier pushed a commit to darwinia-network/frontier that referenced this pull request Sep 23, 2024
* Fix inconsistent `latest_block_hash` (polkadot-evm#1424)

* Add `best_hash` method

* Update earliest tag matched value

* Fix CI tests

* Code clean

* Fix review comments

* Update comment

* Fix compile after solving conflicts

* Remove the broken changes

* Update trait bound

* Simplify trait bound

* FIX ci
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