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

Add VSCMatured packets instead of acks #188

Merged
merged 43 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b1be924
iterate over all consumer chains
mpoke Jun 1, 2022
002a81f
add pending VSCs
mpoke Jun 7, 2022
7bb7b98
fix merge conflict
mpoke Jun 7, 2022
7c7070d
replace UnbondingTime with PacketMaturityTime; add method to compute …
mpoke Jun 9, 2022
54868ee
store unbonding time on consumer chain
mpoke Jun 9, 2022
ae06dfb
Merge branch 'marius/80_unbonding_period' into marius/27-pending-unbo…
mpoke Jun 9, 2022
ad20154
Update x/ccv/consumer/keeper/keeper.go
mpoke Jun 9, 2022
a55ddde
fix EndBlockCallback on provider; add test for pendingVSCs
mpoke Jun 9, 2022
32b3e1d
Merge branch 'main' into marius/27-pending-unbonding
mpoke Jun 20, 2022
a3ffcc7
Merge branch 'main' into marius/80_unbonding_period
mpoke Jun 21, 2022
ded30b6
fix merge conflicts
mpoke Jun 22, 2022
851249c
fix GetConsumerClient for nonexisting chainID
mpoke Jun 22, 2022
9d3adea
fix client unbonding times in tests
mpoke Jun 22, 2022
657eb53
fix merge conflict
mpoke Jun 23, 2022
dd8ab04
Merge branch 'marius/80_unbonding_period' into marius/27-pending-unbo…
mpoke Jun 23, 2022
1c061d3
wip
mpoke Jun 23, 2022
3990e1c
TestUndelegationDuringInit done
mpoke Jun 23, 2022
d9772bb
fix TestUnbondingNoConsumer
mpoke Jun 23, 2022
082236a
test multiple pending VSC packets
mpoke Jun 23, 2022
e4217da
fix merge conflict
mpoke Jun 23, 2022
65567ef
fix merge conflicts
mpoke Jun 24, 2022
6e42ed7
add VSCMaturedPacketData and remove packets from UnbondingSequence
mpoke Jun 24, 2022
a384af9
add found return to GetPendingVSCs
mpoke Jun 27, 2022
fb9a87b
apply changes from review
mpoke Jun 28, 2022
024568e
fix TestUndelegationDuringInit
mpoke Jun 28, 2022
942e0d4
fix TestUndelegationEdgeCase
mpoke Jun 28, 2022
7a32f0d
fix TestTimelyUndelegation1 and rename to TestUndelegationConsumerFirst
mpoke Jun 28, 2022
6f3dc32
fix TestTimelyUndelegation2 and rename to TestUndelegationProviderFirst
mpoke Jun 28, 2022
d027f1e
cleanup unbonding tests
mpoke Jun 28, 2022
c861cb2
fix KeeperTestSuite/TestOnRecvPacket
mpoke Jun 28, 2022
0cc84b9
fix KeeperTestSuite/TestUnbondMaturePackets
mpoke Jun 28, 2022
86b7d44
fix TestPacketRoundtrip
mpoke Jun 28, 2022
cc334d0
Merge branch 'marius/27-pending-unbonding' into marius/39-vsc-matured…
mpoke Jun 28, 2022
f1dd9e9
fix merge conflicts
mpoke Jun 29, 2022
92c130f
Merge branch 'main' into marius/39-vsc-matured-packets
mpoke Jun 30, 2022
10d3083
fixing ibc ack handling - wip
mpoke Jun 30, 2022
d811e7e
handle ibc acks correctly
mpoke Jun 30, 2022
41e6bab
remove TODO
mpoke Jun 30, 2022
61153cd
fix typo
mpoke Jul 4, 2022
a0e8d4a
Update x/ccv/consumer/keeper/relay.go
mpoke Jul 4, 2022
2c3448f
add logging error on ErrorAcknowledgement
mpoke Jul 5, 2022
345fed1
add logging error on ErrorAcknowledgement
mpoke Jul 5, 2022
0b7b4e8
fix merge conflicts
mpoke Jul 7, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ require (

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220621053640-83aa2792664d
github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220628105017-c48f8e2dadb8
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb v1.2.3-0.20180221223340-01288bdb0883/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220621053640-83aa2792664d h1:FUv+s9xpIvqajVEtLe7aZyK7G14ufXWzim+rBJWHFf4=
github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220621053640-83aa2792664d/go.mod h1:dt5cqIuPmhJYE3voSCXi9pImDVZCnW+/y2BkZTYgmw8=
github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220628105017-c48f8e2dadb8 h1:Mkx4PqaeVHnzGid5mBBGhuuyxZ2hYTfQ+cACAOpw0bU=
github.com/informalsystems/ibc-go/v3 v3.0.0-beta1.0.20220628105017-c48f8e2dadb8/go.mod h1:dt5cqIuPmhJYE3voSCXi9pImDVZCnW+/y2BkZTYgmw8=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
9 changes: 4 additions & 5 deletions proto/interchain_security/ccv/consumer/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ message GenesisState {
ibc.lightclients.tendermint.v1.ClientState provider_client_state = 5;
// ProviderConsensusState filled in on new chain, nil on restart.
ibc.lightclients.tendermint.v1.ConsensusState provider_consensus_state = 6;
repeated UnbondingSequence unbonding_sequences = 7 [(gogoproto.nullable) = false];
repeated MaturingVSCPacket maturing_packets = 7 [(gogoproto.nullable) = false];
repeated .tendermint.abci.ValidatorUpdate initial_val_set = 8 [(gogoproto.nullable) = false];
}

// UnbondingSequence defines the genesis information for each unbonding packet sequence.
message UnbondingSequence {
uint64 sequence = 1;
uint64 unbonding_time = 2;
ibc.core.channel.v1.Packet unbonding_packet = 3 [(gogoproto.nullable) = false];
message MaturingVSCPacket {
uint64 vscId = 1;
uint64 maturity_time = 2;
}
15 changes: 11 additions & 4 deletions proto/interchain_security/ccv/v1/ccv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "tendermint/abci/types.proto";

// This packet is sent from provider chain to consumer chain if the validator set for consumer chain
// changes (due to new bonding/unbonding messages or slashing events)
// The acknowledgement from consumer chain will be sent asynchronously once unbonding period is over,
// A VSCMatured packet from consumer chain will be sent asynchronously once unbonding period is over,
// and this will function as `UnbondingOver` message for this packet.
message ValidatorSetChangePacketData {
repeated .tendermint.abci.ValidatorUpdate validator_updates = 1
Expand All @@ -28,9 +28,16 @@ message UnbondingOp {
repeated string unbonding_consumer_chains = 2;
}

// This packet is sent from the consumer chain to the provider chain.
// The acknowledgement will be sent asynchrounously when the jailing
// will be started on the provider chain.
// This packet is sent from the consumer chain to the provider chain
// to notify that a VSC packet reached maturity on the consumer chain.
message VSCMaturedPacketData {
// the id of the VSC packet that reached maturity
uint64 valset_update_id = 1;
}

// This packet is sent from the consumer chain to the provider chain
// to request the slashing of a validator as a result of an infraction
// committed on the consumer chain.
message SlashPacketData {
tendermint.abci.Validator validator = 1
[(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"validator\""];
Expand Down
24 changes: 10 additions & 14 deletions x/ccv/consumer/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
"github.com/cosmos/interchain-security/x/ccv/consumer/types"
utils "github.com/cosmos/interchain-security/x/ccv/utils"
Expand Down Expand Up @@ -92,9 +91,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *types.GenesisState) []abci.V
// set provider channel id.
k.SetProviderChannel(ctx, state.ProviderChannelId)
// set all unbonding sequences
for _, us := range state.UnbondingSequences {
k.SetPacketMaturityTime(ctx, us.Sequence, us.UnbondingTime)
k.SetUnbondingPacket(ctx, us.Sequence, us.UnbondingPacket)
for _, mp := range state.MaturingPackets {
k.SetPacketMaturityTime(ctx, mp.VscId, mp.MaturityTime)
}
}

Expand All @@ -119,20 +117,18 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
// ValUpdates must be filled in off-line
gs := types.NewRestartGenesisState(clientID, channelID, nil, nil, params)

unbondingSequences := []types.UnbondingSequence{}
cb := func(seq uint64, packet channeltypes.Packet) bool {
timeNs := k.GetPacketMaturityTime(ctx, seq)
us := types.UnbondingSequence{
Sequence: seq,
UnbondingTime: timeNs,
UnbondingPacket: packet,
maturingPackets := []types.MaturingVSCPacket{}
cb := func(vscId, timeNs uint64) bool {
mat := types.MaturingVSCPacket{
VscId: vscId,
MaturityTime: timeNs,
}
unbondingSequences = append(unbondingSequences, us)
maturingPackets = append(maturingPackets, mat)
return false
}
k.IterateUnbondingPacket(ctx, cb)
k.IteratePacketMaturityTime(ctx, cb)

gs.UnbondingSequences = unbondingSequences
gs.MaturingPackets = maturingPackets
return gs
}
clientID, ok := k.GetProviderClient(ctx)
Expand Down
5 changes: 1 addition & 4 deletions x/ccv/consumer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (suite *KeeperTestSuite) TestGenesis() {
)
packet := channeltypes.NewPacket(pd.GetBytes(), 1, providertypes.PortID, suite.path.EndpointB.ChannelID, consumertypes.PortID, suite.path.EndpointA.ChannelID,
clienttypes.NewHeight(1, 0), 0)
suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvPacket(suite.consumerChain.GetContext(), packet, pd)
suite.consumerChain.App.(*app.App).ConsumerKeeper.OnRecvVSCPacket(suite.consumerChain.GetContext(), packet, pd)

// mocking the fact that consumer chain validators should be provider chain validators
// TODO: Fix testing suite so we can initialize both chains with the same validator set
Expand All @@ -79,9 +79,6 @@ func (suite *KeeperTestSuite) TestGenesis() {
unbondingPeriod, found := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx)
suite.Require().True(found)
suite.Require().Equal(uint64(origTime.Add(unbondingPeriod).UnixNano()), maturityTime, "maturity time is not set correctly in genesis")
unbondingPacket, err := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetUnbondingPacket(suite.consumerChain.GetContext(), 1)
suite.Require().NoError(err)
suite.Require().Equal(&packet, unbondingPacket, "unbonding packet is not set correctly in genesis")

suite.Require().NotPanics(func() {
suite.consumerChain.App.(*app.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), restartGenesis)
Expand Down
75 changes: 10 additions & 65 deletions x/ccv/consumer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (k Keeper) DeletePendingChanges(ctx sdk.Context) {
}

// IteratePacketMaturityTime iterates through the VSC packet maturity times set in the store
func (k Keeper) IteratePacketMaturityTime(ctx sdk.Context, cb func(seq, timeNs uint64) bool) {
func (k Keeper) IteratePacketMaturityTime(ctx sdk.Context, cb func(vscId, timeNs uint64) bool) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.PacketMaturityTimePrefix))

Expand All @@ -249,83 +249,28 @@ func (k Keeper) IteratePacketMaturityTime(ctx sdk.Context, cb func(seq, timeNs u
}
}

// SetPacketMaturityTime sets the maturity time for a given received VSC packet sequence
func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, sequence, maturityTime uint64) {
// SetPacketMaturityTime sets the maturity time for a given received VSC packet id
func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, vscId, maturityTime uint64) {
store := ctx.KVStore(k.storeKey)
timeBytes := make([]byte, 8)
binary.BigEndian.PutUint64(timeBytes, maturityTime)
store.Set(types.PacketMaturityTimeKey(sequence), timeBytes)
store.Set(types.PacketMaturityTimeKey(vscId), timeBytes)
}

// GetPacketMaturityTime gets the maturity time for a given received VSC packet sequence
func (k Keeper) GetPacketMaturityTime(ctx sdk.Context, sequence uint64) uint64 {
// GetPacketMaturityTime gets the maturity time for a given received VSC packet id
func (k Keeper) GetPacketMaturityTime(ctx sdk.Context, vscId uint64) uint64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.PacketMaturityTimeKey(sequence))
bz := store.Get(types.PacketMaturityTimeKey(vscId))
if bz == nil {
return 0
}
return binary.BigEndian.Uint64(bz)
}

// DeletePacketMaturityTime deletes the the maturity time for a given received VSC packet sequence
func (k Keeper) DeletePacketMaturityTime(ctx sdk.Context, sequence uint64) {
// DeletePacketMaturityTime deletes the the maturity time for a given received VSC packet id
func (k Keeper) DeletePacketMaturityTime(ctx sdk.Context, vscId uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.PacketMaturityTimeKey(sequence))
}

// IterateUnbondingPacket iterates through the unbonding packets set in the store
func (k Keeper) IterateUnbondingPacket(ctx sdk.Context, cb func(seq uint64, packet channeltypes.Packet) bool) error {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.UnbondingPacketPrefix))

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
seqBytes := iterator.Key()[len([]byte(types.UnbondingPacketPrefix)):]
seq := binary.BigEndian.Uint64(seqBytes)

var packet channeltypes.Packet
err := packet.Unmarshal(iterator.Value())
if err != nil {
return err
}

if cb(seq, packet) {
break
}
}
return nil
}

