Store private domain state, receipts and finalized headers
ReferencesMIP-8
Part of the private domains M1 stack. Storage only: nothing writes the new tables until the runloop PR at the top of the stack. Needs triedb review.
It adds four tables under DOMAIN_NIBBLE, next to M0's three (#2761):
| Table | Key after the chain ID | Value | Lifetime |
|---|---|---|---|
DOMAIN_STATE (3) |
the STATE table layout |
accounts and storage (slots, or pages from MIP-8) | state |
DOMAIN_CODE (4) |
code hash | code | state |
DOMAIN_RECEIPT (5) |
rlp(index) | encoded receipt | replaced with every L1 block, like DOMAIN_TRANSACTION |
DOMAIN_FINALIZED_HEADER (6) |
be64(domain block number) | rlp(FinalizedDomainHeader) |
the last 256 blocks |
- State root.
DOMAIN_STATEhas Merkle compute below the domain key. The domain key's node computes the domain's state root the same way theSTATEtable node computes the L1's, and the L1 state root doesn't cover it. A test commits the same state to a domain and to the L1 and checks that the roots match, for both slot and page encoding. - Code apart from the L1's. The statesync server sends the whole L1 code table to any syncing peer, so domain code gets its own table.
- Headers for
BLOCKHASH. Each domain block deletes the header 256 blocks back, so whatBLOCKHASHreads doesn't depend on how much history a node keeps. History beyond that is reached throughDOMAIN_BLOCK_NUMBER. - Two stages.
DomainBlockCommitgains the block's state deltas, code and receipts, written in the first commit stage.add_domain_finalized_headerswrites the headers in the second, once the first has computed the state roots. - No cache.
CommitBuilder::account_updatesbuilds the account trie updates for either the L1 or a domain. Only the L1's go toproposal_post_state_, which feeds theTrieDbcache keyed by address. Domain reads bypass that cache too. The page commit builder reads a domain's pages from the domain's trie.
Db gains the domain state readers. TrieDb implements them and the statesync server context forwards them. TrieRODb gains the receipt and header readers that monad-cli uses.
Tests: test_domain_block_db, on slot- and page-encoded dbs:
- the domain state root equals the root of the same state committed to the L1, and the L1 doesn't see it
- a later write to a domain storage page keeps the slots already in it
- domain code and receipts stay out of the L1 tables, and receipts are replaced with each L1 block
- only the last 256 finalized headers are kept, and older versions still have theirs
- every domain table is rewritten in quiet blocks
馃 Generated with Claude Code