-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ibc clients creation stuck #639
Changes from 8 commits
6f23a46
3926418
0f7ac3e
1f13b4b
9a7d5c4
b53501b
1426a86
a6846c5
de7d8c7
830fe28
92b8d7a
0e40add
ef1122d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package relayer | ||
|
||
import ( | ||
"github.com/dymensionxyz/roller/cmd/consts" | ||
roller_utils "github.com/dymensionxyz/roller/utils" | ||
) | ||
|
||
func (r *Relayer) CheckClientsExist() (bool, error) { | ||
rlyCfg, err := ReadRlyConfig(r.Home) | ||
if err != nil { | ||
return false, err | ||
|
||
} | ||
clientIDRollapp_raw, err := roller_utils.GetNestedValue(rlyCfg, []string{"paths", consts.DefaultRelayerPath, "dst", "client-id"}) | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
clientIDHub_raw, err := roller_utils.GetNestedValue(rlyCfg, []string{"paths", consts.DefaultRelayerPath, "src", "client-id"}) | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
clientIDRollapp := clientIDRollapp_raw.(string) | ||
clientIDHub := clientIDHub_raw.(string) | ||
|
||
if clientIDRollapp == "" || clientIDHub == "" { | ||
r.logger.Printf("can't find clients in the config for both rollapp and hub") | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,22 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt | |
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
//after successful update clients, keep running in the background | ||
updateClientsCmd := r.GetUpdateClientsCmd() | ||
utils.RunCommandEvery(ctx, updateClientsCmd.Path, updateClientsCmd.Args[1:], 20, utils.WithDiscardLogging()) | ||
// Run send funds command from sequencer to itself to make sure the chain is | ||
// progressing for connection and channel creation. | ||
// replaced update clients to avoid account sequence mismatch and | ||
// premature heights updates e.g "TrustedHeight {1 x} must be less than header height {1 y}" | ||
sequecerAddress, err := utils.GetAddressBinary(utils.KeyConfig{ | ||
Dir: filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp), | ||
ID: consts.KeysIds.RollappSequencer, | ||
}, seq.RlpCfg.RollappBinary) | ||
if err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
sendFundsCmd := seq.GetSendCmd(sequecerAddress) | ||
utils.RunCommandEvery(ctx, sendFundsCmd.Path, sendFundsCmd.Args[1:], 20, utils.WithDiscardLogging()) | ||
|
||
//wait for block to be created | ||
status := "Waiting for state update before creating the channel..." | ||
status := "Validating rollapp height > 2 before creating clients..." | ||
fmt.Printf("💈 %s\n", status) | ||
if err := r.WriteRelayerStatus(status); err != nil { | ||
return ConnectionChannels{}, err | ||
|
@@ -34,15 +44,59 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt | |
return ConnectionChannels{}, err | ||
} | ||
|
||
// Create client if it doesn't exist or override is true | ||
clientsExist := false | ||
if !override { | ||
// Check if clients exist | ||
clientsExist, err = r.CheckClientsExist() | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore err as u don't won't to return here |
||
return ConnectionChannels{}, err | ||
} | ||
} | ||
if !clientsExist { | ||
// We always pass override otherwise this command hangs if there are too many clients | ||
// in the hub as it iterates all to check if this client exists | ||
createClientsCmd := r.getCreateClientsCmd(true) | ||
status = "Creating clients..." | ||
fmt.Printf("💈 %s\n", status) | ||
if err := r.WriteRelayerStatus(status); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
if err := utils.ExecBashCmd(createClientsCmd, logFileOption); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
} | ||
|
||
// Sleep for a few seconds to make sure the clients are created | ||
// otherwise the connection creation attempt fails | ||
time.Sleep(10 * time.Second) | ||
|
||
connectionID, _ := r.GetActiveConnection() | ||
if connectionID == "" || override { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if u set |
||
status = "Creating connection..." | ||
fmt.Printf("💈 %s\n", status) | ||
if err := r.WriteRelayerStatus(status); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
createConnectionCmd := r.getCreateConnectionCmd(override) | ||
if err := utils.ExecBashCmd(createConnectionCmd, logFileOption); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
} | ||
|
||
var src, dst string | ||
|
||
// we ran create channel with override, as it not recovarable anyway | ||
createLinkCmd := r.getCreateLinkCmd(override) | ||
status = "Creating link..." | ||
createChannelCmd := r.getCreateChannelCmd(true) | ||
status = "Creating channel..." | ||
fmt.Printf("💈 %s\n", status) | ||
if err := r.WriteRelayerStatus(status); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
if err := utils.ExecBashCmd(createLinkCmd, logFileOption); err != nil { | ||
if err := r.WriteRelayerStatus(status); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
if err := utils.ExecBashCmd(createChannelCmd, logFileOption); err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
status = "Validating channel established..." | ||
|
@@ -51,7 +105,7 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt | |
return ConnectionChannels{}, err | ||
} | ||
|
||
src, dst, err := r.LoadActiveChannel() | ||
src, dst, err = r.LoadActiveChannel() | ||
if err != nil { | ||
return ConnectionChannels{}, err | ||
} | ||
|
@@ -69,64 +123,50 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt | |
}, nil | ||
} | ||
|
||
// waitForValidRollappHeight waits for the rollapp height to be greater than 2 otherwise | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. because we open a connection optimistically so only the rollapp height is important. |
||
// it will fail to create clients. | ||
func waitForValidRollappHeight(seq *sequencer.Sequencer) error { | ||
initialHubHeightStr, err := seq.GetHubHeight() | ||
if err != nil { | ||
return err | ||
} | ||
initialHubHeight, err := strconv.Atoi(initialHubHeightStr) | ||
if err != nil { | ||
return err | ||
} | ||
initialRollappHeightStr, err := seq.GetRollappHeight() | ||
if err != nil { | ||
return err | ||
} | ||
initialRollappHeight, err := strconv.Atoi(initialRollappHeightStr) | ||
if err != nil { | ||
return err | ||
} | ||
logger := utils.GetRollerLogger(seq.RlpCfg.Home) | ||
for { | ||
time.Sleep(30 * time.Second) | ||
hubHeightStr, err := seq.GetHubHeight() | ||
if err != nil { | ||
fmt.Printf("💈 Error getting rollapp hub height, %s", err.Error()) | ||
continue | ||
} | ||
hubHeight, err := strconv.Atoi(hubHeightStr) | ||
if err != nil { | ||
fmt.Printf("💈 Error converting hub height to int, %s", err.Error()) | ||
continue | ||
} | ||
if hubHeight < 3 { | ||
fmt.Printf("💈 Waiting for the rollapp height on the hub to be greater than 2, current height: %d\n", hubHeight) | ||
continue | ||
} | ||
if hubHeight <= initialHubHeight { | ||
fmt.Printf("💈 Waiting for the rollapp height on the hub to be greater than initial height,"+ | ||
" initial height: %d, current height: %d\n", initialHubHeight, hubHeight) | ||
continue | ||
} | ||
time.Sleep(10 * time.Second) | ||
rollappHeightStr, err := seq.GetRollappHeight() | ||
if err != nil { | ||
fmt.Printf("💈 Error getting rollapp height, %s", err.Error()) | ||
logger.Printf("💈 Error getting rollapp height, %s", err.Error()) | ||
continue | ||
} | ||
rollappHeight, err := strconv.Atoi(rollappHeightStr) | ||
if err != nil { | ||
fmt.Printf("💈 Error converting rollapp height to int, %s", err.Error()) | ||
logger.Printf("💈 Error converting rollapp height to int, %s", err.Error()) | ||
continue | ||
} | ||
if rollappHeight <= initialRollappHeight { | ||
fmt.Printf("💈 Waiting for rollapp height to be greater than initial height,"+ | ||
" initial height: %d,current height: %d\n", initialRollappHeight, rollappHeight) | ||
if rollappHeight <= 2 { | ||
logger.Printf("💈 Waiting for rollapp height to be greater than 2") | ||
continue | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func (r *Relayer) getCreateLinkCmd(override bool) *exec.Cmd { | ||
args := []string{"tx", "link", "-t", "300s", "--src-port", "transfer", "--dst-port", "transfer", "--version", "ics20-1"} | ||
func (r *Relayer) getCreateClientsCmd(override bool) *exec.Cmd { | ||
args := []string{"tx", "clients"} | ||
args = append(args, r.getRelayerDefaultArgs()...) | ||
if override { | ||
args = append(args, "--override") | ||
} | ||
return exec.Command(consts.Executables.Relayer, args...) | ||
} | ||
|
||
func (r *Relayer) getCreateConnectionCmd(override bool) *exec.Cmd { | ||
args := []string{"tx", "connection", "-t", "300s", "-d"} | ||
if override { | ||
args = append(args, "--override") | ||
} | ||
args = append(args, r.getRelayerDefaultArgs()...) | ||
return exec.Command(consts.Executables.Relayer, args...) | ||
} | ||
|
||
func (r *Relayer) getCreateChannelCmd(override bool) *exec.Cmd { | ||
args := []string{"tx", "channel", "-t", "300s", "-r", "5", "-d"} | ||
if override { | ||
args = append(args, "--override") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sequencer | ||
|
||
import ( | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/dymensionxyz/roller/cmd/consts" | ||
) | ||
|
||
// TODO(FIXME): Assumptions on rollapp price and keyring backend | ||
func (seq *Sequencer) GetSendCmd(destAddress string) *exec.Cmd { | ||
rollappConfigDir := filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp) | ||
cmd := exec.Command( | ||
seq.RlpCfg.RollappBinary, | ||
"tx", "bank", "send", | ||
consts.KeysIds.RollappSequencer, destAddress, "1"+seq.RlpCfg.Denom, | ||
"--home", rollappConfigDir, | ||
"--broadcast-mode", "block", | ||
"--keyring-backend", "test", | ||
"--yes", | ||
) | ||
return cmd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to return the err, and ignore it by the caller
keep same standard as in
GetActiveConnection