Add solo machine timestamp check (#7392)
* add check in header updates for non decreasing timestamp Add check in update.go that the header timestamp is non decreasing compared to the consensus state timestamp. Unit test added in update_test.go * update error message * update godoc Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
0ddb2bd74f
commit
2a4d0ec62c
@ -11,6 +11,8 @@ import (
|
||||
// CheckHeaderAndUpdateState checks if the provided header is valid and updates
|
||||
// the consensus state if appropriate. It returns an error if:
|
||||
// - the client or header provided are not parseable to solo machine types
|
||||
// - the header sequence does not match the current sequence
|
||||
// - the header timestamp is less than the consensus state timestamp
|
||||
// - the currently registered public key did not provide the update signature
|
||||
func (cs ClientState) CheckHeaderAndUpdateState(
|
||||
ctx sdk.Context, cdc codec.BinaryMarshaler, clientStore sdk.KVStore,
|
||||
@ -37,7 +39,15 @@ func checkHeader(cdc codec.BinaryMarshaler, clientState *ClientState, header *He
|
||||
if header.Sequence != clientState.Sequence {
|
||||
return sdkerrors.Wrapf(
|
||||
clienttypes.ErrInvalidHeader,
|
||||
"sequence provided in the header does not match the client state sequence (%d != %d)", header.Sequence, clientState.Sequence,
|
||||
"header sequence does not match the client state sequence (%d != %d)", header.Sequence, clientState.Sequence,
|
||||
)
|
||||
}
|
||||
|
||||
// assert update timestamp is not less than current consensus state timestamp
|
||||
if header.Timestamp < clientState.ConsensusState.Timestamp {
|
||||
return sdkerrors.Wrapf(
|
||||
clienttypes.ErrInvalidHeader,
|
||||
"header timestamp is less than to the consensus state timestamp (%d < %d)", header.Timestamp, clientState.ConsensusState.Timestamp,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,15 @@ func (suite *SoloMachineTestSuite) TestCheckHeaderAndUpdateState() {
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"invalid timestamp in header",
|
||||
func() {
|
||||
clientState = suite.solomachine.ClientState()
|
||||
h := suite.solomachine.CreateHeader()
|
||||
h.Timestamp--
|
||||
header = h
|
||||
}, false,
|
||||
},
|
||||
{
|
||||
"signature uses wrong sequence",
|
||||
func() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user