Skip to content

Commit

Permalink
Merge pull request ethereum#596 from thanhnguyennguyen/snapshot-fix-b…
Browse files Browse the repository at this point in the history
…ug-out-of-range

tomox-snapshot: check size of priceTree
  • Loading branch information
ngtuna authored Jul 30, 2019
2 parents 66c9e64 + bafbd7d commit 41d565b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tomox/redblacktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (tree *Tree) Size() uint64 {
func (tree *Tree) Keys(dryrun bool) [][]byte {
keys := make([][]byte, tree.size)
it := tree.Iterator()
for i := 0; it.Next(dryrun); i++ {
for i := 0; it.Next(dryrun) && i < len(keys); i++ {
keys[i] = it.Key()
}
return keys
Expand All @@ -224,7 +224,7 @@ func (tree *Tree) Keys(dryrun bool) [][]byte {
func (tree *Tree) Values(dryrun bool) [][]byte {
values := make([][]byte, tree.size)
it := tree.Iterator()
for i := 0; it.Next(dryrun); i++ {
for i := 0; it.Next(dryrun) && i < len(values); i++ {
values[i] = it.Value()
}
return values
Expand Down
1 change: 1 addition & 0 deletions tomox/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func prepareOrderTreeData(tree *OrderTree) (*OrderTreeSnapshot, error) {
if !tree.NotEmpty() || tree.PriceTree.Size() == 0 {
return snap, nil
}

// foreach each price, snapshot its orderlist
for _, key := range tree.PriceTree.Keys(false) {
priceKeyHash := common.BytesToHash(key)
Expand Down
2 changes: 1 addition & 1 deletion tomox/tomox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ func (tomox *TomoX) Snapshot(blockHash common.Hash) error {
}(time.Now())

if snap, err = newSnapshot(tomox, blockHash); err != nil {
return nil
return err
}
if err = snap.store(tomox.db); err != nil {
return err
Expand Down

0 comments on commit 41d565b

Please sign in to comment.