From 1ae3863e435a2a8b5f75885cc4afce7054d44829 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Thu, 13 Oct 2022 16:32:57 +0300 Subject: [PATCH] Make more checks if status is invalid even if the block exists --- app/protocol/flows/v5/blockrelay/ibd.go | 4 ++++ app/rpc/rpchandlers/get_blocks.go | 2 +- domain/consensus/consensus.go | 10 +++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/protocol/flows/v5/blockrelay/ibd.go b/app/protocol/flows/v5/blockrelay/ibd.go index f8130f33b..5e1e5a13d 100644 --- a/app/protocol/flows/v5/blockrelay/ibd.go +++ b/app/protocol/flows/v5/blockrelay/ibd.go @@ -181,6 +181,10 @@ func (flow *handleIBDFlow) negotiateMissingSyncerChainSegment() (*externalapi.Do return nil, nil, err } if info.Exists { + if info.BlockStatus == externalapi.StatusInvalid { + return nil, nil, protocolerrors.Errorf(true, "Sent invalid chain block %s", syncerChainHash) + } + currentHighestKnownSyncerChainHash = syncerChainHash break } diff --git a/app/rpc/rpchandlers/get_blocks.go b/app/rpc/rpchandlers/get_blocks.go index 444de710c..2bb8b0834 100644 --- a/app/rpc/rpchandlers/get_blocks.go +++ b/app/rpc/rpchandlers/get_blocks.go @@ -37,7 +37,7 @@ func HandleGetBlocks(context *rpccontext.Context, _ *router.Router, request appm return nil, err } - if !blockInfo.Exists { + if !blockInfo.Exists || blockInfo.BlockStatus == externalapi.StatusInvalid { return &appmessage.GetBlocksResponseMessage{ Error: appmessage.RPCErrorf("Could not find lowHash %s", getBlocksRequest.LowHash), }, nil diff --git a/domain/consensus/consensus.go b/domain/consensus/consensus.go index a615869f6..518d7d608 100644 --- a/domain/consensus/consensus.go +++ b/domain/consensus/consensus.go @@ -853,12 +853,16 @@ func (s *consensus) GetVirtualSelectedParentChainFromBlock(blockHash *externalap } func (s *consensus) validateBlockHashExists(stagingArea *model.StagingArea, blockHash *externalapi.DomainHash) error { - exists, err := s.blockStatusStore.Exists(s.databaseContext, stagingArea, blockHash) + status, err := s.blockStatusStore.Get(s.databaseContext, stagingArea, blockHash) + if database.IsNotFoundError(err) { + return errors.Errorf("block %s does not exist", blockHash) + } if err != nil { return err } - if !exists { - return errors.Errorf("block %s does not exist", blockHash) + + if status == externalapi.StatusInvalid { + return errors.Errorf("block %s is invalid", blockHash) } return nil }