Skip to content
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: sdk prefix change handle for neutron and archway #119

Merged
merged 9 commits into from
Aug 15, 2023
3 changes: 3 additions & 0 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ loop:
break
}

icp.log.Debug("Verified block ",
zap.Int64("height", int64(processedheight)))

icp.latestBlock = provider.LatestBlock{
Height: uint64(processedheight),
}
Expand Down
2 changes: 0 additions & 2 deletions relayer/chains/wasm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ func (ap *WasmProvider) Init(ctx context.Context) error {
}
ap.LightProvider = lightprovider

ap.SetSDKContext()

clientCtx := client.Context{}.
WithClient(rpcClient).
WithFromName(ap.PCfg.Key).
Expand Down
3 changes: 2 additions & 1 deletion relayer/chains/wasm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,20 @@
}

func (ap *WasmProvider) QueryClientConsensusState(ctx context.Context, chainHeight int64, clientid string, clientHeight ibcexported.Height) (*clienttypes.QueryConsensusStateResponse, error) {

consensusStateParam, err := types.NewConsensusStateByHeight(clientid, uint64(clientHeight.GetRevisionHeight())).Bytes()

Check warning on line 317 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L316-L317

Added lines #L316 - L317 were not covered by tests
consensusState, err := ap.QueryIBCHandlerContractProcessed(ctx, consensusStateParam)
if err != nil {
return nil, err
}

cdc := codec.NewProtoCodec(ap.Cdc.InterfaceRegistry)
csState, err := clienttypes.UnmarshalConsensusState(cdc, consensusState)
if err != nil {

Check warning on line 325 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L323-L325

Added lines #L323 - L325 were not covered by tests
return nil, err
}

anyConsensusState, err := clienttypes.PackConsensusState(csState)

Check warning on line 329 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L329

Added line #L329 was not covered by tests
if err != nil {
return nil, err
}
Expand All @@ -334,7 +334,8 @@
}

func (ap *WasmProvider) QueryIBCHandlerContract(ctx context.Context, param wasmtypes.RawContractMessage) (*wasmtypes.QuerySmartContractStateResponse, error) {

done := ap.SetSDKContext()
defer done()

Check warning on line 338 in relayer/chains/wasm/query.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/query.go#L337-L338

Added lines #L337 - L338 were not covered by tests
return ap.QueryClient.SmartContractState(ctx, &wasmtypes.QuerySmartContractStateRequest{
Address: ap.PCfg.IbcHandlerAddress,
QueryData: param,
Expand Down
5 changes: 5 additions & 0 deletions relayer/chains/wasm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,16 +745,16 @@
}

if msg.Type() == MethodUpdateClient {
if err := retry.Do(func() error {
if err := ap.BroadcastTx(cliCtx, txBytes, []provider.RelayerMessage{msg}, asyncCtx, defaultBroadcastWaitTimeout, asyncCallback, true); err != nil {
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
}

Check warning on line 752 in relayer/chains/wasm/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/tx.go#L748-L752

Added lines #L748 - L752 were not covered by tests
}
return err
}, retry.Context(ctx), rtyAtt, retry.Delay(time.Millisecond*time.Duration(ap.PCfg.BlockInterval)), rtyErr); err != nil {
ap.log.Error("Failed to update client", zap.Any("Message", msg))
return err

Check warning on line 757 in relayer/chains/wasm/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/tx.go#L754-L757

Added lines #L754 - L757 were not covered by tests
}
continue
}
Expand Down Expand Up @@ -807,6 +807,8 @@
func (ap *WasmProvider) LogSuccessTx(res *sdk.TxResponse, msgs []provider.RelayerMessage) {
// Include the chain_id
fields := []zapcore.Field{zap.String("chain_id", ap.ChainId())}
done := ap.SetSDKContext()
defer done()

Check warning on line 811 in relayer/chains/wasm/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/tx.go#L810-L811

Added lines #L810 - L811 were not covered by tests

// Include the gas used
fields = append(fields, zap.Int64("gas_used", res.GasUsed))
Expand Down Expand Up @@ -879,6 +881,9 @@
}

func (ap *WasmProvider) buildMessages(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) ([]byte, uint64, error) {
done := ap.SetSDKContext()
defer done()

Check warning on line 886 in relayer/chains/wasm/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/tx.go#L884-L886

Added lines #L884 - L886 were not covered by tests
for _, msg := range msgs {
if err := msg.ValidateBasic(); err != nil {
return nil, 0, err
Expand Down Expand Up @@ -1006,8 +1011,8 @@

ap.log.Info("Submitted transaction",
zap.String("chain_id", ap.PCfg.ChainID),
zap.String("tx_hash", res.TxHash),
msgTypesField(msgs),

Check warning on line 1015 in relayer/chains/wasm/tx.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/tx.go#L1014-L1015

Added lines #L1014 - L1015 were not covered by tests
)

if shouldWait {
Expand Down
15 changes: 8 additions & 7 deletions relayer/chains/wasm/wasm_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
// SetSDKContext sets the SDK config to the proper bech32 prefixes for wasm.
// Don't use this unless you know what you're doing.
// TODO: :dagger: :knife: :chainsaw: remove this function
func (ap *WasmProvider) SetSDKContext() {
func (ap *WasmProvider) SetSDKContext() func() {

Check warning on line 20 in relayer/chains/wasm/wasm_prefix.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/wasm_prefix.go#L19-L20

Added lines #L19 - L20 were not covered by tests
sdkConfigMutex.Lock()
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(ap.PCfg.AccountPrefix, app.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(ap.PCfg.AccountPrefix, app.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen())
sdkConfigMutex.Unlock()
cfg_update := sdk.GetConfig()
cfg_update.SetBech32PrefixForAccount(ap.PCfg.AccountPrefix, app.Bech32PrefixAccPub)
cfg_update.SetBech32PrefixForValidator(ap.PCfg.AccountPrefix, app.Bech32PrefixValPub)
cfg_update.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg_update.SetAddressVerifier(wasmtypes.VerifyAddressLen())
return sdkConfigMutex.Unlock

Check warning on line 27 in relayer/chains/wasm/wasm_prefix.go

View check run for this annotation

Codecov / codecov/patch

relayer/chains/wasm/wasm_prefix.go#L22-L27

Added lines #L22 - L27 were not covered by tests
}
Loading