// SetUnbondingPacket sets the unbonding packet for a given received packet sequence
func (k Keeper) SetUnbondingPacket(ctx sdk.Context, sequence uint64, packet channeltypes.Packet) error {
store := ctx.KVStore(k.storeKey)
bz, err := packet.Marshal()
if err != nil {
return err
}
store.Set(types.UnbondingPacketKey(sequence), bz)
return nil
}

// GetUnbondingPacket gets the unbonding packet for a given received packet sequence
func (k Keeper) GetUnbondingPacket(ctx sdk.Context, sequence uint64) (*channeltypes.Packet, error) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.UnbondingPacketKey(sequence))
if bz == nil {
return nil, sdkerrors.Wrapf(channeltypes.ErrInvalidPacket, "packet does not exist at sequence: %d", sequence)
}
var packet channeltypes.Packet
err := packet.Unmarshal(bz)
if err != nil {
return nil, err
}
return &packet, nil
}

// DeleteUnbondingPacket deletes the unbonding packet
func (k Keeper) DeleteUnbondingPacket(ctx sdk.Context, sequence uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.UnbondingPacketKey(sequence))
store.Delete(types.PacketMaturityTimeKey(vscId))
}

// VerifyProviderChain verifies that the chain trying to connect on the channel handshake
Expand Down
43 changes: 0 additions & 43 deletions x/ccv/consumer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,49 +216,6 @@ func (suite *KeeperTestSuite) TestPacketMaturityTime() {
})
}

