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

finality: move voting power dist update to finality module #216

Merged

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Oct 21, 2024

First step of #24

This PR moves the voting power distribution update algorithm to x/finality. This is a major refactoring that includes

  • moving max_active_finality_providers parameter to x/finality
  • moving many functions in x/btcstaking/power_dist_change.go and relevant tests to x/finality
  • moving test utilities under x/btcstaking/keeper_test.go to a new module testutil/btcstaking-helper, and use it for existing tests of x/btcstaking and x/finality
  • removing the cyclic dependency between x/btcstaking and x/finality, as well as their hooks. Now the hooks in these 2 modules are not necessary, as the only dependency between them is that x/finality will invoke x/btcstaking, but not the other way

TODOs in subsequent PRs:

  • moving some relevant query APIs to x/finality
  • moving the voting power dist cache and voting power table KV stores to x/finality

@SebastianElvis SebastianElvis marked this pull request as ready for review October 22, 2024 04:43
@SebastianElvis SebastianElvis requested a review from a team as a code owner October 22, 2024 04:43
@SebastianElvis SebastianElvis requested review from gitferry, KonradStaniec, RafilxTenfen and a team and removed request for a team October 22, 2024 04:43
Copy link
Collaborator

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

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

shouldn't this whole migration be done first on feature branch ?

@@ -84,8 +66,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
func (k Keeper) BeginBlocker(ctx context.Context) error {
// index BTC height at the current height
k.IndexBTCHeight(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

as both k.IndexBTCHeight(ctx) and k.UpdatePowerDist(ctx) are happening in BeginBlocker, it means in our v0.9.0 chain there is already data created and saved to database due to its usage.

This will probably means we require some data migration during upgrade

Copy link
Member Author

@SebastianElvis SebastianElvis Oct 22, 2024

Choose a reason for hiding this comment

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

Compared to TGE chain, not really actually. The IndexBTCHeight is same in TGE chain and this version. The only difference is the voting power dist cache. As in TGE chain the code always triggers here, there is no voting power dist cache or voting power table recorded. Thus even after we move both KV stores to x/finality, the upgrade handler does not need to do any extra thing for it.

This is probably why the upgrade e2e test works properly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ahh true ! so in tge chain prefix, there is no distribution caches anywhere as there is no staker/fp with voting power. thanks for explanantion 👍

@SebastianElvis
Copy link
Member Author

SebastianElvis commented Oct 22, 2024

shouldn't this whole migration be done first on feature branch ?

Fine with me on having a feature branch for this. However, given that 1) this PR is self-contained, and 2) this PR breaks a lot of things while we have a fast development schedule, I'm more inclined to merge it first. Do you have any concern on having it in main before finishing the entire feature?

@KonradStaniec
Copy link
Collaborator

Fine with me on having a feature branch for this. However, given that 1) this PR is self-contained, and 2) this PR breaks a lot of things while we have a fast development schedule, I'm more inclined to merge it first. Do you have any concern on having it in main before finishing the entire feature?

My main concern is that it is not yet finished feature/change which leads to few problems:

  • it is now hard to asses how the final change will look like after all kv stores move etc.
  • later after merge there will several commits on main branch corresponding to this one conceptual change.

I know we are on fast development schedule, but tbh if this whole feature ends up devnet5 then imo it will be fine. Or maybe we can delay devnet4 by one day if it will be possible to land this. Do you think it is feasible ?

@SebastianElvis SebastianElvis changed the base branch from main to feat/voting-power-table-refactor October 22, 2024 07:59
@SebastianElvis
Copy link
Member Author

My main concern is that it is not yet finished feature/change which leads to few problems:

  • it is now hard to asses how the final change will look like after all kv stores move etc.
  • later after merge there will several commits on main branch corresponding to this one conceptual change.

I know we are on fast development schedule, but tbh if this whole feature ends up devnet5 then imo it will be fine. Or maybe we can delay devnet4 by one day if it will be possible to land this. Do you think it is feasible ?

