Skip to content

Commit

Permalink
tomox-snapshot: check size of priceTree
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnguyennguyen committed Jul 30, 2019
1 parent a1f9df1 commit bafbd7d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tomox/redblacktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,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 @@ -216,7 +216,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
3 changes: 2 additions & 1 deletion tomox/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ func prepareOrderTreeData(tree *OrderTree) (*OrderTreeSnapshot, error) {
snap.OrderTreeItem = serializedTree

snap.OrderList = make(map[common.Hash]*OrderListSnapshot)
if !tree.NotEmpty() {
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 @@ -1176,7 +1176,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 bafbd7d

Please sign in to comment.