-
Notifications
You must be signed in to change notification settings - Fork 242
Batch confirm messages, and update events to contain topic+tag #600
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
Conversation
cb63884 to
9c3bf75
Compare
Codecov Report
@@ Coverage Diff @@
## main #600 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 305 305
Lines 18297 18357 +60
=========================================
+ Hits 18297 18357 +60
Continue to review full report at Codecov.
|
…e messages to dispatched Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
dae5d2e to
90948ee
Compare
| if err := bp.database.InsertEvent(ctx, event); err != nil { | ||
| return err | ||
| for _, topic := range msg.Header.Topics { | ||
| // One event per topic |
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.
Nothing inherently wrong with this, but it's one of those things that will need to be clearly release-noted. For any apps that use multiple topics, they'll suddenly get more events with copies of the same data - so it just reinforces the need for those apps to have idempotent data processing.
awrichar
left a comment
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.
There are 2 weird things about this PR:
- We have two new fields ("topic" and "tag") that are unused for the majority of our event types (although they are used with the most common event type "message_confirmed")
- Messages with multiple topics will now get multiple events emitted which all contain the same message
But after staring and thinking for a while, I'm on the same page - I think the benefits (being able to query messages in order and being able to batch update the messages upon confirmation) outweigh the weirdness. I haven't been able to think of any alternate proposal that's better on those two counts. Since the weird things are mostly only visible to "advanced" users and are fairly easy to explain/design around, I'm on board.
|
Alright the one other alternative that occurs to me is adding a special query param to /messages that would indicate "fetch confirmed messages only, and in the order they were confirmed, by doing a join with the events table". In theory, that would eliminate the need to put topic and tag on the events table...I think. |
While "topic" is clearly useful in terms of ordering, "tag" is not quite as justifiable to be duplicated this way. Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
|
Pushed a proposal to pull "tag" back out, as I think it's harder to justify here. If we can take this a step further and make "topic" meaningful for events other than messages, then it feels like a more complete change. |
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Removing approval as it sounds like this is going to continue evolving a bit longer
|
Further updates being added:
|
…ents Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
| func (em *eventManager) getChainListenerByIDCached(ctx context.Context, id *fftypes.UUID) (*fftypes.ContractListener, error) { | ||
| return em.getChainListenerCached(fmt.Sprintf("id:%s", id), func() (*fftypes.ContractListener, error) { | ||
| return em.database.GetContractListenerByID(ctx, id) | ||
| }) | ||
| } |
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.
Glad to see this can take advantage of caching now
Currently there is no clean way to query messages on a given
topicin the same order that they were dispatched to your application.More worryingly, we imply that the that you might be able to use the
confirmedtimestamp of the message as a substitute, as currently it's unique for each message. The problem with this is that timestamps are not guaranteed to only move forwards.The only object in FireFly that is guaranteed to have a sequence you can rely upon is
events, and these are delivered to your application with themessagein-line in the case of amessage_confirmedevent. We just added?fetchreferences(thanks @shorsher) on the/eventsresource collection, so that's an important piece of the puzzle. So with the extra change in this PR, if you want to query messages on a topic in the order they happened you just do:/api/v1/namespaces/{NS}/events?type=message_confirmed&fetchreferences&topic=MYTOPICsequenceis the default sort - so you can add&sort=sequencefor ascendingIn a PR chain with #599
topicas am indexed field on events (64 chars)topicsin a message to generates multiplemessage_confirmedevents.confirmedtimestampThis has two benefits:
Topic events
message_confirmedmessage_rejectedblockchain_event_receivedff_batch_pinfor the built-in batch pin listener.Topic from the listener if specified.
Listener ID as string otherwise
token_pool_confirmedtoken_transfer_confirmedtoken_transfer_op_failedtoken_approval_confirmednamespace_confirmedff_definitionsdatatype_confirmedff_definitionsidentity_confirmedff_definitionsidentity_updatedff_definitionscontract_interface_confirmedff_definitionscontract_api_confirmedff_definitions