fixed bug with block rollback; re-orgs should work now
This commit is contained in:
parent
1834d95b43
commit
79987722bb
7 changed files with 16 additions and 13 deletions
|
@ -773,8 +773,10 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block *btcutil.Block, view
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = b.claimTrie.ResetHeight(node.parent.height); err != nil {
|
if b.claimTrie != nil {
|
||||||
return err
|
if err = b.claimTrie.ResetHeight(node.parent.height); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune fully spent entries and mark all entries in the view unmodified
|
// Prune fully spent entries and mark all entries in the view unmodified
|
||||||
|
|
|
@ -318,12 +318,13 @@ func (ct *ClaimTrie) ResetHeight(height int32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
passedHashFork := ct.height >= param.ActiveParams.AllClaimsInMerkleForkHeight && height < param.ActiveParams.AllClaimsInMerkleForkHeight
|
passedHashFork := ct.height >= param.ActiveParams.AllClaimsInMerkleForkHeight && height < param.ActiveParams.AllClaimsInMerkleForkHeight
|
||||||
ct.height = height
|
|
||||||
hash, err := ct.blockRepo.Get(height)
|
hash, err := ct.blockRepo.Get(height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ct.height = height // keep this before the rebuild
|
||||||
|
|
||||||
if passedHashFork {
|
if passedHashFork {
|
||||||
names = nil // force them to reconsider all names
|
names = nil // force them to reconsider all names
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,9 +338,14 @@ func BenchmarkClaimTrie_AppendBlock(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
ht := ct.height
|
ht := ct.height
|
||||||
h1 = *ct.MerkleHash()
|
h1 = *ct.MerkleHash()
|
||||||
ct.Close()
|
|
||||||
b.Logf("Running AppendBlock bench with %d names in %f sec. Height: %d, Hash: %s",
|
b.Logf("Running AppendBlock bench with %d names in %f sec. Height: %d, Hash: %s",
|
||||||
b.N, time.Since(start).Seconds(), ht, h1.String())
|
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 {
|
func randomName() []byte {
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestNilNameHandling(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCollapsedTriePerformance(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)
|
data := make([][]byte, inserts)
|
||||||
rand.Seed(42)
|
rand.Seed(42)
|
||||||
for i := 0; i < inserts; i++ {
|
for i := 0; i < inserts; i++ {
|
||||||
|
|
|
@ -42,13 +42,7 @@ func (rt *RamTrie) SetRoot(h *chainhash.Hash) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// should technically clear the old trie first:
|
// should technically clear the old trie first, but this is abused for partial rebuilds so don't
|
||||||
if rt.Nodes > 1 {
|
|
||||||
rt.Root = &collapsedVertex{key: make(KeyType, 0)}
|
|
||||||
rt.Nodes = 1
|
|
||||||
runtime.GC()
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrFullRebuildRequired
|
return ErrFullRebuildRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ func (repo *Pebble) DropChanges(name []byte, finalHeight int32) error {
|
||||||
return errors.Wrapf(err, "in load changes for %s", name)
|
return errors.Wrapf(err, "in load changes for %s", name)
|
||||||
}
|
}
|
||||||
i := 0
|
i := 0
|
||||||
for ; i < len(changes); i++ {
|
for ; i < len(changes); i++ { // assuming changes are ordered by height
|
||||||
if changes[i].Height > finalHeight {
|
if changes[i].Height > finalHeight {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
env GORACE="halt_on_error=1" go test -race -tags="rpctest" -covermode atomic -coverprofile=profile.cov ./...
|
env GORACE="halt_on_error=1" go test -race -tags="rpctest" -covermode atomic -coverprofile=profile.cov ./...
|
||||||
|
go test -bench=. -benchtime=4000x ./claimtrie/
|
||||||
|
|
||||||
# Automatic checks
|
# Automatic checks
|
||||||
golangci-lint run --deadline=10m --disable-all \
|
golangci-lint run --deadline=10m --disable-all \
|
||||||
|
|
Loading…
Reference in a new issue