blockchain: Add bulk import mode.
This adds a bulk import mode that provides a mechanism to indicate that several validation checks can be avoided when bulk importing blocks already known to be valid. It will be used by the block importer in a subsequent commit. This provides an alternative mechanism to the current solution of passing a BehaviorFlags parameter around, which is inconvenient and makes it harder to determine where flags are being set.
This commit is contained in:
parent
03ddfd45ab
commit
c3e1031717
@ -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) {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user