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

feat: sdk v0.50.x upgrade #8274

Merged
merged 95 commits into from
May 24, 2024
Merged

feat: sdk v0.50.x upgrade #8274

merged 95 commits into from
May 24, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented May 17, 2024

Closes: #XXX

What is the purpose of the change

References

SDK Upgrading Guide: https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#v050x
DYDX Upgrade PRs:

Notes

Testing and Verifying

Keeping track here of TODOs that will likely transcend this PR:

  • Check on ante CheckIfBlocked, smartaccount AnteHandle, smartaccount ValidateAuthenticatorFeePayer, smartacount GenerateAuthenticationRequest, smartaccount PostHandle. These all use GetMsgV1Signers to determine the signers, since GetSigners() was removed.
  • Benchmark how much the new SQS block processing logic slows down sync speed.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A


// Using branch osmo/v0.37.4
// UNFORKING v2 TODO: No longer use wasmd fork, added logic to app.toml override to use 1000 instead of default 100 cache size, which was the reason for having the fork in the first place.
Copy link
Member Author

Choose a reason for hiding this comment

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

.

go.mod Outdated
// github.com/osmosis-labs/osmosis/osmoutils => ./osmoutils
// github.com/osmosis-labs/osmosis/x/epochs => ./x/epochs
// github.com/osmosis-labs/osmosis/x/ibc-hooks => ./x/ibc-hooks
// UNFORKING v2 TOOD: Need to manually define these until we tag, it keeps trying to "upgrade" which actually downgrades us to the old sdk sub module logic
Copy link
Member Author

Choose a reason for hiding this comment

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

.

@p0mvn
Copy link
Member

p0mvn commented May 21, 2024

Unclear what this line in the upgrading.md is talking about https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#stringer. As in, do we need to ensure .String() isn't used anywhere in the state machine now??

I think we should just review if there are state-machine usages. If so, look at the scope of the modified methods

@p0mvn
Copy link
Member

p0mvn commented May 21, 2024

Do we continue using osmomath types for math types or do we replace all of them with the math package https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#math

I think we can continue using osmomath as is. I think what they refer to is different from the purpose of our osmomath aliasing which was made to avoid the verbosity of LegacyDec. Additionally, we often need to import both BigDec and other sdk math types. Having a single math import makes a light but meaningful cognitive overhead reduction.

In any way, removing aliases is a state-compatible change which we can do at any time if it's ever needed

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Great work on powering through this!

I'm far from being done but just wanted to leave some initial comments as to avoid a single large review cycles

