rollback on hash mismatch
This commit is contained in:
parent
9c9bd3e3a5
commit
1834d95b43
2 changed files with 8 additions and 9 deletions
blockchain
|
@ -586,7 +586,7 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
|
||||||
|
|
||||||
// Handle LBRY Claim Scripts
|
// Handle LBRY Claim Scripts
|
||||||
if b.claimTrie != nil {
|
if b.claimTrie != nil {
|
||||||
if err := b.ParseClaimScripts(block, node, view, false, current); err != nil {
|
if err := b.ParseClaimScripts(block, node, view, current); err != nil {
|
||||||
return ruleError(ErrBadClaimTrie, err.Error())
|
return ruleError(ErrBadClaimTrie, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1881,7 +1881,7 @@ func rebuildMissingClaimTrieData(b *BlockChain, done <-chan struct{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if h >= b.claimTrie.Height() {
|
if h >= b.claimTrie.Height() {
|
||||||
err = b.ParseClaimScripts(block, n, view, true, false)
|
err = b.ParseClaimScripts(block, n, view, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (b *BlockChain) SetClaimtrieHeader(block *btcutil.Block, view *UtxoViewpoin
|
||||||
b.chainLock.Lock()
|
b.chainLock.Lock()
|
||||||
defer b.chainLock.Unlock()
|
defer b.chainLock.Unlock()
|
||||||
|
|
||||||
err := b.ParseClaimScripts(block, nil, view, false, false)
|
err := b.ParseClaimScripts(block, nil, view, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "in parse claim scripts")
|
return errors.Wrapf(err, "in parse claim scripts")
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,7 @@ func (b *BlockChain) SetClaimtrieHeader(block *btcutil.Block, view *UtxoViewpoin
|
||||||
return errors.Wrapf(err, "in reset height")
|
return errors.Wrapf(err, "in reset height")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockChain) ParseClaimScripts(block *btcutil.Block, bn *blockNode, view *UtxoViewpoint,
|
func (b *BlockChain) ParseClaimScripts(block *btcutil.Block, bn *blockNode, view *UtxoViewpoint, shouldFlush bool) error {
|
||||||
failOnHashMiss bool, shouldFlush bool) error {
|
|
||||||
ht := block.Height()
|
ht := block.Height()
|
||||||
|
|
||||||
for _, tx := range block.Transactions() {
|
for _, tx := range block.Transactions() {
|
||||||
|
@ -56,10 +55,10 @@ func (b *BlockChain) ParseClaimScripts(block *btcutil.Block, bn *blockNode, view
|
||||||
|
|
||||||
hash := b.claimTrie.MerkleHash()
|
hash := b.claimTrie.MerkleHash()
|
||||||
if bn != nil && bn.claimTrie != *hash {
|
if bn != nil && bn.claimTrie != *hash {
|
||||||
if failOnHashMiss {
|
// undo our AppendBlock call as we've decided that our interpretation of the block data is incorrect,
|
||||||
return errors.Errorf("height: %d, ct.MerkleHash: %s != node.ClaimTrie: %s", ht, *hash, bn.claimTrie)
|
// or that the person who made the block assembled the pieces incorrectly.
|
||||||
}
|
_ = b.claimTrie.ResetHeight(b.claimTrie.Height() - 1)
|
||||||
node.LogOnce(fmt.Sprintf("\n\nHeight: %d, ct.MerkleHash: %s != node.ClaimTrie: %s, Error: %s", ht, *hash, bn.claimTrie, err))
|
return errors.Errorf("height: %d, computed hash: %s != header's ClaimTrie: %s", ht, *hash, bn.claimTrie)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue