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

LSM staking migration #17

Merged
merged 22 commits into from
Aug 10, 2023
Merged

Conversation

riley-stride
Copy link
Collaborator

@riley-stride riley-stride commented Jul 8, 2023

  • Migrates staking to support state changes from LSM
  • Registers the migration as consensus version 3
  • Migration applies the following changes:
    • Params: adds ValidatorBondFactor, ValidatorLiquidStakingCap, GlobalLiquidStakingCap
    • Validators: adds LiquidShares and ValidatorBondShares
    • Delegation: adds ValidatorBond
    • Runs RefreshTotalLiquidStakedTokens to determine the total stake from ICA accounts
  • Question for reviewers: Do we need to do anything in the upgrade handler for newly deprecated min_self_delegation?

@riley-stride riley-stride marked this pull request as draft July 10, 2023 16:58
Copy link

@xlab xlab left a comment

Choose a reason for hiding this comment

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

Does types.TotalLiquidStakedTokensKey need to be set with sdk.ZeroInt() bytes? I did it for peace of mind, to avoid any nil panics when this global counter is not initialized.

@sampocs sampocs changed the title Gaia v11 LSM upgrade handler LSM staking migration Aug 2, 2023
@sampocs sampocs marked this pull request as ready for review August 2, 2023 23:31
@sampocs
Copy link
Collaborator

sampocs commented Aug 2, 2023

@xlab Sorry for the delay!

Does types.TotalLiquidStakedTokensKey need to be set with sdk.ZeroInt() bytes? I did it for peace of mind, to avoid any nil panics when this global counter is not initialized.

Don't we return zero in the case of uninitialized bits [ref]?

@xlab
Copy link

xlab commented Aug 3, 2023

@xlab Sorry for the delay!

Does types.TotalLiquidStakedTokensKey need to be set with sdk.ZeroInt() bytes? I did it for peace of mind, to avoid any nil panics when this global counter is not initialized.

Don't we return zero in the case of uninitialized bits [ref]?

Yes it does now, I am just having some flashbacks when it didn't and our testnet crashed :D
So now I'm setting to zero, just in case.. I think it's ok either way now.

Copy link

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

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

Added some comments.

Don't you also need to bump the consensus version of the x/staking module when performing a migration?

// ConsensusVersion implements AppModule/ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 2 }


// migrateUBDEntries will remove the ubdEntries with same creation_height
// and create a new ubdEntry with updated balance and initial_balance
func migrateUBDEntries(ctx sdk.Context, store storetypes.KVStore, cdc codec.BinaryCodec, legacySubspace exported.Subspace) error {
Copy link

Choose a reason for hiding this comment

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

Can we have a test for this?

I'm not sure it exists on cosmos-sdk v47?

It can be setup like so:

  1. create old entries -> have multiple entries at the same block height
  2. migrate entries -> confirm that entries at the same height got merged

I'm also willing to accept this if this function is tested somewhere, but I don't see that being the case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

unit test added in latest commits

@MSalopek
Copy link

MSalopek commented Aug 8, 2023

Beware that this will be a long migration (long as in taking a lot of time).

The list of delegations is >800k records, and every delegation has multiple entries.

@sampocs
Copy link
Collaborator

sampocs commented Aug 8, 2023

@MSalopek

Don't you also need to bump the consensus version

Great catch! updated in above commit

Copy link

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

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

Making a comment because I cannot review unchanged code.

Think you also need to register the upgrade handler in x/staking/module.go

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
	types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
	querier := keeper.Querier{Keeper: am.keeper}
	types.RegisterQueryServer(cfg.QueryServer(), querier)
	m := keeper.NewMigrator(am.keeper)
	cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)

+	if err := cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3); err != nil {
+		panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
	}
}

Copy link

@MSalopek MSalopek left a comment

Choose a reason for hiding this comment

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

Looks good after changes.

Thanks!

@sampocs sampocs merged commit 0041b6a into v0.45.16-ics-lsm Aug 10, 2023
22 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants