Skip to content

Commit

Permalink
Merge pull request #230 from icon-project/feat/range-query-impl-conf-…
Browse files Browse the repository at this point in the history
…timed

feat: made blocks configuratble and use the block-rpc for most cases decreasing the api usage
  • Loading branch information
bcsainju authored Aug 12, 2024
2 parents aa717ee + 24949d4 commit 5ab7b29
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 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
5 changes: 3 additions & 2 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
31 changes: 25 additions & 6 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,14 +466,28 @@ 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 := 7
if ccp.chainProvider.PCfg.BlockRPCMinDelta > 0 {
minDelta = ccp.chainProvider.PCfg.BlockRPCMinDelta
}
if ccp.chainProvider.rangeSupport && delta > int64(minDelta) {
status, err := ccp.chainProvider.BlockRPCClient.Status(ctx)
if err != nil {
ccp.log.Warn("Error occurred fetching block status", zap.Error(err))
return nil
}
if persistence.latestQueriedBlock > status.SyncInfo.LatestBlockHeight &&
persistence.latestHeight > status.SyncInfo.LatestBlockHeight {
persistence.latestHeight = status.SyncInfo.LatestBlockHeight
ccp.log.Debug("Fetching range block",
zap.Int64("last_height", persistence.latestQueriedBlock),
zap.Int64("latest_height", status.SyncInfo.LatestBlockHeight),
zap.Int64("delta", delta))
persistence.latestHeight = status.SyncInfo.LatestBlockHeight
heighttoSync = syncUpHeight()
if persistence.latestQueriedBlock > status.SyncInfo.LatestBlockHeight {
ccp.log.Debug("resetting range block",
zap.Int64("last_height", persistence.latestQueriedBlock),
zap.Int64("latest_height", status.SyncInfo.LatestBlockHeight))
persistence.latestQueriedBlock = status.SyncInfo.LatestBlockHeight
return nil
}
if (persistence.latestQueriedBlock + 1) >= persistence.latestHeight {
return nil
Expand All @@ -478,7 +497,7 @@ func (ccp *WasmChainProcessor) queryCycle(ctx context.Context, persistence *quer
}
blocks, err = ccp.getBlocksToProcess(ctx, persistence.latestQueriedBlock+1)
if err != nil {
ccp.log.Info("error occurred getting blocks")
ccp.log.Warn("error occurred getting blocks", zap.Error(err))
return nil
}
maxBlock := findMaxBlock(blocks)
Expand Down

0 comments on commit 5ab7b29

Please sign in to comment.