Skip to content
This repository was archived by the owner on Jan 7, 2026. It is now read-only.

feat: get blockNumber from Ethers.js event data#312

Merged
bajtos merged 5 commits intomainfrom
feat-roundstart-epoch-from-event
May 21, 2024
Merged

feat: get blockNumber from Ethers.js event data#312
bajtos merged 5 commits intomainfrom
feat-roundstart-epoch-from-event

Conversation

@bajtos
Copy link
Copy Markdown
Member

@bajtos bajtos commented May 16, 2024

I found a way how to access the ContractEventPayload from the contract event listener function. By getting the block number from the event data, we don't have to make another RPC call to find the block number via potentially expensive & slow eth_getLogs.

Very loosely related to:

bajtos added 2 commits May 16, 2024 16:58
Move the function from inside `startRoundTracker` to the top level.

Signed-off-by: Miroslav Bajtoš <[email protected]>
I found a way how to access the ContractEventPayload from the contract
event listener function. By getting the block number from the event
data, we don't have to make another RPC call to find the block number
via potentially expensive & slow `eth_getLogs`.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos requested a review from juliangruber May 16, 2024 15:22
@bajtos
Copy link
Copy Markdown
Member Author

bajtos commented May 16, 2024

This pull request is based on #310 and it's blocked until we land that refactor.

bajtos added 2 commits May 16, 2024 17:25
Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos marked this pull request as ready for review May 20, 2024 15:35
@bajtos bajtos merged commit d1aab4c into main May 21, 2024
@bajtos bajtos deleted the feat-roundstart-epoch-from-event branch May 21, 2024 07:05
Comment thread lib/round-tracker.js
Comment on lines +35 to +42
const event = args.pop()
const blockNumber = event?.log?.blockNumber
if (blockNumber === undefined) {
console.warn(
'Ethers.js event data did not include ContractEventPayload with the block number. ' +
'Will call `eth_getLogs` to find the round start epoch.'
)
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work very well. 👍🏻 We are advancing rounds, and the warning is not printed.

2024-05-21T08:56:31Z app[5683210c621628] cdg [info]Mapped 0x8460766Edc62B525fc1FA4D628FC79229dC73031 IE round index 7310n to SPARK round number 12733n (start epoch: 3932512)
2024-05-21T08:56:33Z app[5683210c621628] cdg [info]SPARK round started: 12733n (epoch: 3932512)
2024-05-21T08:56:33Z app[9185e760f41658] cdg [info]Mapped 0x8460766Edc62B525fc1FA4D628FC79229dC73031 IE round index 7310n to SPARK round number 12733n (start epoch: 3932512)
2024-05-21T08:56:33Z app[9185e760f41658] cdg [info]SPARK round started: 12733n (epoch: 3932512)
2024-05-21T08:56:33Z app[3d8dd965ae2998] cdg [info]Mapped 0x8460766Edc62B525fc1FA4D628FC79229dC73031 IE round index 7310n to SPARK round number 12733n (start epoch: 3932512)
2024-05-21T08:56:33Z app[3d8dd965ae2998] cdg [info]SPARK round started: 12733n (epoch: 3932512)
2024-05-21T08:56:34Z app[48ed67dc0e0308] cdg [info]Mapped 0x8460766Edc62B525fc1FA4D628FC79229dC73031 IE round index 7310n to SPARK round number 12733n (start epoch: 3932512)
2024-05-21T08:56:34Z app[48ed67dc0e0308] cdg [info]SPARK round started: 12733n (epoch: 3932512)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants