Skip to content

Commit

Permalink
made RPC query speed respectful and configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Aug 8, 2023
1 parent 129837b commit 5c128ce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion zetaclient/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,16 @@ func (ob *EVMChainClient) IsSendOutTxProcessed(sendHash string, nonce int, coint
// FIXME: there's a chance that a txhash in OutTxChan may not deliver when Stop() is called
// observeOutTx periodically checks all the txhash in potential outbound txs
func (ob *EVMChainClient) observeOutTx() {
// read env variables if set
timeoutNonce, err := strconv.Atoi(os.Getenv("OS_TIMEOUT_NONCE"))
if err != nil || timeoutNonce <= 0 {
timeoutNonce = 100 * 3 // process up to 100 hashes
}
ob.logger.ObserveOutTx.Warn().Msgf("observeOutTx using timeoutNonce %d seconds", timeoutNonce)
rpcRestTime, err := strconv.Atoi(os.Getenv("OS_RPC_REST_TIME"))
if err != nil || rpcRestTime <= 0 {
rpcRestTime = 500 // 500ms
}
ob.logger.ObserveOutTx.Info().Msgf("observeOutTx using timeoutNonce %d seconds, rpcRestTime %d ms", timeoutNonce, rpcRestTime)

ticker := time.NewTicker(time.Duration(ob.GetChainConfig().CoreParams.OutTxTicker) * time.Second)
for {
Expand All @@ -426,6 +431,7 @@ func (ob *EVMChainClient) observeOutTx() {
break TRACKERLOOP
default:
receipt, transaction, err := ob.queryTxByHash(txHash.TxHash, int64(nonceInt))
time.Sleep(time.Duration(rpcRestTime) * time.Millisecond)
if err == nil && receipt != nil { // confirmed
ob.mu.Lock()
ob.outTXConfirmedReceipts[ob.GetIndex(int(nonceInt))] = receipt
Expand Down Expand Up @@ -455,6 +461,9 @@ func (ob *EVMChainClient) observeOutTx() {

break TXHASHLOOP
}
if err != nil {
ob.logger.ObserveOutTx.Error().Err(err).Msgf("error queryTxByHash: chain %s hash %s", ob.chain.String(), txHash.TxHash)
}
//<-inTimeout
}
}
Expand Down

0 comments on commit 5c128ce

Please sign in to comment.