From 26c7db251f6a3f4b0acb4f6454e3e6472cfeb5a0 Mon Sep 17 00:00:00 2001 From: Ori Newman Date: Thu, 13 Oct 2022 19:22:00 +0300 Subject: [PATCH] Make more checks if status is invalid even if the block exists (#2158) * Make more checks if status is invalid even if the block exists * Use HasHeader --- 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 f8130f33ba..5e1e5a13d0 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 444de710c9..eb45fab01a 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.HasHeader() { 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 a615869f6b..518d7d608d 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 }