From aec1dcdeefbfe274b28880c0290d9245e2a30100 Mon Sep 17 00:00:00 2001 From: Jason Yellick <7431583+jyellick@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:02:07 -0400 Subject: [PATCH] Delete retain_list_builder.go (#7096) I was walking the code to try to understand in a bit more detail how the state root hash is constructed and stumbled across `retain_list_builder.go` as a consumer of the retain list APIs. But, as far as I can tell, this file doesn't seem to actually be used anywhere (including tests), and, it's seen no development (other than import fixes) since 2020 or so. All linting and tests still pass for me locally without it, so, I believe it's safe to simply remove. Co-authored-by: Jason Yellick --- turbo/trie/retain_list_builder.go | 86 ------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 turbo/trie/retain_list_builder.go diff --git a/turbo/trie/retain_list_builder.go b/turbo/trie/retain_list_builder.go deleted file mode 100644 index 62a057debf0..00000000000 --- a/turbo/trie/retain_list_builder.go +++ /dev/null @@ -1,86 +0,0 @@ -package trie - -import ( - libcommon "github.com/ledgerwatch/erigon-lib/common" - - "github.com/ledgerwatch/erigon/common" -) - -// RetainListBuilder is the structure that accumulates the list of keys that were read or changes (touched) during -// the execution of a block. It also tracks the contract codes that were created and used during the execution -// of a block -type RetainListBuilder struct { - touches [][]byte // Read/change set of account keys (account hashes) - storageTouches [][]byte // Read/change set of storage keys (account hashes concatenated with storage key hashes) - proofCodes map[libcommon.Hash]struct{} // Contract codes that have been accessed (codeHash) - createdCodes map[libcommon.Hash]struct{} // Contract codes that were created (deployed) (codeHash) -} - -// NewRetainListBuilder creates new ProofGenerator and initialised its maps -func NewRetainListBuilder() *RetainListBuilder { - return &RetainListBuilder{ - proofCodes: make(map[libcommon.Hash]struct{}), - createdCodes: make(map[libcommon.Hash]struct{}), - } -} - -// AddTouch adds a key (in KEY encoding) into the read/change set of account keys -func (rlb *RetainListBuilder) AddTouch(touch []byte) { - rlb.touches = append(rlb.touches, common.CopyBytes(touch)) -} - -// AddStorageTouch adds a key (in KEY encoding) into the read/change set of storage keys -func (rlb *RetainListBuilder) AddStorageTouch(touch []byte) { - rlb.storageTouches = append(rlb.storageTouches, common.CopyBytes(touch)) -} - -// ExtractTouches returns accumulated read/change sets and clears them for the next block's execution -func (rlb *RetainListBuilder) ExtractTouches() ([][]byte, [][]byte) { - touches := rlb.touches - storageTouches := rlb.storageTouches - rlb.touches = nil - rlb.storageTouches = nil - return touches, storageTouches -} - -// extractCodeTouches returns the set of all contract codes that were required during the block's execution -// but were not created during that same block. It also clears the set for the next block's execution -func (rlb *RetainListBuilder) extractCodeTouches() map[libcommon.Hash]struct{} { - proofCodes := rlb.proofCodes - rlb.proofCodes = make(map[libcommon.Hash]struct{}) - rlb.createdCodes = make(map[libcommon.Hash]struct{}) - return proofCodes -} - -// ReadCode registers that given contract code has been accessed during current block's execution -func (rlb *RetainListBuilder) ReadCode(codeHash libcommon.Hash) { - if _, ok := rlb.proofCodes[codeHash]; !ok { - rlb.proofCodes[codeHash] = struct{}{} - } -} - -// CreateCode registers that given contract code has been created (deployed) during current block's execution -func (rlb *RetainListBuilder) CreateCode(codeHash libcommon.Hash) { - if _, ok := rlb.proofCodes[codeHash]; !ok { - rlb.createdCodes[codeHash] = struct{}{} - } -} - -func (rlb *RetainListBuilder) Build() *RetainList { - rl := NewRetainList(0) - - touches, storageTouches := rlb.ExtractTouches() - codeTouches := rlb.extractCodeTouches() - - for _, touch := range touches { - rl.AddKey(touch) - } - for _, touch := range storageTouches { - rl.AddKey(touch) - } - for codeHash := range codeTouches { - rl.AddCodeTouch(codeHash) - } - - return rl -}