-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add logs websocket subscription for live smart-contract events #98
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
Open
Test0rMaik
wants to merge
11
commits into
klever-io:develop
Choose a base branch
from
Test0rMaik:feat/websocket-logs-subscription
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1bfce37
feat: add logs websocket subscription for live smart-contract events
Test0rMaik d775e90
fix: address review — deterministic sync in new LOGS tests
Test0rMaik c42f173
fix: address review — assert SetReadDeadline errors in new logs test
Test0rMaik 0bf16da
fix: address review — join StartServer goroutine in logs delivery test
Test0rMaik f8c9c91
fix: address review round 2 — logs field parity, dropped-log bug, rac…
Test0rMaik 1475657
fix: address review round 3 (fbsobreira) — tx-pointer race, log-conve…
Test0rMaik ff2ce14
fix: address security audit — O(n) subscriber scan on commit goroutin…
Test0rMaik 0e8b27e
test: cover repeated-unsubscribe not driving logsSubscriberCount nega…
Test0rMaik 1190bee
fix: address review round 6 (fbsobreira) — ws/ES payload parity, lock…
Test0rMaik 5cdf94a
fix: address audit findings on round 6 — retention-clear-before-bulk-…
Test0rMaik 0d71d56
test: fix tx-hash keying in lightweight-mode test so it actually exer…
Test0rMaik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[efficiency — plausible] New: caching
LogsDBpins every queued block's hex-expanded logs in the elastic work-item backlogCaching the conversion on
PreparedBlockDataextends its lifetime from "one elastic worker iteration" to "however long the work item sits inchanWorkItems", which isindexerCacheSizedeep — 100 by default (config/node/external.yaml:3,indexer/dataDispatcher.go:41).Failure scenario: Elasticsearch stalls,
dataDispatcher.doWorkretries with backoff up to 5 minutes, the queue fills, and 100 blocks' worth of converted logs — topics and data hex-encoded, so roughly 2× the raw bytes — stay pinned in memory on top of the already-retainedTxs/TxsMap/Altered. It only bites when websocket + ES are both enabled and a LOGS subscriber exists, which is the intended production configuration.Not necessarily worth changing — the CPU saving is real and this is a memory-for-CPU trade you may well want. But it is worth making deliberately rather than as a side effect, and the retention change is not mentioned anywhere. If it does concern you, clearing
prepared.LogsDBonce the elastic worker has consumed it would cap the exposure to the in-flight block.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.
Took your suggested remediation in 4238e76:
p.LogsDB = nil; p.LogsResults = nilnow happens afterdoBulkRequestssucceeds, not before. Two independent audit agents I ran before pushing caught that my first attempt cleared them before the bulk request could fail — sincedataDispatcher.doWorkretries a failed work item on the samePreparedBlockData, that would have forced the retry to recomputeExtractDataFromLogson the elastic worker goroutine, reintroducing the exact race this whole round of fixes exists to prevent. AddedTestElasticProcessor_SaveTransactions_KeepsCachedLogsOnBulkRequestError(fields must survive an error) alongside the existing clear-on-success test; mutation-tested both orderings.