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

fix: create delegation reverse index over multiple blocks at 1000 items per block #622

Merged
merged 2 commits into from
Aug 30, 2024

Conversation

PaddyMc
Copy link
Collaborator

@PaddyMc PaddyMc commented Aug 28, 2024

Description

Currently our migration takes 1 min to completed with network effects at worst case scenario we could see 15 mins downtime.

This PR migrates the reverse index creation at 1000 items per block, this number was chosen to have the migration run for 1hr.

(190_000_000 * 2) / 60 => 1hr-ish

How to test

run tests

  1. cd x/staking/keeper
  2. go test ./... --run TestKeeperTestSuite/TestDelegationsByValidatorMigrations

run in-place-testnet and query the node

  1. Link this branch to the osmosis node in go.mod
  2. Run the in-place-testnet commands (ping @PaddyMc) if you don't know how
  3. Wait for the block processing to complete, in EndBlocker you can also increase the items per block
  4. run => osmosisd q staking delegations-to osmovaloper14lzvt4gdwh2q4ymyjqma0p4j4aykpn92l4warr
  5. this is still error, but on an in-place-testnet error GetValidator, debug through the query working as expected

Copy link

@PaddyMc your pull request is missing a changelog!

@PaddyMc PaddyMc force-pushed the fix/staking-migration branch 2 times, most recently from d83c4c6 to d99377a Compare August 28, 2024 18:51
x/staking/keeper/abci.go Fixed Show fixed Hide fixed
Comment on lines 26 to 35
func() {
defer func() {
if r := recover(); r != nil {
k.Logger(sdk.UnwrapSDKContext(ctx)).Error("Panic in MigrateDelegationsByValidatorIndex", "recover", r)
}
}()

// Only migrate 1000 items per block to make sure block times don't grow too much
k.MigrateDelegationsByValidatorIndex(sdk.UnwrapSDKContext(ctx), 1000)
}()

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
@PaddyMc PaddyMc force-pushed the fix/staking-migration branch from d99377a to 8e4a89e Compare August 29, 2024 08:02
@PaddyMc PaddyMc force-pushed the fix/staking-migration branch from 8e4a89e to a8ff26f Compare August 29, 2024 14:03
x/staking/keeper/abci.go Fixed Show resolved Hide resolved
Copy link
Member

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Great job! Didn't realize this was only in Undelegate

}()

// Only migrate 10000 items per block to make the migration as fast as possible
k.MigrateDelegationsByValidatorIndex(sdk.UnwrapSDKContext(ctx), 10000)

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.
@PaddyMc PaddyMc merged commit c88c7c3 into osmo/v0.50.x Aug 30, 2024
43 of 45 checks passed
@PaddyMc PaddyMc deleted the fix/staking-migration branch August 30, 2024 09:41
Comment on lines +112 to +117
// Check the store to see if there is a value stored under the key
key := store.Get(types.NextMigrateDelegationsByValidatorIndexKey)
if key != nil {
// Users will never see this error as if there is an error the function defaults to the legacy implementation below
return fmt.Errorf("store migration is not finished, try again later")
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a TODO to remove after v26, so we don't keep code that people a year from now will not remember why it was added.

Comment on lines +66 to +76
delAddrLen := bz[0]
bz = bz[1:] // remove the length byte of delegator address.
if len(bz) == 0 {
return nil, nil, fmt.Errorf("no bytes left to parse delegator address: %X", bz)
}

del := bz[:int(delAddrLen)]
bz = bz[int(delAddrLen):] // remove the length byte of a delegator address
if len(bz) == 0 {
return nil, nil, fmt.Errorf("no bytes left to parse delegator address: %X", bz)
}
Copy link
Member

Choose a reason for hiding this comment

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

Im confused by the comments here. It looks like we remove the length bye of the delegator address, and then the comments are saying we do it again on the same bz that we already removed the length byte on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah this is an incorrect comment what happens is:

  1. remove the length prefix
  2. remove the delegator address

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.

3 participants