Skip to content

Commit

Permalink
Add pathName to CreateClient, CreateConnection, CreateChannel
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Dec 6, 2023
1 parent 8819863 commit 6cd8ddf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
16 changes: 10 additions & 6 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func createClientsCmd(ctx *config.Context) *cobra.Command {
" path by querying headers from each chain and then sending the corresponding create-client messages",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, src, dst, err := ctx.Config.ChainsFromPath(args[0])
pathName := args[0]
c, src, dst, err := ctx.Config.ChainsFromPath(pathName)
if err != nil {
return err
}
Expand Down Expand Up @@ -93,7 +94,7 @@ func createClientsCmd(ctx *config.Context) *cobra.Command {
dstHeight = clienttypes.NewHeight(latestHeight.GetRevisionNumber(), height)
}

return core.CreateClients(c[src], c[dst], srcHeight, dstHeight)
return core.CreateClients(pathName, c[src], c[dst], srcHeight, dstHeight)
},
}
cmd.Flags().Uint64(flagSrcHeight, defaultSrcHeight, "src header at this height is submitted to dst chain")
Expand Down Expand Up @@ -136,7 +137,8 @@ func createConnectionCmd(ctx *config.Context) *cobra.Command {
a connection between two chains with a configured path in the config file`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, src, dst, err := ctx.Config.ChainsFromPath(args[0])
pathName := args[0]
c, src, dst, err := ctx.Config.ChainsFromPath(pathName)
if err != nil {
return err
}
Expand All @@ -154,7 +156,7 @@ func createConnectionCmd(ctx *config.Context) *cobra.Command {
return err
}

return core.CreateConnection(c[src], c[dst], to)
return core.CreateConnection(pathName, c[src], c[dst], to)
},
}

Expand All @@ -169,7 +171,8 @@ func createChannelCmd(ctx *config.Context) *cobra.Command {
create a channel between two chains with a configured path in the config file`),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
c, src, dst, err := ctx.Config.ChainsFromPath(args[0])
pathName := args[0]
c, src, dst, err := ctx.Config.ChainsFromPath(pathName)
if err != nil {
return err
}
Expand All @@ -186,7 +189,8 @@ func createChannelCmd(ctx *config.Context) *cobra.Command {
if _, err = c[dst].GetAddress(); err != nil {
return err
}
return core.CreateChannel(c[src], c[dst], to)

return core.CreateChannel(pathName, c[src], c[dst], to)
},
}

Expand Down
2 changes: 0 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type Config struct {
chains Chains `yaml:"-" json:"-"`

HomePath string `yaml:"-" json:"-"`
Path string `yaml:"-" json:"-"`
}

