Skip to content

Commit 3edd855

Browse files
committed
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
1 parent 442a131 commit 3edd855

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

relayer/chains/wasm/provider.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"os"
88
"path"
9-
"strings"
109
"sync"
1110
"time"
1211

@@ -54,6 +53,7 @@ type WasmProviderConfig struct {
5453
ChainName string `json:"-" yaml:"-"`
5554
ChainID string `json:"chain-id" yaml:"chain-id"`
5655
RPCAddr string `json:"rpc-addr" yaml:"rpc-addr"`
56+
BlockRPCAddr string `json:"block-rpc-addr" yaml:"block-rpc-addr"`
5757
AccountPrefix string `json:"account-prefix" yaml:"account-prefix"`
5858
KeyringBackend string `json:"keyring-backend" yaml:"keyring-backend"`
5959
GasAdjustment float64 `json:"gas-adjustment" yaml:"gas-adjustment"`
@@ -278,6 +278,7 @@ type WasmProvider struct {
278278
Keybase keyring.Keyring
279279
KeyringOptions []keyring.Option
280280
RPCClient rpcclient.Client
281+
BlockRPCClient rpcclient.Client
281282
QueryClient wasmtypes.QueryClient
282283
LightProvider provtypes.Provider
283284
Cdc Codec
@@ -351,15 +352,16 @@ func (ap *WasmProvider) Init(ctx context.Context) error {
351352
return err
352353
}
353354
ap.RPCClient = rpcClient
354-
page := 1
355+
355356
ap.rangeSupport = false
356-
_, err = rpcClient.TxSearch(ctx, "execute._contract_address='invalid' AND tx.height>=38769995", true, &page, &page, "asc")
357-
if err != nil && strings.Contains(err.Error(), "strict equality") {
358-
ap.log.Info("given RPC doesn't Supports range queries")
359-
} else {
357+
if ap.PCfg.BlockRPCAddr != "" {
358+
blockRpcClient, err := NewRPCClient(ap.PCfg.BlockRPCAddr, timeout)
359+
if err != nil {
360+
return err
361+
}
362+
ap.BlockRPCClient = blockRpcClient
360363
ap.rangeSupport = true
361364
}
362-
363365
lightprovider, err := prov.New(ap.PCfg.ChainID, ap.PCfg.RPCAddr)
364366
if err != nil {
365367
return err

relayer/chains/wasm/wasm_chain_processor.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func NewWasmChainProcessor(log *zap.Logger, provider *WasmProvider, metrics *pro
8282

8383
var (
8484
inSyncNumBlocksThreshold = int64(2)
85+
numOffsetBlocks = int64(2)
8586
)
8687

8788
const (
@@ -286,7 +287,7 @@ func (ccp *WasmChainProcessor) Run(ctx context.Context, initialBlockHistory uint
286287

287288
ccp.log.Debug("Entering Wasm main query loop")
288289
if ccp.chainProvider.rangeSupport {
289-
inSyncNumBlocksThreshold = 5
290+
inSyncNumBlocksThreshold = 10
290291
}
291292
ticker := time.NewTicker(persistence.minQueryLoopDuration)
292293
defer ticker.Stop()
@@ -372,7 +373,7 @@ func (ccp *WasmChainProcessor) getBlocksToProcess(ctx context.Context, blockToRe
372373
defer cancelQueryCtx()
373374
page := int(1)
374375
perPage := int(50)
375-
txsResult, err := ccp.chainProvider.RPCClient.TxSearch(queryCtx, queryFilter, true, &page, &perPage, "asc")
376+
txsResult, err := ccp.chainProvider.BlockRPCClient.TxSearch(queryCtx, queryFilter, true, &page, &perPage, "asc")
376377
var resultArr []int64
377378
if err != nil {
378379
return []int64{}, err
@@ -454,7 +455,7 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
454455

455456
syncUpHeight := func() int64 {
456457
if ccp.chainProvider.rangeSupport {
457-
return persistence.latestHeight - inSyncNumBlocksThreshold + 2
458+
return persistence.latestHeight - numOffsetBlocks
458459
}
459460
if persistence.latestHeight-persistence.latestQueriedBlock > MaxBlockFetch {
460461
return persistence.latestQueriedBlock + MaxBlockFetch
@@ -463,7 +464,8 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
463464
}
464465
var blocks []int64
465466
heighttoSync := syncUpHeight()
466-
if ccp.chainProvider.rangeSupport {
467+
delta := persistence.latestHeight - persistence.latestQueriedBlock
468+
if ccp.chainProvider.rangeSupport && delta > 20 {
467469
if (persistence.latestQueriedBlock + 1) >= persistence.latestHeight {
468470
return nil
469471
}
@@ -578,7 +580,6 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
578580
)
579581
continue
580582
}
581-
582583
pp.HandleNewData(chainID, processor.ChainProcessorCacheData{
583584
LatestBlock: ccp.latestBlock,
584585
LatestHeader: latestHeader,

0 commit comments

Comments
 (0)