Skip to content

Commit

Permalink
Make more checks if status is invalid even if the block exists (#2158)
Browse files Browse the repository at this point in the history
* Make more checks if status is invalid even if the block exists

* Use HasHeader
  • Loading branch information
someone235 authored Oct 13, 2022
1 parent 4d435f2 commit 26c7db2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/protocol/flows/v5/blockrelay/ibd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion app/rpc/rpchandlers/get_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions domain/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 26c7db2

Please sign in to comment.