Skip to content

Commit

Permalink
RFC 12 Implementation: Proposal generation (#3747)
Browse files Browse the repository at this point in the history
Refs: keep-network/tbtc-v2#737
Depends on: #3745

Here we present the third part of the changes meant to implement [RFC
12: Decentralized wallet
coordination](https://github.com/keep-network/tbtc-v2/blob/main/docs/rfc/rfc-12.adoc)
in the tBTC wallet client. This pull request focuses on proposal
generation.

### Remove wallet coordination from the maintainer module

So far, the maintainer bot implemented in the `pkg/maintainer` package
was responsible for wallet coordination. The logic was living in the
`pkg/maintainer/wallet` sub-package. As the maintainer bot is no longer
responsible for wallet coordination, we are detaching the wallet
coordination from there. This has also an impact on the maintainer-cli.
Commands responsible for deposit sweep and redemption proposal
submission are no longer available.

### Move code from `pkg/maintainer/wallet` package to `pkg/tbtcpg`

Although the maintainer no longer uses the wallet coordination code,
that code is still useful for the new coordination mechanism. It
contains the logic necessary to produce coordination proposals. Hence,
we moved it to the new `pkg/tbtcpg` package and exposed an entry point
component `ProposalGenerator` that implements the
`tbtc.CoordinationProposalGenerator` interface. Thanks to that, the
`pkg/tbtc` package can use the code from `pkg/tbtcpg` to generate
coordination proposals.

Ideally, the code from `pkg/tbtcpg` should be embedded into `pkg/tbtc`.
However, both packages are not compatible out of the box. Merging them
would require a lot of breaking changes. As RFC 12 implementation is
already a complex task, we decided to keep `pkg/tbtcpg` as a separate
being for now, to reduce risk.

Last but not least, the code in `pkg/tbtcpg` was simplified. This code
no longer needs to handle proposals for multiple wallets at the same
time so focusing on a single wallet allowed us to remove redundant code
and facilitate further maintenance.

### Wire up `pkg/tbtcpg` package to `pkg/tbtc`

As mentioned in the previous section, the `pkg/tbtcpg` implements the
`tbtc.CoordinationProposalGenerator` interface so it can be used to
generate proposals within the new coordination mechanism. This was
achieved by injecting the `tbtcpg.ProposalGenerator` as a dependency to
`tbtc.node`, during the setup process.

### Next steps

The next steps on the way towards RFC 12 implementation are:

- Finalize coordination result processing (i.e. implement the
`processCoordinationResult` function and refactor `node`'s handlers
appropriately)
- Remove the existing chain-based mechanism (i.e. detach
`WalletCoordinator`'s events handlers and remove unnecessary code from
`chain.go`)
- Modify the SPV maintainter to not rely on `WalletCoordinator`'s events
during unproven transactions lookup
  • Loading branch information
tomaszslabon authored Dec 4, 2023
2 parents 4b78c97 + e5b0a76 commit 090e7f7
Show file tree
Hide file tree
Showing 49 changed files with 1,181 additions and 2,083 deletions.
36 changes: 0 additions & 36 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
chainEthereum "github.com/keep-network/keep-core/pkg/chain/ethereum"
"github.com/keep-network/keep-core/pkg/clientinfo"
"github.com/keep-network/keep-core/pkg/maintainer/spv"
"github.com/keep-network/keep-core/pkg/maintainer/wallet"
"github.com/keep-network/keep-core/pkg/net/libp2p"
"github.com/keep-network/keep-core/pkg/tbtc"
)
Expand Down Expand Up @@ -327,41 +326,6 @@ func initMaintainerFlags(command *cobra.Command, cfg *config.Config) {
"Disable Bitcoin difficulty proxy.",
)

command.Flags().BoolVar(
&cfg.Maintainer.WalletCoordination.Enabled,
"walletCoordination",
false,
"Start wallet coordination maintainer.",
)

command.Flags().DurationVar(
&cfg.Maintainer.WalletCoordination.RedemptionInterval,
"walletCoordination.redemptionInterval",
wallet.DefaultRedemptionInterval,
"The time interval in which pending redemptions requests are checked.",
)

command.Flags().Uint16Var(
&cfg.Maintainer.WalletCoordination.RedemptionWalletsLimit,
"walletCoordination.redemptionWalletsLimit",
wallet.DefaultRedemptionWalletsLimit,
"Limits the number of wallets that can receive a redemption proposal in the same time.",
)

command.Flags().Uint64Var(
&cfg.Maintainer.WalletCoordination.RedemptionRequestAmountLimit,
"walletCoordination.redemptionRequestAmountLimit",
wallet.DefaultRedemptionRequestAmountLimit,
"Limits the redemption requests to the ones below the given satoshi value.",
)

command.Flags().DurationVar(
&cfg.Maintainer.WalletCoordination.DepositSweepInterval,
"walletCoordination.depositSweepInterval",
wallet.DefaultDepositSweepInterval,
"The time interval in which unswept deposits are checked.",
)

command.Flags().BoolVar(
&cfg.Maintainer.Spv.Enabled,
"spv",
Expand Down
37 changes: 0 additions & 37 deletions cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,43 +239,6 @@ var cmdFlagsTests = map[string]struct {
expectedValueFromFlag: true,
defaultValue: false,
},
"maintainer.walletCoordination": {
readValueFunc: func(c *config.Config) interface{} { return c.Maintainer.WalletCoordination.Enabled },
flagName: "--walletCoordination",
flagValue: "", // don't provide any value
expectedValueFromFlag: true,
defaultValue: false,
},
"maintainer.walletCoordination.redemptionInterval": {
readValueFunc: func(c *config.Config) interface{} { return c.Maintainer.WalletCoordination.RedemptionInterval },
flagName: "--walletCoordination.redemptionInterval",
flagValue: "7h",
expectedValueFromFlag: 7 * time.Hour,
defaultValue: 3 * time.Hour,
},
"maintainer.walletCoordination.redemptionWalletsLimit": {
readValueFunc: func(c *config.Config) interface{} { return c.Maintainer.WalletCoordination.RedemptionWalletsLimit },
flagName: "--walletCoordination.redemptionWalletsLimit",
flagValue: "10",
expectedValueFromFlag: uint16(10),
defaultValue: uint16(3),
},
"maintainer.walletCoordination.redemptionRequestAmountLimit": {
readValueFunc: func(c *config.Config) interface{} {
return c.Maintainer.WalletCoordination.RedemptionRequestAmountLimit
},
flagName: "--walletCoordination.redemptionRequestAmountLimit",
flagValue: "500",
expectedValueFromFlag: uint64(500),
defaultValue: uint64(10 * 1e8),
},
"maintainer.walletCoordination.depositSweepInterval": {
readValueFunc: func(c *config.Config) interface{} { return c.Maintainer.WalletCoordination.DepositSweepInterval },
flagName: "--walletCoordination.depositSweepInterval",
flagValue: "35h",
expectedValueFromFlag: 35 * time.Hour,
defaultValue: 48 * time.Hour,
},
"maintainer.spv": {
readValueFunc: func(c *config.Config) interface{} { return c.Maintainer.Spv.Enabled },
flagName: "--spv",
Expand Down
1 change: 0 additions & 1 deletion cmd/maintainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func maintainers(cmd *cobra.Command, args []string) error {
btcChain,
btcDiffChain,
tbtcChain,
tbtcChain,
)

<-ctx.Done()
Expand Down
Loading

0 comments on commit 090e7f7

Please sign in to comment.