From 6bc7a4eb854e7ea2fef721fdcae8c361db581afe Mon Sep 17 00:00:00 2001 From: Svarog Date: Sun, 7 Feb 2021 16:12:15 +0200 Subject: [PATCH] Allow GetMissingBlockBodyHashes return an empty list if the missing blocks were requested before IBD start (#1498) * Allow GetMissingBlockBodyHashes return an empty list if the missing blocks were requested before IBD start * Add link to issue in comment about error to be fixed --- app/protocol/flows/blockrelay/ibd.go | 7 +++++++ .../consensusstatemanager/import_pruning_utxo_set.go | 2 +- domain/consensus/processes/syncmanager/antipast.go | 10 ++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/protocol/flows/blockrelay/ibd.go b/app/protocol/flows/blockrelay/ibd.go index b0d937b0a..54e65ed46 100644 --- a/app/protocol/flows/blockrelay/ibd.go +++ b/app/protocol/flows/blockrelay/ibd.go @@ -468,6 +468,13 @@ func (flow *handleRelayInvsFlow) syncMissingBlockBodies(highHash *externalapi.Do if err != nil { return err } + if len(hashes) == 0 { + // Blocks can be inserted inside the DAG during IBD if those were requested before IBD started. + // In rare cases, all the IBD blocks might be already inserted by the time we reach this point. + // In these cases - GetMissingBlockBodyHashes would return an empty array. + log.Debugf("No missing block body hashes found.") + return nil + } for offset := 0; offset < len(hashes); offset += ibdBatchSize { var hashesToRequest []*externalapi.DomainHash diff --git a/domain/consensus/processes/consensusstatemanager/import_pruning_utxo_set.go b/domain/consensus/processes/consensusstatemanager/import_pruning_utxo_set.go index f69387f13..81e9d4a7e 100644 --- a/domain/consensus/processes/consensusstatemanager/import_pruning_utxo_set.go +++ b/domain/consensus/processes/consensusstatemanager/import_pruning_utxo_set.go @@ -86,7 +86,7 @@ func (csm *consensusStateManager) importPruningPoint(newPruningPoint *externalap return err } - log.Debugf("Staging the new pruning point") + log.Debugf("Staging the new pruning point %s", newPruningPointHash) csm.pruningStore.StagePruningPoint(newPruningPointHash) log.Debugf("Populating the pruning point with UTXO entries") diff --git a/domain/consensus/processes/syncmanager/antipast.go b/domain/consensus/processes/syncmanager/antipast.go index 44c85968e..82c9b1744 100644 --- a/domain/consensus/processes/syncmanager/antipast.go +++ b/domain/consensus/processes/syncmanager/antipast.go @@ -126,8 +126,14 @@ func (sm *syncManager) missingBlockBodyHashes(highHash *externalapi.DomainHash) lowHash = selectedChild } if !foundHeaderOnlyBlock { - // TODO: Once block children are fixed, this error - // should be returned instead of simply logged + if lowHash == highHash { + // Blocks can be inserted inside the DAG during IBD if those were requested before IBD started. + // In rare cases, all the IBD blocks might be already inserted by the time we reach this point. + // In these cases - return an empty list of blocks to sync + return []*externalapi.DomainHash{}, nil + } + // TODO: Once block children are fixed (https://github.com/kaspanet/kaspad/issues/1499), + // this error should be returned rather the logged log.Errorf("no header-only blocks between %s and %s", lowHash, highHash) }