Skip to content
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

Merged
merged 49 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ba651e3
reformat consumer genesis test
sainoe Jul 18, 2022
a87495d
remove validator fill in of ExportAppStateAndValidators
sainoe Jul 19, 2022
e3919b5
checkpoint, testing export genesis consumer
sainoe Jul 25, 2022
3dcd610
test consumer export
sainoe Jul 27, 2022
a815a15
make pass the tests
sainoe Jul 29, 2022
b25f968
fix export height to valset update id in consumer
sainoe Aug 2, 2022
4a06760
pass the tests
sainoe Aug 3, 2022
7b48c09
pass the tests
sainoe Aug 3, 2022
1378a52
* Update the provider and consumer export/init genesis with the new C…
sainoe Aug 11, 2022
c3cfeb4
remove pendingVSCPackets
sainoe Aug 12, 2022
0e548e4
remove references in create consumer chain proposal setters and getters
sainoe Aug 22, 2022
9a70d95
merge with remotes
sainoe Aug 22, 2022
524a0aa
fix unchecked errors
sainoe Aug 22, 2022
2a670e0
Merge branch 'main' into sainoe/export-genesis
sainoe Sep 29, 2022
65dc723
fix iterator bug
sainoe Sep 29, 2022
c711ecb
fix last nits
sainoe Sep 29, 2022
a4e83d8
Merge remote-tracking branch 'upstream/main' into sainoe/export-genesis
sainoe Sep 29, 2022
ecb643a
fix linter
sainoe Sep 30, 2022
06b5df5
Fix conflicts and make pass the tests
sainoe Oct 3, 2022
4ec85d5
format provider genesis tests
sainoe Oct 3, 2022
8017c29
format consumer genesis tests
sainoe Oct 3, 2022
d62dc16
Merge branch 'main' into sainoe/export-genesis
jtremback Oct 4, 2022
f1a415e
clarify consumer keeper genesis
sainoe Oct 6, 2022
9ea6c5a
push missing merge commit
sainoe Oct 6, 2022
5f03831
remove unused test helpers
sainoe Oct 7, 2022
03c643c
Merge branch 'main' into sainoe/export-genesis-2
shaspitz Oct 7, 2022
eb59e50
Feat: update consumer init and export genesis
sainoe Nov 9, 2022
de20341
Revert "Feat: update consumer init and export genesis"
sainoe Nov 9, 2022
c856708
merge main
sainoe Nov 9, 2022
d3b5bef
* Add LastTransmissionBlockHeight to consumer genesis proto
sainoe Nov 7, 2022
c292da4
Update consumer init
sainoe Nov 9, 2022
74aa7e9
Update consumer genesis export
sainoe Nov 9, 2022
19e4b93
fix last nits
sainoe Nov 9, 2022
0599369
Fix consumer InitGenesis
sainoe Nov 10, 2022
de4a73e
Update comments in genesis.proto
sainoe Nov 10, 2022
30b141c
format consumer genesis test
sainoe Nov 10, 2022
0399487
update comments
sainoe Nov 10, 2022
255c96d
Update provider genesis comments
sainoe Nov 14, 2022
1d06cd7
fix small lint errs
shaspitz Nov 14, 2022
26ec9e8
Merge branch 'main' into sainoe/export-genesis-2
shaspitz Nov 14, 2022
ebd590b
Merge branch 'main' into sainoe/export-genesis-2
shaspitz Nov 15, 2022
d0d5db1
* Update consumer genesis validation
sainoe Nov 15, 2022
4aca97e
Document consumer genesis validation
sainoe Nov 17, 2022
fd9dc10
Document consumer genesis validation
sainoe Nov 17, 2022
50ae321
Merge branch 'main' into sainoe/export-genesis-2
sainoe Nov 18, 2022
af1aebb
Update after #448 merge
sainoe Nov 18, 2022
6d93504
Merge branch 'sainoe/export-genesis-2' into export-2-upstream
sainoe Nov 18, 2022
504c44c
Merge branch 'main' into sainoe/export-genesis-2
shaspitz Nov 18, 2022
aff5156
Update x/ccv/consumer/types/genesis.go
jtremback Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
"github.com/cosmos/interchain-security/x/ccv/consumer/types"
consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types"
ccv "github.com/cosmos/interchain-security/x/ccv/types"

Expand Down Expand Up @@ -125,34 +124,40 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *consumertypes.GenesisSt
panic("provider client does not exist")
}

maturingPackets := []types.MaturingVSCPacket{}
maturingPackets := []consumertypes.MaturingVSCPacket{}
k.IteratePacketMaturityTime(ctx, func(vscId, timeNs uint64) bool {
mat := types.MaturingVSCPacket{
mat := consumertypes.MaturingVSCPacket{
VscId: vscId,
MaturityTime: timeNs,
}
maturingPackets = append(maturingPackets, mat)
return false
})

outstandingDowntimes := []types.OutstandingDowntime{}
outstandingDowntimes := []consumertypes.OutstandingDowntime{}
k.IterateOutstandingDowntime(ctx, func(addr string) bool {
od := types.OutstandingDowntime{
od := consumertypes.OutstandingDowntime{
ValidatorConsensusAddress: addr,
}
outstandingDowntimes = append(outstandingDowntimes, od)
return true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: #459

})

genesis = types.NewRestartGenesisState(
// TODO: update GetLastTransmissionBlockHeight to not return an error
ltbh, err := k.GetLastTransmissionBlockHeight(ctx)
if err != nil {
panic(err)
}

genesis = consumertypes.NewRestartGenesisState(
clientID,
channelID,
maturingPackets,
valset,
k.GetHeightToValsetUpdateIDs(ctx),
consumertypes.SlashRequests{},
outstandingDowntimes,
consumertypes.LastTransmissionBlockHeight{},
*ltbh,
params,
)
} else {
Expand Down
4 changes: 2 additions & 2 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestInitGenesis(t *testing.T) {
[]consumertypes.OutstandingDowntime{
{ValidatorConsensusAddress: sdk.ConsAddress(validator.Bytes()).String()},
},
consumertypes.LastTransmissionBlockHeight{Height: int64(blockHeight)},
consumertypes.LastTransmissionBlockHeight{Height: int64(100)},
params,
),
func(ctx sdk.Context, ck consumerkeeper.Keeper, gs *consumertypes.GenesisState) {
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestExportGenesis(t *testing.T) {
updatedHeightValsetUpdateIDs := append(defaultHeightValsetUpdateIDs,
consumertypes.HeightToValsetUpdateID{ValsetUpdateId: vscID + 1, Height: blockHeight + 1},
)
ltbh := consumertypes.LastTransmissionBlockHeight{Height: int64(blockHeight)}
ltbh := consumertypes.LastTransmissionBlockHeight{Height: int64(1000)}
// create default parameters for a new chain
params := types.DefaultParams()
params.Enabled = true
Expand Down
14 changes: 14 additions & 0 deletions x/ccv/consumer/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewRestartGenesisState(clientID, channelID string,
HeightToValsetUpdateId: heightToValsetUpdateIDs,
PendingSlashRequests: pendingSlashRequests,
OutstandingDowntimeSlashing: outstandingDowntimes,
LastTransmissionBlockHeight: lastTransBlockHeight,
}
}

Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could we extract a variable handshakeInProgress := ... and do if handshakeInProgress { . It might be more readable.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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")
}
Expand Down
47 changes: 42 additions & 5 deletions x/ccv/consumer/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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[:])

Expand All @@ -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,
},
{
Expand All @@ -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,
},
{
Expand Down Expand Up @@ -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{},
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. These genesis validation tests need some adjustments as well.

Expand Down