Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: made blocks configuratble and use the block-rpc for most cases decreasing the api usage #230

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading