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

Event streams #74

Merged
merged 22 commits into from
Aug 14, 2024
Merged

Event streams #74

merged 22 commits into from
Aug 14, 2024

Conversation

peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Aug 9, 2024

Depends on hyperledger/firefly-signer#71 (in a chain with hyperledger/firefly-signer#70)

  • Adds internal type event streams
    • These are "upserted" on startup of the block indexer
    • No sophisticated lifecycle management yet
    • Internal event handlers are passed a DB transaction that will be committed with the checkpoint update
    • No other types yet (like gRPC / WebSockets with batch-acknowledgement)
      • Partially because not enough of the engine framework exists
      • Partially because the most critically needed event listener is the state confirmation one
  • Component test updated to show its use (fyi @gabriel-indik )
  • Builds the event stream system on top of the block indexer
    • Quite a bit different to previous generations of this tech, due to the existence of the index
    • Catchup mode now exploits the DB index of all event signatures, meaning no need to page through blocks
    • No event data is stored in the index, just the events with their signatures
  • Optimized for smaller number of high throughput events
    • No selection on address currently (easy to add later if use cases come up)
    • A go channel queue is held for every event stream, buffering events from the main indexer after confirmation there
    • Event streams are passed any logs where topic[0] matches one or more signatures from the ABI
      • Note that ABI signatures are imprecise for parsing (param names, indexed etc.)
    • Detailed parsing of the events happens in the detector for each event stream
    • Matched events are pushed to the dispatcher
    • The dispatcher does batching and delivery to the stream
  • The list of events requested in the abi for a stream cannot be modified
  • Bunch of other framework code in types went in too
    • GORM seems to not support JSON serialization of sub-structs (only sub-arrays) so types.JSONP to support this
    • Added a types.Enum with an updated way to work with enums using generics

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
…into eth-eventstreams

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>
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>
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>
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>
@peterbroadhurst peterbroadhurst marked this pull request as ready for review August 12, 2024 04:23
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
func ABIBySolDefinition(ctx context.Context, a abi.ABI) (map[string]*abi.Entry, error) {
byDefs := make(map[string]*abi.Entry)
for _, e := range a {
solDef, childStructs, err := e.SolidityDefCtx(ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the new feature that gives Solidity-like definitions of events/structs (hopefully useful for various other things too, such as TypedData <-> Struct helpers we've discussed in the past)

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@@ -24,7 +24,7 @@ ext {
include "mocks/**/*.go"
}

targetCoverage = 93
targetCoverage = 94
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

)

type EnumStringOptions interface {
~string
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this sorcery

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL "Approximation constraint element" is a thing

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>
return -1, err
}
baseBlock := int64(-1)
if len(checkpoints) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it sensible to use gorm First or Take when we're only looking for one record?

Copy link
Contributor Author

@peterbroadhurst peterbroadhurst Aug 14, 2024

Choose a reason for hiding this comment

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

If you use First (or Take which seems like what we want) it gives you an error, you need to check against:

errors.Is(result.Error, gorm.ErrRecordNotFound)

This seems less readable imho than just using an array and checking in our code.
So I'm leaving it for this PR - as it's what I've done elsewhere.

Would be fine to see a different pattern go in if preferred, but it would I think be worth being standardized in all the places we do this already.

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@peterbroadhurst peterbroadhurst merged commit d990b83 into main Aug 14, 2024
2 checks passed
@peterbroadhurst peterbroadhurst deleted the eth-eventstreams branch August 14, 2024 19:10
awrichar pushed a commit that referenced this pull request Sep 13, 2024
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.

2 participants