Skip to content

Commit

Permalink
block header tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Apr 8, 2024
1 parent ce33465 commit 599dac2
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 821 deletions.
13 changes: 8 additions & 5 deletions x/lightclient/keeper/block_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ func (k Keeper) CheckNewBlockHeader(
// validate block height as it's not part of the header itself
chainState, found := k.GetChainState(ctx, chainID)
if found && chainState.EarliestHeight > 0 && chainState.EarliestHeight < height {
_, found = k.GetBlockHeader(ctx, parentHash)
if !found {
return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found")
}
if height != chainState.LatestHeight+1 {
return nil, cosmoserrors.Wrap(types.ErrNoParentHash, fmt.Sprintf(
return nil, cosmoserrors.Wrap(types.ErrInvalidHeight, fmt.Sprintf(
"invalid block height: wanted %d, got %d",
chainState.LatestHeight+1,
height,
))
}
_, found = k.GetBlockHeader(ctx, parentHash)
if !found {
return nil, cosmoserrors.Wrap(types.ErrNoParentHash, "parent block header not found")
}
}

// Check timestamp
Expand Down Expand Up @@ -130,6 +130,9 @@ func (k Keeper) AddBlockHeader(
}
} else {
// update the chain state with the latest block header
// TODO: these checks would need to be more sophisticated for production
// We should investigate and implement the correct assumptions for adding new block header
// https://github.com/zeta-chain/node/issues/1997
if height > chainState.LatestHeight {
chainState.LatestHeight = height
chainState.LatestBlockHash = blockHash
Expand Down
Loading

0 comments on commit 599dac2

Please sign in to comment.