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

fix: race condition in last processed height #38

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

gusin13
Copy link
Collaborator

@gusin13 gusin13 commented Nov 11, 2024

Error
https://babylonlabsworkspace.slack.com/archives/G07EDCXTXHR/p1731311842336389?thread_ts=1731302004.980249&cid=G07EDCXTXHR

time":"2024-11-11T07:55:51Z","message":"successfully pushed pending staking event"}
2024-11-11T07:55:51.876773464Z {"level":"debug","time":"2024-11-11T07:55:51Z","message":"Processing covenant quorum reached event"}
2024-11-11T07:55:51.878861071Z {"level":"error","error":"failed to get BTC delegation by staking tx hash: BTC delegation not found when getting by staking tx hash","time":"2024-11-11T07:55:51Z","message":"Failed to process event"}
2024-11-11T07:55:51.881024168Z panic: failed to get BTC delegation by staking tx hash: BTC delegation not found when getting by staking tx hash
2024-11-11T07:55:51.881046363Z 
2024-11-11T07:55:51.881051088Z goroutine 1 [running]:
2024-11-11T07:55:51.881055730Z github.com/babylonlabs-io/babylon-staking-indexer/internal/services.(*Service).processEvent(0xc0010fa080, {0x38b5240, 0xc000d942a0}, {{0x2f18396, 0x2}, {{0xc000f012f0, 0x30}, {0xc000db0900, 0x3, 0x3}}})
2024-11-11T07:55:51.881060074Z  /go/src/github.com/babylonlabs-io/babylon-staking-indexer/internal/services/events.go:92 +0x53b
2024-11-11T07:55:51.881088470Z github.com/babylonlabs-io/babylon-staking-indexer/internal/services.(*Service).StartBbnEventProcessor(0xc0010fa080, {0x38b5110?, 0x5501a20?})
2024-11-11T07:55:51.881091615Z  /go/src/github.com/babylonlabs-io/babylon-staking-indexer/internal/services/events.go:49 +0x188
2024-11-11T07:55:51.881094568Z github.com/babylonlabs-io/babylon-staking-indexer/internal/services.(*Service).StartIndexerSync(0xc0010fa080, {0x38b5110, 0x5501a20})
2024-11-11T07:55:51.881097686Z  /go/src/github.com/babylonlabs-io/babylon-staking-indexer/internal/services/service.go:72 +0x125
2024-11-11T07:55:51.881100586Z main.main()
2024-11-11T07:55:51.881104118Z  /go/src/github.com/babylonlabs-io/babylon-staking-indexer/cmd/babylon-staking-indexer/main.go:76 +0x528

Currently we have a main goroutine which consumes the events from channel and a separate go routine which parses the Babylon blocks and pushes these events to channel and then immediately updates last processed height.
If there is any issue in processing events, the last processed will point to a different height (as the go routine doesn't care if the event was successfully processed)

Fix - I removed the bbn event processor goroutine, its better to process events and then update ast processed height in th same routine to make sure all events at specific height are processed successfully.

Copy link
Collaborator

@jrwbabylonlab jrwbabylonlab left a comment

Choose a reason for hiding this comment

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

I think the alternative solution would be create a custom "block processed event" internally and feed into bbnEventProcessor.
Eitherway, LGTM

@jrwbabylonlab jrwbabylonlab merged commit db9071b into main Nov 11, 2024
11 checks passed
@jrwbabylonlab jrwbabylonlab deleted the gusin13/fix-race-last-processed-ht branch November 11, 2024 13:00
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