Skip to content

Commit

Permalink
feat: adding functions for pre-start of node + pre-start of all nodes…
Browse files Browse the repository at this point in the history
… in a chain (#1123)

* cherry-pick skip changes

* update where pre-start nodes is executed

* linting
  • Loading branch information
nivasan1 authored May 10, 2024
1 parent 65cce0c commit 0559b76
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ChainNode struct {
GrpcConn *grpc.ClientConn
TestName string
Image ibc.DockerImage
preStartNode func(*ChainNode)

// Additional processes that need to be run on a per-validator basis.
Sidecars SidecarProcesses
Expand Down Expand Up @@ -97,6 +98,12 @@ func NewChainNode(log *zap.Logger, validator bool, chain *CosmosChain, dockerCli
return tn
}

// WithPreStartNode sets the preStartNode function for the ChainNode
func (tn *ChainNode) WithPreStartNode(preStartNode func(*ChainNode)) *ChainNode {
tn.preStartNode = preStartNode
return tn
}

// ChainNodes is a collection of ChainNode
type ChainNodes []*ChainNode

Expand Down Expand Up @@ -1185,6 +1192,10 @@ func (tn *ChainNode) StartContainer(ctx context.Context) error {
}
}

if tn.preStartNode != nil {
tn.preStartNode(tn)
}

if err := tn.containerLifecycle.StartContainer(ctx); err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ type CosmosChain struct {
Provider *CosmosChain
Consumers []*CosmosChain

// preStartNodes is able to mutate the node containers before
// they are all started
preStartNodes func(*CosmosChain)

// Additional processes that need to be run on a per-chain basis.
Sidecars SidecarProcesses

Expand Down Expand Up @@ -119,6 +123,12 @@ func NewCosmosChain(testName string, chainConfig ibc.ChainConfig, numValidators
}
}

// WithPreStartNodes sets the preStartNodes function.
func (c *CosmosChain) WithPreStartNodes(preStartNodes func(*CosmosChain)) {
c.preStartNodes = preStartNodes
}


// GetCodec returns the codec for the chain.
func (c *CosmosChain) GetCodec() *codec.ProtoCodec {
return c.cdc
Expand Down Expand Up @@ -899,6 +909,10 @@ func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGene
return err
}

if c.preStartNodes != nil {
c.preStartNodes(c)
}

if c.cfg.PreGenesis != nil {
err := c.cfg.PreGenesis(chainCfg)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions chain/cosmos/ics.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ func (c *CosmosChain) StartConsumer(testName string, ctx context.Context, additi

chainNodes := c.Nodes()

if c.preStartNodes != nil {
c.preStartNodes(c)
}

for _, cn := range chainNodes {
if err := cn.OverwriteGenesisFile(ctx, genbz); err != nil {
return err
Expand Down

0 comments on commit 0559b76

Please sign in to comment.