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

Implement ADR 026 #7029

Merged
merged 63 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0b2ca3a
Add allow_governance_override_after_expiry flag to tendermint NewCrea…
dauTT Aug 12, 2020
7eb83d5
1) Add LatestTimestamp to ClientState struct by adding a new attribut…
dauTT Aug 12, 2020
4e131a5
Fix tests
dauTT Aug 13, 2020
54e2c10
1) Add allow_governance_override_after_expiry flag to tendemint clien…
dauTT Aug 13, 2020
46753bc
Cosmetic changes
dauTT Aug 13, 2020
bbaf594
Fix tests
dauTT Aug 13, 2020
0ec9447
Add Unfreeze function
dauTT Aug 13, 2020
11e5545
Add new ClientUpdateProposal type
dauTT Aug 15, 2020
7725884
Add minor fixes
dauTT Aug 16, 2020
024c7a6
Add NewClientUpdateProposalHandler unit tests
dauTT Aug 16, 2020
4c7331e
Merge branch 'master' into dauTT/ADR-26-issue-6998
dauTT Aug 16, 2020
2481b5e
Fix proto-lint-docker
dauTT Aug 16, 2020
ec39812
Delete x/ibc/07-tendermint/tendermint_test.go
dauTT Aug 17, 2020
449f7b6
Follow convention to put signer last in msg function signature
dauTT Aug 18, 2020
ab5264f
1) Add GetLatestTimestamp function to ClientStatus interface
dauTT Aug 18, 2020
b85e6c9
1) Add override flag to UpdateClient function
dauTT Aug 20, 2020
b454bf8
Refactor HandleClientUpdateProposal
dauTT Aug 20, 2020
73cbb37
1) Extend exported Header interface with MarshalBinaryBare and Unmars…
dauTT Aug 21, 2020
b7dae11
1) Uncomment tests and clean up code
dauTT Aug 21, 2020
619e55a
Cosmetic changes
dauTT Aug 21, 2020
c9cf600
Add TODO comments
dauTT Aug 21, 2020
49c0aa3
Merge branch 'master' into dauTT/ADR-26-issue-6998
dauTT Aug 22, 2020
ad5c261
Fix header MarshalBinaryBare, UnmarshalBinaryBare by using protobuf e…
dauTT Aug 22, 2020
bad2bfc
Merge branch 'master' into dauTT/ADR-26-issue-6998
dauTT Aug 22, 2020
bbc0af4
Merge branch 'master' into ADR-26-issue-6998
cwgoes Aug 24, 2020
935ffd7
Merge branch 'master' into ADR-26-issue-6998
fedekunze Aug 24, 2020
ad196fa
Merge branch 'master' into ADR-26-issue-6998
dauTT Aug 26, 2020
b7cab36
Merge branch 'master' into ADR-26-issue-6998
fedekunze Aug 26, 2020
f9090dc
Fix proto comments
dauTT Aug 26, 2020
928ca3e
Fix override logic
dauTT Aug 26, 2020
5eb466b
Merge branch 'master' into ADR-26-issue-6998
dauTT Aug 26, 2020
01f6857
undo gettimestamp for solo machine and localhost
colin-axner Aug 28, 2020
05a5e26
add update after proposal func, some major refactoring in progress, v…
colin-axner Aug 28, 2020
8656f98
fix tendermint proposal update handling
colin-axner Aug 31, 2020
9514076
fix merge conflicts
colin-axner Aug 31, 2020
592c5b1
run make proto-gen
colin-axner Aug 31, 2020
8151bb9
merge master
colin-axner Sep 1, 2020
40ca6b9
remove timestamp from tendemint client
colin-axner Sep 1, 2020
6c6af7f
fix merge conflicts
colin-axner Sep 1, 2020
408033e
fix build issue for tm types
colin-axner Sep 1, 2020
27d75b9
apply various review comments
colin-axner Sep 1, 2020
2787e3a
add tests for 02-client functionality
colin-axner Sep 2, 2020
c1d997e
self review fixes
colin-axner Sep 2, 2020
b19a842
merge master
colin-axner Sep 2, 2020
8067630
typo
colin-axner Sep 2, 2020
11ebacf
update tests slightly
colin-axner Sep 3, 2020
7266199
Merge branch 'master' of github.com:cosmos/cosmos-sdk into ADR-26-iss…
colin-axner Sep 3, 2020
500eeee
update tendermint proposal handling tests
colin-axner Sep 3, 2020
28b14e9
Update x/ibc/02-client/keeper/proposal.go
colin-axner Sep 4, 2020
6420c71
Update x/ibc/07-tendermint/types/proposal_handle.go
colin-axner Sep 4, 2020
82b75c4
Update x/ibc/07-tendermint/types/proposal_handle.go
colin-axner Sep 4, 2020
2228c11
apply most of @fedekunze and some of @AdityaSripal suggestions
colin-axner Sep 4, 2020
4d0c535
Merge branch 'ADR-26-issue-6998' of github.com:dauTT/cosmos-sdk into …
colin-axner Sep 4, 2020
020c6ff
convert test to bools
colin-axner Sep 4, 2020
7042150
update docs and increase code cov
colin-axner Sep 4, 2020
ca6393b
merge master
colin-axner Sep 4, 2020
234ad00
fix build
colin-axner Sep 4, 2020
ffdf601
fix typo, remove omitempty
colin-axner Sep 4, 2020
567aa2a
add switch
colin-axner Sep 4, 2020
90d92bf
apply @fedekunze latest suggestions
colin-axner Sep 4, 2020
d4053ab
fix lint
colin-axner Sep 4, 2020
01663a9
Update x/ibc/02-client/keeper/proposal_test.go
AdityaSripal Sep 4, 2020
5bcd982
Merge branch 'master' into ADR-26-issue-6998
mergify[bot] Sep 4, 2020
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
1 change: 1 addition & 0 deletions client/grpc/reflection/reflection.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/grpc/simulate/simulate.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions proto/ibc/client/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ message ClientConsensusStates {
[(gogoproto.moretags) = "yaml:\"consensus_states\""];
}

