-
Notifications
You must be signed in to change notification settings - Fork 208
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
When re-creating listeners in EVMConnect/EthConnect/FabConnect use the last event block #1534
Conversation
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
// is passed through, and the listener does not exist. | ||
fb := database.BlockchainEventQueryFactory.NewFilter(ctx).Sort("-protocolid").Limit(1) | ||
latestEvents, _, err := mm.database.GetBlockchainEvents(ctx, mm.namespace.Name, fb.Eq( | ||
"listener", nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not using the multiparty listener ID here? We don't have access to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically the thing that distinguishes the blockchainevents
for the multi-party BatchPin
events, is the lack of a listener
reference (there isn't one in the FF model for the BatchPin
case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah makes sense
Signed-off-by: Peter Broadhurst <[email protected]>
PR has been updated based on the conversation here, so that in the case a specific block number is supplied the recreated listener will still restart on the block before the last event (if that's after the specified block): #1531 (comment) |
Will be testing this one today e2e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewing I thought about a crazy edge case... The protocol ID is block number/transaction number /event number so if we recreate a listener with block number of the last protocol ID but we haven't consumed all the events from that block could we lose those events? Is it safer to go one down of the procotol id or am I over complicating this? Would have to see how FireFly acknowledges events from FFTM and maybe the assumption you have made is that you get all the events per block in the webscoket?
Ah you covered this already https://github.com/hyperledger/firefly/pull/1534/files#diff-eb673d841796eecd85e0b4f676fb8de03a03b31b2a7d66a5c63d600aab57e2dfR217 sorry |
Have tested this one E2E by doing the following experiment:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
This is the reason we go one block back: firefly/internal/blockchain/ethereum/eventstream.go Lines 216 to 218 in 8dd5a0d
|
Yeah I realised with #1534 (comment) |
See #1531
Every time Core starts, it confirms all the listeners exist that it needs for all of:
BatchPin
listeners for any multi-party namespaces/activatepool
This is needed for two cases:
In both of these cases, the logic was naive for the
newest
/latest
case - where it treats "now" as the latest event.That is a problem, as it might be a long time since the original listener was created, and it might have delivered many events already. In which case there might be "gaps" we skip over between the last event detected by the old listener, and the first event we detect on the new one.
This PR closes that window, by looking at the
protocolId
of the last event - which is architecturally required to be a lexicographically sorted string identifying the position of the event on the blockchain.If there's been a previous event, that's used by the blockchain connector as the
fromBlock
for the new listener.Also, if
"oldest"
or an explicit block number is used, and the block number is before the block determined by the above process, then the newer block is used.