func (suite *KeeperTestSuite) TestUnbondingPacket() {
pk1, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey())
suite.Require().NoError(err)
pk2, err := cryptocodec.ToTmProtoPublicKey(ed25519.GenPrivKey().PubKey())
suite.Require().NoError(err)

for i := 0; i < 5; i++ {
pd := ccv.NewValidatorSetChangePacketData(
[]abci.ValidatorUpdate{
{
PubKey: pk1,
Power: int64(i),
},
{
PubKey: pk2,
Power: int64(i + 5),
},
},
1,
nil,
)
packet := channeltypes.NewPacket(pd.GetBytes(), uint64(i), "provider", "channel-1", "consumer", "channel-1",
clienttypes.NewHeight(1, 0), 0)
suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.SetUnbondingPacket(suite.ctx, uint64(i), packet)
}

// ensure that packets are iterated by sequence
i := 0
suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.IterateUnbondingPacket(suite.ctx, func(seq uint64, packet channeltypes.Packet) bool {
suite.Require().Equal(uint64(i), seq)
gotPacket, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, seq)
suite.Require().NoError(err)
suite.Require().Equal(&packet, gotPacket, "packet from get and iteration do not match")
i++
return false
})

suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.DeleteUnbondingPacket(suite.ctx, 0)
gotPacket, err := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingPacket(suite.ctx, 0)
suite.Require().Error(err)
suite.Require().Nil(gotPacket, "packet is not nil after delete")
}

func (suite *KeeperTestSuite) TestVerifyProviderChain() {
var connectionHops []string
channelID := "channel-0"
Expand Down
Loading