Skip to content

MNT PART 1: core/types: adopt pyquarkchain account encoding - #54

Open
ping-ke wants to merge 2 commits into
goshard/basefrom
feature/py-mnt-core-types
Open

MNT PART 1: core/types: adopt pyquarkchain account encoding#54
ping-ke wants to merge 2 commits into
goshard/basefrom
feature/py-mnt-core-types

Conversation

@ping-ke

@ping-ke ping-ke commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Adopt the pyquarkchain-compatible QuarkChain account representation and RLP codec for goshard's shard chain.

This PR establishes the account-level consensus format for the subsequent state, trie, snapshot, and command migrations.

Changes

  • Replace the Ethereum StateAccount balance field with QuarkChain unified token balances.
  • Add FullShardKey to the account consensus representation.
  • Add pyquarkchain-compatible six-field account RLP encoding and decoding.
  • Add QKC balance helpers and deep-copy support.
  • Add account codec, balance, and copy tests.

Scope

This PR is limited to the account model and codec in core/types.

The following work will be included in subsequent PRs:

  1. core/state

    • Integrate unified token balances into stateObject and StateDB.
    • Update state mutation, journaling, copying, and related tests.
  2. trie, trie/bintrie, and triedb

    • Update account storage and trie commit/load logic.
  3. core/state/snapshot and eth/protocols/snap

    • Update snapshot conversion and snap synchronization.
  4. cmd/geth, cmd/evm, and remaining callers

    • Migrate account construction and replace direct StateAccount.Balance access with Balance().

This migration does not provide compatibility with existing Ethereum/geth data, old goshard data, or local pyquarkchain/goquarkchain database data. Local state only needs to remain internally self-consistent and can be rebuilt through P2P synchronization.

The current list-based token balance representation and 16 non-zero-token limit are intentional.

Tests

go test ./core/types

@ping-ke ping-ke changed the title core/types: adopt pyquarkchain account encoding MNT PART 1: core/types: adopt pyquarkchain account encoding Aug 31, 2026
Comment thread core/types/state_account.go Outdated
@syntrust

syntrust commented Sep 8, 2026

Copy link
Copy Markdown
$ go build ./...
# github.com/ethereum/go-ethereum/trie/bintrie
trie/bintrie/trie.go:222:2: cannot assign to acc.Balance (neither addressable nor a map index expression)
trie/bintrie/trie.go:248:30: acc.Balance.Bytes undefined (type func() *uint256.Int has no field or method Bytes)

FullShardKey: acct.FullShardKey,
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This comment is the only thing standing between the node and a silently wrong state root - nothing in the tree actually disables snap sync or the flat reader, and geth enables the snapshot by default. Once core/state is wired up in PR 2, core/state/database_mpt.go:159 calls EncodeMPTState() -> SlimAccountRLP on every commit, so the snapshot layer stores accounts with MNT balances and FullShardKey dropped, and core/state/reader.go:110 rebuilds StateAccount from them. That fails silently rather than loudly.

The conversion is also lossy in a second way the comment does not mention: FullAccount builds its balances with NewQKCTokenBalances(slim.Balance), which inserts an explicit zero entry when the balance is zero. Re-encoding then yields token_balances = 0x00c0 instead of the empty string, so even a pure-QKC account with a zero balance round-trips to a different leaf hash - snapshot-driven trie regeneration (core/state/snapshot/conversion.go) would produce a different state root.

SlimAccountRLP itself is on the unconditional commit path, so it cannot panic. Please put a real guard on the consuming side instead - refuse to construct the snapshot / flat reader, or return an error from the snapshot read path in core/state/reader.go - so that "must not be enabled" is enforced rather than documented.

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.

3 participants