[NOD-1527] Allow to process headers while in missing utxo set sync state (#1018)

* [NOD-1527] Allow to process headers while in missing utxo set sync state

* [NOD-1527] Add isHeaderOnlyBlock function
This commit is contained in:
Ori Newman 2020-11-10 04:43:18 -08:00 committed by GitHub
parent 32da4440ba
commit 31c5264430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,20 +15,25 @@ func (bp *blockProcessor) validateAndInsertBlock(block *externalapi.DomainBlock)
hash := consensusserialization.HeaderHash(block.Header)
if mode.State == externalapi.SyncStateMissingUTXOSet {
headerTipsPruningPoint, err := bp.consensusStateManager.HeaderTipsPruningPoint()
if err != nil {
return err
}
if isHeaderOnlyBlock(block) {
// Allow processing headers while in state SyncStateMissingUTXOSet
mode.State = externalapi.SyncStateHeadersFirst
} else {
headerTipsPruningPoint, err := bp.consensusStateManager.HeaderTipsPruningPoint()
if err != nil {
return err
}
if *hash != *headerTipsPruningPoint {
return errors.Errorf("cannot insert blocks other than the header pruning point "+
"while in %s mode", mode.State)
}
if *hash != *headerTipsPruningPoint {
return errors.Errorf("cannot insert blocks other than the header pruning point "+
"while in %s mode", mode.State)
}
mode.State = externalapi.SyncStateMissingBlockBodies
mode.State = externalapi.SyncStateMissingBlockBodies
}
}
if mode.State == externalapi.SyncStateHeadersFirst && len(block.Transactions) != 0 {
if mode.State == externalapi.SyncStateHeadersFirst && !isHeaderOnlyBlock(block) {
mode.State = externalapi.SyncStateNormal
log.Warnf("block %s contains transactions while validating in header only mode", hash)
}
@ -138,6 +143,10 @@ func (bp *blockProcessor) updateReachabilityReindexRoot(oldHeadersSelectedTip *e
return bp.reachabilityManager.UpdateReindexRoot(headersSelectedTip)
}
func isHeaderOnlyBlock(block *externalapi.DomainBlock) bool {
return len(block.Transactions) == 0
}
func (bp *blockProcessor) checkBlockStatus(hash *externalapi.DomainHash, mode *externalapi.SyncInfo) error {
exists, err := bp.blockStatusStore.Exists(bp.databaseContext, hash)
if err != nil {