Final IBC migration and Amino removal (#7157)
* migrate tm messages and change header/evidence to pointers * remove amino * add nil checks and test for pointer changes * fix format
This commit is contained in:
parent
2df04d6eb6
commit
1f7a2787aa
|
@ -78,7 +78,7 @@ message MsgCreateClient {
|
|||
message MsgUpdateClient {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
Header header = 2 [(gogoproto.nullable) = false];
|
||||
Header header = 2;
|
||||
}
|
||||
|
||||
// MsgSubmitClientMisbehaviour defines an sdk.Msg type that supports submitting
|
||||
|
@ -87,6 +87,6 @@ message MsgSubmitClientMisbehaviour {
|
|||
option (gogoproto.goproto_getters) = false;
|
||||
bytes submitter = 1
|
||||
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
Evidence evidence = 2 [(gogoproto.nullable) = false];
|
||||
Evidence evidence = 2;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,12 +78,10 @@ message Evidence {
|
|||
string chain_id = 2 [(gogoproto.moretags) = "yaml:\"chain_id\""];
|
||||
Header header_1 = 3 [
|
||||
(gogoproto.customname) = "Header1",
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "yaml:\"header_1\""
|
||||
];
|
||||
Header header_2 = 4 [
|
||||
(gogoproto.customname) = "Header2",
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "yaml:\"header_2\""
|
||||
];
|
||||
}
|
||||
|
@ -103,7 +101,6 @@ message Evidence {
|
|||
message Header {
|
||||
.tendermint.types.SignedHeader signed_header = 1 [
|
||||
(gogoproto.embed) = true,
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "yaml:\"signed_header\""
|
||||
];
|
||||
|
||||
|
@ -119,3 +116,55 @@ message Fraction {
|
|||
int64 numerator = 1;
|
||||
int64 denominator = 2;
|
||||
}
|
||||
|
||||
// MsgCreateClient defines a message to create a tendermint client.
|
||||
message MsgCreateClient {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
Header header = 2;
|
||||
Fraction trust_level = 3 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "yaml:\"trust_level\""
|
||||
];
|
||||
google.protobuf.Duration trusting_period = 4 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true,
|
||||
(gogoproto.moretags) = "yaml:\"trusting_period\""
|
||||
];
|
||||
google.protobuf.Duration unbonding_period = 5 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true,
|
||||
(gogoproto.moretags) = "yaml:\"unbonding_period\""
|
||||
];
|
||||
google.protobuf.Duration max_clock_drift = 6 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.stdduration) = true,
|
||||
(gogoproto.moretags) = "yaml:\"max_clock_drift\""
|
||||
];
|
||||
repeated ics23.ProofSpec proof_specs = 8
|
||||
[(gogoproto.moretags) = "yaml:\"proof_specs\""];
|
||||
bytes signer = 7
|
||||
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
}
|
||||
|
||||
// MsgCreateClient defines an sdk.Msg to update a tendermint client state to
|
||||
// the given header.
|
||||
message MsgUpdateClient {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
|
||||
Header header = 2;
|
||||
bytes signer = 3
|
||||
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
}
|
||||
|
||||
// MsgSubmitClientMisbehaviour defines an sdk.Msg type that submits Evidence for
|
||||
// light client misbehaviour.
|
||||
message MsgSubmitClientMisbehaviour {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
Evidence evidence = 1;
|
||||
bytes submitter = 2
|
||||
[(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
|
@ -47,8 +48,10 @@ func QueryClientStateABCI(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var clientState exported.ClientState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &clientState); err != nil {
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
clientState, err := types.UnmarshalClientState(cdc, res.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -57,7 +60,7 @@ func QueryClientStateABCI(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -102,8 +105,10 @@ func QueryConsensusStateABCI(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var cs exported.ConsensusState
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &cs); err != nil {
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
cs, err := types.UnmarshalConsensusState(cdc, res.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -112,7 +117,7 @@ func QueryConsensusStateABCI(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -155,7 +160,7 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64,
|
|||
}
|
||||
|
||||
header := ibctmtypes.Header{
|
||||
SignedHeader: *protoCommit,
|
||||
SignedHeader: protoCommit,
|
||||
ValidatorSet: protoValset,
|
||||
}
|
||||
|
||||
|
|
|
@ -57,16 +57,16 @@ func (suite *KeeperTestSuite) TestCreateClient() {
|
|||
|
||||
func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
||||
// Must create header creation functions since suite.header gets recreated on each test case
|
||||
createFutureUpdateFn := func(s *KeeperTestSuite) ibctmtypes.Header {
|
||||
createFutureUpdateFn := func(s *KeeperTestSuite) *ibctmtypes.Header {
|
||||
return ibctmtypes.CreateTestHeader(testChainID, int64(suite.header.GetHeight()+3), int64(suite.header.GetHeight()), suite.header.Header.Time.Add(time.Hour),
|
||||
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||
}
|
||||
createPastUpdateFn := func(s *KeeperTestSuite) ibctmtypes.Header {
|
||||
createPastUpdateFn := func(s *KeeperTestSuite) *ibctmtypes.Header {
|
||||
return ibctmtypes.CreateTestHeader(testChainID, int64(suite.header.GetHeight()-2), int64(suite.header.GetHeight())-4, suite.header.Header.Time,
|
||||
suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||
}
|
||||
var (
|
||||
updateHeader ibctmtypes.Header
|
||||
updateHeader *ibctmtypes.Header
|
||||
clientState *ibctmtypes.ClientState
|
||||
)
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ type KeeperTestSuite struct {
|
|||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
consensusState *ibctmtypes.ConsensusState
|
||||
header ibctmtypes.Header
|
||||
header *ibctmtypes.Header
|
||||
valSet *tmtypes.ValidatorSet
|
||||
valSetHash tmbytes.HexBytes
|
||||
privVal tmtypes.PrivValidator
|
||||
|
|
|
@ -10,16 +10,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
)
|
||||
|
||||
// RegisterCodec registers the IBC client interfaces and types
|
||||
func RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterInterface((*exported.ClientState)(nil), nil) // remove after genesis migration
|
||||
cdc.RegisterInterface((*exported.MsgCreateClient)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.MsgUpdateClient)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.ConsensusState)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.Header)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.Misbehaviour)(nil), nil)
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers the client interfaces to protobuf Any.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
registry.RegisterInterface(
|
||||
|
@ -37,22 +27,14 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||
}
|
||||
|
||||
var (
|
||||
amino = codec.New()
|
||||
|
||||
// SubModuleCdc references the global x/ibc/02-client module codec. Note, the codec should
|
||||
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
||||
// still used for that purpose.
|
||||
// ONLY be used in certain instances of tests and for JSON encoding.
|
||||
//
|
||||
// The actual codec used for serialization should be provided to x/ibc/02-client and
|
||||
// defined at the application level.
|
||||
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCodec(amino)
|
||||
amino.Seal()
|
||||
}
|
||||
|
||||
// PackClientState constructs a new Any packed with the given client state value. It returns
|
||||
// an error if the client state can't be casted to a protobuf message or if the concrete
|
||||
// implemention is not registered to the protobuf codec.
|
||||
|
|
|
@ -49,12 +49,14 @@ func queryConnectionABCI(clientCtx client.Context, connectionID string) (*types.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var connection types.ConnectionEnd
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &connection); err != nil {
|
||||
if err := cdc.UnmarshalBinaryBare(res.Value, &connection); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -92,12 +94,14 @@ func queryClientConnectionsABCI(clientCtx client.Context, clientID string) (*typ
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var paths []string
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &paths); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
clientutils "github.com/cosmos/cosmos-sdk/x/ibc/02-client/client/utils"
|
||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
|
@ -49,7 +50,9 @@ func queryPacketCommitmentABCI(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -90,12 +93,14 @@ func queryChannelABCI(clientCtx client.Context, portID, channelID string) (*type
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var channel types.Channel
|
||||
if err := clientCtx.LegacyAmino.UnmarshalBinaryBare(res.Value, &channel); err != nil {
|
||||
if err := cdc.UnmarshalBinaryBare(res.Value, &channel); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -229,7 +234,9 @@ func queryNextSequenceRecvABCI(clientCtx client.Context, portID, channelID strin
|
|||
return nil, err
|
||||
}
|
||||
|
||||
proofBz, err := clientCtx.LegacyAmino.MarshalBinaryBare(res.ProofOps)
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
proofBz, err := cdc.MarshalBinaryBare(res.ProofOps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
)
|
||||
|
||||
|
@ -35,7 +35,7 @@ func NewCreateClientCmd() *cobra.Command {
|
|||
Long: `Create a new tendermint IBC client.
|
||||
- 'trust-level' flag can be a fraction (eg: '1/3') or 'default'
|
||||
- 'proof-specs' flag can be JSON input, a path to a .json file or 'default'`,
|
||||
Example: fmt.Sprintf("%s tx ibc %s create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --proof-specs [path/to/proof-specs.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, ibctmtypes.SubModuleName),
|
||||
Example: fmt.Sprintf("%s tx ibc %s create [client-id] [path/to/consensus_state.json] [trusting_period] [unbonding_period] [max_clock_drift] --trust-level default --proof-specs [path/to/proof-specs.json] --from node0 --home ../node0/<app>cli --chain-id $CID", version.AppName, types.SubModuleName),
|
||||
Args: cobra.ExactArgs(5),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
|
@ -46,27 +46,29 @@ func NewCreateClientCmd() *cobra.Command {
|
|||
|
||||
clientID := args[0]
|
||||
|
||||
var header ibctmtypes.Header
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[1]), &header); err != nil {
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var header *types.Header
|
||||
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil {
|
||||
// check for file path if JSON input is not provided
|
||||
contents, err := ioutil.ReadFile(args[1])
|
||||
if err != nil {
|
||||
return errors.New("neither JSON input nor path to .json file were provided for consensus header")
|
||||
}
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &header); err != nil {
|
||||
if err := cdc.UnmarshalJSON(contents, &header); err != nil {
|
||||
return errors.Wrap(err, "error unmarshalling consensus header file")
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
trustLevel ibctmtypes.Fraction
|
||||
trustLevel types.Fraction
|
||||
specs []*ics23.ProofSpec
|
||||
)
|
||||
|
||||
lvl, _ := cmd.Flags().GetString(flagTrustLevel)
|
||||
|
||||
if lvl == "default" {
|
||||
trustLevel = ibctmtypes.NewFractionFromTm(light.DefaultTrustLevel)
|
||||
trustLevel = types.NewFractionFromTm(light.DefaultTrustLevel)
|
||||
} else {
|
||||
trustLevel, err = parseFraction(lvl)
|
||||
if err != nil {
|
||||
|
@ -92,18 +94,18 @@ func NewCreateClientCmd() *cobra.Command {
|
|||
spc, _ := cmd.Flags().GetString(flagProofSpecs)
|
||||
if spc == "default" {
|
||||
specs = commitmenttypes.GetSDKSpecs()
|
||||
} else if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(spc), &specs); err != nil {
|
||||
} else if err := cdc.UnmarshalJSON([]byte(spc), &specs); err != nil {
|
||||
// check for file path if JSON input not provided
|
||||
contents, err := ioutil.ReadFile(spc)
|
||||
if err != nil {
|
||||
return errors.New("neither JSON input nor path to .json file was provided for proof specs flag")
|
||||
}
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &specs); err != nil {
|
||||
if err := cdc.UnmarshalJSON(contents, &specs); err != nil {
|
||||
return errors.Wrap(err, "error unmarshalling proof specs file")
|
||||
}
|
||||
}
|
||||
|
||||
msg := ibctmtypes.NewMsgCreateClient(
|
||||
msg := types.NewMsgCreateClient(
|
||||
clientID, header, trustLevel, trustingPeriod, ubdPeriod, maxClockDrift, specs, clientCtx.GetFromAddress(),
|
||||
)
|
||||
|
||||
|
@ -131,7 +133,7 @@ func NewUpdateClientCmd() *cobra.Command {
|
|||
Long: "update existing tendermint client with a tendermint header",
|
||||
Example: fmt.Sprintf(
|
||||
"$ %s tx ibc %s update [client-id] [path/to/header.json] --from node0 --home ../node0/<app>cli --chain-id $CID",
|
||||
version.AppName, ibctmtypes.SubModuleName,
|
||||
version.AppName, types.SubModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
@ -143,19 +145,21 @@ func NewUpdateClientCmd() *cobra.Command {
|
|||
|
||||
clientID := args[0]
|
||||
|
||||
var header ibctmtypes.Header
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[1]), &header); err != nil {
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var header *types.Header
|
||||
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil {
|
||||
// check for file path if JSON input is not provided
|
||||
contents, err := ioutil.ReadFile(args[1])
|
||||
if err != nil {
|
||||
return errors.New("neither JSON input nor path to .json file were provided")
|
||||
}
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &header); err != nil {
|
||||
if err := cdc.UnmarshalJSON(contents, &header); err != nil {
|
||||
return errors.Wrap(err, "error unmarshalling header file")
|
||||
}
|
||||
}
|
||||
|
||||
msg := ibctmtypes.NewMsgUpdateClient(clientID, header, clientCtx.GetFromAddress())
|
||||
msg := types.NewMsgUpdateClient(clientID, header, clientCtx.GetFromAddress())
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -179,7 +183,7 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
|
|||
Long: "submit a client misbehaviour to invalidate to invalidate previous state roots and prevent future updates",
|
||||
Example: fmt.Sprintf(
|
||||
"$ %s tx ibc %s misbehaviour [path/to/evidence.json] --from node0 --home ../node0/<app>cli --chain-id $CID",
|
||||
version.AppName, ibctmtypes.SubModuleName,
|
||||
version.AppName, types.SubModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
@ -189,19 +193,21 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
var ev evidenceexported.Evidence
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var ev *types.Evidence
|
||||
if err := cdc.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
|
||||
// check for file path if JSON input is not provided
|
||||
contents, err := ioutil.ReadFile(args[0])
|
||||
if err != nil {
|
||||
return errors.New("neither JSON input nor path to .json file were provided")
|
||||
}
|
||||
if err := clientCtx.LegacyAmino.UnmarshalJSON(contents, &ev); err != nil {
|
||||
if err := cdc.UnmarshalJSON(contents, &ev); err != nil {
|
||||
return errors.Wrap(err, "error unmarshalling evidence file")
|
||||
}
|
||||
}
|
||||
|
||||
msg := ibctmtypes.NewMsgSubmitClientMisbehaviour(ev, clientCtx.GetFromAddress())
|
||||
msg := types.NewMsgSubmitClientMisbehaviour(ev, clientCtx.GetFromAddress())
|
||||
if err := msg.ValidateBasic(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -215,24 +221,25 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func parseFraction(fraction string) (ibctmtypes.Fraction, error) {
|
||||
func parseFraction(fraction string) (types.Fraction, error) {
|
||||
fr := strings.Split(fraction, "/")
|
||||
if len(fr) != 2 || fr[0] == fraction {
|
||||
return ibctmtypes.Fraction{}, fmt.Errorf("fraction must have format 'numerator/denominator' got %s", fraction)
|
||||
return types.Fraction{}, fmt.Errorf("fraction must have format 'numerator/denominator' got %s", fraction)
|
||||
}
|
||||
|
||||
numerator, err := strconv.ParseInt(fr[0], 10, 64)
|
||||
if err != nil {
|
||||
return ibctmtypes.Fraction{}, fmt.Errorf("invalid trust-level numerator: %w", err)
|
||||
return types.Fraction{}, fmt.Errorf("invalid trust-level numerator: %w", err)
|
||||
}
|
||||
|
||||
denominator, err := strconv.ParseInt(fr[1], 10, 64)
|
||||
if err != nil {
|
||||
return ibctmtypes.Fraction{}, fmt.Errorf("invalid trust-level denominator: %w", err)
|
||||
return types.Fraction{}, fmt.Errorf("invalid trust-level denominator: %w", err)
|
||||
}
|
||||
|
||||
return ibctmtypes.Fraction{
|
||||
return types.Fraction{
|
||||
Numerator: numerator,
|
||||
Denominator: denominator,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -3,23 +3,10 @@ package types
|
|||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
)
|
||||
|
||||
// RegisterCodec registers the necessary x/ibc/07-tendermint interfaces and conrete types
|
||||
// on the provided Amino codec. These types are used for Amino JSON serialization.
|
||||
func RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterConcrete(ClientState{}, "ibc/client/tendermint/ClientState", nil)
|
||||
cdc.RegisterConcrete(ConsensusState{}, "ibc/client/tendermint/ConsensusState", nil)
|
||||
cdc.RegisterConcrete(Header{}, "ibc/client/tendermint/Header", nil)
|
||||
cdc.RegisterConcrete(Evidence{}, "ibc/client/tendermint/Evidence", nil)
|
||||
cdc.RegisterConcrete(&MsgCreateClient{}, "ibc/client/tendermint/MsgCreateClient", nil)
|
||||
cdc.RegisterConcrete(&MsgUpdateClient{}, "ibc/client/tendermint/MsgUpdateClient", nil)
|
||||
cdc.RegisterConcrete(&MsgSubmitClientMisbehaviour{}, "ibc/client/tendermint/MsgSubmitClientMisbehaviour", nil)
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers the tendermint concrete evidence and client-related
|
||||
// implementations and interfaces.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
|
@ -38,19 +25,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||
}
|
||||
|
||||
var (
|
||||
amino = codec.New()
|
||||
|
||||
// SubModuleCdc references the global x/ibc/07-tendermint module codec. Note, the codec should
|
||||
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
||||
// still used for that purpose.
|
||||
// ONLY be used in certain instances of tests and for JSON encoding.
|
||||
//
|
||||
// The actual codec used for serialization should be provided to x/ibc/07-tendermint and
|
||||
// defined at the application level.
|
||||
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
)
|
||||
|
||||
func init() {
|
||||
cryptocodec.RegisterCrypto(amino)
|
||||
RegisterCodec(amino)
|
||||
amino.Seal()
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ var (
|
|||
)
|
||||
|
||||
// NewEvidence creates a new Evidence instance.
|
||||
func NewEvidence(clientID, chainID string, header1, header2 Header) *Evidence {
|
||||
func NewEvidence(clientID, chainID string, header1, header2 *Header) *Evidence {
|
||||
return &Evidence{
|
||||
ClientId: clientID,
|
||||
ChainId: chainID,
|
||||
|
@ -87,6 +87,12 @@ func (ev Evidence) GetTime() time.Time {
|
|||
|
||||
// ValidateBasic implements Evidence interface
|
||||
func (ev Evidence) ValidateBasic() error {
|
||||
if ev.Header1 == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidHeader, "evidence Header1 cannot be nil")
|
||||
}
|
||||
if ev.Header2 == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidHeader, "evidence Header2 cannot be nil")
|
||||
}
|
||||
if ev.Header1.TrustedHeight == 0 {
|
||||
return sdkerrors.Wrap(ErrInvalidHeaderHeight, "evidence Header1 must have non-zero trusted height")
|
||||
}
|
||||
|
|
|
@ -10,15 +10,14 @@ import (
|
|||
|
||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
)
|
||||
|
||||
func (suite *TendermintTestSuite) TestEvidence() {
|
||||
signers := []tmtypes.PrivValidator{suite.privVal}
|
||||
|
||||
ev := &ibctmtypes.Evidence{
|
||||
ev := &types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
}
|
||||
|
@ -53,140 +52,153 @@ func (suite *TendermintTestSuite) TestEvidenceValidateBasic() {
|
|||
|
||||
testCases := []struct {
|
||||
name string
|
||||
evidence *ibctmtypes.Evidence
|
||||
malleateEvidence func(ev *ibctmtypes.Evidence) error
|
||||
evidence *types.Evidence
|
||||
malleateEvidence func(ev *types.Evidence) error
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
"valid evidence",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
true,
|
||||
},
|
||||
{
|
||||
"evidence Header1 is nil",
|
||||
types.NewEvidence(clientID, chainID, nil, suite.header),
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"evidence Header2 is nil",
|
||||
types.NewEvidence(clientID, chainID, suite.header, nil),
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
|
||||
{
|
||||
"valid evidence with different trusted headers",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-3, suite.now.Add(time.Minute), suite.valSet, bothValSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-3, suite.now.Add(time.Minute), suite.valSet, bothValSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
true,
|
||||
},
|
||||
{
|
||||
"trusted height is 0 in Header1",
|
||||
&ibctmtypes.Evidence{
|
||||
Header1: ibctmtypes.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
&types.Evidence{
|
||||
Header1: types.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
Header2: suite.header,
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"trusted height is 0 in Header2",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, 0, suite.now.Add(time.Minute), suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"trusted valset is nil in Header1",
|
||||
&ibctmtypes.Evidence{
|
||||
Header1: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
|
||||
&types.Evidence{
|
||||
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
|
||||
Header2: suite.header,
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"trusted valset is nil in Header2",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now.Add(time.Minute), suite.valSet, nil, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"invalid client ID ",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: "GAIA",
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"wrong chainID on header1",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
ChainId: "ethermint",
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"wrong chainID on header2",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader("ethermint", height, height-1, suite.now, suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"mismatched heights",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, 6, 4, suite.now, suite.valSet, suite.valSet, signers),
|
||||
Header2: types.CreateTestHeader(chainID, 6, 4, suite.now, suite.valSet, suite.valSet, signers),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"same block id",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: suite.header,
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error { return nil },
|
||||
func(ev *types.Evidence) error { return nil },
|
||||
false,
|
||||
},
|
||||
{
|
||||
"header 1 doesn't have 2/3 majority",
|
||||
&ibctmtypes.Evidence{
|
||||
Header1: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
&types.Evidence{
|
||||
Header1: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
Header2: suite.header,
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error {
|
||||
func(ev *types.Evidence) error {
|
||||
// voteSet contains only altVal which is less than 2/3 of total power (height/1height)
|
||||
wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(ev.Header1.GetHeight()), 1, tmproto.PrecommitType, altValSet)
|
||||
blockID, err := tmtypes.BlockIDFromProto(&ev.Header1.Commit.BlockID)
|
||||
|
@ -202,13 +214,13 @@ func (suite *TendermintTestSuite) TestEvidenceValidateBasic() {
|
|||
},
|
||||
{
|
||||
"header 2 doesn't have 2/3 majority",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error {
|
||||
func(ev *types.Evidence) error {
|
||||
// voteSet contains only altVal which is less than 2/3 of total power (height/1height)
|
||||
wrongVoteSet := tmtypes.NewVoteSet(chainID, int64(ev.Header2.GetHeight()), 1, tmproto.PrecommitType, altValSet)
|
||||
blockID, err := tmtypes.BlockIDFromProto(&ev.Header2.Commit.BlockID)
|
||||
|
@ -224,14 +236,14 @@ func (suite *TendermintTestSuite) TestEvidenceValidateBasic() {
|
|||
},
|
||||
{
|
||||
"validators sign off on wrong commit",
|
||||
&ibctmtypes.Evidence{
|
||||
&types.Evidence{
|
||||
Header1: suite.header,
|
||||
Header2: ibctmtypes.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
Header2: types.CreateTestHeader(chainID, height, height-1, suite.now, bothValSet, suite.valSet, bothSigners),
|
||||
ChainId: chainID,
|
||||
ClientId: clientID,
|
||||
},
|
||||
func(ev *ibctmtypes.Evidence) error {
|
||||
tmBlockID := ibctmtypes.MakeBlockID(tmhash.Sum([]byte("other_hash")), 3, tmhash.Sum([]byte("other_partset")))
|
||||
func(ev *types.Evidence) error {
|
||||
tmBlockID := types.MakeBlockID(tmhash.Sum([]byte("other_hash")), 3, tmhash.Sum([]byte("other_partset")))
|
||||
ev.Header2.Commit.BlockID = tmBlockID.ToProto()
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -55,10 +55,13 @@ func (h Header) GetTime() time.Time {
|
|||
// NOTE: TrustedHeight and TrustedValidators may be empty when creating client
|
||||
// with MsgCreateClient
|
||||
func (h Header) ValidateBasic(chainID string) error {
|
||||
if h.SignedHeader == nil {
|
||||
return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint signed header cannot be nil")
|
||||
}
|
||||
if h.Header == nil {
|
||||
return sdkerrors.Wrap(clienttypes.ErrInvalidHeader, "tendermint header cannot be nil")
|
||||
}
|
||||
tmSignedHeader, err := tmtypes.SignedHeaderFromProto(&h.SignedHeader)
|
||||
tmSignedHeader, err := tmtypes.SignedHeaderFromProto(h.SignedHeader)
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "header is not a tendermint header")
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (suite *TendermintTestSuite) TestGetTime() {
|
|||
|
||||
func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
|
||||
var (
|
||||
header types.Header
|
||||
header *types.Header
|
||||
chainID string
|
||||
)
|
||||
testCases := []struct {
|
||||
|
@ -34,9 +34,12 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
|
|||
expPass bool
|
||||
}{
|
||||
{"valid header", func() {}, true},
|
||||
{"signed header is nil", func() {
|
||||
{"header is nil", func() {
|
||||
header.Header = nil
|
||||
}, false},
|
||||
{"signed header is nil", func() {
|
||||
header.SignedHeader = nil
|
||||
}, false},
|
||||
{"signed header failed tendermint ValidateBasic", func() {
|
||||
header = suite.chainA.LastHeader
|
||||
chainID = "chainid"
|
||||
|
@ -59,6 +62,8 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
|
|||
tc := tc
|
||||
|
||||
suite.Run(tc.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
chainID = suite.chainA.ChainID // must be explicitly changed in malleate
|
||||
header = suite.chainA.LastHeader // must be explicitly changed in malleate
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
|
|||
// checkMisbehaviourHeader checks that a Header in Misbehaviour is valid evidence given
|
||||
// a trusted ConsensusState
|
||||
func checkMisbehaviourHeader(
|
||||
clientState *ClientState, consState *ConsensusState, header Header, currentTimestamp time.Time,
|
||||
clientState *ClientState, consState *ConsensusState, header *Header, currentTimestamp time.Time,
|
||||
) error {
|
||||
|
||||
tmTrustedValset, err := tmtypes.ValidatorSetFromProto(header.TrustedValidators)
|
||||
|
|
|
@ -21,35 +21,15 @@ var (
|
|||
_ evidenceexported.MsgSubmitEvidence = (*MsgSubmitClientMisbehaviour)(nil)
|
||||
)
|
||||
|
||||
// MsgCreateClient defines a message to create an IBC client
|
||||
type MsgCreateClient struct {
|
||||
ClientID string `json:"client_id" yaml:"client_id"`
|
||||
Header Header `json:"header" yaml:"header"`
|
||||
TrustLevel Fraction `json:"trust_level" yaml:"trust_level"`
|
||||
TrustingPeriod time.Duration `json:"trusting_period" yaml:"trusting_period"`
|
||||
UnbondingPeriod time.Duration `json:"unbonding_period" yaml:"unbonding_period"`
|
||||
MaxClockDrift time.Duration `json:"max_clock_drift" yaml:"max_clock_drift"`
|
||||
ProofSpecs []*ics23.ProofSpec `json:"proof_specs" yaml:"proof_specs"`
|
||||
Signer sdk.AccAddress `json:"address" yaml:"address"`
|
||||
}
|
||||
|
||||
// this is a constant to satisfy the linter
|
||||
const TODO = "TODO"
|
||||
|
||||
// dummy implementation of proto.Message
|
||||
func (msg *MsgCreateClient) Reset() {}
|
||||
func (msg *MsgCreateClient) String() string { return TODO }
|
||||
func (msg *MsgCreateClient) ProtoMessage() {}
|
||||
|
||||
// NewMsgCreateClient creates a new MsgCreateClient instance
|
||||
func NewMsgCreateClient(
|
||||
id string, header Header, trustLevel Fraction,
|
||||
id string, header *Header, trustLevel Fraction,
|
||||
trustingPeriod, unbondingPeriod, maxClockDrift time.Duration,
|
||||
specs []*ics23.ProofSpec, signer sdk.AccAddress,
|
||||
) *MsgCreateClient {
|
||||
|
||||
return &MsgCreateClient{
|
||||
ClientID: id,
|
||||
ClientId: id,
|
||||
Header: header,
|
||||
TrustLevel: trustLevel,
|
||||
TrustingPeriod: trustingPeriod,
|
||||
|
@ -84,7 +64,8 @@ func (msg MsgCreateClient) ValidateBasic() error {
|
|||
if msg.Signer.Empty() {
|
||||
return sdkerrors.ErrInvalidAddress
|
||||
}
|
||||
if msg.Header.SignedHeader.Header == nil {
|
||||
|
||||
if msg.Header == nil || msg.Header.SignedHeader == nil || msg.Header.SignedHeader.Header == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidHeader, "header cannot be nil")
|
||||
}
|
||||
// ValidateBasic of provided header with self-attested chain-id
|
||||
|
@ -106,12 +87,12 @@ func (msg MsgCreateClient) ValidateBasic() error {
|
|||
return sdkerrors.Wrap(ErrInvalidProofSpecs, "proof spec cannot be nil")
|
||||
}
|
||||
}
|
||||
return host.ClientIdentifierValidator(msg.ClientID)
|
||||
return host.ClientIdentifierValidator(msg.ClientId)
|
||||
}
|
||||
|
||||
// GetSignBytes implements sdk.Msg
|
||||
func (msg MsgCreateClient) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg))
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
||||
}
|
||||
|
||||
// GetSigners implements sdk.Msg
|
||||
|
@ -121,7 +102,7 @@ func (msg MsgCreateClient) GetSigners() []sdk.AccAddress {
|
|||
|
||||
// GetClientID implements clientexported.MsgCreateClient
|
||||
func (msg MsgCreateClient) GetClientID() string {
|
||||
return msg.ClientID
|
||||
return msg.ClientId
|
||||
}
|
||||
|
||||
// GetClientType implements clientexported.MsgCreateClient
|
||||
|
@ -149,22 +130,10 @@ func (msg MsgCreateClient) InitializeClientState() clientexported.ClientState {
|
|||
)
|
||||
}
|
||||
|
||||
// MsgUpdateClient defines a message to update an IBC client
|
||||
type MsgUpdateClient struct {
|
||||
ClientID string `json:"client_id" yaml:"client_id"`
|
||||
Header Header `json:"header" yaml:"header"`
|
||||
Signer sdk.AccAddress `json:"address" yaml:"address"`
|
||||
}
|
||||
|
||||
// dummy implementation of proto.Message
|
||||
func (msg *MsgUpdateClient) Reset() {}
|
||||
func (msg *MsgUpdateClient) String() string { return TODO }
|
||||
func (msg *MsgUpdateClient) ProtoMessage() {}
|
||||
|
||||
// NewMsgUpdateClient creates a new MsgUpdateClient instance
|
||||
func NewMsgUpdateClient(id string, header Header, signer sdk.AccAddress) *MsgUpdateClient {
|
||||
func NewMsgUpdateClient(id string, header *Header, signer sdk.AccAddress) *MsgUpdateClient {
|
||||
return &MsgUpdateClient{
|
||||
ClientID: id,
|
||||
ClientId: id,
|
||||
Header: header,
|
||||
Signer: signer,
|
||||
}
|
||||
|
@ -185,12 +154,19 @@ func (msg MsgUpdateClient) ValidateBasic() error {
|
|||
if msg.Signer.Empty() {
|
||||
return sdkerrors.ErrInvalidAddress
|
||||
}
|
||||
return host.ClientIdentifierValidator(msg.ClientID)
|
||||
if msg.Header == nil || msg.Header.SignedHeader == nil || msg.Header.Header == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidHeader, "header cannot be nil")
|
||||
}
|
||||
// ValidateBasic of provided header with self-attested chain-id
|
||||
if err := msg.Header.ValidateBasic(msg.Header.Header.GetChainID()); err != nil {
|
||||
return err
|
||||
}
|
||||
return host.ClientIdentifierValidator(msg.ClientId)
|
||||
}
|
||||
|
||||
// GetSignBytes implements sdk.Msg
|
||||
func (msg MsgUpdateClient) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg))
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
||||
}
|
||||
|
||||
// GetSigners implements sdk.Msg
|
||||
|
@ -200,7 +176,7 @@ func (msg MsgUpdateClient) GetSigners() []sdk.AccAddress {
|
|||
|
||||
// GetClientID implements clientexported.MsgUpdateClient
|
||||
func (msg MsgUpdateClient) GetClientID() string {
|
||||
return msg.ClientID
|
||||
return msg.ClientId
|
||||
}
|
||||
|
||||
// GetHeader implements clientexported.MsgUpdateClient
|
||||
|
@ -208,22 +184,10 @@ func (msg MsgUpdateClient) GetHeader() clientexported.Header {
|
|||
return msg.Header
|
||||
}
|
||||
|
||||
// MsgSubmitClientMisbehaviour defines an sdk.Msg type that supports submitting
|
||||
// Evidence for client misbehaviour.
|
||||
type MsgSubmitClientMisbehaviour struct {
|
||||
Evidence evidenceexported.Evidence `json:"evidence" yaml:"evidence"`
|
||||
Submitter sdk.AccAddress `json:"submitter" yaml:"submitter"`
|
||||
}
|
||||
|
||||
// dummy implementation of proto.Message
|
||||
func (msg MsgSubmitClientMisbehaviour) Reset() {}
|
||||
func (msg MsgSubmitClientMisbehaviour) String() string { return TODO }
|
||||
func (msg MsgSubmitClientMisbehaviour) ProtoMessage() {}
|
||||
|
||||
// NewMsgSubmitClientMisbehaviour creates a new MsgSubmitClientMisbehaviour
|
||||
// instance.
|
||||
func NewMsgSubmitClientMisbehaviour(e evidenceexported.Evidence, s sdk.AccAddress) MsgSubmitClientMisbehaviour {
|
||||
return MsgSubmitClientMisbehaviour{Evidence: e, Submitter: s}
|
||||
func NewMsgSubmitClientMisbehaviour(e *Evidence, s sdk.AccAddress) *MsgSubmitClientMisbehaviour {
|
||||
return &MsgSubmitClientMisbehaviour{Evidence: e, Submitter: s}
|
||||
}
|
||||
|
||||
// Route returns the MsgSubmitClientMisbehaviour's route.
|
||||
|
@ -252,7 +216,7 @@ func (msg MsgSubmitClientMisbehaviour) ValidateBasic() error {
|
|||
// GetSignBytes returns the raw bytes a signer is expected to sign when submitting
|
||||
// a MsgSubmitClientMisbehaviour message.
|
||||
func (msg MsgSubmitClientMisbehaviour) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(msg))
|
||||
return sdk.MustSortJSON(SubModuleCdc.MustMarshalJSON(&msg))
|
||||
}
|
||||
|
||||
// GetSigners returns the single expected signer for a MsgSubmitClientMisbehaviour.
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
types "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
)
|
||||
|
||||
func (suite *TendermintTestSuite) TestMsgCreateClientValidateBasic() {
|
||||
|
@ -28,7 +29,10 @@ func (suite *TendermintTestSuite) TestMsgCreateClientValidateBasic() {
|
|||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, types.DefaultTrustLevel, 0, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "zero trusting period passed"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, types.DefaultTrustLevel, trustingPeriod, 0, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "zero unbonding period passed"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), nil), false, "Empty address passed"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, types.Header{}, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "nil header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, &types.Header{}, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "empty header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, nil, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "nil header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, &types.Header{SignedHeader: nil}, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "nil header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, &types.Header{SignedHeader: &tmproto.SignedHeader{Header: nil}}, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "nil header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, invalidHeader, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, commitmenttypes.GetSDKSpecs(), signer), false, "invalid header"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, []*ics23.ProofSpec{nil}, signer), false, "invalid proof specs"},
|
||||
{types.NewMsgCreateClient(exported.ClientTypeTendermint, suite.header, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, nil, signer), false, "nil proof specs"},
|
||||
|
@ -54,9 +58,13 @@ func (suite *TendermintTestSuite) TestMsgUpdateClient() {
|
|||
expPass bool
|
||||
errMsg string
|
||||
}{
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, types.Header{}, signer), true, "success msg should pass"},
|
||||
{types.NewMsgUpdateClient("(badClient)", types.Header{}, signer), false, "invalid client id passed"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, types.Header{}, nil), false, "Empty address passed"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, suite.header, signer), true, "success msg should pass"},
|
||||
{types.NewMsgUpdateClient("(badClient)", &types.Header{}, signer), false, "invalid client id passed"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, suite.header, nil), false, "Empty address passed"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, &types.Header{}, nil), false, "empty Header"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, nil, nil), false, "nil header"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, &types.Header{SignedHeader: nil}, nil), false, "nil signed header"},
|
||||
{types.NewMsgUpdateClient(exported.ClientTypeTendermint, &types.Header{SignedHeader: &tmproto.SignedHeader{Header: nil}}, nil), false, "nil tendermint header"},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -36,12 +36,11 @@ type TendermintTestSuite struct {
|
|||
|
||||
// TODO: deprecate usage in favor of testing package
|
||||
ctx sdk.Context
|
||||
aminoCdc *codec.LegacyAmino
|
||||
cdc codec.Marshaler
|
||||
privVal tmtypes.PrivValidator
|
||||
valSet *tmtypes.ValidatorSet
|
||||
valsHash tmbytes.HexBytes
|
||||
header ibctmtypes.Header
|
||||
header *ibctmtypes.Header
|
||||
now time.Time
|
||||
headerTime time.Time
|
||||
clientTime time.Time
|
||||
|
@ -56,7 +55,6 @@ func (suite *TendermintTestSuite) SetupTest() {
|
|||
checkTx := false
|
||||
app := simapp.Setup(checkTx)
|
||||
|
||||
suite.aminoCdc = app.LegacyAmino()
|
||||
suite.cdc = app.AppCodec()
|
||||
|
||||
// now is the time of the current chain, must be after the updating header
|
||||
|
|
|
@ -22,7 +22,7 @@ func MakeBlockID(hash []byte, partSetSize uint32, partSetHash []byte) tmtypes.Bl
|
|||
}
|
||||
|
||||
// CreateTestHeader creates a mock header for testing only.
|
||||
func CreateTestHeader(chainID string, height, trustedHeight int64, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) Header {
|
||||
func CreateTestHeader(chainID string, height, trustedHeight int64, timestamp time.Time, tmValSet, tmTrustedVals *tmtypes.ValidatorSet, signers []tmtypes.PrivValidator) *Header {
|
||||
var (
|
||||
valSet *tmproto.ValidatorSet
|
||||
trustedVals *tmproto.ValidatorSet
|
||||
|
@ -72,8 +72,8 @@ func CreateTestHeader(chainID string, height, trustedHeight int64, timestamp tim
|
|||
}
|
||||
}
|
||||
|
||||
return Header{
|
||||
SignedHeader: signedHeader,
|
||||
return &Header{
|
||||
SignedHeader: &signedHeader,
|
||||
ValidatorSet: valSet,
|
||||
TrustedHeight: uint64(trustedHeight),
|
||||
TrustedValidators: trustedVals,
|
||||
|
|
|
@ -38,10 +38,10 @@ func (cs ClientState) CheckHeaderAndUpdateState(
|
|||
ctx sdk.Context, cdc codec.BinaryMarshaler, clientStore sdk.KVStore,
|
||||
header clientexported.Header,
|
||||
) (clientexported.ClientState, clientexported.ConsensusState, error) {
|
||||
tmHeader, ok := header.(Header)
|
||||
tmHeader, ok := header.(*Header)
|
||||
if !ok {
|
||||
return nil, nil, sdkerrors.Wrapf(
|
||||
clienttypes.ErrInvalidHeader, "expected type %T, got %T", Header{}, header,
|
||||
clienttypes.ErrInvalidHeader, "expected type %T, got %T", &Header{}, header,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
|
|||
}
|
||||
|
||||
// checkTrustedHeader checks that consensus state matches trusted fields of Header
|
||||
func checkTrustedHeader(header Header, consState *ConsensusState) error {
|
||||
func checkTrustedHeader(header *Header, consState *ConsensusState) error {
|
||||
if header.TrustedHeight != consState.Height {
|
||||
return sdkerrors.Wrapf(
|
||||
ErrInvalidHeaderHeight,
|
||||
|
@ -93,7 +93,7 @@ func checkTrustedHeader(header Header, consState *ConsensusState) error {
|
|||
// CONTRACT: consState.Height == header.TrustedHeight
|
||||
func checkValidity(
|
||||
clientState *ClientState, consState *ConsensusState,
|
||||
header Header, currentTimestamp time.Time,
|
||||
header *Header, currentTimestamp time.Time,
|
||||
) error {
|
||||
if err := checkTrustedHeader(header, consState); err != nil {
|
||||
return err
|
||||
|
@ -104,7 +104,7 @@ func checkValidity(
|
|||
return sdkerrors.Wrap(err, "trusted validator set in not tendermint validator set type")
|
||||
}
|
||||
|
||||
tmSignedHeader, err := tmtypes.SignedHeaderFromProto(&header.SignedHeader)
|
||||
tmSignedHeader, err := tmtypes.SignedHeaderFromProto(header.SignedHeader)
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(err, "signed header in not tendermint signed header type")
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ func checkValidity(
|
|||
}
|
||||
|
||||
// update the consensus state from a new header
|
||||
func update(clientState *ClientState, header Header) (*ClientState, *ConsensusState) {
|
||||
func update(clientState *ClientState, header *Header) (*ClientState, *ConsensusState) {
|
||||
if header.GetHeight() > clientState.LatestHeight {
|
||||
clientState.LatestHeight = header.GetHeight()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
|
|||
var (
|
||||
clientState *types.ClientState
|
||||
consensusState *types.ConsensusState
|
||||
newHeader types.Header
|
||||
newHeader *types.Header
|
||||
currentTime time.Time
|
||||
)
|
||||
|
||||
|
|
|
@ -7,11 +7,6 @@ import (
|
|||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
)
|
||||
|
||||
// REMOVE: once simapp uses proto
|
||||
func RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterConcrete(ClientState{}, "ibc/client/localhost/ClientState", nil)
|
||||
}
|
||||
|
||||
// RegisterInterfaces register the ibc interfaces submodule implementations to protobuf
|
||||
// Any.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
|
|
|
@ -43,33 +43,11 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||
)
|
||||
}
|
||||
|
||||
// RegisterCodec registers the necessary x/ibc/23-commitment interfaces and concrete types
|
||||
// on the provided Amino codec. These types are used for Amino JSON serialization.
|
||||
func RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterInterface((*exported.Root)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.Prefix)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.Path)(nil), nil)
|
||||
cdc.RegisterInterface((*exported.Proof)(nil), nil)
|
||||
|
||||
cdc.RegisterConcrete(MerkleRoot{}, "ibc/commitment/MerkleRoot", nil)
|
||||
cdc.RegisterConcrete(MerklePrefix{}, "ibc/commitment/MerklePrefix", nil)
|
||||
cdc.RegisterConcrete(MerklePath{}, "ibc/commitment/MerklePath", nil)
|
||||
cdc.RegisterConcrete(MerkleProof{}, "ibc/commitment/MerkleProof", nil)
|
||||
}
|
||||
|
||||
var (
|
||||
amino = codec.New()
|
||||
|
||||
// SubModuleCdc references the global x/ibc/23-commitmentl module codec. Note, the codec should
|
||||
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
|
||||
// still used for that purpose.
|
||||
// ONLY be used in certain instances of tests and for JSON encoding.
|
||||
//
|
||||
// The actual codec used for serialization should be provided to x/ibc/23-commitmentl and
|
||||
// defined at the application level.
|
||||
SubModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterCodec(amino)
|
||||
amino.Seal()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
|
@ -42,10 +41,9 @@ const (
|
|||
type IBCTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cdc *codec.LegacyAmino
|
||||
ctx sdk.Context
|
||||
app *simapp.SimApp
|
||||
header ibctmtypes.Header
|
||||
header *ibctmtypes.Header
|
||||
}
|
||||
|
||||
func (suite *IBCTestSuite) SetupTest() {
|
||||
|
@ -63,7 +61,6 @@ func (suite *IBCTestSuite) SetupTest() {
|
|||
|
||||
suite.header = ibctmtypes.CreateTestHeader(chainID, height, height-1, now, valSet, valSet, []tmtypes.PrivValidator{privVal})
|
||||
|
||||
suite.cdc = suite.app.LegacyAmino()
|
||||
suite.ctx = suite.app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/keeper"
|
||||
)
|
||||
|
||||
type KeeperTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cdc *codec.LegacyAmino
|
||||
ctx sdk.Context
|
||||
keeper *keeper.Keeper
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
isCheckTx := false
|
||||
app := simapp.Setup(isCheckTx)
|
||||
|
||||
suite.cdc = app.LegacyAmino()
|
||||
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{})
|
||||
suite.keeper = app.IBCKeeper
|
||||
}
|
||||
|
||||
func TestKeeperTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(KeeperTestSuite))
|
||||
}
|
|
@ -76,7 +76,7 @@ func NewUpdateClientCmd() *cobra.Command {
|
|||
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var header types.Header
|
||||
var header *types.Header
|
||||
if err := cdc.UnmarshalJSON([]byte(args[1]), &header); err != nil {
|
||||
// check for file path if JSON input is not provided
|
||||
contents, err := ioutil.ReadFile(args[1])
|
||||
|
@ -116,7 +116,7 @@ func NewSubmitMisbehaviourCmd() *cobra.Command {
|
|||
|
||||
cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry)
|
||||
|
||||
var ev types.Evidence
|
||||
var ev *types.Evidence
|
||||
if err := cdc.UnmarshalJSON([]byte(args[0]), &ev); err != nil {
|
||||
// check for file path if JSON input is not provided
|
||||
contents, err := ioutil.ReadFile(args[0])
|
||||
|
|
|
@ -15,7 +15,7 @@ func (suite *SoloMachineTestSuite) TestEvidence() {
|
|||
suite.Require().Equal(suite.solomachine.ClientID, ev.GetClientID())
|
||||
suite.Require().Equal("client", ev.Route())
|
||||
suite.Require().Equal("client_misbehaviour", ev.Type())
|
||||
suite.Require().Equal(tmbytes.HexBytes(tmhash.Sum(types.SubModuleCdc.MustMarshalBinaryBare(&ev))), ev.Hash())
|
||||
suite.Require().Equal(tmbytes.HexBytes(tmhash.Sum(types.SubModuleCdc.MustMarshalBinaryBare(ev))), ev.Hash())
|
||||
suite.Require().Equal(int64(suite.solomachine.Sequence), ev.GetHeight())
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func (suite *SoloMachineTestSuite) TestEvidenceValidateBasic() {
|
|||
suite.Run(tc.name, func() {
|
||||
|
||||
ev := suite.solomachine.CreateEvidence()
|
||||
tc.malleateEvidence(&ev)
|
||||
tc.malleateEvidence(ev)
|
||||
|
||||
err := ev.ValidateBasic()
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ func (suite *SoloMachineTestSuite) TestHeaderValidateBasic() {
|
|||
|
||||
cases := []struct {
|
||||
name string
|
||||
header types.Header
|
||||
header *types.Header
|
||||
expPass bool
|
||||
}{
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ func (suite *SoloMachineTestSuite) TestHeaderValidateBasic() {
|
|||
},
|
||||
{
|
||||
"sequence is zero",
|
||||
types.Header{
|
||||
&types.Header{
|
||||
Sequence: 0,
|
||||
Signature: header.Signature,
|
||||
NewPublicKey: header.NewPublicKey,
|
||||
|
@ -29,7 +29,7 @@ func (suite *SoloMachineTestSuite) TestHeaderValidateBasic() {
|
|||
},
|
||||
{
|
||||
"signature is empty",
|
||||
types.Header{
|
||||
&types.Header{
|
||||
Sequence: header.Sequence,
|
||||
Signature: []byte{},
|
||||
NewPublicKey: header.NewPublicKey,
|
||||
|
@ -38,7 +38,7 @@ func (suite *SoloMachineTestSuite) TestHeaderValidateBasic() {
|
|||
},
|
||||
{
|
||||
"public key is nil",
|
||||
types.Header{
|
||||
&types.Header{
|
||||
Sequence: header.Sequence,
|
||||
Signature: header.Signature,
|
||||
NewPublicKey: nil,
|
||||
|
|
|
@ -18,11 +18,11 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
|
|||
misbehaviour clientexported.Misbehaviour,
|
||||
) (clientexported.ClientState, error) {
|
||||
|
||||
evidence, ok := misbehaviour.(Evidence)
|
||||
evidence, ok := misbehaviour.(*Evidence)
|
||||
if !ok {
|
||||
return nil, sdkerrors.Wrapf(
|
||||
clienttypes.ErrInvalidClientType,
|
||||
"evidence type %T, expected %T", misbehaviour, Evidence{},
|
||||
"evidence type %T, expected %T", misbehaviour, &Evidence{},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func (cs ClientState) CheckMisbehaviourAndUpdateState(
|
|||
// over two different messages at the same sequence.
|
||||
// NOTE: a check that the evidence message data are not equal is done by
|
||||
// evidence.ValidateBasic which is called by the 02-client keeper.
|
||||
func checkMisbehaviour(clientState ClientState, evidence Evidence) error {
|
||||
func checkMisbehaviour(clientState ClientState, evidence *Evidence) error {
|
||||
pubKey := clientState.ConsensusState.GetPubKey()
|
||||
|
||||
data := EvidenceSignBytes(evidence.Sequence, evidence.SignatureOne.Data)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
evidenceexported "github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
||||
)
|
||||
|
||||
|
@ -34,6 +35,9 @@ func (msg MsgCreateClient) Type() string {
|
|||
|
||||
// ValidateBasic implements sdk.Msg
|
||||
func (msg MsgCreateClient) ValidateBasic() error {
|
||||
if msg.ConsensusState == nil {
|
||||
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be nil")
|
||||
}
|
||||
if err := msg.ConsensusState.ValidateBasic(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -72,7 +76,7 @@ func (msg MsgCreateClient) InitializeClientState() clientexported.ClientState {
|
|||
}
|
||||
|
||||
// NewMsgUpdateClient creates a new MsgUpdateClient instance
|
||||
func NewMsgUpdateClient(id string, header Header) *MsgUpdateClient {
|
||||
func NewMsgUpdateClient(id string, header *Header) *MsgUpdateClient {
|
||||
return &MsgUpdateClient{
|
||||
ClientId: id,
|
||||
Header: header,
|
||||
|
@ -91,6 +95,9 @@ func (msg MsgUpdateClient) Type() string {
|
|||
|
||||
// ValidateBasic implements sdk.Msg
|
||||
func (msg MsgUpdateClient) ValidateBasic() error {
|
||||
if msg.Header == nil {
|
||||
return sdkerrors.Wrap(ErrInvalidHeader, "header cannot be nil")
|
||||
}
|
||||
if err := msg.Header.ValidateBasic(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -119,7 +126,7 @@ func (msg MsgUpdateClient) GetHeader() clientexported.Header {
|
|||
|
||||
// NewMsgSubmitClientMisbehaviour creates a new MsgSubmitClientMisbehaviour
|
||||
// instance.
|
||||
func NewMsgSubmitClientMisbehaviour(e Evidence, s sdk.AccAddress) *MsgSubmitClientMisbehaviour {
|
||||
func NewMsgSubmitClientMisbehaviour(e *Evidence, s sdk.AccAddress) *MsgSubmitClientMisbehaviour {
|
||||
return &MsgSubmitClientMisbehaviour{Evidence: e, Submitter: s}
|
||||
}
|
||||
|
||||
|
@ -155,7 +162,7 @@ func (msg MsgSubmitClientMisbehaviour) GetSigners() []sdk.AccAddress {
|
|||
}
|
||||
|
||||
func (msg MsgSubmitClientMisbehaviour) GetEvidence() evidenceexported.Evidence {
|
||||
return &msg.Evidence
|
||||
return msg.Evidence
|
||||
}
|
||||
|
||||
func (msg MsgSubmitClientMisbehaviour) GetSubmitter() sdk.AccAddress {
|
||||
|
|
|
@ -12,6 +12,7 @@ func (suite *SoloMachineTestSuite) TestMsgCreateClientValidateBasic() {
|
|||
}{
|
||||
{"valid msg", types.NewMsgCreateClient(suite.solomachine.ClientID, suite.solomachine.ConsensusState()), true},
|
||||
{"invalid client id", types.NewMsgCreateClient("(BADCLIENTID)", suite.solomachine.ConsensusState()), false},
|
||||
{"nil consensus state", types.NewMsgCreateClient(suite.solomachine.ClientID, nil), false},
|
||||
{"invalid consensus state with zero sequence", types.NewMsgCreateClient(suite.solomachine.ClientID, &types.ConsensusState{0, suite.solomachine.ConsensusState().PublicKey, suite.solomachine.Time}), false},
|
||||
{"invalid consensus state with zero timestamp", types.NewMsgCreateClient(suite.solomachine.ClientID, &types.ConsensusState{1, suite.solomachine.ConsensusState().PublicKey, 0}), false},
|
||||
{"invalid consensus state with nil pubkey", types.NewMsgCreateClient(suite.solomachine.ClientID, &types.ConsensusState{suite.solomachine.Sequence, nil, suite.solomachine.Time}), false},
|
||||
|
@ -37,9 +38,10 @@ func (suite *SoloMachineTestSuite) TestMsgUpdateClientValidateBasic() {
|
|||
}{
|
||||
{"valid msg", types.NewMsgUpdateClient(suite.solomachine.ClientID, header), true},
|
||||
{"invalid client id", types.NewMsgUpdateClient("(BADCLIENTID)", header), false},
|
||||
{"invalid header - sequence is zero", types.NewMsgUpdateClient(suite.solomachine.ClientID, types.Header{0, header.Signature, header.NewPublicKey}), false},
|
||||
{"invalid header - signature is empty", types.NewMsgUpdateClient(suite.solomachine.ClientID, types.Header{header.Sequence, []byte{}, header.NewPublicKey}), false},
|
||||
{"invalid header - pubkey is empty", types.NewMsgUpdateClient(suite.solomachine.ClientID, types.Header{header.Sequence, header.Signature, nil}), false},
|
||||
{"nil header", types.NewMsgUpdateClient(suite.solomachine.ClientID, nil), false},
|
||||
{"invalid header - sequence is zero", types.NewMsgUpdateClient(suite.solomachine.ClientID, &types.Header{0, header.Signature, header.NewPublicKey}), false},
|
||||
{"invalid header - signature is empty", types.NewMsgUpdateClient(suite.solomachine.ClientID, &types.Header{header.Sequence, []byte{}, header.NewPublicKey}), false},
|
||||
{"invalid header - pubkey is empty", types.NewMsgUpdateClient(suite.solomachine.ClientID, &types.Header{header.Sequence, header.Signature, nil}), false},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
|
@ -38,7 +38,7 @@ func EvidenceSignBytes(sequence uint64, data []byte) []byte {
|
|||
// HeaderSignBytes returns the sign bytes for verification of misbehaviour.
|
||||
//
|
||||
// Format: {sequence}{header.newPubKey}
|
||||
func HeaderSignBytes(header Header) []byte {
|
||||
func HeaderSignBytes(header *Header) []byte {
|
||||
return append(
|
||||
sdk.Uint64ToBigEndian(header.Sequence),
|
||||
header.GetPubKey().Bytes()...,
|
||||
|
|
|
@ -311,8 +311,8 @@ var xxx_messageInfo_MsgCreateClient proto.InternalMessageInfo
|
|||
|
||||
// MsgUpdateClient defines a message to update an IBC client
|
||||
type MsgUpdateClient struct {
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"`
|
||||
Header Header `protobuf:"bytes,2,opt,name=header,proto3" json:"header"`
|
||||
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty" yaml:"client_id"`
|
||||
Header *Header `protobuf:"bytes,2,opt,name=header,proto3" json:"header,omitempty"`
|
||||
}
|
||||
|
||||
func (m *MsgUpdateClient) Reset() { *m = MsgUpdateClient{} }
|
||||
|
@ -352,7 +352,7 @@ var xxx_messageInfo_MsgUpdateClient proto.InternalMessageInfo
|
|||
// arbitrary Evidence.
|
||||
type MsgSubmitClientMisbehaviour struct {
|
||||
Submitter github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=submitter,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"submitter,omitempty"`
|
||||
Evidence Evidence `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence"`
|
||||
Evidence *Evidence `protobuf:"bytes,2,opt,name=evidence,proto3" json:"evidence,omitempty"`
|
||||
}
|
||||
|
||||
func (m *MsgSubmitClientMisbehaviour) Reset() { *m = MsgSubmitClientMisbehaviour{} }
|
||||
|
@ -405,52 +405,52 @@ func init() {
|
|||
}
|
||||
|
||||
var fileDescriptor_6cc2ee18f7f86d4e = []byte{
|
||||
// 718 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0x4d, 0x6f, 0xd3, 0x30,
|
||||
0x18, 0x6e, 0xba, 0x6a, 0x6a, 0xbd, 0xd1, 0x8d, 0xa8, 0x43, 0xa5, 0x4c, 0xcd, 0x14, 0x09, 0x6d,
|
||||
0x1c, 0x96, 0x28, 0x70, 0xdb, 0x6d, 0x29, 0x93, 0x80, 0x69, 0x1a, 0x4a, 0x87, 0x84, 0x00, 0xa9,
|
||||
0x72, 0x12, 0xaf, 0xb5, 0xd6, 0xc4, 0x21, 0x76, 0x5a, 0xca, 0x2f, 0xe0, 0x08, 0x37, 0x8e, 0xfc,
|
||||
0x01, 0x24, 0x7e, 0x02, 0x9c, 0xd8, 0x09, 0xed, 0xc8, 0x29, 0x42, 0xdb, 0x3f, 0xe8, 0x91, 0x13,
|
||||
0x6a, 0xec, 0xa6, 0x4d, 0x35, 0xad, 0xe2, 0x43, 0xe2, 0x14, 0xfb, 0xcd, 0xeb, 0xe7, 0x7d, 0x9e,
|
||||
0xf7, 0xc3, 0x06, 0x06, 0xb6, 0x1d, 0xbd, 0x8b, 0xdb, 0x1d, 0xe6, 0x74, 0x31, 0xf2, 0x19, 0xd5,
|
||||
0x29, 0xe9, 0x12, 0x0f, 0x3a, 0x1d, 0xec, 0x23, 0xbd, 0x67, 0x4c, 0x6f, 0xb5, 0x20, 0x24, 0x8c,
|
||||
0xc8, 0x0a, 0xb6, 0x1d, 0x6d, 0xfa, 0x88, 0x36, 0xed, 0xd3, 0x33, 0x6a, 0x9b, 0x0e, 0xa1, 0x1e,
|
||||
0xa1, 0xba, 0x0d, 0x29, 0xd2, 0x9d, 0x70, 0x10, 0x30, 0xa2, 0xf7, 0x0c, 0x1b, 0x31, 0x68, 0x88,
|
||||
0x2d, 0x47, 0xaa, 0x55, 0xda, 0xa4, 0x4d, 0x92, 0xa5, 0x3e, 0x5a, 0x71, 0xab, 0xfa, 0x4d, 0x02,
|
||||
0x4b, 0x8d, 0x04, 0xb9, 0xc9, 0x20, 0x43, 0x72, 0x03, 0xac, 0x1c, 0x87, 0xe4, 0x35, 0xf2, 0x5b,
|
||||
0x14, 0xbd, 0x8c, 0x90, 0xef, 0xa0, 0xaa, 0xb4, 0x21, 0x6d, 0x15, 0xcc, 0xda, 0x30, 0x56, 0x6e,
|
||||
0x0c, 0xa0, 0xd7, 0xdd, 0x51, 0x67, 0x1c, 0x54, 0xab, 0xcc, 0x2d, 0x4d, 0x61, 0x90, 0x19, 0x58,
|
||||
0x71, 0x88, 0x4f, 0x91, 0x4f, 0x23, 0xda, 0xa2, 0x23, 0xdc, 0x6a, 0x7e, 0x43, 0xda, 0x5a, 0xba,
|
||||
0xab, 0x6b, 0x73, 0xe4, 0x68, 0x8d, 0xf1, 0xb9, 0x84, 0xce, 0x74, 0xd4, 0x19, 0x44, 0xd5, 0x2a,
|
||||
0x3b, 0x19, 0xdf, 0x9d, 0xc2, 0x9b, 0x0f, 0x4a, 0x4e, 0xfd, 0x28, 0x81, 0x72, 0x16, 0x44, 0xae,
|
||||
0x81, 0x62, 0x56, 0x8c, 0x95, 0xee, 0xe5, 0xe7, 0x00, 0x04, 0x91, 0xdd, 0xc5, 0x4e, 0xeb, 0x04,
|
||||
0x0d, 0x04, 0xcb, 0xdb, 0x1a, 0xcf, 0xa9, 0x36, 0xca, 0xa9, 0x26, 0x92, 0x28, 0x72, 0xaa, 0x3d,
|
||||
0x4e, 0xbc, 0xf7, 0xd1, 0xc0, 0x5c, 0x1b, 0xc6, 0xca, 0x75, 0xce, 0x6d, 0x02, 0xa1, 0x5a, 0xa5,
|
||||
0x60, 0xec, 0x21, 0xaf, 0x83, 0x12, 0xc3, 0x1e, 0xa2, 0x0c, 0x7a, 0x41, 0x75, 0x21, 0x89, 0x3c,
|
||||
0x31, 0x08, 0xbe, 0x9f, 0x24, 0xb0, 0xf8, 0x00, 0x41, 0x17, 0x85, 0x57, 0xf2, 0x5c, 0x07, 0x25,
|
||||
0x8a, 0xdb, 0x3e, 0x64, 0x51, 0xc8, 0x93, 0xb9, 0x6c, 0x4d, 0x0c, 0xf2, 0x31, 0x28, 0xfb, 0xa8,
|
||||
0xdf, 0x9a, 0x52, 0xb2, 0xf0, 0x3b, 0x4a, 0x6e, 0x0e, 0x63, 0x65, 0x8d, 0x2b, 0xc9, 0xc2, 0xa8,
|
||||
0xd6, 0xb2, 0x8f, 0xfa, 0xa9, 0xa3, 0xa0, 0xfc, 0x35, 0x0f, 0x8a, 0x7b, 0x3d, 0xec, 0x26, 0xc4,
|
||||
0x0c, 0x50, 0xe2, 0xa5, 0x6c, 0x61, 0x37, 0x61, 0x5d, 0x32, 0x2b, 0xc3, 0x58, 0x59, 0x15, 0x45,
|
||||
0x1b, 0xff, 0x52, 0xad, 0x22, 0x5f, 0x3f, 0x74, 0x33, 0x3a, 0xf3, 0x33, 0x3a, 0x03, 0x70, 0x2d,
|
||||
0x95, 0xd5, 0x22, 0x3e, 0x12, 0x42, 0x8c, 0xb9, 0x8d, 0xd3, 0x1c, 0x9f, 0xda, 0xf5, 0xdd, 0xfb,
|
||||
0x90, 0x41, 0xb3, 0x3a, 0x8c, 0x95, 0x0a, 0x67, 0x91, 0x41, 0x54, 0xad, 0xe5, 0x74, 0x7f, 0xe8,
|
||||
0xcf, 0x44, 0x64, 0x7d, 0x52, 0x2d, 0xfc, 0xd3, 0x88, 0xac, 0x4f, 0xa6, 0x23, 0x1e, 0xf5, 0xc9,
|
||||
0x4e, 0x71, 0x94, 0xc5, 0xf7, 0xa3, 0x4c, 0x3e, 0x02, 0xab, 0xb3, 0x28, 0xd9, 0x4a, 0x4b, 0xb3,
|
||||
0x95, 0x96, 0x41, 0xc1, 0x85, 0x0c, 0x8a, 0x16, 0x48, 0xd6, 0xa2, 0x2a, 0x4f, 0x41, 0xe5, 0x68,
|
||||
0xdc, 0x5b, 0xc8, 0x4d, 0x61, 0xe7, 0xe0, 0x65, 0x5a, 0x34, 0x7f, 0x79, 0x8b, 0x7e, 0x96, 0xc0,
|
||||
0xca, 0x01, 0x6d, 0x37, 0x42, 0x04, 0x19, 0xe2, 0x97, 0xc5, 0x9f, 0x94, 0xfd, 0x7f, 0xde, 0x0a,
|
||||
0xef, 0xb8, 0x84, 0x27, 0x81, 0xfb, 0x57, 0x12, 0xf6, 0xc0, 0x62, 0x27, 0x99, 0x55, 0xc1, 0x7c,
|
||||
0x73, 0x2e, 0x73, 0x3e, 0xda, 0x66, 0xe1, 0x34, 0x56, 0x72, 0x96, 0x38, 0x2c, 0x38, 0x7d, 0x91,
|
||||
0xc0, 0xad, 0x03, 0xda, 0x6e, 0x46, 0xb6, 0x87, 0x19, 0xe7, 0x74, 0x80, 0xa9, 0x8d, 0x3a, 0xb0,
|
||||
0x87, 0x49, 0x14, 0xca, 0x87, 0xa0, 0x44, 0x93, 0x7f, 0x0c, 0x85, 0xbc, 0x70, 0xa6, 0xf1, 0x33,
|
||||
0x56, 0xb6, 0xdb, 0x98, 0x75, 0x22, 0x5b, 0x73, 0x88, 0xa7, 0x8b, 0xbb, 0x9f, 0x7f, 0xb6, 0xa9,
|
||||
0x7b, 0xa2, 0xb3, 0x41, 0x80, 0xa8, 0xb6, 0xeb, 0x38, 0xbb, 0xae, 0x1b, 0x22, 0x4a, 0xad, 0x09,
|
||||
0x86, 0xbc, 0x0f, 0x8a, 0x48, 0x8c, 0xad, 0xe0, 0x7f, 0x67, 0x2e, 0xff, 0xf1, 0x9c, 0x0b, 0x05,
|
||||
0x29, 0x00, 0xd7, 0x60, 0xbe, 0x38, 0x3d, 0xaf, 0x4b, 0x67, 0xe7, 0x75, 0xe9, 0xc7, 0x79, 0x5d,
|
||||
0x7a, 0x7b, 0x51, 0xcf, 0x9d, 0x5d, 0xd4, 0x73, 0xdf, 0x2f, 0xea, 0xb9, 0x67, 0xe6, 0x95, 0x34,
|
||||
0x5f, 0xe9, 0xe9, 0x53, 0xb8, 0x7d, 0xd9, 0x5b, 0x98, 0xc8, 0xb0, 0x17, 0x93, 0x37, 0xea, 0xde,
|
||||
0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x93, 0xca, 0x1e, 0x4a, 0x38, 0x07, 0x00, 0x00,
|
||||
// 716 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0x4d, 0x6f, 0xd3, 0x4c,
|
||||
0x10, 0x8e, 0xd3, 0xa8, 0x4a, 0xb6, 0x7d, 0xd3, 0xbe, 0x56, 0x8a, 0x42, 0xa8, 0xe2, 0xca, 0x12,
|
||||
0x6a, 0x39, 0xd4, 0x96, 0xe1, 0xd6, 0x0b, 0xaa, 0x43, 0x25, 0x3e, 0x54, 0x15, 0x39, 0x45, 0x42,
|
||||
0x80, 0x14, 0xad, 0xed, 0xad, 0xb3, 0x6a, 0xec, 0x35, 0xde, 0x75, 0x42, 0xf8, 0x05, 0x48, 0x5c,
|
||||
0x38, 0x72, 0xe4, 0x0f, 0x20, 0x71, 0xe7, 0xc2, 0x0d, 0x4e, 0xa8, 0x47, 0x4e, 0x11, 0x6a, 0xfe,
|
||||
0x41, 0x8e, 0x9c, 0x50, 0xbc, 0x1b, 0x27, 0x8e, 0xaa, 0x46, 0x7c, 0x48, 0x9c, 0xbc, 0x3b, 0x9e,
|
||||
0x79, 0xe6, 0x79, 0x66, 0x66, 0x77, 0x81, 0x81, 0x6d, 0x47, 0xef, 0x60, 0xaf, 0xcd, 0x9c, 0x0e,
|
||||
0x46, 0x01, 0xa3, 0x3a, 0x25, 0x1d, 0xe2, 0x43, 0xa7, 0x8d, 0x03, 0xa4, 0x77, 0x8d, 0xd9, 0xad,
|
||||
0x16, 0x46, 0x84, 0x11, 0x59, 0xc1, 0xb6, 0xa3, 0xcd, 0x86, 0x68, 0xb3, 0x3e, 0x5d, 0xa3, 0xb6,
|
||||
0xed, 0x10, 0xea, 0x13, 0xaa, 0xdb, 0x90, 0x22, 0xdd, 0x89, 0xfa, 0x21, 0x23, 0x7a, 0xd7, 0xb0,
|
||||
0x11, 0x83, 0x86, 0xd8, 0x72, 0xa4, 0x5a, 0xc5, 0x23, 0x1e, 0x49, 0x96, 0xfa, 0x78, 0xc5, 0xad,
|
||||
0xea, 0x57, 0x09, 0xac, 0x34, 0x12, 0xe4, 0x26, 0x83, 0x0c, 0xc9, 0x0d, 0xb0, 0x76, 0x12, 0x91,
|
||||
0x97, 0x28, 0x68, 0x51, 0xf4, 0x3c, 0x46, 0x81, 0x83, 0xaa, 0xd2, 0x96, 0xb4, 0x53, 0x30, 0x6b,
|
||||
0xa3, 0x81, 0x72, 0xa5, 0x0f, 0xfd, 0xce, 0x9e, 0x3a, 0xe7, 0xa0, 0x5a, 0x65, 0x6e, 0x69, 0x0a,
|
||||
0x83, 0xcc, 0xc0, 0x9a, 0x43, 0x02, 0x8a, 0x02, 0x1a, 0xd3, 0x16, 0x1d, 0xe3, 0x56, 0xf3, 0x5b,
|
||||
0xd2, 0xce, 0xca, 0x4d, 0x5d, 0x5b, 0x20, 0x47, 0x6b, 0x4c, 0xe2, 0x12, 0x3a, 0xb3, 0x59, 0xe7,
|
||||
0x10, 0x55, 0xab, 0xec, 0x64, 0x7c, 0xf7, 0x0a, 0xaf, 0xde, 0x29, 0x39, 0xf5, 0xbd, 0x04, 0xca,
|
||||
0x59, 0x10, 0xb9, 0x06, 0x8a, 0x59, 0x31, 0x56, 0xba, 0x97, 0x9f, 0x02, 0x10, 0xc6, 0x76, 0x07,
|
||||
0x3b, 0xad, 0x53, 0xd4, 0x17, 0x2c, 0xaf, 0x6b, 0xbc, 0xa6, 0xda, 0xb8, 0xa6, 0x9a, 0x28, 0xa2,
|
||||
0xa8, 0xa9, 0xf6, 0x30, 0xf1, 0x7e, 0x80, 0xfa, 0xe6, 0xc6, 0x68, 0xa0, 0xfc, 0xcf, 0xb9, 0x4d,
|
||||
0x21, 0x54, 0xab, 0x14, 0x4e, 0x3c, 0xe4, 0x4d, 0x50, 0x62, 0xd8, 0x47, 0x94, 0x41, 0x3f, 0xac,
|
||||
0x2e, 0x25, 0x99, 0xa7, 0x06, 0xc1, 0xf7, 0x83, 0x04, 0x96, 0xef, 0x22, 0xe8, 0xa2, 0xe8, 0x52,
|
||||
0x9e, 0x9b, 0xa0, 0x44, 0xb1, 0x17, 0x40, 0x16, 0x47, 0xbc, 0x98, 0xab, 0xd6, 0xd4, 0x20, 0x9f,
|
||||
0x80, 0x72, 0x80, 0x7a, 0xad, 0x19, 0x25, 0x4b, 0xbf, 0xa2, 0xe4, 0xea, 0x68, 0xa0, 0x6c, 0x70,
|
||||
0x25, 0x59, 0x18, 0xd5, 0x5a, 0x0d, 0x50, 0x2f, 0x75, 0x14, 0x94, 0x3f, 0xe7, 0x41, 0xf1, 0xa0,
|
||||
0x8b, 0xdd, 0x84, 0x98, 0x01, 0x4a, 0xbc, 0x95, 0x2d, 0xec, 0x26, 0xac, 0x4b, 0x66, 0x65, 0x34,
|
||||
0x50, 0xd6, 0x45, 0xd3, 0x26, 0xbf, 0x54, 0xab, 0xc8, 0xd7, 0xf7, 0xdc, 0x8c, 0xce, 0xfc, 0x9c,
|
||||
0xce, 0x10, 0xfc, 0x97, 0xca, 0x6a, 0x91, 0x00, 0x09, 0x21, 0xc6, 0xc2, 0xc1, 0x69, 0x4e, 0xa2,
|
||||
0xf6, 0x03, 0xf7, 0x0e, 0x64, 0xd0, 0xac, 0x8e, 0x06, 0x4a, 0x85, 0xb3, 0xc8, 0x20, 0xaa, 0xd6,
|
||||
0x6a, 0xba, 0x3f, 0x0a, 0xe6, 0x32, 0xb2, 0x1e, 0xa9, 0x16, 0xfe, 0x6a, 0x46, 0xd6, 0x23, 0xb3,
|
||||
0x19, 0x8f, 0x7b, 0x64, 0xaf, 0x38, 0xae, 0xe2, 0xdb, 0x71, 0x25, 0xef, 0x83, 0xf5, 0x79, 0x94,
|
||||
0x6c, 0xa7, 0xa5, 0xf9, 0x4e, 0xcb, 0xa0, 0xe0, 0x42, 0x06, 0xc5, 0x08, 0x24, 0x6b, 0xd1, 0x95,
|
||||
0xc7, 0xa0, 0x72, 0x3c, 0x99, 0x2d, 0xe4, 0xa6, 0xb0, 0x0b, 0xf0, 0x32, 0x23, 0x9a, 0xbf, 0x78,
|
||||
0x44, 0x3f, 0x49, 0x60, 0xed, 0x90, 0x7a, 0x8d, 0x08, 0x41, 0x86, 0xf8, 0x65, 0xf1, 0x3b, 0x6d,
|
||||
0xff, 0x97, 0xb7, 0xc2, 0x6b, 0x2e, 0xe1, 0x51, 0xe8, 0xfe, 0x91, 0x84, 0xdb, 0x60, 0xb9, 0x9d,
|
||||
0x9c, 0x55, 0xc1, 0x7c, 0x7b, 0x21, 0x73, 0x7e, 0xb4, 0x2d, 0x11, 0x26, 0xd8, 0x7c, 0x94, 0xc0,
|
||||
0xb5, 0x43, 0xea, 0x35, 0x63, 0xdb, 0xc7, 0x8c, 0xb3, 0x39, 0xc4, 0xd4, 0x46, 0x6d, 0xd8, 0xc5,
|
||||
0x24, 0x8e, 0xe4, 0x23, 0x50, 0xa2, 0xc9, 0x3f, 0x86, 0x22, 0xde, 0x32, 0xd3, 0xf8, 0x31, 0x50,
|
||||
0x76, 0x3d, 0xcc, 0xda, 0xb1, 0xad, 0x39, 0xc4, 0xd7, 0xc5, 0xad, 0xcf, 0x3f, 0xbb, 0xd4, 0x3d,
|
||||
0xd5, 0x59, 0x3f, 0x44, 0x54, 0xdb, 0x77, 0x9c, 0x7d, 0xd7, 0x8d, 0x10, 0xa5, 0xd6, 0x14, 0x43,
|
||||
0x3e, 0x00, 0x45, 0x24, 0x0e, 0xac, 0x60, 0x7e, 0x63, 0x21, 0xf3, 0xc9, 0x09, 0xb7, 0xd2, 0x50,
|
||||
0xce, 0xde, 0x7c, 0xf6, 0xe5, 0xbc, 0x2e, 0x9d, 0x9d, 0xd7, 0xa5, 0xef, 0xe7, 0x75, 0xe9, 0xcd,
|
||||
0xb0, 0x9e, 0x3b, 0x1b, 0xd6, 0x73, 0xdf, 0x86, 0xf5, 0xdc, 0x13, 0xf3, 0x52, 0x82, 0x2f, 0xf4,
|
||||
0xf4, 0xf9, 0xdb, 0xbd, 0xe8, 0xfd, 0x4b, 0x04, 0xd8, 0xcb, 0xc9, 0xbb, 0x74, 0xeb, 0x67, 0x00,
|
||||
0x00, 0x00, 0xff, 0xff, 0xee, 0x37, 0x2c, 0xb2, 0x2c, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *ClientState) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -778,16 +778,18 @@ func (m *MsgUpdateClient) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
{
|
||||
size, err := m.Header.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if m.Header != nil {
|
||||
{
|
||||
size, err := m.Header.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintSolomachine(dAtA, i, uint64(size))
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintSolomachine(dAtA, i, uint64(size))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
if len(m.ClientId) > 0 {
|
||||
i -= len(m.ClientId)
|
||||
copy(dAtA[i:], m.ClientId)
|
||||
|
@ -818,16 +820,18 @@ func (m *MsgSubmitClientMisbehaviour) MarshalToSizedBuffer(dAtA []byte) (int, er
|
|||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
{
|
||||
size, err := m.Evidence.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if m.Evidence != nil {
|
||||
{
|
||||
size, err := m.Evidence.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintSolomachine(dAtA, i, uint64(size))
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintSolomachine(dAtA, i, uint64(size))
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
if len(m.Submitter) > 0 {
|
||||
i -= len(m.Submitter)
|
||||
copy(dAtA[i:], m.Submitter)
|
||||
|
@ -988,8 +992,10 @@ func (m *MsgUpdateClient) Size() (n int) {
|
|||
if l > 0 {
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
}
|
||||
l = m.Header.Size()
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
if m.Header != nil {
|
||||
l = m.Header.Size()
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
@ -1003,8 +1009,10 @@ func (m *MsgSubmitClientMisbehaviour) Size() (n int) {
|
|||
if l > 0 {
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
}
|
||||
l = m.Evidence.Size()
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
if m.Evidence != nil {
|
||||
l = m.Evidence.Size()
|
||||
n += 1 + l + sovSolomachine(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
@ -2005,6 +2013,9 @@ func (m *MsgUpdateClient) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.Header == nil {
|
||||
m.Header = &Header{}
|
||||
}
|
||||
if err := m.Header.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2125,6 +2136,9 @@ func (m *MsgSubmitClientMisbehaviour) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.Evidence == nil {
|
||||
m.Evidence = &Evidence{}
|
||||
}
|
||||
if err := m.Evidence.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ func (cs ClientState) CheckHeaderAndUpdateState(
|
|||
ctx sdk.Context, cdc codec.BinaryMarshaler, clientStore sdk.KVStore,
|
||||
header clientexported.Header,
|
||||
) (clientexported.ClientState, clientexported.ConsensusState, error) {
|
||||
smHeader, ok := header.(Header)
|
||||
smHeader, ok := header.(*Header)
|
||||
if !ok {
|
||||
return nil, nil, sdkerrors.Wrapf(
|
||||
clienttypes.ErrInvalidHeader, "header type %T is not solomachine", header,
|
||||
clienttypes.ErrInvalidHeader, "header type %T, expected %T", header, &Header{},
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ func (cs ClientState) CheckHeaderAndUpdateState(
|
|||
}
|
||||
|
||||
// checkHeader checks if the Solo Machine update signature is valid.
|
||||
func checkHeader(clientState *ClientState, header Header) error {
|
||||
func checkHeader(clientState *ClientState, header *Header) error {
|
||||
// assert update sequence is current sequence
|
||||
if header.Sequence != clientState.ConsensusState.Sequence {
|
||||
return sdkerrors.Wrapf(
|
||||
|
@ -51,7 +51,7 @@ func checkHeader(clientState *ClientState, header Header) error {
|
|||
}
|
||||
|
||||
// update the consensus state to the new public key and an incremented sequence
|
||||
func update(clientState *ClientState, header Header) (*ClientState, *ConsensusState) {
|
||||
func update(clientState *ClientState, header *Header) (*ClientState, *ConsensusState) {
|
||||
consensusState := &ConsensusState{
|
||||
// increment sequence number
|
||||
Sequence: clientState.ConsensusState.Sequence + 1,
|
||||
|
|
|
@ -38,7 +38,7 @@ func (suite *SoloMachineTestSuite) TestCheckHeaderAndUpdateState() {
|
|||
"invalid header type",
|
||||
func() {
|
||||
clientState = suite.solomachine.ClientState()
|
||||
header = ibctmtypes.Header{}
|
||||
header = &ibctmtypes.Header{}
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
@ -113,9 +113,9 @@ func (suite *SoloMachineTestSuite) TestCheckHeaderAndUpdateState() {
|
|||
|
||||
if tc.expPass {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(header.(types.Header).NewPublicKey, clientState.(*types.ClientState).ConsensusState.PublicKey)
|
||||
suite.Require().Equal(header.(*types.Header).NewPublicKey, clientState.(*types.ClientState).ConsensusState.PublicKey)
|
||||
suite.Require().Equal(uint64(0), clientState.(*types.ClientState).FrozenSequence)
|
||||
suite.Require().Equal(header.(types.Header).Sequence+1, clientState.(*types.ClientState).ConsensusState.Sequence)
|
||||
suite.Require().Equal(header.(*types.Header).Sequence+1, clientState.(*types.ClientState).ConsensusState.Sequence)
|
||||
suite.Require().Equal(consensusState, clientState.(*types.ClientState).ConsensusState)
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
|
|
|
@ -41,10 +41,8 @@ func (AppModuleBasic) Name() string {
|
|||
return host.ModuleName
|
||||
}
|
||||
|
||||
// RegisterCodec registers the ibc module's types for the given codec.
|
||||
func (AppModuleBasic) RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
types.RegisterCodec(cdc)
|
||||
}
|
||||
// RegisterCodec does nothing. IBC does not support amino.
|
||||
func (AppModuleBasic) RegisterCodec(*codec.LegacyAmino) {}
|
||||
|
||||
// DefaultGenesis returns default genesis state as raw bytes for the ibc
|
||||
// module.
|
||||
|
@ -62,9 +60,8 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
|
|||
return gs.Validate()
|
||||
}
|
||||
|
||||
// RegisterRESTRoutes registers the REST routes for the ibc module.
|
||||
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
||||
}
|
||||
// RegisterRESTRoutes does nothing. IBC does not support legacy REST routes.
|
||||
func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) {}
|
||||
|
||||
// GetTxCmd returns the root tx command for the ibc module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
|
|
|
@ -22,10 +22,6 @@ func TestRandomizedGenState(t *testing.T) {
|
|||
s := rand.NewSource(1)
|
||||
r := rand.New(s)
|
||||
|
||||
// Make sure to register cdc.
|
||||
// Otherwise RandomizedGenState will panic!
|
||||
types.RegisterCodec(cdc)
|
||||
|
||||
simState := module.SimulationState{
|
||||
AppParams: make(simtypes.AppParams),
|
||||
Cdc: cdc,
|
||||
|
|
|
@ -66,8 +66,8 @@ type TestChain struct {
|
|||
|
||||
App *simapp.SimApp
|
||||
ChainID string
|
||||
LastHeader ibctmtypes.Header // header for last block height committed
|
||||
CurrentHeader tmproto.Header // header for current block height
|
||||
LastHeader *ibctmtypes.Header // header for last block height committed
|
||||
CurrentHeader tmproto.Header // header for current block height
|
||||
QueryServer types.QueryServer
|
||||
TxConfig client.TxConfig
|
||||
Codec codec.BinaryMarshaler
|
||||
|
@ -407,7 +407,7 @@ func (chain *TestChain) UpdateTMClient(counterparty *TestChain, clientID string)
|
|||
}
|
||||
|
||||
// CreateTMClientHeader creates a TM header to update the TM client.
|
||||
func (chain *TestChain) CreateTMClientHeader() ibctmtypes.Header {
|
||||
func (chain *TestChain) CreateTMClientHeader() *ibctmtypes.Header {
|
||||
vsetHash := chain.Vals.Hash()
|
||||
tmHeader := tmtypes.Header{
|
||||
Version: version.Consensus{Block: 2, App: 2},
|
||||
|
@ -434,7 +434,7 @@ func (chain *TestChain) CreateTMClientHeader() ibctmtypes.Header {
|
|||
commit, err := tmtypes.MakeCommit(blockID, chain.CurrentHeader.Height, 1, voteSet, chain.Signers, chain.CurrentHeader.Time)
|
||||
require.NoError(chain.t, err)
|
||||
|
||||
signedHeader := tmproto.SignedHeader{
|
||||
signedHeader := &tmproto.SignedHeader{
|
||||
Header: tmHeader.ToProto(),
|
||||
Commit: commit.ToProto(),
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ func (chain *TestChain) CreateTMClientHeader() ibctmtypes.Header {
|
|||
|
||||
// Do not set trusted field here, these fields can be inserted before relaying messages to a client.
|
||||
// The relayer is responsible for querying client and injecting appropriate trusted fields.
|
||||
return ibctmtypes.Header{
|
||||
return &ibctmtypes.Header{
|
||||
SignedHeader: signedHeader,
|
||||
ValidatorSet: valSet,
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func (solo *Solomachine) ConsensusState() *solomachinetypes.ConsensusState {
|
|||
|
||||
// CreateHeader generates a new private/public key pair and creates the
|
||||
// necessary signature to construct a valid solo machine header.
|
||||
func (solo *Solomachine) CreateHeader() solomachinetypes.Header {
|
||||
func (solo *Solomachine) CreateHeader() *solomachinetypes.Header {
|
||||
// generate new private key and signature for header
|
||||
newPrivKey := ed25519.GenPrivKey()
|
||||
data := append(sdk.Uint64ToBigEndian(solo.Sequence), newPrivKey.PubKey().Bytes()...)
|
||||
|
@ -66,7 +66,7 @@ func (solo *Solomachine) CreateHeader() solomachinetypes.Header {
|
|||
publicKey, err := std.DefaultPublicKeyCodec{}.Encode(newPrivKey.PubKey())
|
||||
require.NoError(solo.t, err)
|
||||
|
||||
header := solomachinetypes.Header{
|
||||
header := &solomachinetypes.Header{
|
||||
Sequence: solo.Sequence,
|
||||
Signature: signature,
|
||||
NewPublicKey: publicKey,
|
||||
|
@ -82,7 +82,7 @@ func (solo *Solomachine) CreateHeader() solomachinetypes.Header {
|
|||
|
||||
// CreateEvidence constructs testing evidence for the solo machine client
|
||||
// by signing over two different data bytes at the same sequence.
|
||||
func (solo *Solomachine) CreateEvidence() solomachinetypes.Evidence {
|
||||
func (solo *Solomachine) CreateEvidence() *solomachinetypes.Evidence {
|
||||
dataOne := []byte("DATA ONE")
|
||||
dataTwo := []byte("DATA TWO")
|
||||
|
||||
|
@ -102,7 +102,7 @@ func (solo *Solomachine) CreateEvidence() solomachinetypes.Evidence {
|
|||
Data: dataTwo,
|
||||
}
|
||||
|
||||
return solomachinetypes.Evidence{
|
||||
return &solomachinetypes.Evidence{
|
||||
ClientId: solo.ClientID,
|
||||
Sequence: solo.Sequence,
|
||||
SignatureOne: &signatureOne,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
|
||||
|
@ -12,15 +11,6 @@ import (
|
|||
solomachinetypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/solomachine/types"
|
||||
)
|
||||
|
||||
// RegisterCodec registers the necessary x/ibc interfaces and concrete types
|
||||
// on the provided Amino codec. These types are used for Amino JSON serialization.
|
||||
func RegisterCodec(cdc *codec.LegacyAmino) {
|
||||
clienttypes.RegisterCodec(cdc)
|
||||
ibctmtypes.RegisterCodec(cdc)
|
||||
localhosttypes.RegisterCodec(cdc)
|
||||
commitmenttypes.RegisterCodec(cdc)
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers x/ibc interfaces into protobuf Any.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
clienttypes.RegisterInterfaces(registry)
|
||||
|
|
Loading…
Reference in New Issue