-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(auth): support legacy global AccountNumber when query historical state (port #23743) #24533
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
Conversation
…state (cosmos#23743) Co-authored-by: HuangYi <[email protected]>
Ironbird - launch a networkTo use Ironbird, you can use the following commands:
Custom Load Test ConfigurationYou can provide a custom load test configuration using the `--load-test-config=` flag:
Use |
📝 WalkthroughWalkthroughThe changes introduce support for a legacy global account number in the x/auth module. A new method retrieves the legacy account number from the old key, and the logic for incrementing the account number now falls back to this legacy value if the new storage key is not found. A new exported constant for the legacy key is added to the types package. Migration and test code are updated to reference this exported key. The changelog is updated with a bug fix entry describing these changes. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AccountKeeper
participant Store
Client->>AccountKeeper: NextAccountNumber(ctx)
AccountKeeper->>Store: Get(new account number key)
alt Key found
Store-->>AccountKeeper: current account number
else Key not found (legacy state)
AccountKeeper->>Store: Get(legacy account number key)
Store-->>AccountKeeper: legacy account number
end
AccountKeeper->>Store: Set(new account number key, incremented value)
AccountKeeper-->>Client: return current account number
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🧰 Additional context used🧬 Code Graph Analysis (3)x/auth/migrations/v5/migrate_test.go (1)
x/auth/migrations/v5/migrate.go (1)
x/auth/keeper/keeper.go (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (11)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
x/auth/keeper/keeper.go
Outdated
n, err := collections.Item[uint64](ak.AccountNumber).Get(ctx) | ||
if err != nil && errors.Is(err, collections.ErrNotFound) { | ||
// this won't happen in the tip of production network, | ||
// but can happen when query historical states, | ||
// fallback to old key for backward-compatibility. | ||
n, err = ak.GetAccountNumberLegacy(ctx) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add some tests for this new flow here?
x/auth/keeper/keeper.go
Outdated
@@ -181,13 +183,38 @@ func (ak AccountKeeper) GetSequence(ctx context.Context, addr sdk.AccAddress) (u | |||
return acc.GetSequence(), nil | |||
} | |||
|
|||
func (ak AccountKeeper) GetAccountNumberLegacy(ctx context.Context) (uint64, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be private
x/auth/keeper/keeper_test.go
Outdated
data, err := val.Marshal() | ||
require.NoError(t, err) | ||
store := storeService.OpenKVStore(ctx) | ||
err = store.Set(types.LegacyGlobalAccountNumberKey, data) | ||
require.NoError(t, err) | ||
|
||
nextNum := ak.NextAccountNumber(ctx) | ||
require.Equal(t, num, nextNum) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be its own t.Run(...)
testcase with a description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execute order matters, seems separate case is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM i would just like some more clarity in the test cases as to what they are testing
Description
for more info
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
in the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit