Skip to content

Commit 9eb9485

Browse files
authored
feat: added range tx search when applicable (#228)
* feat: added range query check and support when applicable * chore: used logger * chore: removed unwanted header checks and fixed docker file * chore: reduced blocks to sync * chore: added config var block-rpc-addr which when available will be used to fetch tx blocks to sync faster else fallbacks to normal slow one * fix: used block height when using range block rpc * fix: fixed issue of skipping blocks when error occurred * fix: added retry when fetching client state which resulted in packets missing procesing * fix: ignored client state errors for now * fix: code refactorings and Pr feedbacks * fix: issue with max blocks in case of empty array * feat: made blocks configuratble and use the block-rpc for most cases decreasing the api usage * feat: added error logs * feat: fixed logs * fix: fixed chain rpc lagging issue * fix: fixed retry issue in case of mempool full * fix: reset lastqueried block if provider returns smaller value * fix: fixed query to adjust last saved height * fix: increased offset
1 parent 246017f commit 9eb9485

File tree

5 files changed

+157
-103
lines changed

5 files changed

+157
-103
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ RUN apk add --update --no-cache make git musl-dev gcc binutils-gold cargo
44

55
ARG BUILDPLATFORM=arm64
66
ARG TARGETPLATFORM=arm64
7-
ARG COSMWASM_VERSION=1.2.3
7+
ARG COSMWASM_VERSION=1.5.0
88

99
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/v${COSMWASM_VERSION}/libwasmvm_muslc.aarch64.a -O /usr/lib/libwasmvm.aarch64.a && \
1010
wget https://github.com/CosmWasm/wasmvm/releases/download/v${COSMWASM_VERSION}/libwasmvm_muslc.x86_64.a -O /usr/lib/libwasmvm.x86_64.a
@@ -50,7 +50,7 @@ RUN ln sh pwd && \
5050
rm ln rm
5151

5252
# Install chain binaries
53-
COPY --from=build-env /bin/rly /bin
53+
COPY --from=build-env /go/bin/rly /bin
5454

5555
# Install trusted CA certificates
5656
COPY --from=busybox-min /etc/ssl/cert.pem /etc/ssl/cert.pem

relayer/chains/icon/icon_chain_processor.go

+4
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,10 @@ func (icp *IconChainProcessor) handlePathProcessorUpdate(ctx context.Context,
671671

672672
if latestHeight != 0 && uint64(latestHeight)-latestHeader.Height() < 3 {
673673
inSync = true
674+
if !icp.inSync {
675+
icp.inSync = true
676+
icp.log.Info("Chain is in sync")
677+
}
674678
}
675679

676680
for _, pp := range icp.pathProcessors {

relayer/chains/wasm/provider.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type WasmProviderConfig struct {
5353
ChainName string `json:"-" yaml:"-"`
5454
ChainID string `json:"chain-id" yaml:"chain-id"`
5555
RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"`
56+
BlockRPCAddr string `json:"block-rpc-addr" yaml:"block-rpc-addr"`
57+
BlockRPCMinDelta int `json:"block-rpc-delta" yaml:"block-rpc-delta"`
58+
BlockRPCRefreshTime int `json:"block-rpc-refresh-time" yaml:"block-rpc-refresh-time"`
5659
AccountPrefix string `json:"account-prefix" yaml:"account-prefix"`
5760
KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"`
5861
GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"`
@@ -256,14 +259,13 @@ func (pc *WasmProviderConfig) NewProvider(log *zap.Logger, homepath string, debu
256259
if pc.Broadcast == "" {
257260
pc.Broadcast = provider.BroadcastModeBatch
258261
}
259-
260262
cp := &WasmProvider{
261263
log: log,
262264
PCfg: pc,
263265
KeyringOptions: []keyring.Option{ethermint.EthSecp256k1Option()},
264266
Input: os.Stdin,
265267
Output: os.Stdout,
266-
268+
rangeSupport: false,
267269
// TODO: this is a bit of a hack, we should probably have a better way to inject modules
268270
Cdc: MakeCodec(pc.Modules, pc.ExtraCodecs),
269271
}
@@ -278,6 +280,7 @@ type WasmProvider struct {
278280
Keybase keyring.Keyring
279281
KeyringOptions []keyring.Option
280282
RPCClient rpcclient.Client
283+
BlockRPCClient rpcclient.Client
281284
QueryClient wasmtypes.QueryClient
282285
LightProvider provtypes.Provider
283286
Cdc Codec
@@ -292,6 +295,7 @@ type WasmProvider struct {
292295

293296
// for comet < v0.37, decode tm events as base64
294297
cometLegacyEncoding bool
298+
rangeSupport bool
295299
}
296300

297301
func (ap *WasmProvider) ProviderConfig() provider.ProviderConfig {
@@ -351,6 +355,15 @@ func (ap *WasmProvider) Init(ctx context.Context) error {
351355
}
352356
ap.RPCClient = rpcClient
353357

358+
ap.rangeSupport = false
359+
if ap.PCfg.BlockRPCAddr != "" {
360+
blockRpcClient, err := NewRPCClient(ap.PCfg.BlockRPCAddr, timeout)
361+
if err != nil {
362+
return err
363+
}
364+
ap.BlockRPCClient = blockRpcClient
365+
ap.rangeSupport = true
366+
}
354367
lightprovider, err := prov.New(ap.PCfg.ChainID, ap.PCfg.RPCAddr)
355368
if err != nil {
356369
return err

relayer/chains/wasm/tx.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var (
5252
rtyAttNum = uint(5)
5353
rtyAtt = retry.Attempts(rtyAttNum)
5454
rtyDel = retry.Delay(time.Millisecond * 400)
55-
specialDel = retry.Delay(time.Second * 30)
55+
specialDel = retry.Delay(time.Second * 10)
5656
rtyErr = retry.LastErrorOnly(true)
5757
numRegex = regexp.MustCompile("[0-9]+")
5858
defaultBroadcastWaitTimeout = 10 * time.Minute
@@ -841,8 +841,9 @@ func (ap *WasmProvider) SendMessagesToMempool(
841841
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
842842
ap.handleAccountSequenceMismatchError(err)
843843
}
844+
return err
844845
}
845-
return err
846+
return nil
846847
}, retry.Context(ctx), retry.Attempts(0), specialDel, rtyErr); err != nil {
847848
ap.log.Error("Failed to update client", zap.Any("Message", msg))
848849
return err
@@ -1309,17 +1310,15 @@ func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
13091310
return events
13101311
}
13111312

1312-
for _, logs := range resp.Logs {
1313-
for _, event := range logs.Events {
1314-
attributes := make(map[string]string)
1315-
for _, attribute := range event.Attributes {
1316-
attributes[attribute.Key] = attribute.Value
1317-
}
1318-
events = append(events, provider.RelayerEvent{
1319-
EventType: event.Type,
1320-
Attributes: attributes,
1321-
})
1313+
for _, event := range resp.Events {
1314+
attributes := make(map[string]string)
1315+
for _, attribute := range event.Attributes {
1316+
attributes[attribute.Key] = attribute.Value
13221317
}
1318+
events = append(events, provider.RelayerEvent{
1319+
EventType: event.Type,
1320+
Attributes: attributes,
1321+
})
13231322
}
13241323
return events
13251324
}

0 commit comments

Comments
 (0)