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

Support for confirmations when listening to events #207

Merged
merged 17 commits into from
Apr 20, 2022

Conversation

peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Mar 22, 2022

  • One of the key work items for support of public blockchains per Support for public blockchains #149
  • Adds a new BlockConfirmationManager (BCM) component
    • Enabled through a new confirmations configuration sub-section section in openapi
    rest:
      rest-gateway:
        rpc:
          url: https://rinkeby.infura.io/v3/...
        openapi:
          catchupModeBlockGap: 50
          catchupModePageSize: 50
          confirmations:
            enabled: true               # Turn on the feature
            requiredConfirmations: 20   # The required number of confirmations to deliver the event
            includeInPayload: true      # Includes an array of the block confirmations in the event
          decimalTransactionIndex: true # Gives consistency in decimal formatting of transactionIndex
        maxTXWaitTime: 300
        maxInFlight: 100
    • Sits in-between the LogProcessor and the EventStream
    • Responsible for detecting confirmations, and only propagating events once confirmed
    • Events stay in-flight until confirmed, so checkpointing logic functions unchanged
    • Performs polling based block listening to add confirmations as soon as they arrive
    • Handles confirmations of historic events when replaying
    • Handles forks that invalidate at any point in the confirmation list
    • Block caching avoids excessive JSON/RPC calls against the node
    • Tested with the Infura gateway for the Rinkeby network
  • Updates handling of removed events
    • Processed by BCM when enabled
    • Ignored otherwise
  • Adds migration for blockedReryDelaySec config typo to blockedRetryDelaySec
  • Adds a hexFormatTransactionIndex option that can be set to false to disable the current behavior where transactionIndex is delivered as 0x01 etc. whereas blockNumber/logIndex are delivered as the string "1"
    • The default has not been changed to avoid impact on production apps

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2022

Codecov Report

Merging #207 (2faf053) into main (dc6f8a7) will increase coverage by 0.05%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
+ Coverage   97.24%   97.30%   +0.05%     
==========================================
  Files          58       59       +1     
  Lines        6944     7246     +302     
==========================================
+ Hits         6753     7051     +298     
- Misses        146      148       +2     
- Partials       45       47       +2     
Impacted Files Coverage Δ
ethconnect/internal/events/logprocessor.go 98.31% <0.00%> (-1.69%) ⬇️
ethconnect/internal/events/submanager.go 99.27% <0.00%> (-0.73%) ⬇️
ethconnect/internal/tx/txnprocessor.go 100.00% <0.00%> (ø)
ethconnect/internal/events/block_confirmations.go 100.00% <0.00%> (ø)
ethconnect/internal/events/eventstream.go 96.99% <0.00%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc6f8a7...2faf053. Read the comment docs.

@peterbroadhurst peterbroadhurst marked this pull request as ready for review April 4, 2022 22:23
@@ -1,3 +1,13 @@
{
"go.lintTool": "golangci-lint"
"go.lintTool": "golangci-lint",
"cSpell.words": [
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏼

intConf.requiredConfirmations = *conf.RequiredConfirmations
}
if conf.BlockCacheSize != nil {
intConf.blockCacheSize = *conf.BlockCacheSize
Copy link
Contributor

Choose a reason for hiding this comment

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

should we enforce a safe upper bound (no idea what that should be though!)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we haven't elsewhere on these. I propose no is ok for now

event: event,
eventStream: eventStream,
}
bcm.pending[eventKey] = pending
Copy link
Contributor

Choose a reason for hiding this comment

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

Not requesting as part of this PR given I'm providing this comment at the last minute, it would be good to have a follow on that wraps updates to bcm.pending with a RWMutex - I'm assuming there's a high likelihood of concurrent updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree a good candidate to look at in the future, and deferrable.

func (bcm *blockConfirmationManager) dispatchConfirmed(confirmed *pendingEvent) {
eventKey := bcm.keyForEvent(confirmed.event)
bcm.log.Infof("Confirmed with %d confirmations event=%s", len(confirmed.confirmations), eventKey)
delete(bcm.pending, eventKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't we have already removed the key from bcm.pending since we moved this event from bcm.pending to confirmed?

Copy link
Contributor Author

@peterbroadhurst peterbroadhurst Apr 20, 2022

Choose a reason for hiding this comment

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

Agreed re-reading the code

Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
@peterbroadhurst peterbroadhurst merged commit b99a40f into hyperledger:main Apr 20, 2022
@peterbroadhurst peterbroadhurst deleted the confirmations branch April 20, 2022 02:42
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.

4 participants