diff --git a/blockchain/chain.go b/blockchain/chain.go index 050e2c4a..c05ae1df 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -248,6 +248,11 @@ type BlockChain struct { // spendPruner prunes spend journal data for disconnected blocks // if there are no consumers left for it. spendPruner *spendpruner.SpendJournalPruner + + // bulkImportMode provides a mechanism to indicate that several validation + // checks can be avoided when bulk importing blocks already known to be valid. + // It is protected by the chain lock. + bulkImportMode bool } const ( @@ -374,6 +379,18 @@ func (p *prevScriptsSnapshot) PrevScript(prevOut *wire.OutPoint) (uint16, []byte return entry.scriptVersion, entry.pkScript, true } +// EnableBulkImportMode provides a mechanism to indicate that several validation +// checks can be avoided when bulk importing blocks already known to be valid. +// This must NOT be enabled in any other circumstance where blocks need to be +// fully validated. +// +// This function is safe for concurrent access. +func (b *BlockChain) EnableBulkImportMode(bulkImportMode bool) { + b.chainLock.Lock() + b.bulkImportMode = bulkImportMode + b.chainLock.Unlock() +} + // GetVoteInfo returns information on consensus deployment agendas and their // respective states at the provided hash, for the provided deployment version. func (b *BlockChain) GetVoteInfo(hash *chainhash.Hash, version uint32) (*VoteInfo, error) { diff --git a/blockchain/process.go b/blockchain/process.go index 0da5aab7..00c763d3 100644 --- a/blockchain/process.go +++ b/blockchain/process.go @@ -436,7 +436,9 @@ func (b *BlockChain) ProcessBlock(block *dcrutil.Block, flags BehaviorFlags) (in // this package and then the ability to specify the fast add flag should be // removed along with the fast add portion of this check here so that it is // solely determined internally. - if flags&BFFastAdd == BFFastAdd || b.isKnownCheckpointAncestor(node) { + if flags&BFFastAdd == BFFastAdd || b.bulkImportMode || + b.isKnownCheckpointAncestor(node) { + b.index.SetStatusFlags(node, statusValidated) flags |= BFFastAdd }