-
Hi there, How can I check if node is in syncing state? I'm using my own node, and it's getting out of sync from time to time - I can see it geth logs. I would like to avoid any rpc calls during this time. |
Beta Was this translation helpful? Give feedback.
Answered by
zemse
Aug 7, 2023
Replies: 1 comment 2 replies
-
There is an RPC method called
A very basic example of how this could be achieved (I have not tested this code). class JsonRpcProviderModified extends JsonRpcProvider {
// override the call method
async call(...args) {
await waitUntilSynced();
return await super.call(...args)
}
async waitUntilSynced() {
while(1) {
const syncing = this.send('eth_syncing');
if (syncing === false) break
}
}
} This might cause performance issues since it will check node is synced or not for every call, so you might want to implement some caching here so that node is synced or not is checked less often. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the node is syncing then the block number will be increasing with great speed, and on('block') is designed to work with synced nodes, I'm not sure how it will work in syncing case, you can try, but I expect a lot of callbacks.