Skip to content

Commit

Permalink
Merge pull request #54 from sei-protocol/yzang/SEI-6501
Browse files Browse the repository at this point in the history
Various fixes from audit
  • Loading branch information
yzang2019 authored Jan 23, 2024
2 parents 39eb03f + decc4f4 commit 94821aa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sc/memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,12 @@ func parseVersion(name string) (int64, error) {
return 0, fmt.Errorf("invalid snapshot name %s", name)
}

v, err := strconv.ParseInt(name[len(SnapshotPrefix):], 10, 32)
v, err := strconv.ParseUint(name[len(SnapshotPrefix):], 10, 32)
if err != nil {
return 0, fmt.Errorf("snapshot version overflows: %d", err)
}

return v, nil
return int64(v), nil
}

// seekSnapshot find the biggest snapshot version that's smaller than or equal to the target version,
Expand Down
4 changes: 0 additions & 4 deletions sc/memiavl/layout_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ func (node *nodeLayout) KeyLeaf() uint32 {
return node.data[3]
}

func (node *nodeLayout) KeyOffset() uint64 {
return uint64(node.data[2]) | uint64(node.data[3])<<32
}

func (node *nodeLayout) Hash() []byte {
return node.hash[:]
}
Expand Down
2 changes: 1 addition & 1 deletion sc/memiavl/multitree.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (t *MultiTree) WriteSnapshot(ctx context.Context, dir string, wp *pond.Work
}

// write the snapshots in parallel and wait all jobs done
group, _ := wp.GroupContext(context.Background())
group, _ := wp.GroupContext(ctx)

for _, entry := range t.trees {
tree, name := entry.Tree, entry.Name
Expand Down
1 change: 1 addition & 0 deletions sc/memiavl/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (t *Tree) Copy(cacheSize int) *Tree {
newTree := *t
// cache is not copied along because it's not thread-safe to access
newTree.cache = NewCache(cacheSize)
newTree.mtx = &sync.RWMutex{}
return &newTree
}

Expand Down
3 changes: 2 additions & 1 deletion ss/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewStateStore(homeDir string, ssConfig config.StateStoreConfig) (types.Stat
return db, nil
}

// RecoverStateStore will be called during initialization to recover the state from rlog
func RecoverStateStore(homePath string, logger logger.Logger, stateStore types.StateStore) error {
ssLatestVersion, err := stateStore.GetLatestVersion()
if err != nil {
Expand Down Expand Up @@ -79,7 +80,7 @@ func RecoverStateStore(homePath string, logger logger.Logger, stateStore types.S
targetStartOffset := uint64(ssLatestVersion) - delta
logger.Info(fmt.Sprintf("Start replaying changelog to recover StateStore from offset %d to %d", targetStartOffset, lastOffset))
if targetStartOffset < lastOffset {
return streamHandler.Replay(targetStartOffset, lastOffset, func(index uint64, entry proto.ChangelogEntry) error {
return streamHandler.Replay(targetStartOffset+1, lastOffset, func(index uint64, entry proto.ChangelogEntry) error {
// commit to state store
for _, cs := range entry.Changesets {
if err := stateStore.ApplyChangeset(entry.Version, cs); err != nil {
Expand Down

0 comments on commit 94821aa

Please sign in to comment.