Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Nov 20, 2024
1 parent eb42c4b commit 3b9b076
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 4 additions & 5 deletions state/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,14 @@ func (sf *factory) newWorkingSet(ctx context.Context, height uint64) (*workingSe
return nil, err
}
var (
rootKey = ArchiveTrieRootKey
createTrie = true
store workingSetStore
)
if height < sf.currentChainHeight {
// archive mode
rootKey = fmt.Sprintf("%s-%d", ArchiveTrieRootKey, height)
createTrie = false
store, err = newFactoryWorkingSetStoreAtHeight(sf.protocolView, flusher, height)
} else {
store, err = newFactoryWorkingSetStore(sf.protocolView, flusher)
}
store, err := newFactoryWorkingSetStore(sf.protocolView, flusher, rootKey, createTrie)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion state/factory/workingset.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (ws *workingSet) Commit(ctx context.Context) error {
return err
}
ws.Reset()
return ws.store.Stop(ctx)
return nil
}

// State pulls a state from DB
Expand Down
19 changes: 17 additions & 2 deletions state/factory/workingsetstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,23 @@ func newStateDBWorkingSetStore(view protocol.View, flusher db.KVStoreFlusher, re
}
}

func newFactoryWorkingSetStore(view protocol.View, flusher db.KVStoreFlusher, trieRootKey string, createTrie bool) (workingSetStore, error) {
tlt, err := newTwoLayerTrie(ArchiveTrieNamespace, flusher.KVStoreWithBuffer(), trieRootKey, createTrie)
func newFactoryWorkingSetStore(view protocol.View, flusher db.KVStoreFlusher) (workingSetStore, error) {
tlt, err := newTwoLayerTrie(ArchiveTrieNamespace, flusher.KVStoreWithBuffer(), ArchiveTrieRootKey, true)
if err != nil {
return nil, err
}

return &factoryWorkingSetStore{
flusher: flusher,
view: view,
tlt: tlt,
trieRoots: make(map[int][]byte),
}, nil
}

func newFactoryWorkingSetStoreAtHeight(view protocol.View, flusher db.KVStoreFlusher, height uint64) (workingSetStore, error) {
rootKey := fmt.Sprintf("%s-%d", ArchiveTrieRootKey, height)
tlt, err := newTwoLayerTrie(ArchiveTrieNamespace, flusher.KVStoreWithBuffer(), rootKey, false)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 3b9b076

Please sign in to comment.