Skip to content

Commit

Permalink
chore(scripts): add trie version as parameter for retrieve-state sc…
Browse files Browse the repository at this point in the history
…ript (#4276)
  • Loading branch information
EclesioMeloJunior authored Oct 24, 2024
1 parent 1ff0b25 commit 2577544
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scripts/retrieve_state/retrieve_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
var (
errZeroLengthResponse = errors.New("zero length response")
errEmptyStateEntries = errors.New("empty state entries")

supportedVersions = map[string]trie.TrieLayout{
"v0": trie.V0,
"v1": trie.V1,
}
)

type StateRequestProvider struct {
Expand Down Expand Up @@ -86,9 +91,10 @@ func (s *StateRequestProvider) processResponse(stateResponse *messages.StateResp
return nil
}

func (s *StateRequestProvider) buildTrie(expectedStorageRootHash common.Hash, destination string) error {
func (s *StateRequestProvider) buildTrie(expectedStorageRootHash common.Hash,
destination string, v trie.TrieLayout) error {
tt := inmemory.NewEmptyTrie()
tt.SetVersion(trie.V1)
tt.SetVersion(v)

entries := make([]string, 0)

Expand Down Expand Up @@ -127,10 +133,14 @@ func (s *StateRequestProvider) buildTrie(expectedStorageRootHash common.Hash, de
}

func main() {
if len(os.Args) != 5 {
log.Fatalf(`
script usage:
go run retrieve_state.go [hash] [expected storage root hash] [network chain spec] [output file]`)
if len(os.Args) != 6 {
log.Fatalf(`script usage:
go run retrieve_state.go [block hash] [expected state root hash] [network chain spec] [v0|v1] [output file]`)
}

version, ok := supportedVersions[os.Args[4]]
if !ok {
log.Fatalf("ERR version not supported: %s", os.Args[4])
}

targetBlockHash := common.MustHexToHash(os.Args[1])
Expand Down Expand Up @@ -186,7 +196,7 @@ func main() {
refreshPeerID = false
}

if err := provider.buildTrie(expectedStorageRootHash, os.Args[4]); err != nil {
if err := provider.buildTrie(expectedStorageRootHash, os.Args[5], version); err != nil {
panic(err)
}
}
Expand Down

0 comments on commit 2577544

Please sign in to comment.