Skip to content

Fix FailedToObtainBlockhash in case of empty slots #506

Open
syntrust wants to merge 2 commits intomainfrom
blockhash-p1
Open

Fix FailedToObtainBlockhash in case of empty slots #506
syntrust wants to merge 2 commits intomainfrom
blockhash-p1

Conversation

@syntrust
Copy link
Collaborator

Issue

The FailedToObtainBlockhash issue was reproduced:

INFO [03-09|14:19:15.072] Calculated a valid hash                  shard=0 block=10,414,872 timestamp=1,773,062,352 randao=8651fa..436b57 nonce=170,011 hash0=d04672..40e44a hash1=000000..8ce8a8 sampleIdxs="[2285954122 5178046772]"
...
INFO [03-09|14:19:40.388] Mining result loop get result            shard=0 block=10,414,872 nonce=170,011
...
ERROR[03-09|14:19:40.399] Estimate gas failed                      error="execution reverted: ErrorData: 0x4882d76b: StorageContract_FailedToObtainBlockhash()"

Cause

The chain head stayed as 10,414,872 for 3 slots during the block mined and tx estimated. The fix in #487 only waits for 1 slot at most.

We need the block number updates to avoid empty blockhash.

Solution

This PR replaces slot-based waiting with a channel-based synchronization that ensures mining results are only submitted after the L1 head has advanced past the mined block.

Tests

Tests done in local devnet:

Waiting for L1 head to advance in the case of an empty slot:

INFO [03-11|11:59:26.576] Calculated a valid hash                  shard=37 block=10,424,641 timestamp=1,773,201,564 randao=3756ab..928ca0 nonce=541,929 hash0=ea0224..c03870 hash1=000001..326081 sampleIdxs="[1226864 1215777]"
...
INFO [03-11|11:59:40.490] Mining result loop get result            shard=37 block=10,424,641 nonce=541,929
INFO [03-11|11:59:40.490] L1 head not advanced since mined block, keep waiting mined=10,424,641 latest=10,424,641
INFO [03-11|11:59:40.490] Waiting for L1 head to advance           mined=10,424,641
INFO [03-11|11:59:49.055] headUpdateCh updated                     new=10,424,642
INFO [03-11|11:59:49.055] L1 head advanced since mined block       mined=10,424,641 latest=10,424,642
INFO [03-11|11:59:49.740] Composed calldata   ...                    

Normal case:

INFO [03-11|14:13:19.923] Calculated a valid hash                  shard=37 block=10,425,204 timestamp=1,773,209,592 randao=0d1b1f..4e2cb9 nonce=482,820 hash0=735e4e..03afb1 hash1=000001..b2a4e3 sampleIdxs="[1224625 1241249]"
...
INFO [03-11|14:13:36.915] Mining result loop get result            shard=37 block=10,425,204 nonce=482,820
INFO [03-11|14:13:36.915] L1 head advanced since mined block       mined=10,425,204 latest=10,425,205
INFO [03-11|14:13:38.683] Composed calldata                        ...

@syntrust syntrust requested review from iteyelmp, ping-ke and qzhodl March 11, 2026 07:08
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.

1 participant