Skip to content

Commit

Permalink
feat: made blocks configuratble and use the block-rpc for most cases …
Browse files Browse the repository at this point in the history
…decreasing the api usage
  • Loading branch information
bcsainju committed Aug 9, 2024
1 parent aa717ee commit 70d9cf5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions relayer/chains/wasm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type WasmProviderConfig struct {
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
16 changes: 14 additions & 2 deletions relayer/chains/wasm/wasm_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ func (ccp *WasmChainProcessor) Run(ctx context.Context, initialBlockHistory uint

ccp.log.Debug("Entering Wasm main query loop")
if ccp.chainProvider.rangeSupport {
inSyncNumBlocksThreshold = 10
inSyncNumBlocksThreshold = 15
defaultQueryLoopTime := 7
if ccp.chainProvider.PCfg.BlockRPCRefreshTime > 0 {
defaultQueryLoopTime = ccp.chainProvider.PCfg.BlockRPCRefreshTime
}
persistence.minQueryLoopDuration = time.Duration(defaultQueryLoopTime) * time.Second
}
ticker := time.NewTicker(persistence.minQueryLoopDuration)
defer ticker.Stop()
Expand Down Expand Up @@ -461,7 +466,14 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
var blocks []int64
heighttoSync := syncUpHeight()
delta := persistence.latestHeight - persistence.latestQueriedBlock
if ccp.chainProvider.rangeSupport && delta > 20 {
minDelta := 10
if ccp.chainProvider.PCfg.BlockRPCMinDelta > 0 {
minDelta = ccp.chainProvider.PCfg.BlockRPCMinDelta
}
if ccp.chainProvider.rangeSupport && delta > int64(minDelta) {
ccp.log.Debug("Fetching range block",
zap.Any("last_height", persistence.latestQueriedBlock),
zap.Any("delta", delta))
status, err := ccp.chainProvider.BlockRPCClient.Status(ctx)
if err != nil {
return nil
Expand Down

0 comments on commit 70d9cf5

Please sign in to comment.