func DefaultConfig(homePath string) Config {
Expand Down Expand Up @@ -106,7 +105,6 @@ func (c *Config) DeleteChain(chain string) *Config {

// ChainsFromPath takes the path name and returns the properly configured chains
func (c *Config) ChainsFromPath(path string) (map[string]*core.ProvableChain, string, string, error) {
c.Path = path

pth, err := c.Paths.Get(path)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func initCoreConfig(c *Config) {
core.SetCoreConfig(config)
}

func (c CoreConfig) UpdateConfigID(chainID string, configID core.ConfigIDType, id string) error {
configPath, err := c.config.Paths.Get(c.config.Path)
func (c CoreConfig) UpdateConfigID(pathName string, chainID string, configID core.ConfigIDType, id string) error {
configPath, err := c.config.Paths.Get(pathName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// CreateChannel runs the channel creation messages on timeout until they pass
// TODO: add max retries or something to this function
func CreateChannel(src, dst *ProvableChain, to time.Duration) error {
func CreateChannel(pathName string, src, dst *ProvableChain, to time.Duration) error {
logger := GetChannelPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateChannel")

Expand All @@ -35,7 +35,7 @@ func CreateChannel(src, dst *ProvableChain, to time.Duration) error {
}

srcMsgIDs, dstMsgIDs := chanSteps.Send(src, dst)
if err := SyncChainConfigsFromEvents(srcMsgIDs, dstMsgIDs, src, dst, ConfigIDChannel); err != nil {
if err := SyncChainConfigsFromEvents(pathName, srcMsgIDs, dstMsgIDs, src, dst, ConfigIDChannel); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/hyperledger-labs/yui-relayer/log"
)

func CreateClients(src, dst *ProvableChain, srcHeight, dstHeight exported.Height) error {
func CreateClients(pathName string, src, dst *ProvableChain, srcHeight, dstHeight exported.Height) error {
logger := GetChainPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateClients")
var (
Expand Down Expand Up @@ -70,7 +70,7 @@ func CreateClients(src, dst *ProvableChain, srcHeight, dstHeight exported.Height
"★ Clients created",
)
}
if err := SyncChainConfigsFromEvents(srcMsgIDs, dstMsgIDs, src, dst, ConfigIDClient); err != nil {
if err := SyncChainConfigsFromEvents(pathName, srcMsgIDs, dstMsgIDs, src, dst, ConfigIDClient); err != nil {
return err
}
}
Expand Down
15 changes: 9 additions & 6 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ const (
)

type ConfigI interface {
UpdateConfigID(chainID string, configID ConfigIDType, id string) error
UpdateConfigID(pathName string, chainID string, configID ConfigIDType, id string) error
}

func SetCoreConfig(c ConfigI) {
if config != nil {
panic("core config already set")
}
config = c
}

Expand Down Expand Up @@ -130,17 +133,17 @@ func (cc ChainProverConfig) Build() (*ProvableChain, error) {
return NewProvableChain(chain, prover), nil
}

func SyncChainConfigsFromEvents(msgIDsSrc, msgIDsDst []MsgID, src, dst *ProvableChain, configID ConfigIDType) error {
if err := SyncChainConfigFromEvents(msgIDsSrc, src, configID); err != nil {
func SyncChainConfigsFromEvents(pathName string, msgIDsSrc, msgIDsDst []MsgID, src, dst *ProvableChain, configID ConfigIDType) error {
if err := SyncChainConfigFromEvents(pathName, msgIDsSrc, src, configID); err != nil {
return err
}
if err := SyncChainConfigFromEvents(msgIDsDst, dst, configID); err != nil {
if err := SyncChainConfigFromEvents(pathName, msgIDsDst, dst, configID); err != nil {
return err
}
return nil
}

func SyncChainConfigFromEvents(msgIDs []MsgID, chain *ProvableChain, configID ConfigIDType) error {
func SyncChainConfigFromEvents(pathName string, msgIDs []MsgID, chain *ProvableChain, configID ConfigIDType) error {
for _, msgID := range msgIDs {
msgRes, err := chain.Chain.GetMsgResult(msgID)
if err != nil {
Expand All @@ -166,7 +169,7 @@ func SyncChainConfigFromEvents(msgIDs []MsgID, chain *ProvableChain, configID Co
}
}
if id != "" {
if err := config.UpdateConfigID(chain.ChainID(), configID, id); err != nil {
if err := config.UpdateConfigID(pathName, chain.ChainID(), configID, id); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
rtyErr = retry.LastErrorOnly(true)
)

func CreateConnection(src, dst *ProvableChain, to time.Duration) error {
func CreateConnection(pathName string, src, dst *ProvableChain, to time.Duration) error {
logger := GetConnectionPairLogger(src, dst)
defer logger.TimeTrack(time.Now(), "CreateConnection")
ticker := time.NewTicker(to)
Expand All @@ -44,7 +44,7 @@ func CreateConnection(src, dst *ProvableChain, to time.Duration) error {
}

srcMsgIDs, dstMsgIDs := connSteps.Send(src, dst)
if err := SyncChainConfigsFromEvents(srcMsgIDs, dstMsgIDs, src, dst, ConfigIDConnection); err != nil {
if err := SyncChainConfigsFromEvents(pathName, srcMsgIDs, dstMsgIDs, src, dst, ConfigIDConnection); err != nil {
return err
}

Expand Down

0 comments on commit 6cd8ddf

Please sign in to comment.