MNT PART 1: core/types: adopt pyquarkchain account encoding - #54
Conversation
|
| FullShardKey: acct.FullShardKey, | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
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
StateAccountbalance field with QuarkChain unified token balances.FullShardKeyto the account consensus representation.Scope
This PR is limited to the account model and codec in
core/types.The following work will be included in subsequent PRs:
core/statestateObjectandStateDB.trie,trie/bintrie, andtriedbcore/state/snapshotandeth/protocols/snapcmd/geth,cmd/evm, and remaining callersStateAccount.Balanceaccess withBalance().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