feat(types): add QuarkChain MNT account and token types#24
Open
ping-ke wants to merge 3 commits into
Open
Conversation
- Add TokenBalances type with sorted list encoding compatible with pyquarkchain - Add StateAccount.MntBalances field and QKC 6-element RLP codec (replaces generated gen_account_rlp.go with hand-written EncodeRLP/DecodeRLP) - Add uint32 RLP encoding helpers for token IDs - Update genesis hashes to reflect QKC 6-element account encoding - Add comprehensive tests: roundtrip, pyquarkchain encode/decode compatibility
ping-ke
requested review from
blockchaindevsh,
iteyelmp,
qizhou,
qzhodl and
syntrust
July 5, 2026 07:30
qzhodl
reviewed
Jul 8, 2026
qzhodl
reviewed
Jul 8, 2026
qzhodl
reviewed
Jul 8, 2026
|
General note: the three inline issues above were all found in a first-pass Codex 5.5 Extra High review with no additional prompt engineering beyond asking it to review this PR. Before requesting review next time, please run a self-review pass with Codex 5.5 Extra High (or an equivalent high-reasoning review mode) and address the obvious state/snapshot/generation issues it finds first. |
Comment 1: SlimAccount only held {Nonce,Balance,Root,CodeHash}, so the
slim-RLP path used by SlimAccountRLP (stateupdate.go account updates/
origins), FullAccount (pathdb rollback in triedb/pathdb/execute.go) and
flatReader.Account (snapshot flat read) silently dropped MntBalances and
FullShardKey. A QKC account served from any of those paths came back with
MntBalances=nil / FullShardKey=0 and re-committed a corrupted account,
forking the trie root.
Extend SlimAccount with:
- MntBal []byte (rlp optional) = TokenBalances.SerializeToBytes()
- FullShardKey uint32 (rlp optional)
MntBal uses the []byte serialization (TokenBalances holds an unexported
map, not RLP-struct-encodable) and preserves the nil-vs-empty distinction
so the 0x80 / 0x8200c0 trie encoding stays byte-stable across the slim
round-trip. Unlike the trie qkcAccountRLP.TokenBal, the QKC default
balance is NOT merged into MntBal — slim keeps it in the Balance field.
Both fields are rlp optional so pre-MNT snapshots still decode. Because
FullAccount now reconstructs both fields, the pathdb rollback path is
covered without further changes.
Extend TestSlimRLPRoundTripEquivalence with fullShardKey / MNT-only /
MNT+QKC+shard cases (direct-QKC-encode == via-slim-encode).
Comment 3: remove the rlpgen go:generate directive. StateAccount now uses
the hand-written QKC codec (EncodeRLP/DecodeRLP in state_account_qkc.go);
regenerating gen_account_rlp.go would reintroduce a conflicting standard
4-field codec that drops MntBalances / FullShardKey. Replaced the
directive with a NOTE explaining why it must stay removed.
Comment 2 (empty() must consider MntBalances) is resolved downstream on
feature/mnt-state (stateObject.empty() checks IsBlankMnt(), covered by
TestEmptyAccountWithMntNotPruned); core/state is not part of this branch.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4 tasks
…reum genesis hashes
ping-ke
force-pushed
the
feature/mnt-core-types
branch
from
July 16, 2026 12:08
3860cb7 to
53e97c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core/types, including a QKC 6-element RLP-encodedStateAccountand aTokenBalancestypeparams/config.goto match the new state root produced by QKC 6-element encodinggen_account_rlp.goand replace it with hand-writtenEncodeRLP/DecodeRLPto support the QKC custom 6-field RLP formatBackground
The standard Ethereum
StateAccountuses 4-element RLP (Nonce, Balance, Root, CodeHash). The QuarkChain protocol extends this with two additional fields:FullShardKey uint32: the shard key of the accountMntBalances TokenBalances: a map of non-default native token balances held by the accountThis change produces a different state root from standard go-ethereum, requiring the genesis hash constants to be updated accordingly.
Changed Files
core/types/gen_account_rlp.gocore/types/state_account.goFullShardKeyandMntBalancesfieldscore/types/state_account_qkc.gocore/types/state_account_qkc_test.gocore/types/token.goTokenBalancestype,DefaultTokenID = 35760(= TokenIDEncode("QKC"))core/types/token_test.gocore/types/uint32_rlp.gocore/types/uint32_rlp_test.goparams/config.goKey Design Decisions
DefaultTokenID = 35760: Equal to
TokenIDEncode("QKC"), consistent with pyquarkchain. The QKC token balance is stored in the standardBalancefield, not in theMntBalancesmap, to preserve EIP-20 compatibility.Slim-RLP vs QKC format: The snapshot layer continues to use slim-RLP (4 fields, compatible with go-ethereum snapshots). The trie stores the QKC 6-element format.
database_mpt.gohandles re-encoding for the pathdb path.Test Plan
go test ./core/types— all pass, including pyquarkchain compatibility vector testsgo build ./...— build successful