fixed bug with block rollback; re-orgs should work now

This commit is contained in:
Brannon King 2021-08-27 10:54:26 -04:00
parent 1834d95b43
commit 79987722bb
7 changed files with 16 additions and 13 deletions

View file

@ -773,8 +773,10 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block *btcutil.Block, view
return err
}
if err = b.claimTrie.ResetHeight(node.parent.height); err != nil {
return err
if b.claimTrie != nil {
if err = b.claimTrie.ResetHeight(node.parent.height); err != nil {
return err
}
}
// Prune fully spent entries and mark all entries in the view unmodified

View file

@ -318,12 +318,13 @@ func (ct *ClaimTrie) ResetHeight(height int32) error {
}
passedHashFork := ct.height >= param.ActiveParams.AllClaimsInMerkleForkHeight && height < param.ActiveParams.AllClaimsInMerkleForkHeight
ct.height = height
hash, err := ct.blockRepo.Get(height)
if err != nil {
return err
}
ct.height = height // keep this before the rebuild
if passedHashFork {
names = nil // force them to reconsider all names
}

View file

@ -338,9 +338,14 @@ func BenchmarkClaimTrie_AppendBlock(b *testing.B) {
b.StopTimer()
ht := ct.height
h1 = *ct.MerkleHash()
ct.Close()
b.Logf("Running AppendBlock bench with %d names in %f sec. Height: %d, Hash: %s",
b.N, time.Since(start).Seconds(), ht, h1.String())
// a very important test of the functionality:
for ct.height > 0 {
err = ct.ResetHeight(ct.height - 1)
r.NoError(err)
}
}
func randomName() []byte {

View file

@ -66,7 +66,7 @@ func TestNilNameHandling(t *testing.T) {
}
func TestCollapsedTriePerformance(t *testing.T) {
inserts := 10000 // increase this to 1M for more interesting results
inserts := 100000 // increase this to 1M for more interesting results
data := make([][]byte, inserts)
rand.Seed(42)
for i := 0; i < inserts; i++ {

View file

@ -42,13 +42,7 @@ func (rt *RamTrie) SetRoot(h *chainhash.Hash) error {
return nil
}
// should technically clear the old trie first:
if rt.Nodes > 1 {
rt.Root = &collapsedVertex{key: make(KeyType, 0)}
rt.Nodes = 1
runtime.GC()
}
// should technically clear the old trie first, but this is abused for partial rebuilds so don't
return ErrFullRebuildRequired
}

View file

@ -86,7 +86,7 @@ func (repo *Pebble) DropChanges(name []byte, finalHeight int32) error {
return errors.Wrapf(err, "in load changes for %s", name)
}
i := 0
for ; i < len(changes); i++ {
for ; i < len(changes); i++ { // assuming changes are ordered by height
if changes[i].Height > finalHeight {
break
}

View file

@ -10,6 +10,7 @@
set -ex
env GORACE="halt_on_error=1" go test -race -tags="rpctest" -covermode atomic -coverprofile=profile.cov ./...
go test -bench=. -benchtime=4000x ./claimtrie/
# Automatic checks
golangci-lint run --deadline=10m --disable-all \