I have a bug listed in many places: Error: filter not found
when using a filter with web3.
from https://blockone.thomsonreuters.com/docs/
It's important to note that, if you're using web3's watch functions, that these are stateful with respect to their backend - they rely on periodic polling with a handle that's only known to the specific node you were talking to when you set them up. Obviously this is a problem if reconnection happens automatically beneath the visibility of your app code- any such handles you are using will be invalidated. Your calls would error due to a bad handle with "Error: filter not found...."- at that point it's your responsibility to re-issue the watch calls. If you happen to reconnect to a node with a different block height, your watchers may miss events. So it's important to check for events since the block of the last received event.
Here is my code
try {
var filterMempool = web3.eth.filter('pending');
filterMempool.watch(function (error, txHash) {
if (error) {
console.log('pending filter error: ' + error);
} else {
try {
const currentTx = web3.eth.getTransaction(txHash);
doSomething(currentTx);
}
catch (err) {
console.log('mempool getTransaction error: ' + err);
}
}
});
}
catch (error) {
console.log(`filterMempool filter error: ${error}`);
}
My questions:
1) How can I re-issue the watch calls ?
2) How to make sure I don't miss any events ?