From 67848302462651515c99e7ae1c66a008fc26ec49 Mon Sep 17 00:00:00 2001 From: Brannon King Date: Wed, 29 Dec 2021 21:30:44 -0800 Subject: [PATCH] [lbry] blockchain: clear statusValid upon statusValidateFailed is set The status management of index does need some refactoring. For now, we just manually clear the statusValid in every occurance of statusValidateFailed being set. Co-authored-by: Roy Lee --- blockchain/chain.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/blockchain/chain.go b/blockchain/chain.go index 4da5fbc1..9a6ec216 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -1004,6 +1004,7 @@ func (b *BlockChain) reorganizeChain(detachNodes, attachNodes *list.List) error err = b.checkConnectBlock(n, block, view, nil) if err != nil { if _, ok := err.(RuleError); ok { + b.index.UnsetStatusFlags(n, statusValid) b.index.SetStatusFlags(n, statusValidateFailed) for de := e.Next(); de != nil; de = de.Next() { dn := de.Value.(*blockNode) @@ -1141,6 +1142,7 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fla if err == nil { b.index.SetStatusFlags(node, statusValid) } else if _, ok := err.(RuleError); ok { + b.index.UnsetStatusFlags(node, statusValid) b.index.SetStatusFlags(node, statusValidateFailed) } else { return false, err @@ -1175,6 +1177,7 @@ func (b *BlockChain) connectBestChain(node *blockNode, block *btcutil.Block, fla // that status of the block as invalid and flush the // index state to disk before returning with the error. if _, ok := err.(RuleError); ok { + b.index.UnsetStatusFlags(node, statusValid) b.index.SetStatusFlags( node, statusValidateFailed, ) @@ -1720,7 +1723,7 @@ func (b *BlockChain) reconsiderBlock(hash *chainhash.Hash) error { } // No need to reconsider, it is already valid. - if node.status.KnownValid() { + if node.status.KnownValid() && !node.status.KnownInvalid() { // second clause works around old bug err := fmt.Errorf("block %s is already valid", hash) return err }