-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update #264 - updates genesis and genesis tests #382
Changes from 1 commit
ba651e3
a87495d
e3919b5
3dcd610
a815a15
b25f968
4a06760
7b48c09
1378a52
c3cfeb4
0e548e4
9a70d95
524a0aa
2a670e0
65dc723
c711ecb
a4e83d8
ecb643a
06b5df5
4ec85d5
8017c29
d62dc16
f1a415e
9ea6c5a
5f03831
03c643c
eb59e50
de20341
c856708
d3b5bef
c292da4
74aa7e9
19e4b93
0599369
de4a73e
30b141c
0399487
255c96d
1d06cd7
26ec9e8
ebd590b
d0d5db1
4aca97e
fd9dc10
50ae321
af1aebb
6d93504
504c44c
aff5156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ func NewRestartGenesisState(clientID, channelID string, | |
HeightToValsetUpdateId: heightToValsetUpdateIDs, | ||
PendingSlashRequests: pendingSlashRequests, | ||
OutstandingDowntimeSlashing: outstandingDowntimes, | ||
LastTransmissionBlockHeight: lastTransBlockHeight, | ||
} | ||
} | ||
|
||
|
@@ -109,6 +110,19 @@ func (gs GenesisState) Validate() error { | |
if gs.ProviderClientId == "" { | ||
return sdkerrors.Wrap(ccv.ErrInvalidGenesis, "provider client id must be set for a restarting consumer genesis state") | ||
} | ||
// handshake is still in progress | ||
if gs.ProviderChannelId == "" && (len(gs.MaturingPackets) != 0 || len(gs.OutstandingDowntimeSlashing) != 0 || gs.LastTransmissionBlockHeight.Height != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: could we extract a variable |
||
return sdkerrors.Wrap( | ||
ccv.ErrInvalidGenesis, | ||
"maturing packets, outstanding downtime slashing and last transmission block height must be empty when handshake isn't completed", | ||
) | ||
} | ||
if gs.HeightToValsetUpdateId == nil { | ||
return sdkerrors.Wrap( | ||
ccv.ErrInvalidGenesis, | ||
"empty height to validator set update id mapping", | ||
) | ||
} | ||
if gs.ProviderClientState != nil || gs.ProviderConsensusState != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is a restart of a running chain where the handshake did not complete, then how is it ever going to get restarted? |
||
return sdkerrors.Wrap(ccv.ErrInvalidGenesis, "provider client state and consensus states must be nil for a restarting genesis state") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,11 +157,19 @@ func TestValidateInitialGenesisState(t *testing.T) { | |
types.NewInitialGenesisState(cs, consensusState, nil, params), | ||
true, | ||
}, | ||
{ | ||
"invalid new consumer genesis state: invalid consensus state validator set hash", | ||
types.NewInitialGenesisState( | ||
cs, ibctmtypes.NewConsensusState( | ||
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("wrong_length_hash")), | ||
valUpdates, params), | ||
true, | ||
}, | ||
{ | ||
"invalid new consumer genesis state: initial validator set does not match validator set hash", | ||
types.NewInitialGenesisState( | ||
cs, ibctmtypes.NewConsensusState( | ||
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("wrong_hash")), | ||
time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), []byte("9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), | ||
valUpdates, params), | ||
true, | ||
}, | ||
|
@@ -206,6 +214,11 @@ func TestValidateRestartGenesisState(t *testing.T) { | |
valHash := valSet.Hash() | ||
valUpdates := tmtypes.TM2PB.ValidatorUpdates(valSet) | ||
|
||
// create default height to validator set update id mapping | ||
heightToValsetUpdateID := []types.HeightToValsetUpdateID{ | ||
{Height: 0, ValsetUpdateId: 0}, | ||
} | ||
|
||
cs := ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) | ||
consensusState := ibctmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), valHash[:]) | ||
|
||
|
@@ -219,7 +232,7 @@ func TestValidateRestartGenesisState(t *testing.T) { | |
}{ | ||
{ | ||
"valid restart consumer genesis state: empty maturing packets", | ||
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, valUpdates, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
false, | ||
}, | ||
{ | ||
|
@@ -228,12 +241,12 @@ func TestValidateRestartGenesisState(t *testing.T) { | |
{1, uint64(time.Now().UnixNano())}, | ||
{3, uint64(time.Now().UnixNano())}, | ||
{5, uint64(time.Now().UnixNano())}, | ||
}, valUpdates, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
}, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
false, | ||
}, | ||
{ | ||
"invalid restart consumer genesis state: channel id is empty", | ||
types.NewRestartGenesisState("", "ccvchannel", nil, valUpdates, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
"invalid restart consumer genesis state: provider id is empty", | ||
types.NewRestartGenesisState("", "ccvchannel", nil, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
true, | ||
}, | ||
{ | ||
|
@@ -291,6 +304,30 @@ func TestValidateRestartGenesisState(t *testing.T) { | |
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, nil, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
true, | ||
}, | ||
{ | ||
"invalid restart consumer genesis state: nil height to validator set id mapping", | ||
types.NewRestartGenesisState("ccvclient", "", | ||
[]types.MaturingVSCPacket{{1, 0}}, valUpdates, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
true, | ||
}, { | ||
"invalid restart consumer genesis state: maturing packet defined when handshake is still in progress", | ||
types.NewRestartGenesisState("ccvclient", "", | ||
[]types.MaturingVSCPacket{{1, 0}}, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, params), | ||
true, | ||
}, | ||
{ | ||
"invalid restart consumer genesis state: outstanding downtime defined when handshake is still in progress", | ||
types.NewRestartGenesisState("ccvclient", "", | ||
nil, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, []types.OutstandingDowntime{{ValidatorConsensusAddress: "cosmosvalconsxxx"}}, | ||
types.LastTransmissionBlockHeight{}, params), | ||
true, | ||
}, | ||
{ | ||
"invalid restart consumer genesis state: last transmission block height defined when handshake is still in progress", | ||
types.NewRestartGenesisState("ccvclient", "", | ||
nil, valUpdates, heightToValsetUpdateID, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{Height: int64(1)}, params), | ||
true, | ||
}, | ||
{ | ||
"invalid restart consumer genesis state: invalid params", | ||
types.NewRestartGenesisState("ccvclient", "ccvchannel", nil, valUpdates, nil, types.SlashRequests{}, nil, types.LastTransmissionBlockHeight{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you doing enough testing of the restart genesis state where the handshake hasn't completed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. These genesis validation tests need some adjustments as well. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto: #459