diff --git a/claimtrie/change/change.go b/claimtrie/change/change.go index 92b8aa3d..0f9c4151 100644 --- a/claimtrie/change/change.go +++ b/claimtrie/change/change.go @@ -22,13 +22,13 @@ type Change struct { Type ChangeType Height int32 - Name []byte `msg:"-"` + Name []byte ClaimID ClaimID OutPoint wire.OutPoint Amount int64 - ActiveHeight int32 // for normalization fork - VisibleHeight int32 + ActiveHeight int32 + VisibleHeight int32 // for normalization fork SpentChildren map[string]bool } diff --git a/claimtrie/claimtrie.go b/claimtrie/claimtrie.go index fe08644d..eec404cb 100644 --- a/claimtrie/claimtrie.go +++ b/claimtrie/claimtrie.go @@ -422,7 +422,7 @@ func (ct *ClaimTrie) makeNameHashNext(names [][]byte, all bool) chan NameHashNex outputs := make(chan NameHashNext, 512) var wg sync.WaitGroup - computeHash := func() { + hashComputationWorker := func() { for name := range inputs { hash, next := ct.nodeManager.Hash(name) outputs <- NameHashNext{name, hash, next} @@ -437,7 +437,7 @@ func (ct *ClaimTrie) makeNameHashNext(names [][]byte, all bool) chan NameHashNex for threads >= 0 { threads-- wg.Add(1) - go computeHash() + go hashComputationWorker() } go func() { if all { diff --git a/claimtrie/merkletrie/collapsedtrie.go b/claimtrie/merkletrie/collapsedtrie.go index 262bc7e6..1d070f1d 100644 --- a/claimtrie/merkletrie/collapsedtrie.go +++ b/claimtrie/merkletrie/collapsedtrie.go @@ -6,7 +6,7 @@ import ( type KeyType []byte -type collapsedVertex struct { // implements sort.Interface +type collapsedVertex struct { children []*collapsedVertex key KeyType merkleHash *chainhash.Hash diff --git a/claimtrie/node/noderepo/pebble.go b/claimtrie/node/noderepo/pebble.go index 1f9e13f5..b3c06c98 100644 --- a/claimtrie/node/noderepo/pebble.go +++ b/claimtrie/node/noderepo/pebble.go @@ -103,15 +103,8 @@ func (repo *Pebble) IterateChildren(name []byte, f func(changes []change.Change) start := make([]byte, len(name)+1) // zeros that last byte; need a constant len for stack alloc? copy(start, name) - end := make([]byte, 256) // max name length is 255 - copy(end, name) - for i := len(name); i < 256; i++ { - end[i] = 255 - } - prefixIterOptions := &pebble.IterOptions{ LowerBound: start, - UpperBound: end, } iter := repo.db.NewIter(prefixIterOptions) @@ -119,6 +112,9 @@ func (repo *Pebble) IterateChildren(name []byte, f func(changes []change.Change) for iter.First(); iter.Valid(); iter.Next() { // NOTE! iter.Key() is ephemeral! + if len(iter.Key()) <= len(name) || !bytes.Equal(name, iter.Key()[:len(name)]) { + break + } changes, err := unmarshalChanges(iter.Key(), iter.Value()) if err != nil { return errors.Wrapf(err, "from unmarshaller at %s", iter.Key())