mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 14:35:53 +00:00
check if blocks exist
This commit is contained in:
parent
ea285755d4
commit
08b6dc74eb
@ -46,7 +46,31 @@ func (flow *handleRequestHeadersFlow) start() error {
|
|||||||
}
|
}
|
||||||
log.Debugf("Received requestHeaders with lowHash: %s, highHash: %s", lowHash, highHash)
|
log.Debugf("Received requestHeaders with lowHash: %s, highHash: %s", lowHash, highHash)
|
||||||
|
|
||||||
isLowSelectedAncestorOfHigh, err := flow.Domain().Consensus().IsInSelectedParentChainOf(lowHash, highHash)
|
consensus := flow.Domain().Consensus()
|
||||||
|
|
||||||
|
lowHashInfo, err := consensus.GetBlockInfo(lowHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !lowHashInfo.Exists {
|
||||||
|
return protocolerrors.Errorf(true, "Block %s does not exist", lowHash)
|
||||||
|
}
|
||||||
|
if lowHashInfo.BlockStatus == externalapi.StatusInvalid {
|
||||||
|
return protocolerrors.Errorf(true, "Block %s is invalid", lowHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
highHashInfo, err := consensus.GetBlockInfo(highHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !highHashInfo.Exists {
|
||||||
|
return protocolerrors.Errorf(true, "Block %s does not exist", highHash)
|
||||||
|
}
|
||||||
|
if highHashInfo.BlockStatus == externalapi.StatusInvalid {
|
||||||
|
return protocolerrors.Errorf(true, "Block %s is invalid", highHash)
|
||||||
|
}
|
||||||
|
|
||||||
|
isLowSelectedAncestorOfHigh, err := consensus.IsInSelectedParentChainOf(lowHash, highHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -62,7 +86,7 @@ func (flow *handleRequestHeadersFlow) start() error {
|
|||||||
// in order to avoid locking the consensus for too long
|
// in order to avoid locking the consensus for too long
|
||||||
// maxBlocks MUST be >= MergeSetSizeLimit + 1
|
// maxBlocks MUST be >= MergeSetSizeLimit + 1
|
||||||
const maxBlocks = 1 << 10
|
const maxBlocks = 1 << 10
|
||||||
blockHashes, _, err := flow.Domain().Consensus().GetHashesBetween(lowHash, highHash, maxBlocks)
|
blockHashes, _, err := consensus.GetHashesBetween(lowHash, highHash, maxBlocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -70,7 +94,7 @@ func (flow *handleRequestHeadersFlow) start() error {
|
|||||||
|
|
||||||
blockHeaders := make([]*appmessage.MsgBlockHeader, len(blockHashes))
|
blockHeaders := make([]*appmessage.MsgBlockHeader, len(blockHashes))
|
||||||
for i, blockHash := range blockHashes {
|
for i, blockHash := range blockHashes {
|
||||||
blockHeader, err := flow.Domain().Consensus().GetBlockHeader(blockHash)
|
blockHeader, err := consensus.GetBlockHeader(blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user