-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: subscribe to bbn websocket new block events #32
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5f7f015
sub new block info from ws
gusin13 1090b42
fix logs
gusin13 0398644
rm redund code
gusin13 42c91a5
fix errs
gusin13 cfc53d2
fix nit
gusin13 2f7fdf2
pull out bbn.start
gusin13 ee77597
fix const
gusin13 3386b3f
fix
gusin13 d5db815
drain chan
gusin13 4da58a1
fix naming
gusin13 2764115
rename
gusin13 71b2ce3
rename
gusin13 66169cd
rename
gusin13 0d20aba
fix
gusin13 1e47086
fix
gusin13 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/babylonlabs-io/babylon-staking-indexer/internal/db/model" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func (db *Database) GetLastProcessedBbnHeight(ctx context.Context) (uint64, error) { | ||
var result model.LastProcessedHeight | ||
err := db.client.Database(db.dbName). | ||
Collection(model.LastProcessedHeightCollection). | ||
FindOne(ctx, bson.M{}).Decode(&result) | ||
if err == mongo.ErrNoDocuments { | ||
// If no document exists, return 0 | ||
return 0, nil | ||
} | ||
if err != nil { | ||
return 0, err | ||
} | ||
return result.Height, nil | ||
} | ||
|
||
func (db *Database) UpdateLastProcessedBbnHeight(ctx context.Context, height uint64) error { | ||
update := bson.M{"$set": bson.M{"height": height}} | ||
opts := options.Update().SetUpsert(true) | ||
_, err := db.client.Database(db.dbName). | ||
Collection(model.LastProcessedHeightCollection). | ||
UpdateOne(ctx, bson.M{}, update, opts) | ||
return err | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package model | ||
|
||
type LastProcessedHeight struct { | ||
Height uint64 `bson:"height"` | ||
} |
This file contains 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 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 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 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.
I would suggest to make the collection generic for storing pointers so that this collection can be used for both BTC and BBN heights. (even for any other pointer values)
So it probably make sense to have a hardcoded primary key for the BBN height
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.
sure, is it ok if we change in later pr when the requirement arises?
btw in what case would we store btc pointer?
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.
The initial plan for syncing withdrawal transactions was to perform the same block scan as BBN blocks by storing the BTC height as a pointer to track the last processed height, avoiding the need to sync historical data. However, since the decision has been made to use this library to subscribe to BTC transaction events, this approach is no longer necessary.
That said, I would still argue for keeping this table generic, allowing us to store any pointer in this collection for future use.
Yes, of course. feel free to raise a ticket and we can track it in later PR
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.
i see sg, have made a ticket to track
#35