Skip to content

Commit

Permalink
Merge pull request #111 from ethereum-optimism/contract-code-method
Browse files Browse the repository at this point in the history
core: reinstate ContractCode function to support snap-sync from legacy DB nodes
  • Loading branch information
protolambda committed Jul 26, 2023
2 parents 7d958e9 + aa7062e commit 18dbad1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/devp2p/internal/ethtest/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ func (s *Suite) TestSnapGetByteCodes(t *utesting.T) {
// A few stateroots
{
nBytes: 10000, hashes: []common.Hash{s.chain.RootAt(0), s.chain.RootAt(999)},
expHashes: 0,
expHashes: 1, // 32-byte keys are detected as code, even if not code (like genesis hash), in legacy lookups.
},
{
nBytes: 10000, hashes: []common.Hash{s.chain.RootAt(0), s.chain.RootAt(0)},
expHashes: 0,
expHashes: 2, // 32-byte keys are detected as code, even if not code (like genesis hash), in legacy lookups.
},
// Empties
{
Expand Down
8 changes: 8 additions & 0 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ func (bc *BlockChain) ContractCodeWithPrefix(hash common.Hash) ([]byte, error) {
return bc.stateCache.(codeReader).ContractCodeWithPrefix(common.Hash{}, hash)
}

// ContractCode retrieves a blob of data associated with a contract hash
// either from ephemeral in-memory cache, or from persistent storage.
// This is a legacy-method, replaced by ContractCodeWithPrefix,
// but required for old databases to serve snap-sync.
func (bc *BlockChain) ContractCode(hash common.Hash) ([]byte, error) {
return bc.stateCache.ContractCode(common.Hash{}, hash)
}

// State returns a new mutable state based on the current HEAD block.
func (bc *BlockChain) State() (*state.StateDB, error) {
return bc.StateAt(bc.CurrentBlock().Root)
Expand Down

0 comments on commit 18dbad1

Please sign in to comment.