-
Notifications
You must be signed in to change notification settings - Fork 75
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
RFC 12 Implementation: Coordination procedure #3745
Merged
Merged
Conversation
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
Here we implement the logic of designating the coordination leader according to the specification presented in RFC 12.
Here we are implementing the code responsible for building an actions checklist that will be used to generate a proposal. We are also adding an outline of the leader's routine.
Here we implement the coordination message type along with all marshaling machinery necessary to transfer it over the wire.
Proposal generation must have a way to identify the wallet. Code currently used by the wallet maintainer (`pkg/maintainer/wallet`) uses 20-byte wallet public key hashes for that purpose. As we plan to reuse it in the new mechanism, we should use the same identifier.
Here we implement the follower's routine along with necessary message validation.
tomaszslabon
approved these changes
Nov 30, 2023
tomaszslabon
added a commit
that referenced
this pull request
Dec 4, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refs: keep-network/tbtc-v2#737
Depends on: #3744
Here we present the second part of the changes meant to implement RFC 12: Decentralized wallet coordination in the tBTC wallet client. This pull request focuses on the coordination procedure.
On the code level, this is about implementing the
coordinationExecutor.coordinate
function.Coordination seed
Calculation of the coordination seed was implemented in the
coordinationExecutor.getSeed
function. This function computes the seed for the given coordination window according to the RFC 12 specification:The computed value is used to initialize the RNG for random operations executed as part of the coordination procedure. Those operations are:
Coordination leader
Leader selection was implemented in the
coordinationExecutor.getLeader
function. It uses the coordination seed to select the leader operator from all operators backing the coordinated wallet. The exact algorithm is:Actions checklist
The next step is determining which wallet actions should be checked and possibly proposed during the coordination window. A list of such actions is called actions checklist. Actions on the list are ordered by priority, in descending order.
For example, if the list is:
[Redemption, DepositSweep, Heartbeat]
, the leader must start by checking if redemption can be proposed. If so, it should do it. Otherwise, it should check the deposit sweep. If neither redemption nor deposit sweep can be proposed, the leader should propose a heartbeat.Actions checklist assembling was implemented in the
coordinationExecutor.getActionsChecklist
function. The exact checklist depends on the coordination window. The specific algorithm is:Leader's routine
If the given operator finds itself to be a leader for the given coordination window, it executes the leader's routine implemented in the
coordinationExecutor.executeLeaderRoutine
function. It uses the actions checklist to generate a proposal and broadcasts the proposal to the followers, using the underlying broadcast channel. It completes the coordination procedure returning the generated proposal as a result.Proposal generator
The leader uses the proposal generator function to generate a proposal based on the actions checklist for the given window. The generator is expected to return a proposal for the first action from the checklist that is valid for the given wallet's state. If none of the actions are valid, the generator returns a no-op proposal.
Implementation of the proposal generator is beyond the scope of this pull request and will be handled in a follow-up PR. The plan is to use the code from
pkg/maintainer/wallet
that is currently used by the wallet maintainer bot.Follower's routine
If the given operator is not the leader for the given coordination window, it executes the follower's routine implemented in the
coordinationExecutor.executeFollowerRoutine
function. It listens for incoming coordination messages and accepts the first message that:The operator-follower completes the coordination procedure returning the received proposal as a result.
Next steps
The next steps on the way towards RFC 12 implementation are:
processCoordinationResult
function and refactornode
's handlers appropriately)WalletCoordinator
's events handlers and remove unnecessary code fromchain.go
)WalletCoordinator
's events during unproven transactions lookup