Skip to content

Commit

Permalink
Interchain Security (#385)
Browse files Browse the repository at this point in the history
* WIP

* Remove ICSType

* dep on cosmos/interchain-security

* Add genesis flows for provider/consumer

* bugfixes and cleanup

* Remove fmt.Printf statements

* cleanup comments

* Add PreGenesis hook to StartConsumer
  • Loading branch information
agouin authored Feb 8, 2023
1 parent 13aaa82 commit 25d7ae3
Show file tree
Hide file tree
Showing 16 changed files with 934 additions and 320 deletions.
42 changes: 42 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ccvclient "github.com/cosmos/interchain-security/x/ccv/provider/client"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
Expand Down Expand Up @@ -153,6 +154,25 @@ func (tn *ChainNode) OverwriteGenesisFile(ctx context.Context, content []byte) e
return nil
}

func (tn *ChainNode) privValFileContent(ctx context.Context) ([]byte, error) {
fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
gen, err := fr.SingleFileContent(ctx, tn.VolumeName, "config/priv_validator_key.json")
if err != nil {
return nil, fmt.Errorf("getting priv_validator_key.json content: %w", err)
}

return gen, nil
}

func (tn *ChainNode) overwritePrivValFile(ctx context.Context, content []byte) error {
fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, "config/priv_validator_key.json", content); err != nil {
return fmt.Errorf("overwriting priv_validator_key.json: %w", err)
}

return nil
}

func (tn *ChainNode) copyGentx(ctx context.Context, destVal *ChainNode) error {
nid, err := tn.NodeID(ctx)
if err != nil {
Expand Down Expand Up @@ -780,6 +800,28 @@ func (tn *ChainNode) TextProposal(ctx context.Context, keyName string, prop Text
return tn.ExecTx(ctx, keyName, command...)
}

func (tn *ChainNode) ConsumerAdditionProposal(ctx context.Context, keyName string, prop ccvclient.ConsumerAdditionProposalJSON) (string, error) {
propBz, err := json.Marshal(prop)
if err != nil {
return "", err
}

fileName := "proposal_" + dockerutil.RandLowerCaseLetterString(4) + ".json"

fw := dockerutil.NewFileWriter(tn.logger(), tn.DockerClient, tn.TestName)
if err := fw.WriteFile(ctx, tn.VolumeName, fileName, propBz); err != nil {
return "", fmt.Errorf("failure writing proposal json: %w", err)
}

filePath := filepath.Join(tn.HomeDir(), fileName)

return tn.ExecTx(ctx, keyName,
"gov", "submit-proposal", "consumer-addition", filePath,
"-b", "block",
"--gas", "auto",
)
}

// DumpContractState dumps the state of a contract at a block height.
func (tn *ChainNode) DumpContractState(ctx context.Context, contractAddress string, height int64) (*DumpContractStateResponse, error) {
stdout, _, err := tn.ExecQuery(ctx,
Expand Down
2 changes: 2 additions & 0 deletions chain/cosmos/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibctypes "github.com/cosmos/ibc-go/v3/modules/core/types"
ccvprovidertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
)

func DefaultEncoding() simappparams.EncodingConfig {
Expand All @@ -25,6 +26,7 @@ func DefaultEncoding() simappparams.EncodingConfig {
banktypes.RegisterInterfaces(cfg.InterfaceRegistry)
ibctypes.RegisterInterfaces(cfg.InterfaceRegistry)
transfertypes.RegisterInterfaces(cfg.InterfaceRegistry)
ccvprovidertypes.RegisterInterfaces(cfg.InterfaceRegistry)

return cfg
}
Expand Down
Loading

0 comments on commit 25d7ae3

Please sign in to comment.