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

Move retry config out of reporter so its accessible by other clients #78

Conversation

gusin13
Copy link
Collaborator

@gusin13 gusin13 commented Oct 1, 2022

Fixes BM-199

Retry config is part of Reporter as of now due to which Babylon and BTC client can't access config params. This PR moves Retry in common config which will be accessible by all clients.

@gusin13 gusin13 force-pushed the BM-199-move-retry-config-out-of-reporter-so-its-accessible-by-other-clients branch from 04e571e to 011bdce Compare October 4, 2022 03:21
@SebastianElvis
Copy link
Member

While this PR is still WIP, one comment is to make retry config (and other potential ones in the future) a part of BaseConfig, rather than having a new RetryConfig. The BaseConfig was reserved exactly for configs that might be shared among modules.

@gusin13 gusin13 marked this pull request as ready for review October 4, 2022 21:51
Copy link
Member

@SebastianElvis SebastianElvis left a comment

Choose a reason for hiding this comment

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

LGTM! Finally we can merge all redundant configs in different modules to CommonConfig 👍

sample-vigilante-docker.yml Outdated Show resolved Hide resolved
reporter/reporter.go Outdated Show resolved Hide resolved
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! Added some comments related to refactoring (and some others that are not entirely related to this PR, we can create another one to address those or do that here, your call):

babylonclient/client.go Outdated Show resolved Hide resolved
babylonclient/client.go Outdated Show resolved Hide resolved
babylonclient/query.go Outdated Show resolved Hide resolved
btcclient/client_block_subscriber.go Outdated Show resolved Hide resolved
btcclient/client_block_subscriber.go Outdated Show resolved Hide resolved
config/common.go Outdated
// CommonConfig defines the server's basic configuration
type CommonConfig struct {
// Backoff interval for the first retry.
RetrySleepTime string `mapstructure:"retry-sleep-time"`
Copy link
Member

Choose a reason for hiding this comment

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

Some configuration entries are parseable time strings, while others are name-denomination (e.g. resend-interval-seconds). We should decide on the format that we want to use and stick to that for everything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, we can make it consistent. Should I change all of them to strings? As this involves submitter also, I will probably do this in a separate PR. cc @gitferry

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Is the format that we want to stick with the one that you have here or the name-denomination one?

Copy link
Member

Choose a reason for hiding this comment

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

I recall there was a suggestion by @aakoshh on one of @gitferry 's PRs that we use the name-denomination one but can't find the comment.

Copy link
Collaborator Author

@gusin13 gusin13 Oct 6, 2022

Choose a reason for hiding this comment

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

found Aakoshh's comment , this one. Also, I noticed for Babylon we are using string format here, so if we change the format we will need to change in BBN as well.

Copy link
Member

Choose a reason for hiding this comment

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

No problem with me and ok with this happening on another PR or here. In this PR we should make sure that we use the final version.

config/reporter.go Outdated Show resolved Hide resolved
@gusin13
Copy link
Collaborator Author

gusin13 commented Oct 8, 2022

@vitsalis I have added suggested fixes in this PR now, feel free to review it again. Here is the summary of issues and fixes.

  1. Central validation - Validation will be done only once when the config is loaded, no need to do it per client. Fixed here
  2. Pass explicitly config attributes - Fixed here
  3. Use a consistent format for time-based attributes -
    • I noticed something cool about the Viper library we use to parse configs, time durations can be directly loaded from yaml so no need to pass it as strings. Fixed here.
    • I have made a separate ticket to refactor this in the submitter. BM-221
  4. Missing validation for netparams - Fixed here

@gusin13 gusin13 requested a review from vitsalis October 8, 2022 21:26
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.

Very nice work, much cleaner! Some very very minor comments, but I'm ok with most of them not happening.

config/babylon.go Outdated Show resolved Hide resolved
return err
}
if cfg.BlockTimeout < 0 {
return errors.New("block-timeout can't be negative")
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BlockTimeout is not being used anywhere in the code but it exists in the config so I think it's fine to keep it 0sec as of now.

config/bitcoin.go Outdated Show resolved Hide resolved
@@ -46,7 +51,7 @@ func DefaultBTCConfig() BTCConfig {
WalletCAFile: defaultBtcWalletCAFile,
WalletLockTime: 10,
TxFee: feeAmount,
NetParams: "simnet",
NetParams: types.BtcSimnet.String(),
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

netparams/bitcoin.go Show resolved Hide resolved
reporter/btc_handlers.go Show resolved Hide resolved
return nil, err
}

func New(cfg *config.ReporterConfig, btcClient *btcclient.Client, babylonClient *babylonclient.Client, retrySleepTime, maxRetrySleepTime time.Duration) (*Reporter, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe split this line since it's getting too long.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -27,7 +28,7 @@ babylon:
key-directory: $TESTNET_PATH/node0/babylond
debug: true
timeout: 20s
block-timeout: ""
block-timeout: ~
Copy link
Member

Choose a reason for hiding this comment

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

Is this a placeholder for an empty string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

block-timeout is a time duration, so it can't be a string. ~ is null value so by default while parsing it will parse it as 0 sec

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

type SupportedBtcNetwork string
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@@ -17,3 +29,13 @@ func GetWrappedTxs(msg *wire.MsgBlock) []*btcutil.Tx {

return btcTxs
}

func GetValidNetParams() map[string]bool {
Copy link
Member

Choose a reason for hiding this comment

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

Since this function is only used for an existence check, why do we abstract this existence check behind a function that returns a map and this map is being used to check for inclusion? No problem with it if it matches your style.

@gusin13 gusin13 merged commit e8d94c6 into main Oct 11, 2022
@gusin13 gusin13 deleted the BM-199-move-retry-config-out-of-reporter-so-its-accessible-by-other-clients branch October 11, 2022 20:54
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