Skip to content

fix: decode pre-v9 state via height-dispatched legacy adapter#12

Open
aluque-peersyst wants to merge 1 commit into
xrplevm:release/v0.6.x-xrplevmfrom
aluque-peersyst:fix/legacy-state-reads
Open

fix: decode pre-v9 state via height-dispatched legacy adapter#12
aluque-peersyst wants to merge 1 commit into
xrplevm:release/v0.6.x-xrplevmfrom
aluque-peersyst:fix/legacy-state-reads

Conversation

@aluque-peersyst

Copy link
Copy Markdown

No description provided.

@JordiParraCrespo JordiParraCrespo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For me the concept ACK.

A few things I would consider:

  1. Move the adapter from /rpc/backend/eth into the legacy module.
  2. Isolate the tests in <file_name>_legacy_test.go. This should help reduce future test conflicts and make the legacy code easier to maintain.
  3. As mentioned in some of the comments, I’d avoid naming things around v9 where possible and use names that are semantically tied to Evmos or Ethermint instead. This would make it easier for other chains to reuse the ideas from this module.
  4. For methods that cannot realistically be supported, such as tracing, I’d make sure we return an explicit “not supported” error rather than leaving the behavior ambiguous.

Comment thread evmd/app.go
// The adapter reads the v9 upgrade record from the state mounted at
// `height`; at pre-v9 heights the record does not exist yet, so exporting
// legacy-layout state is unsupported.
return app.legacyAdapter.Load(app.NewUncachedContext(true, cmtproto.Header{}))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do we need to do it here? The legacyAdapter is already loaded in the app.go no?

Comment thread legacy/adapter.go
cdc codec.BinaryCodec
uk UpgradeKeeper
ak AccountKeeper
v9Height int64

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would name this as: cosmosEvmHeight

Comment thread legacy/adapter.go
)

// V9 is the upgrade that migrated Ethermint state layouts to cosmos/evm.
const V9 = "v9.0.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would use a name like: COSMOS_EVM_UPGRADE_VERSION

Comment thread legacy/adapter.go
@@ -0,0 +1,79 @@
// Package legacy reads EVM state written in layouts that predate the v9

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here instead of always like assuming that the version is V9 we can have a more generic approach in order that other chains can plug and play this utils

Comment thread legacy/adapter_test.go
Comment on lines +18 to +19
// loadedAdapter builds an adapter and reads its upgrade height once
func loadedAdapter(t *testing.T, v9Height int64) *legacy.LegacyAdapter {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would name this function as newLoadedTestLegacyAdapter

Comment thread legacy/params.go

// UnmarshalLegacyParams converts pre-v9 (Ethermint) EVM params bytes to the
// current schema.
func (l *LegacyAdapter) UnmarshalLegacyParams(bz []byte) (evmtypes.Params, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here I would unify the naming with the GetCodeHash that we do not use the GetLegacyCodeHash.
When using it we use legacyAdapter.UnmarshalParams

Comment thread legacy/params.go
// to the current schema. The encodings are wire-compatible (current-schema
// decoding silently rescales base_fee by 10^-18) so the height dispatch is
// the only safeguard.
func (l *LegacyAdapter) UnmarshalFeeMarketParams(bz []byte) (fmtypes.Params, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here we should unify with the naming of the previous function

Comment thread legacy/params.go
return evmtypes.Params{}, fmt.Errorf("unmarshal legacy EVM params: %w", err)
}

// "ethereum_3855" → 3855, mirroring the v9 upgrade migration.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would not include in the comments

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