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

chore(marketplace): switch to websocket #1166

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

2-towns
Copy link
Contributor

@2-towns 2-towns commented Mar 17, 2025

Linea is supporting only Websocket.

So it would be better to use it in our testing.

Depends on codex-storage/nim-ethers#112.

Copy link
Contributor

@emizzle emizzle left a comment

Choose a reason for hiding this comment

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

Nice job. What about handling websocket resubscriptions after 5 minutes?

@2-towns
Copy link
Contributor Author

2-towns commented Mar 18, 2025

Nice job. What about handling websocket resubscriptions after 5 minutes?

I am still exploring the issue, I am not sure how to reproduce it.

proc resubscribeOnTimeout() {.async.} =
while true:
await sleepAsync(5.int64.minutes)
#await ethProvider.resubscribeAll()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@emizzle What do you think about this approach ? I would add a resubscribeAll to JsonRpcProvider in nim-ethers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't mind the idea, though I'm not convinced we should put this functionality in ethers, as it is a client-specific (hardhat) workaround. However, i'm not entirely sure we'll have a choice.

Also, we are going to run into issues when we cancel all subscriptions and then resubscribe: there will have been blocks mined in between that potentially have events in the logs and we may not have subscribed in time to call the respective subscription callbacks. I believe we discussed this in the past and we reasoned that we might need to inspect the logs for the blocks that had been mined between unsubscribing and re-subscribing. Maybe we could get away with simply re-subscribing only (not unsubscribing), then deduplicating subscription callbacks somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind the idea, though I'm not convinced we should put this functionality in ethers, as it is a client-specific (hardhat) workaround. However, i'm not entirely sure we'll have a choice.

Yes I wanted to keep the workaround out of ethers but it is hard. Let's say I move the resubscribeAll into the client, I would need to expose some fields from ethers: the subscriptions from JsonRpcProvider, the callbacks from JsonRpcSubscriptions and potentially adding and exposing a mapping between the JsonNode and the EventFilter. I feel it safer to add a method resubscribeAll to ethers rather than exposing those fields.

Also, we are going to run into issues when we cancel all subscriptions and then resubscribe: there will have been blocks mined in between that potentially have events in the logs and we may not have subscribed in time to call the respective subscription callbacks. I believe we discussed this in the past and we reasoned that we might need to inspect the logs for the blocks that had been mined between unsubscribing and re-subscribing. Maybe we could get away with simply re-subscribing only (not unsubscribing), then deduplicating subscription callbacks somehow?

We could just re-subscribe first then remove the old subscription. deduplicating subscription callbacks seems simple, we just need to delete the callback for the JsonNode corresponding to that subscription.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found another approach to keep the resubscribe in the client, but it requires one change in ethers: move the logEvents (currently in PollingSubscriptions) to JsonRpcSubscriptions. Thanks to that, we can keep track of the events per subscription in WebSocketSubscriptions as well (see here).

Then, in the client, I access the private fields of the JsonRpcSubscriptions and register first a new subscription and then remove the old one so we don't lose any block mined event.

@2-towns 2-towns force-pushed the chore/re-enable-hardhat-websocket branch from 89b8fdc to b6e6596 Compare March 19, 2025 13:19
@2-towns 2-towns marked this pull request as ready for review March 19, 2025 13:21
Copy link
Member

@AuHau AuHau left a comment

Choose a reason for hiding this comment

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

Well the Hardhat bug is just unfortunate :-( It is hacky approach, but I can't think of better one, so LGTM.

Comment on lines 8 to 9
# from pkg/json_rpc/rpcclient import RpcClient
# from pkg/ethers import JsonRpcProvider, JsonRpcSubscriptions
Copy link
Member

Choose a reason for hiding this comment

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

Remove commented out imports please ;-)

@AuHau AuHau self-requested a review March 19, 2025 16:30
@AuHau
Copy link
Member

AuHau commented Mar 19, 2025

Actually, I have (I think 😅) a better idea - what about adding this functionality (automatically resubscriptions) directly to the nim-ethers under compile flag? No hacky private property access needed. It will be cleanly turned on only when the nim-ether's user needs... IMHO better then this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants