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

reporter: improving resilience #69

Merged
merged 4 commits into from
Sep 21, 2022
Merged

reporter: improving resilience #69

merged 4 commits into from
Sep 21, 2022

Conversation

SebastianElvis
Copy link
Member

Fixes BM-186

This PR implements some measures to improve the reporter's resilience.

It is separated from #52. The PR #52 will be dedicated for implementing the bitcoind-compatible BTC client.

client.Client = rpcClient
return client, nil
}

func (c *Client) SubscribeBlocksByWebSocket() {
if err := c.NotifyBlocks(); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are getting error here , do we want to retry to improve resilience?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree. Added a function MustSubscribeBlocksByWebSocket and made the reporter to use it 👍

@@ -8,6 +8,21 @@ import (
"github.com/btcsuite/btcd/wire"
)

// GetBestBlock provides similar functionality with the btcd.rpcclient.GetBestBlock function
// We implement this, because this function is only provided by btcd.
func (c *Client) GetBestBlock() (*chainhash.Hash, uint64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

correct me if wrong, this is to support bitcoind? So vigilante can switch easily b/w different clients right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also can you explain if bitcoind is a go implementation of bitcoin core just like btcd, if yes I couldn't find the go package

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep. The reason of implementing this again rather than using the one provided by rpcclient is that the provided one uses APIs that are not supported by bitcoind. https://github.com/btcsuite/btcd/blob/a27738721a1ecdae504fb4738846401544a53e4d/rpcclient/extensions.go#L189-L192

Copy link
Member Author

Choose a reason for hiding this comment

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

also can you explain if bitcoind is a go implementation of bitcoin core just like btcd, if yes I couldn't find the go package

It's https://github.com/bitcoin/bitcoin. This is the earliest and most widely used Bitcoin implementation, and is written in C++.

@gusin13 gusin13 self-requested a review September 21, 2022 03:31
Copy link
Collaborator

@gusin13 gusin13 left a comment

Choose a reason for hiding this comment

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

Overall LGTM 👍

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

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

Nice work! Some minor stuff:

@@ -69,6 +72,22 @@ func (c *Client) QueryBTCCheckpointParams() (*btcctypes.Params, error) {
return &resp.Params, nil
}

func (c *Client) MustQueryBTCCheckpointParams() *btcctypes.Params {
var params *btcctypes.Params
err := types.Retry(1*time.Second, 1*time.Minute, func() error { // TODO parameterise
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the same retrying parameters that are used elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the parameters are attached to reporter's config, that Babylon client does not have access. Updated the TODO on making the retry parameters universal for all packages.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks! A github issue might help keep track as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! Created #70


func (c *Client) MustSubscribeBlocksByWebSocket() {
err := types.Retry(1*time.Second, 1*time.Minute, func() error { // TODO parameterise
return c.NotifyBlocks()
Copy link
Member

Choose a reason for hiding this comment

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

We could use the SubscribeBlocksByWebSocket here.

@@ -24,6 +24,12 @@ func (r *Reporter) Init() {

/* ensure BTC has catched up with BBN header chain */

// Find the base height
_, bbnBaseHeight, err = r.babylonClient.QueryBaseHeader()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can make this a MustQueryBaseHeader.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah @gusin13 has a ticket https://babylon-chain.atlassian.net/browse/BM-183 dedicated for replacing panics with Must-style functions.

@@ -75,13 +83,9 @@ func (r *Reporter) Init() {
}
log.Debugf("BTC cache size: %d", tempBTCCache.Size())

/* Initial consistency check: whether the `max(bbn_tip_height - confirmation_depth, bbn_base_height)`-th block is same */
r.btcClient.MustSubscribeBlocksByWebSocket()
Copy link
Member

Choose a reason for hiding this comment

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

Why was this moved here?

Copy link
Member Author

@SebastianElvis SebastianElvis Sep 21, 2022

Choose a reason for hiding this comment

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

We want to ensure that the block subscription starts right after snapshotting the BTC chain (which is done by initBTCCache), so that the subscribed blocks and snapshotted blocks do not have overlap. Otherwise, if we subscribe too early, then they will have overlap, leading to duplicated header/ckpt submissions.

Added some justification on this.

@SebastianElvis SebastianElvis merged commit 4c053fb into main Sep 21, 2022
@SebastianElvis SebastianElvis deleted the reporter-resilience branch September 21, 2022 06:44
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.

3 participants