// ClientUpdateProposal is a governance proposal. If it passes, the client is
// updated with the provided header. The update may fail if the header is not
// valid given certain conditions specified by the client implementation.
message ClientUpdateProposal {
option (gogoproto.goproto_getters) = false;
// the title of the update proposal
string title = 1;
// the description of the proposal
string description = 2;
// the client identifier for the client to be updated if the proposal passes
string client_id = 3 [(gogoproto.moretags) = "yaml:\"client_id\""];
// the header used to update the client if the proposal passes
google.protobuf.Any header = 4;
}

// MsgCreateClient defines a message to create an IBC client
message MsgCreateClient {
// client unique identifier
Expand Down
10 changes: 10 additions & 0 deletions proto/ibc/tendermint/tendermint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ message ClientState {
// Proof specifications used in verifying counterparty state
repeated ics23.ProofSpec proof_specs = 8
[(gogoproto.moretags) = "yaml:\"proof_specs\""];

// This flag, when set to true, will allow governance to recover a client
// which has expired
bool allow_update_after_expiry = 9
[(gogoproto.moretags) = "yaml:\"allow_update_after_expiry,omitempty\""];
// This flag, when set to true, will allow governance to unfreeze a client
// whose chain has experienced a misbehaviour event
bool allow_update_after_misbehaviour = 10
[(gogoproto.moretags) =
"yaml:\"allow_update_after_misbehaviour,omitempty\""];
}

// ConsensusState defines the consensus state from Tendermint.
Expand Down
24 changes: 13 additions & 11 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
transfer "github.com/cosmos/cosmos-sdk/x/ibc-transfer"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc-transfer/keeper"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc-transfer/types"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
ibckeeper "github.com/cosmos/cosmos-sdk/x/ibc/keeper"
Expand Down Expand Up @@ -244,17 +245,6 @@ func NewSimApp(
)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter,
)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand All @@ -266,6 +256,18 @@ func NewSimApp(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
)

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientUpdateProposalHandler(app.IBCKeeper.ClientKeeper))
app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter,
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
Expand Down
1 change: 1 addition & 0 deletions x/auth/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/bank/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/distribution/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/evidence/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/gov/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/ibc-transfer/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions x/ibc/02-client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
)
Expand Down Expand Up @@ -93,3 +94,16 @@ func HandleMsgSubmitMisbehaviour(ctx sdk.Context, k keeper.Keeper, msg *types.Ms
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
}

// NewClientUpdateProposalHandler defines the client update proposal handler
func NewClientUpdateProposalHandler(k keeper.Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
case *types.ClientUpdateProposal:
return k.ClientUpdateProposal(ctx, c)

default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized ibc proposal content type: %T", c)
}
}
}
76 changes: 76 additions & 0 deletions x/ibc/02-client/handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package client_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/cosmos-sdk/x/ibc/exported"
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
)

func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() {
var (
content govtypes.Content
err error
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"valid update client proposal", func() {
clientA, _ := suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
clientState := suite.chainA.GetClientState(clientA)

tmClientState, ok := clientState.(*ibctmtypes.ClientState)
suite.Require().True(ok)
tmClientState.AllowUpdateAfterMisbehaviour = true
tmClientState.FrozenHeight = clienttypes.NewHeight(0, tmClientState.GetLatestHeight())
suite.chainA.App.IBCKeeper.ClientKeeper.SetClientState(suite.chainA.GetContext(), clientA, tmClientState)

// use next header for chainB to update the client on chainA
header, err := suite.chainA.ConstructUpdateTMClientHeader(suite.chainB, clientA)
suite.Require().NoError(err)

content, err = clienttypes.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, clientA, header)
suite.Require().NoError(err)
}, true,
},
{
"nil proposal", func() {
content = nil
}, false,
},
{
"unsupported proposal type", func() {
content = distributiontypes.NewCommunityPoolSpendProposal(ibctesting.Title, ibctesting.Description, suite.chainA.SenderAccount.GetAddress(), sdk.NewCoins(sdk.NewCoin("communityfunds", sdk.NewInt(10))))
}, false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

tc.malleate()

proposalHandler := client.NewClientUpdateProposalHandler(suite.chainA.App.IBCKeeper.ClientKeeper)

err = proposalHandler(suite.chainA.GetContext(), content)

if tc.expPass {
suite.Require().NoError(err)
} else {
suite.Require().Error(err)
}
})
}

}
2 changes: 1 addition & 1 deletion x/ibc/02-client/keeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (k Keeper) CreateClient(
return clientState, nil
}

// UpdateClient updates the consensus state and the state root from a provided header
// UpdateClient updates the consensus state and the state root from a provided header.
func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.Header) (exported.ClientState, error) {
clientType, found := k.GetClientType(ctx, clientID)
if !found {
Expand Down
Loading