From 9a50df0b6228310dc1eb01c132d18467eaebfb4c Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 11 Jul 2025 10:22:26 +0800 Subject: [PATCH] core/rawdb: do prefixed lookup first #24288 (#1209) Co-authored-by: Martin Holst Swende --- core/rawdb/accessors_state.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/rawdb/accessors_state.go b/core/rawdb/accessors_state.go index b55998e043..6af2372a65 100644 --- a/core/rawdb/accessors_state.go +++ b/core/rawdb/accessors_state.go @@ -41,16 +41,14 @@ func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) { // ReadCode retrieves the contract code of the provided code hash. func ReadCode(db ethdb.KeyValueReader, hash common.Hash) []byte { - // Try with the legacy code scheme first, if not then try with current - // scheme. Since most of the code will be found with legacy scheme. - // - // todo(rjl493456442) change the order when we forcibly upgrade the code - // scheme with snapshot. - data, _ := db.Get(hash[:]) + // Try with the prefixed code scheme first, if not then try with legacy + // scheme. + data := ReadCodeWithPrefix(db, hash) if len(data) != 0 { return data } - return ReadCodeWithPrefix(db, hash) + data, _ = db.Get(hash[:]) + return data } // ReadCodeWithPrefix retrieves the contract code of the provided code hash.