app.SetStreamingManager(
storetypes.StreamingManager{
ABCIListeners: []storetypes.ABCIListener{sqsStreamingService},
StopNodeOnErr: true,
Copy link
Member

@p0mvn p0mvn May 21, 2024

Choose a reason for hiding this comment

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

Note: to self: would like to look into this more pre-merge

Comment on lines 294 to 297
delegation, err := k.stakingKeeper.GetDelegation(ctx, delegator, val.ValAddr)
if err != nil {
return fmt.Errorf("No delegation found for delegator %s to validator %s\n", delegator, val.ValAddr)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this logically equivalent to before?

From my understanding, the error can be returned in 2 cases:

  • database error
  • the key is actually not present.

Should we also format errors so that the clients can know why there is no delegation?

Alternatively, maybe we could bubble up the error without any custom message.

An ditto for most other calls of GetDelegation

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah agreed with this, for simplicity I decided to just bubble up the error, because the sdk returns an error now instead of false if the value is nil (https://github.com/osmosis-labs/cosmos-sdk/blob/1a5662f2a4586735a64388386eaf23a62dfddad9/x/staking/keeper/delegation.go#L30-L32)

Previously we still returned the delegation even if the value was nil (https://github.com/cosmos/cosmos-sdk/blob/7009a2e0cdb93b286199bbaa22e8880aeec83c8c/x/staking/keeper/delegation.go#L15-L27)

Change here c780c73

@@ -175,48 +190,42 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }
// If they have, we unmarshal the current consensus params, update the target gas, and cache the value.
// This is done to improve performance by not having to fetch and unmarshal the consensus params on every block.
// TODO: Move this to EIP-1559 code
// UNFORKING v2 TODO: Do we still want to use cachedConsParams here? I guess it removes the need to do arithmetic operations on every block.
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense for me to keep

initRootCmd(rootCmd, encodingConfig)
initRootCmd(rootCmd, encodingConfig, tempApp)

// UNFORKING v2 TODO: I don't think we have an option but to implement this. With out, the sdk queries do not show up in the CLI.
Copy link
Member

Choose a reason for hiding this comment

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

Why would we not want to implement this? Is it because we already have osmocli that is customized and tailored to our needs?

@czarcas7ic
Copy link
Member Author

czarcas7ic commented May 21, 2024

I think we should just review if there are state-machine usages. If so, look at the scope of the modified methods

Maybe I am not understanding, but don't we use it essentially everywhere in a stateful manner? Here is a random example:

From: from.String(),
To: to.String(),

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

In this cycle, reviewed:

  • pool manager
  • protorev
  • smart-account
  • superfluid
  • tokenfactory
  • twap
  • txfees
  • valset-pref

There were some tests that I will aim to come back to reviewing in more detail after 1 full iteration.

@@ -70,9 +73,14 @@ func (decorator *SendBlockDecorator) CheckIfBlocked(msgs []sdk.Msg) error {
return nil
}
for _, msg := range msgs {
signers := msg.GetSigners()
// UNFORKING v2 TODO: GetSigners is no longer available
Copy link
Member

Choose a reason for hiding this comment

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

Could we start tracking to do some specific testnet tests on this?

Comment on lines 25 to 27
if err != nil {
panic(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should generally break APIs and bubble up any errors.

For example, this panic might lead to a chain halt because we do not have a panic-catching hook for begin block:

k.RefreshIntermediaryDelegationAmounts(ctx, accs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good call, doing now

Copy link
Member Author

Choose a reason for hiding this comment

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

[]int64{0},
[]int64{0},
[]int64{},
[]int64{}, // UNFORKING v2 TODO: We no longer can slash unbonded validators, verify that this is correct
Copy link
Member

Choose a reason for hiding this comment

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

Could you share more context on this?

Why did this change?

@@ -91,7 +100,10 @@ func (k Keeper) GetOrCreateIntermediaryAccount(ctx sdk.Context, denom, valAddr s
// create a new account. We use base accounts, as this is what's done for cosmwasm smart contract accounts.
// and in the off-chance someone manages to find a bug that forces the account's creation.
if !k.ak.HasAccount(ctx, intermediaryAcct.GetAccAddress()) {
k.ak.SetAccount(ctx, authtypes.NewBaseAccount(intermediaryAcct.GetAccAddress(), nil, 0, 0))
// UNFORKING v2 TODO: I now need to set NextAccountNumber with k.ak.NextAccountNumber(ctx) instead of using zero, due to new invariant checks.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure - why do we now need this and why it wasn't needed before. Could you please link the invariants mentioned?

@@ -142,3 +146,85 @@ func (s *KeeperTestSuite) TestTryUnbondingSuperfluidLockupDirectly() {
})
}
}

func (s *KeeperTestSuite) handleEquivocationEvidence(ctx context.Context, evidence *types.Equivocation) error {
Copy link
Member

Choose a reason for hiding this comment

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

Was this purely copied from the old method that was removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly, this is now a private method in the sdk, but its kind of silly given all the methods within it are public. So instead of straying further from the sdk, and because this is only used in tests, I added here manually.

@@ -68,7 +71,15 @@ func GetSignerAndSignatures(tx sdk.Tx) (signers []sdk.AccAddress, signatures []s
}

// Retrieve messages from the transaction.
signers = sigTx.GetSigners()
// UNFORKING v2 TODO: I dont know if ranging over the address bytes and assigning to AccAddress is correct
Copy link
Member

Choose a reason for hiding this comment

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

I am not 100% sure of the internal details but this looks reasonable to me. I think that we can rely on the unit and integration tests for asserting correctness


return rawCWAddr, bech32CWAddr
}
// TESTS MOVED DIRECTLY TO x/cosmwasmpool/pool_module_test.go to prevent circular imports (specifically on osmosis app for the test suite)
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - shall we delete then?

Comment on lines -352 to -360
// ensure only the right amount of sigs have been checked
if tc.checks > 0 {
s.Require().GreaterOrEqual(res.GasMeter().GasConsumed(), uint64(baseGas+(tc.checks-1)*approachingGasPerSig))
s.Require().LessOrEqual(res.GasMeter().GasConsumed(), uint64(baseGas+tc.checks*approachingGasPerSig))
} else {
if tc.checkGas {
s.Require().LessOrEqual(res.GasMeter().GasConsumed(), uint64(baseGas))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: come back to this

I don't quite get why this is removed

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually this was likely removed by @nicolaslara when he corrected the remaining issues in the smart accounts module. He will likely be able to expand further on why this was safe (good call pointing it out though)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can look at this module by itself after the merge

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

  • lockup
  • mint
  • pool-incentives

only one comment

@@ -75,6 +75,7 @@ func (s *KeeperTestSuite) TestRepeatedLockTokensDistinctDurationGas() {

avgGas, maxGas := s.measureAvgAndMaxLockGas(totalNumLocks, defaultAddr, coinsFn, durFn)
fmt.Printf("test deets: total locks created %d\n", totalNumLocks)
s.Assert().LessOrEqual(int(avgGas), 100000, "average gas / lock")
// UNFORKING v2 TODO: This increased from 100000
Copy link
Member

Choose a reason for hiding this comment

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

I think that's fine

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

Reviewed all remaining modules. Skipped protos, tests, and simulation

Have remaining:

  • osmoutils
  • osmomath
  • SQS integration
  • app wiring

x/concentrated-liquidity/types/msgs_test.go Outdated Show resolved Hide resolved
// v1.0.0-beta.3 is incompatible, so we use v1.0.0-beta.2
github.com/cosmos/cosmos-proto => github.com/cosmos/cosmos-proto v1.0.0-beta.2
// Using branch osmo/v0.38.x
// https://github.com/osmosis-labs/cometbft/releases/tag/v0.37.4-v25-osmo-2
Copy link
Member

Choose a reason for hiding this comment

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

nit is this tag relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not, will replace tags when getting closer to release time. I suppose I could also just make an rc0

Comment on lines +191 to +205
func (s *sqsStreamingService) processBlockChangeSet() error {
if s.changeSet == nil {
return nil
}

for _, kv := range s.changeSet {
for _, listener := range s.writeListeners[s.storeKeyMap[kv.StoreKey]] {
if err := listener.OnWrite(s.storeKeyMap[kv.StoreKey], kv.Key, kv.Value, kv.Delete); err != nil {
return err
}
}
}

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how this affects block time processing. We should create an issue and track validating that the performance hit is acceptable relative to the expected lowered block time

Copy link
Member Author

Choose a reason for hiding this comment

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

Added this to the list of things to test

// github.com/osmosis-labs/osmosis/osmoutils => ../osmoutils
)
// Our cosmos-sdk branch is: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo/v0.50.x, current branch: osmo/v0.50.x. Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/1a5662f2a4586735a64388386eaf23a62dfddad9
// https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.47.5-v25-osmo-1
Copy link
Member

Choose a reason for hiding this comment

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

nit: is the tag correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not, am waiting closer to release to do the first tag, but can do it sooner if needed

Copy link
Contributor

@PaddyMc PaddyMc left a comment

Choose a reason for hiding this comment

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

Great work here!

Review all module updates, protos, wiring and ran in-place-testnet also read through and validated the UNFORKING TODOs

Created this doc to help with the UNFORKING comments:
https://www.notion.so/osmosiszone/Unforking-TODOs-9c17730015164849afc81e99ee8d1146

@czarcas7ic
Copy link
Member Author

czarcas7ic commented May 24, 2024

Merging, with the understanding we have to address all outstanding unforking v2 TODOs prior to release.

Thanks all for the reviews!

@czarcas7ic czarcas7ic merged commit 5bff216 into main May 24, 2024
1 check passed
@czarcas7ic czarcas7ic deleted the adam/v0.50.x-upgrade branch May 24, 2024 20:16
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

I've looked over the remaining files and don't have more to point out other than what's already been discussed or noted in unforking TODOs.

Great work @czarcas7ic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:CLI C:docs Improvements or additions to documentation C:simulator Edits simulator or simulations C:x/concentrated-liquidity C:x/epochs C:x/gamm Changes, features and bugs related to the gamm module. C:x/incentives C:x/lockup C:x/mint C:x/pool-incentives C:x/poolmanager C:x/superfluid C:x/tokenfactory C:x/twap Changes to the twap module C:x/txfees T:build T:CI V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants