Skip to content

Commit e670c37

Browse files
extract method for block hash correction
1 parent 549c64f commit e670c37

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

fvm/evm/offchain/blocks/block_context.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,9 @@ func NewBlockContext(
4848
return gethCommon.Hash{}
4949
}
5050

51-
// For testnet & mainnet, we fetch the block hash from the hard-coded
52-
// array of hashes.
53-
if chainID == flow.Mainnet && hashHeight < blockHashListFixHCUEVMHeightMainnet {
54-
return fixedHashes[flow.Mainnet][hashHeight%256]
55-
} else if chainID == flow.Testnet && blockHashListBugIntroducedHCUEVMHeightTestnet <= hashHeight && hashHeight < blockHashListFixHCUEVMHeightTestnet {
56-
return fixedHashes[flow.Testnet][hashHeight%256]
51+
hash, ok := UseBlockHashCorrection(chainID, height, hashHeight)
52+
if ok {
53+
return hash
5754
}
5855

5956
return getHashByHeight(hashHeight)
@@ -64,6 +61,18 @@ func NewBlockContext(
6461
}, nil
6562
}
6663

64+
// UseBlockHashCorrection returns the block hash correction for the given chain ID, EVM height, and queried EVM height, and a boolean indicating whether the correction should be used.
65+
func UseBlockHashCorrection(chainID flow.ChainID, evmHeightOfCurrentBlock uint64, queriedEVMHeight uint64) (gethCommon.Hash, bool) {
66+
// For testnet & mainnet, we fetch the block hash from the hard-coded
67+
// array of hashes.
68+
if chainID == flow.Mainnet && evmHeightOfCurrentBlock < blockHashListFixHCUEVMHeightMainnet {
69+
return fixedHashes[flow.Mainnet][queriedEVMHeight%256], true
70+
} else if chainID == flow.Testnet && blockHashListBugIntroducedHCUEVMHeightTestnet <= evmHeightOfCurrentBlock && evmHeightOfCurrentBlock < blockHashListFixHCUEVMHeightTestnet {
71+
return fixedHashes[flow.Testnet][queriedEVMHeight%256], true
72+
}
73+
return gethCommon.Hash{}, false
74+
}
75+
6776
// Testnet52 - Height Coordinated Upgrade 4, Nov 21, 2024
6877
// Flow Block: 94361765 4c9edc817afeaaa6aeb5e63504ed3f5ba8bcbba3931e53f5437d911a1129b431
6978
// PR: https://github.com/onflow/flow-go/pull/6734

0 commit comments

Comments
 (0)