Skip to content

Commit

Permalink
Self review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 26, 2022
1 parent 0e92324 commit 6c64521
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dot/state/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ func TestService_PruneStorage(t *testing.T) {
time.Sleep(1 * time.Second)

for _, v := range prunedArr {
_, err := serv.Storage.tries.getTrie(v.hash)
require.Error(t, err)
_, has := serv.Storage.tries.rootToTrie[v.hash]
require.False(t, has)
}
}

Expand Down
14 changes: 2 additions & 12 deletions dot/state/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewStorageState(db chaindb.Database, blockState *BlockState,

storageTable := chaindb.NewTable(db, storagePrefix)

rootToTrie := newRootToTrieMap(storageTable, t)
tries := newTries(storageTable, t)

var p pruner.Pruner
if onlinePruner.Mode == pruner.Full {
Expand All @@ -69,7 +69,7 @@ func NewStorageState(db chaindb.Database, blockState *BlockState,

return &StorageState{
blockState: blockState,
tries: rootToTrie,
tries: tries,
db: storageTable,
observerList: []Observer{},
pruner: p,
Expand Down Expand Up @@ -151,16 +151,6 @@ func (s *StorageState) loadTrie(root *common.Hash) (*trie.Trie, error) {
}

return s.tries.getTrie(*root)
// if t, has := s.tries.get(*root); has && t != nil {
// return t, nil
// }

// tr, err := s.LoadFromDB(*root)
// if err != nil {
// return nil, errTrieDoesNotExist(*root)
// }

// return tr, nil
}

// ExistsStorage check if the key exists in the storage trie with the given storage hash
Expand Down
2 changes: 1 addition & 1 deletion dot/state/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestStorage_StoreTrie_NotSyncing(t *testing.T) {

err = storage.StoreTrie(ts, nil)
require.NoError(t, err)
require.Equal(t, 2, len(storage.tries.rootToTrie))
require.Equal(t, 2, storage.tries.triesInMemory())
}

func TestGetStorageChildAndGetStorageFromChild(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions dot/state/tries.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type tries struct {
mapMutex sync.RWMutex
}

func newRootToTrieMap(db chaindb.Database, t *trie.Trie) *tries {
func newTries(db chaindb.Database, t *trie.Trie) *tries {
return &tries{
rootToTrie: map[common.Hash]*trie.Trie{
t.MustHash(): t,
Expand Down Expand Up @@ -97,7 +97,6 @@ func (t *tries) getTrie(root common.Hash) (tr *trie.Trie, err error) {
return nil, fmt.Errorf("cannot load root from database: %w", err)
}

fmt.Println("ROOT RETRIEVED: ", tr.RootNode())
calculatedRootHash := tr.MustHash()
if !calculatedRootHash.Equal(root) {
panic(fmt.Sprintf("trie does not have expected root, expected %s but got %s",
Expand Down
4 changes: 2 additions & 2 deletions dot/state/tries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import (
"github.com/stretchr/testify/require"
)

func Test_newRootToTrieMap(t *testing.T) {
func Test_newTries(t *testing.T) {
t.Parallel()

db := &chaindb.BadgerDB{}
tr := trie.NewEmptyTrie()

rootToTrie := newRootToTrieMap(db, tr)
rootToTrie := newTries(db, tr)

expectedRootToTrie := &tries{
rootToTrie: map[common.Hash]*trie.Trie{
Expand Down

0 comments on commit 6c64521

Please sign in to comment.