Skip to content

Commit

Permalink
feat: added range tx search when applicable (#228)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bcsainju authored Aug 21, 2024
1 parent 246017f commit 9eb9485
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 103 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --update --no-cache make git musl-dev gcc binutils-gold cargo

ARG BUILDPLATFORM=arm64
ARG TARGETPLATFORM=arm64
ARG COSMWASM_VERSION=1.2.3
ARG COSMWASM_VERSION=1.5.0

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

# Install chain binaries
COPY --from=build-env /bin/rly /bin
COPY --from=build-env /go/bin/rly /bin

# Install trusted CA certificates
COPY --from=busybox-min /etc/ssl/cert.pem /etc/ssl/cert.pem
Expand Down
4 changes: 4 additions & 0 deletions relayer/chains/icon/icon_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ func (icp *IconChainProcessor) handlePathProcessorUpdate(ctx context.Context,

if latestHeight != 0 && uint64(latestHeight)-latestHeader.Height() < 3 {
inSync = true
if !icp.inSync {
icp.inSync = true
icp.log.Info("Chain is in sync")
}
}

for _, pp := range icp.pathProcessors {
Expand Down
17 changes: 15 additions & 2 deletions relayer/chains/wasm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type WasmProviderConfig struct {
ChainName string `json:"-" yaml:"-"`
ChainID string `json:"chain-id" yaml:"chain-id"`
RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"`
BlockRPCAddr string `json:"block-rpc-addr" yaml:"block-rpc-addr"`
BlockRPCMinDelta int `json:"block-rpc-delta" yaml:"block-rpc-delta"`
BlockRPCRefreshTime int `json:"block-rpc-refresh-time" yaml:"block-rpc-refresh-time"`
AccountPrefix string `json:"account-prefix" yaml:"account-prefix"`
KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"`
GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"`
Expand Down Expand Up @@ -256,14 +259,13 @@ func (pc *WasmProviderConfig) NewProvider(log *zap.Logger, homepath string, debu
if pc.Broadcast == "" {
pc.Broadcast = provider.BroadcastModeBatch
}

cp := &WasmProvider{
log: log,
PCfg: pc,
KeyringOptions: []keyring.Option{ethermint.EthSecp256k1Option()},
Input: os.Stdin,
Output: os.Stdout,

rangeSupport: false,
// TODO: this is a bit of a hack, we should probably have a better way to inject modules
Cdc: MakeCodec(pc.Modules, pc.ExtraCodecs),
}
Expand All @@ -278,6 +280,7 @@ type WasmProvider struct {
Keybase keyring.Keyring
KeyringOptions []keyring.Option
RPCClient rpcclient.Client
BlockRPCClient rpcclient.Client
QueryClient wasmtypes.QueryClient
LightProvider provtypes.Provider
Cdc Codec
Expand All @@ -292,6 +295,7 @@ type WasmProvider struct {

// for comet < v0.37, decode tm events as base64
cometLegacyEncoding bool
rangeSupport bool
}

func (ap *WasmProvider) ProviderConfig() provider.ProviderConfig {
Expand Down Expand Up @@ -351,6 +355,15 @@ func (ap *WasmProvider) Init(ctx context.Context) error {
}
ap.RPCClient = rpcClient

ap.rangeSupport = false
if ap.PCfg.BlockRPCAddr != "" {
blockRpcClient, err := NewRPCClient(ap.PCfg.BlockRPCAddr, timeout)
if err != nil {
return err
}
ap.BlockRPCClient = blockRpcClient
ap.rangeSupport = true
}
lightprovider, err := prov.New(ap.PCfg.ChainID, ap.PCfg.RPCAddr)
if err != nil {
return err
Expand Down
23 changes: 11 additions & 12 deletions relayer/chains/wasm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
rtyAttNum = uint(5)
rtyAtt = retry.Attempts(rtyAttNum)
rtyDel = retry.Delay(time.Millisecond * 400)
specialDel = retry.Delay(time.Second * 30)
specialDel = retry.Delay(time.Second * 10)
rtyErr = retry.LastErrorOnly(true)
numRegex = regexp.MustCompile("[0-9]+")
defaultBroadcastWaitTimeout = 10 * time.Minute
Expand Down Expand Up @@ -841,8 +841,9 @@ func (ap *WasmProvider) SendMessagesToMempool(
if strings.Contains(err.Error(), sdkerrors.ErrWrongSequence.Error()) {
ap.handleAccountSequenceMismatchError(err)
}
return err
}
return err
return nil
}, retry.Context(ctx), retry.Attempts(0), specialDel, rtyErr); err != nil {
ap.log.Error("Failed to update client", zap.Any("Message", msg))
return err
Expand Down Expand Up @@ -1309,17 +1310,15 @@ func parseEventsFromTxResponse(resp *sdk.TxResponse) []provider.RelayerEvent {
return events
}

for _, logs := range resp.Logs {
for _, event := range logs.Events {
attributes := make(map[string]string)
for _, attribute := range event.Attributes {
attributes[attribute.Key] = attribute.Value
}
events = append(events, provider.RelayerEvent{
EventType: event.Type,
Attributes: attributes,
})
for _, event := range resp.Events {
attributes := make(map[string]string)
for _, attribute := range event.Attributes {
attributes[attribute.Key] = attribute.Value
}
events = append(events, provider.RelayerEvent{
EventType: event.Type,
Attributes: attributes,
})
}
return events
}
Expand Down
Loading

0 comments on commit 9eb9485

Please sign in to comment.