Alright, make sense. Targeted this PR to a feature branch then. I don't think we need to bother to delay devnet 4 for this feature though. Let's stick to the original schedule and target to have this feature in devnet 5.

@SebastianElvis SebastianElvis merged commit a2dd350 into feat/voting-power-table-refactor Oct 22, 2024
20 checks passed
@SebastianElvis SebastianElvis deleted the move-voting-power-dist-cache branch October 22, 2024 08:50
SebastianElvis added a commit that referenced this pull request Oct 23, 2024
First step of #24

This PR moves the voting power distribution update algorithm to
`x/finality`. This is a major refactoring that includes

- moving `max_active_finality_providers` parameter to `x/finality`
- moving many functions in `x/btcstaking/power_dist_change.go` and
relevant tests to `x/finality`
- moving test utilities under `x/btcstaking/keeper_test.go` to a new
module `testutil/btcstaking-helper`, and use it for existing tests of
`x/btcstaking` and `x/finality`
- removing the cyclic dependency between `x/btcstaking` and
`x/finality`, as well as their hooks. Now the hooks in these 2 modules
are not necessary, as the only dependency between them is that
`x/finality` will invoke `x/btcstaking`, but not the other way

TODOs in subsequent PRs:

- moving some relevant query APIs to `x/finality`
- moving the voting power dist cache and voting power table KV stores to
`x/finality`
SebastianElvis added a commit that referenced this pull request Oct 23, 2024
First step of #24

This PR moves the voting power distribution update algorithm to
`x/finality`. This is a major refactoring that includes

- moving `max_active_finality_providers` parameter to `x/finality`
- moving many functions in `x/btcstaking/power_dist_change.go` and
relevant tests to `x/finality`
- moving test utilities under `x/btcstaking/keeper_test.go` to a new
module `testutil/btcstaking-helper`, and use it for existing tests of
`x/btcstaking` and `x/finality`
- removing the cyclic dependency between `x/btcstaking` and
`x/finality`, as well as their hooks. Now the hooks in these 2 modules
are not necessary, as the only dependency between them is that
`x/finality` will invoke `x/btcstaking`, but not the other way

TODOs in subsequent PRs:

- moving some relevant query APIs to `x/finality`
- moving the voting power dist cache and voting power table KV stores to
`x/finality`
SebastianElvis added a commit that referenced this pull request Oct 25, 2024
First step of #24

This PR moves the voting power distribution update algorithm to
`x/finality`. This is a major refactoring that includes

- moving `max_active_finality_providers` parameter to `x/finality`
- moving many functions in `x/btcstaking/power_dist_change.go` and
relevant tests to `x/finality`
- moving test utilities under `x/btcstaking/keeper_test.go` to a new
module `testutil/btcstaking-helper`, and use it for existing tests of
`x/btcstaking` and `x/finality`
- removing the cyclic dependency between `x/btcstaking` and
`x/finality`, as well as their hooks. Now the hooks in these 2 modules
are not necessary, as the only dependency between them is that
`x/finality` will invoke `x/btcstaking`, but not the other way

TODOs in subsequent PRs:

- moving some relevant query APIs to `x/finality`
- moving the voting power dist cache and voting power table KV stores to
`x/finality`
SebastianElvis added a commit that referenced this pull request Oct 29, 2024
First step of #24

This PR moves the voting power distribution update algorithm to
`x/finality`. This is a major refactoring that includes

- moving `max_active_finality_providers` parameter to `x/finality`
- moving many functions in `x/btcstaking/power_dist_change.go` and
relevant tests to `x/finality`
- moving test utilities under `x/btcstaking/keeper_test.go` to a new
module `testutil/btcstaking-helper`, and use it for existing tests of
`x/btcstaking` and `x/finality`
- removing the cyclic dependency between `x/btcstaking` and
`x/finality`, as well as their hooks. Now the hooks in these 2 modules
are not necessary, as the only dependency between them is that
`x/finality` will invoke `x/btcstaking`, but not the other way

TODOs in subsequent PRs:

- moving some relevant query APIs to `x/finality`
- moving the voting power dist cache and voting power table KV stores to
`x/finality`
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.

2 participants