Skip to content
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
15 changes: 11 additions & 4 deletions packages/txm/lib/BlockMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class BlockMonitor {
private txmgr: TransactionManager
private unwatch: (() => void) | undefined
private blockTimeout: ReturnType<typeof setTimeout> | undefined
private latestProcessedBlockNumber: bigint | undefined
constructor(_transactionManager: TransactionManager) {
this.txmgr = _transactionManager
}
Expand All @@ -27,10 +28,6 @@ export class BlockMonitor {
this.unwatch = this.txmgr.viemClient.watchBlocks({
onBlock: this.onNewBlock.bind(this),
...(this.txmgr.transportProtocol === "http" ? { pollingInterval: this.txmgr.pollingInterval } : {}),
onError: (error) => {
Logger.instance.error(LogTag.TXM, "Error watching blocks", error)
this.resetBlockSubscription()
},
})
}

Expand All @@ -40,6 +37,16 @@ export class BlockMonitor {
return
}

if (this.latestProcessedBlockNumber && block.number <= this.latestProcessedBlockNumber) {
Logger.instance.warn(
LogTag.TXM,
"Received block number less than or equal to latest processed block number. Skipping.",
)
return
}

this.latestProcessedBlockNumber = block.number

if (this.blockTimeout) clearTimeout(this.blockTimeout)
eventBus.emit(Topics.NewBlock, block)

Expand Down
2 changes: 1 addition & 1 deletion packages/txm/lib/NonceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class NonceManager {

// Only called when a transaction that has reserved a nonce ultimately doesn't reach the mempool
public returnNonce(nonce: number) {
const index = this.returnedNonceQueue.findIndex((n) => nonce > n)
const index = this.returnedNonceQueue.findIndex((n) => nonce < n)

if (index === -1) {
this.returnedNonceQueue.push(nonce)
Expand Down
Loading