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

WIP: feat: bitcoin elections #5457

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from
Draft

WIP: feat: bitcoin elections #5457

wants to merge 42 commits into from

Conversation

kylezs
Copy link
Contributor

@kylezs kylezs commented Nov 28, 2024

WIP: This will become the base branch/PR for the conversion of the bitcoin witnessing to the new elections pallet.

Pull Request

Closes: PRO-1772

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have written sufficient tests.
  • I have written and tested required migrations.
  • I have updated documentation where appropriate.

Summary

@kylezs kylezs force-pushed the feat/block-witnesser-es branch from 3abae7c to 92b9f65 Compare November 28, 2024 14:21
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 38.54077% with 716 lines in your changes missing coverage. Please review.

Project coverage is 71%. Comparing base (acd6dd9) to head (dcbc040).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
engine/src/witness/btc_e.rs 0% 99 Missing ⚠️
...e-chain/runtime/src/chainflip/bitcoin_elections.rs 11% 92 Missing ⚠️
...ons/src/electoral_systems/block_height_tracking.rs 60% 77 Missing and 6 partials ⚠️
..._systems/block_height_tracking/state_machine_es.rs 0% 70 Missing ⚠️
...e/src/state_chain_observer/client/electoral_api.rs 0% 69 Missing ⚠️
...elections/src/electoral_systems/block_witnesser.rs 68% 28 Missing and 22 partials ⚠️
...ctoral_systems/block_height_tracking/primitives.rs 62% 39 Missing and 4 partials ⚠️
...ectoral_systems/block_height_tracking/consensus.rs 0% 41 Missing ⚠️
state-chain/chains/src/lib.rs 26% 35 Missing and 2 partials ⚠️
engine/src/elections.rs 0% 26 Missing ⚠️
... and 15 more
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #5457     +/-   ##
=======================================
- Coverage     72%     71%     -1%     
=======================================
  Files        495     508     +13     
  Lines      88356   89413   +1057     
  Branches   88356   89413   +1057     
=======================================
- Hits       63340   63311     -29     
- Misses     22448   23395    +947     
- Partials    2568    2707    +139     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

MxmUrw and others added 24 commits January 27, 2025 10:26
Both `ElectoralSystem` and `ElectoralSystemRunner` inherit from it.
The voter api can now signal that it doesn't have anything to vote for
by returning `Ok(None)`. Previously, in such cases we had to return `Err(..)`,
which lead to the RetrierClient scheduling an exponential backoff.
* refactor: unprocessed data as Vec<> in state

* WIP

* clean up and initialise btc elections voters
WIP
(currently doesn't compile because of one missing function)
MxmUrw and others added 16 commits January 27, 2025 12:53
 - Add new `ChainProgress` enum as interface between BHW and BW.
 - Fix bug where going from the first special election to the proper election
   consensus leaves some wrong state.
 - Restructure into multiple files.
* wip

* divide logic between enum variants
Include both ranges in `ChainProgress::Reorg` variant.
Fix BHW bugs, now reorgs are processed correctly.
* WIP: Add state machine approach to BHW.

* Refactor BHW to have `N : Step` parameter.

This means that N can be a witness range if required,
without further changes necessary to the BHW ES.
…#5516)

* Sketch state machine for BW.

* Rewrite state machine abstraction for BW.

* WIP: Begin implementing BW as state machine.

Currently missing: GenerateElectionProperties Hook.

* WIP: Get election creation and deletion working for BW.

* WIP: refactor: restructuring BW code into multiple files.

* WIP: add test for BW (input generators, spec).

* WIP: Fully switch BW and BHW ESs over to new way of instantiating state machine ESs.

* WIP: chore: Clean up.

* WIP: increase strategy coverage for BW, some bugs exist.

* WIP: rewrite ElectionTracker logic for BW.

It now also works for cases where the reorg range arbitrarily intersects with the ongoing elections.

* WIP: Fix generation of new reorg indices.

* WIP: Improve step spec for BW.

* WIP: refactor step specification for BW, make it more readable.

* WIP: Use hook for safemode instead of settings.

* WIP: reorganize. Move generic SM files into state_machine module.

* WIP: run cargo fix to cleanup imports.

* WIP: Fix more warnings.

* WIP: run cargo fmt.

* WIP: Refactor BHW, add some comments.

* WIP: refactor: move the state machine of block_height_tracking
into its own file.

* WIP: feat: add `BlockHeightChangeHook` called from the BHW when the block height changes.

* WIP: fix: remove `ProcessedUpTo` check in `active_deposit_channels_at`.

The deposit channels open at a chainblock do not depend on how much we have processed already. I assume!

* WIP: Allow for submission of multiple blocks when initializing BHW.

* WIP: refactor `BlockWitnessRange`

 - It now takes a `ChainWitnessConfig` as parameter
 - BHW works with this range type now

* WIP: Allow BW state machine to use BlockWitnessRange as block number.

* WIP: begin porting manual BW tests to new SM based BW.

* WIP: chore: Apply suggestions from code review

Co-authored-by: kylezs <kyle@chainflip.io>

* WIP: Refactor state machine ES as to always forward the current election properties to the SM input.

* WIP: refactor: better names found after catchup discussion.

---------

Co-authored-by: kylezs <kyle@chainflip.io>
…en in safemode.

Added tests which make sure that this will eventually lead to all elections being stopped.
* impl BitcoinDepositChannelWitessingProcessor

* impl BitcoinDepositChannelWitessingProcessor

* WIP

* WIP

* WIP State Machin Block Processor impl

* WIP State Machin Block Processor impl

* fix comflicts
@MxmUrw MxmUrw force-pushed the feat/block-witnesser-es branch from f8982b8 to 6e6a0d2 Compare January 27, 2025 14:53
@MxmUrw
Copy link
Contributor

MxmUrw commented Jan 27, 2025

I rebased on #5589, which should hopefully soon be merged into main.

* BitcoinLiveness election

* - set initial penalty
- set SC blocks interval for election to 10 (1m)
* WIP prop testing & clippy

* move BlockProcessor inside cf-election pallet
- generalize it, general logic the same for every chain
- keep hook implementation dependant on the chain for custom behaviour

* allow hook to mutate self, such that we can implement a general hook counter for testing

* compile and clippy pass succesfully
TODO: write all the tests

* unit tests (not exhaustive)

* add docs

* lint & clippy

* - make cleanOld a method of the BlockProcessor

* rename to state_machine

* use Hook for safety_margin

* rebase
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