Skip to content

Commit 3be8f45

Browse files
fix(txm): configure polling interval if the rpc protocol is http
1 parent 48ae59d commit 3be8f45

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

packages/transaction-manager/lib/BlockMonitor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export class BlockMonitor {
2020

2121
this.txmgr.viemClient.watchBlocks({
2222
onBlock: this.onNewBlock.bind(this),
23+
...(this.txmgr.transportProtocol === "http"
24+
? {
25+
pollingInterval: Math.floor(
26+
(Number(this.txmgr.blockTime) * 1000) / this.txmgr.pollingIntervalFraction,
27+
),
28+
}
29+
: {}),
2330
})
2431
}
2532

packages/transaction-manager/lib/TransactionManager.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export type TransactionManagerConfig = {
6363
* Defaults to false.
6464
*/
6565
allowDebug?: boolean
66+
67+
/**
68+
* Specifies the fraction of the block time to be used as the polling interval.
69+
* This setting is applicable only when the RPC protocol is HTTP.
70+
* By default, the polling interval is set to 1/8 of the block time, meaning the system will poll every 1/8th of the block time.
71+
*/
72+
pollingIntervalFraction?: number
6673
}
6774
/** The private key of the account used for signing transactions. */
6875
privateKey: Hex
@@ -159,6 +166,8 @@ export class TransactionManager {
159166
public readonly rpcAllowDebug: boolean
160167
public readonly blockTime: bigint
161168
public readonly finalizedTransactionPurgeTime: number
169+
public readonly pollingIntervalFraction: number
170+
public readonly transportProtocol: "http" | "websocket"
162171

163172
public started: boolean
164173

@@ -171,12 +180,14 @@ export class TransactionManager {
171180
throw protocol.error
172181
}
173182

183+
this.transportProtocol = protocol.value
184+
174185
const retries = _config.rpc.retries || 2
175186
const retryDelay = _config.rpc.retryDelay || 50
176187
const timeout = _config.rpc.timeout || 500
177188

178189
let transport: ViemTransport
179-
if (protocol.value === "http") {
190+
if (this.transportProtocol === "http") {
180191
transport = viemHttpTransport(_config.rpc.url, {
181192
timeout,
182193
retryCount: retries,
@@ -250,6 +261,8 @@ export class TransactionManager {
250261
this.blockTime = _config.blockTime || 2n
251262
this.finalizedTransactionPurgeTime = _config.finalizedTransactionPurgeTime || 2 * 60 * 1000
252263

264+
this.pollingIntervalFraction = _config.rpc.pollingIntervalFraction || 8
265+
253266
this.started = false
254267
}
255268

0 commit comments

Comments
 (0)