Repository navigation
fix(drive)!: never serve a contract parsed under another protocol version from the cache - #5993
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-11-19T14:16:08.692Z |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit 67d558e) · triage: critical |
…sion from the cache A contract is parsed under the protocol version of its reader, and protocol version 15 parses some stored contracts differently from 14 (a document type whose summed property is not bounded within 2^27 keeps its sums in 128 bits). Query threads read committed state at the protocol version of the platform state they loaded, which on the first block of a version, and for a query that loaded it just before, is the previous one, and they cache what they parsed. A block that read such a cached copy wrote state another node, with an empty cache, would not. Every DataContractFetchInfo now records the protocol version that parsed it (set where the contract is parsed, fetch_contract_v0). get_contract_with_fetch_info generation 1, selected only by protocol version 15 (DRIVE_CONTRACT_METHOD_VERSIONS_V5): - looks up through DataContractCache::get_parsed_under, which treats an entry parsed under another protocol version as a miss (no fallback to the global cache from the block cache); - bills a cache hit its cost priced under the reader's protocol version, never a fee stored on the entry, since generation 0 can store a fee a reader of another version priced (check_tx estimation writes the cache through fetch_bound_root_with_fee). Generation 0 keeps the version-blind lookup for protocol versions 14 and earlier, as their blocks were executed. v15 note 51. In-place changes to shipped generations (inert): fetch_contract_v0 records the new field, read only by generation 1; the fee-refresh copy in get_contract_with_fetch_info_v0 copies it, and generation 1 never bills a stored fee. The shield characterizations in nullifier_batch_guard hash the Debug output of the validated action, which now names the protocol version its cached contract was parsed under. They strip that field, as they strip the other incidental Debug fields, and keep their original pins: with only that field removed every pinned hash still matches (actions, errors, context charges, lowered operations, exact fees, roots and nonces), so no charge changed. Tests would have caught this in CI: ✖ before the fix (on unchanged v5.1-dev, and again with generation 0 selected at protocol version 15), ✔ after: - big_sums_tests::should_write_a_tip_after_the_activation_as_a_node_without_a_lagging_query_does (different root hashes before the fix) - get_contract_with_fetch_info parse_version::should_not_serve_a_block_at_protocol_version_15_the_reading_a_protocol_version_14_query_cached - parse_version::should_never_serve_a_block_at_protocol_version_15_a_reading_a_concurrent_protocol_version_14_query_caches (threaded; 20 of 20 block reads got the protocol version 14 parse before the fix) - parse_version::should_check_the_protocol_version_of_a_cached_copy_only_from_generation_1 - parse_version::should_bill_a_cache_hit_at_protocol_version_15_what_a_cold_read_bills_whatever_fee_the_entry_carries (✖ with a generation 1 that trusted the stored fee: billed 1 instead of 29120) Co-Authored-By: Claude Opus 5.5 <[email protected]>
aecd199 to
67d558e
Compare
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The protocol-versioned contract cache changes are consistent with the existing cache lifecycle and versioned dispatch architecture. Generation 1 is selected only by protocol version 15, rejects entries parsed under another version, and reprices cache hits from the reader’s cost; earlier generations retain their historical behavior. No in-scope correctness, consensus, security, layering, or Rust-quality findings were identified. The Rust workspace test check was still in progress in the supplied CI snapshot, with no failed code checks caused by this change.
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change to consensus-critical contract parsing, protocol-version dispatch, cache behavior, persisted state interpretation, and fee calculation in rs-drive, including migration-sensitive logic that can change committed state across protocol activation. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
|
Bots are done — your move: post |
Issue being fixed or feature implemented
A data contract is parsed under the protocol version of whoever reads it, and two protocol versions can parse the same stored contract differently. Protocol version 15 already does for some contracts: since #5987 a document type whose summed property is not bounded within 2^27 keeps its sums in 128 bits. #5983 adds another difference: nested object members in
positionorder.Query threads read committed state at the protocol version of the platform state they loaded, and they fill the shared contract cache with what they parse. On the first block of a new protocol version that is still the previous version. The same holds for a query that loaded the state just before the block's state was published. A block whose transactional read fell back to such a cached copy could then write different state than a node with an empty cache, for example a sum tree of a different width, or a token configuration update storing differently compiled contract bytes. The emptying of the cache on the first block of a protocol change does not cover this: a query can put its copy back during that block or after the promotion.
This must merge before protocol version 15 ships. #5983 depends on it.
What was done?
DataContractFetchInforecords the protocol version that parsed it (parsed_under_protocol_version). It is set where the contract is parsed (fetch_contract_v0).DataContractCache::get_parsed_undertreats an entry parsed under another protocol version as a miss:getis unchanged and version-blind.get_contract_with_fetch_infogeneration 1, selected only by protocol version 15 (DRIVE_CONTRACT_METHOD_VERSIONS_V5→DRIVE_VERSION_V10), differs from generation 0 in two ways:get_parsed_under.DataContractCache/DataContractFetchInfodocs, the token configuration update comment (which assumed 14 and 15 compile a contract alike) and the book's cache section (drive/finalize-tasks.md) describe the rule.SystemDataContractskeys on(protocol_version, contract).In-place changes to shipped generations
fetch_contract0 (fetch_contract_v0)parsed_under_protocol_versionon the entry it buildsget_contract_with_fetch_info1, selected only by protocol version 15, reads the field.get_contract_with_fetch_info0perform_events_on_first_block_of_protocol_change2token_config_update_transitionconverter 0 (token_config_update_transition.rs)How Has This Been Tested?
Red first, then green:
big_sums_tests::should_write_a_tip_after_the_activation_as_a_node_without_a_lagging_query_does: after the activation block (conversion, commit, promotion), the entry is evicted and a protocol 14 query caches its reading; the next protocol 15 block adds a tip with the contract the cache serves. The state must match a node without that query.parse_version::should_not_serve_a_block_at_protocol_version_15_the_reading_a_protocol_version_14_query_cachedparse_version::should_never_serve_a_block_at_protocol_version_15_a_reading_a_concurrent_protocol_version_14_query_caches: a query thread at 14 runs next to 20 blocks at 15, each evicting, waiting for the query's insert, then reading, committing and promoting.parse_version::should_check_the_protocol_version_of_a_cached_copy_only_from_generation_1: generation 0 at 14 still serves a cross-version copy (pin); generation 1 at 15 does not.parse_version::should_bill_a_cache_hit_at_protocol_version_15_what_a_cold_read_bills_whatever_fee_the_entry_carriesget_parsed_under.cargo test -p drive -p drive-abci -p platform-version --all-features --lib --tests -- --skip shield(CI's filter): all pass. That is drive 4419, drive-abci 4561, strategy tests 125, platform-version 27, plus the integration test binaries. The shield-named tests of drive and drive-abci separately: 622 passed. The two shield characterizations innullifier_batch_guardhash the Debug output of the validated action, which now names the protocol version its cached contract was parsed under. They strip that field, as they strip the other incidental Debug fields, and keep their original pins: no action, charge, operation, fee or root changed.cargo clippy -p drive -p drive-abci -p platform-version --all-features --all-targets: clean.Breaking Changes
From protocol version 15, a cached data contract is served only to a reader at the protocol version that parsed it, and a cache hit is billed its cost priced at the reader's protocol version.
DataContractFetchInfohas a new crate-private field. Protocol versions 14 and earlier are unchanged.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
67d558e/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit