Skip to content

Commit

Permalink
Check for ID and header before adding block
Browse files Browse the repository at this point in the history
  • Loading branch information
sgerbino committed Oct 26, 2022
1 parent 2ec7112 commit b2d92b4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/bstore/reqhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,19 @@ func getAncestorIDAtHeight(backend BlockStoreBackend, blockID []byte, height uin
func (handler *RequestHandler) AddBlock(req *block_store.AddBlockRequest) (*block_store.AddBlockResponse, error) {

if req.GetBlockToAdd() == nil {
return nil, errors.New("Cannot add empty optional block")
return nil, errors.New("cannot add empty optional block")
}

block := req.GetBlockToAdd()

if block.GetId() == nil {
return nil, errors.New("block id must not be nil")
}

if block.GetHeader() == nil {
return nil, errors.New("block header must not be nil")
}

record := block_store.BlockRecord{}

record.BlockId = block.GetId()
Expand All @@ -418,7 +427,7 @@ func (handler *RequestHandler) AddBlock(req *block_store.AddBlockRequest) (*bloc

record.Receipt = req.GetReceiptToAdd()

if block.Header.Height > 1 {
if block.GetHeader().GetHeight() > 1 {
previousHeights := getPreviousHeights(block.GetHeader().GetHeight())

record.PreviousBlockIds = make([][]byte, len(previousHeights))
Expand Down

0 comments on commit b2d92b4

Please sign in to comment.