mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-08 23:26:42 +00:00
Compare blue score with selected tip when checking if a pruning point… (#2169)
* Compare blue score with selected tip when checking if a pruning point proof is needed * Don't redeclare err Co-authored-by: Michael Sutton <mikisiton2@gmail.com>
This commit is contained in:
parent
09d698dd0e
commit
9fbfba17b6
@ -1,6 +1,7 @@
|
|||||||
package blockrelay
|
package blockrelay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/kaspanet/kaspad/app/appmessage"
|
"github.com/kaspanet/kaspad/app/appmessage"
|
||||||
"github.com/kaspanet/kaspad/app/protocol/common"
|
"github.com/kaspanet/kaspad/app/protocol/common"
|
||||||
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
peerpkg "github.com/kaspanet/kaspad/app/protocol/peer"
|
||||||
@ -70,16 +71,17 @@ func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
isFinishedSuccessfully := false
|
isFinishedSuccessfully := false
|
||||||
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
flow.UnsetIBDRunning()
|
flow.UnsetIBDRunning()
|
||||||
flow.logIBDFinished(isFinishedSuccessfully)
|
flow.logIBDFinished(isFinishedSuccessfully, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
relayBlockHash := consensushashing.BlockHash(block)
|
relayBlockHash := consensushashing.BlockHash(block)
|
||||||
|
|
||||||
log.Debugf("IBD started with peer %s and relayBlockHash %s", flow.peer, relayBlockHash)
|
log.Infof("IBD started with peer %s and relayBlockHash %s", flow.peer, relayBlockHash)
|
||||||
log.Debugf("Syncing blocks up to %s", relayBlockHash)
|
log.Infof("Syncing blocks up to %s", relayBlockHash)
|
||||||
log.Debugf("Trying to find highest known syncer chain block from peer %s with relay hash %s", flow.peer, relayBlockHash)
|
log.Infof("Trying to find highest known syncer chain block from peer %s with relay hash %s", flow.peer, relayBlockHash)
|
||||||
|
|
||||||
syncerHeaderSelectedTipHash, highestKnownSyncerChainHash, err := flow.negotiateMissingSyncerChainSegment()
|
syncerHeaderSelectedTipHash, highestKnownSyncerChainHash, err := flow.negotiateMissingSyncerChainSegment()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -98,7 +100,7 @@ func (flow *handleIBDFlow) runIBDIfNotRunning(block *externalapi.DomainBlock) er
|
|||||||
|
|
||||||
if shouldDownloadHeadersProof {
|
if shouldDownloadHeadersProof {
|
||||||
log.Infof("Starting IBD with headers proof")
|
log.Infof("Starting IBD with headers proof")
|
||||||
err := flow.ibdWithHeadersProof(syncerHeaderSelectedTipHash, relayBlockHash, block.Header.DAAScore())
|
err = flow.ibdWithHeadersProof(syncerHeaderSelectedTipHash, relayBlockHash, block.Header.DAAScore())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -265,7 +267,7 @@ func (flow *handleIBDFlow) negotiateMissingSyncerChainSegment() (*externalapi.Do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Found highest known syncer chain block %s from peer %s",
|
log.Infof("Found highest known syncer chain block %s from peer %s",
|
||||||
highestKnownSyncerChainHash, flow.peer)
|
highestKnownSyncerChainHash, flow.peer)
|
||||||
|
|
||||||
return syncerHeaderSelectedTipHash, highestKnownSyncerChainHash, nil
|
return syncerHeaderSelectedTipHash, highestKnownSyncerChainHash, nil
|
||||||
@ -280,10 +282,10 @@ func (flow *handleIBDFlow) isGenesisVirtualSelectedParent() (bool, error) {
|
|||||||
return virtualSelectedParent.Equal(flow.Config().NetParams().GenesisHash), nil
|
return virtualSelectedParent.Equal(flow.Config().NetParams().GenesisHash), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleIBDFlow) logIBDFinished(isFinishedSuccessfully bool) {
|
func (flow *handleIBDFlow) logIBDFinished(isFinishedSuccessfully bool, err error) {
|
||||||
successString := "successfully"
|
successString := "successfully"
|
||||||
if !isFinishedSuccessfully {
|
if !isFinishedSuccessfully {
|
||||||
successString = "(interrupted)"
|
successString = fmt.Sprintf("(interrupted: %s)", err)
|
||||||
}
|
}
|
||||||
log.Infof("IBD with peer %s finished %s", flow.peer, successString)
|
log.Infof("IBD with peer %s finished %s", flow.peer, successString)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,12 @@ func (flow *handleIBDFlow) shouldSyncAndShouldDownloadHeadersProof(
|
|||||||
|
|
||||||
var highestSharedBlockFound, isPruningPointInSharedBlockChain bool
|
var highestSharedBlockFound, isPruningPointInSharedBlockChain bool
|
||||||
if highestKnownSyncerChainHash != nil {
|
if highestKnownSyncerChainHash != nil {
|
||||||
highestSharedBlockFound = true
|
blockInfo, err := flow.Domain().Consensus().GetBlockInfo(highestKnownSyncerChainHash)
|
||||||
|
if err != nil {
|
||||||
|
return false, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
highestSharedBlockFound = blockInfo.HasBody()
|
||||||
pruningPoint, err := flow.Domain().Consensus().PruningPoint()
|
pruningPoint, err := flow.Domain().Consensus().PruningPoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, false, err
|
return false, false, err
|
||||||
@ -87,21 +92,21 @@ func (flow *handleIBDFlow) shouldSyncAndShouldDownloadHeadersProof(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleIBDFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(relayBlock *externalapi.DomainBlock) (bool, error) {
|
func (flow *handleIBDFlow) checkIfHighHashHasMoreBlueWorkThanSelectedTipAndPruningDepthMoreBlueScore(relayBlock *externalapi.DomainBlock) (bool, error) {
|
||||||
headersSelectedTip, err := flow.Domain().Consensus().GetHeadersSelectedTip()
|
virtualSelectedParent, err := flow.Domain().Consensus().GetVirtualSelectedParent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
headersSelectedTipInfo, err := flow.Domain().Consensus().GetBlockInfo(headersSelectedTip)
|
virtualSelectedTipInfo, err := flow.Domain().Consensus().GetBlockInfo(virtualSelectedParent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if relayBlock.Header.BlueScore() < headersSelectedTipInfo.BlueScore+flow.Config().NetParams().PruningDepth() {
|
if relayBlock.Header.BlueScore() < virtualSelectedTipInfo.BlueScore+flow.Config().NetParams().PruningDepth() {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return relayBlock.Header.BlueWork().Cmp(headersSelectedTipInfo.BlueWork) > 0, nil
|
return relayBlock.Header.BlueWork().Cmp(virtualSelectedTipInfo.BlueWork) > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (flow *handleIBDFlow) syncAndValidatePruningPointProof() (*externalapi.DomainHash, error) {
|
func (flow *handleIBDFlow) syncAndValidatePruningPointProof() (*externalapi.DomainHash, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user