Skip to content

Land verified payload stack - #1692

Merged
metaphoric-dev merged 18 commits into
mainfrom
stack/02-state-payload
Oct 28, 2026
Merged

metaphoric-dev merged 18 commits into
mainfrom
stack/02-state-payload

Conversation

@metaphoric-dev

@metaphoric-dev metaphoric-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Draft subsystem stack split from PR #1687.

Base: f024fc3
Tip: 69ccdb8
Full repository gate: native-gate-20261027T230010Z-1140364 (scripts/ci-pr.sh all, exit 0).

Scope: state and payload.
This is a verified stack tip. Do not rebase or reparent it
without owner approval.

No better-than-Core claim. No mainnet qualification.

See also: #1687

Sync impact: YES. SyncChain::commit_window and connect_historical move from owned Block plus Bytes to borrowed BlockPayload slices without changing outcomes, follower order, or settlement. Affected clauses: SYNC-02, SYNC-05, SYNC-06, SYNC-04, and ARCH-07b. Smallest proofs: crates/node/tests/sync_smoke.rs, crates/node/tests/overhaul_durable_head.rs, and chain_effects.rs::committed_connect_settlement_failure.

RetriggerView in GreptileConfidence Score: 4/5

Fix snapshot-seed cancellation before merging; a normal shutdown can otherwise abandon a worker that keeps writing.

Findings

  1. P1 Seed ignores shutdown ▶
  2. P2 Seed makes tiny file reads ▶
  3. P2 Seed offer can hang publication ▶

Summary

The PR replaces separate block/body pairs with immutable BlockPayload values. It also adds witnessed snapshot seeds, portable transaction-index bundles, historical prefix reads, and checkpoint side-branch recovery.

  • Block handling carries decoded blocks and their exact bytes together.
  • Checkpoints preserve eligible side-branch headers for restart.
  • Script index rebuilds can start from a verified snapshot and catch up from history.
  • Operators can export or restore transaction lookup index bundles at startup.
  • Historical index queries report the chain prefix their answers cover.
  • Block sync replans a body request when its peer answers notfound.
  • ZMQ can publish the bodies of newly accepted transactions as rawtx.
  • Index writes and storage scans expose bounded, per-family work.
  • Mining submissions reuse exact block bytes and accept a legacy fee default.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Raw[Wire or stored bytes] --> Payload[BlockPayload]
    Local[Locally built block] --> Payload
    Payload --> Apply[Chainstate commit]
    Apply --> Followers[Ordered followers]
    Apply --> Checkpoint[Witnessed checkpoint]
    Checkpoint --> Seed[ScriptLive seed]
    Seed --> Index[Index rows and watermark]
    Index --> Queries[Strict and historical reads]
Loading

Reviews (5) · Last reviewed commit: "Adapt merged sync tests to branch owners..." · Reviewed by Greptile

metaphorics added 2 commits October 28, 2026 01:41
Use primitive metric conversion, one bounded collector, direct undo-codec re-exports, and one set-level scan-limit check. Keep decode and scan behavior unchanged.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

This PR introduces the "verified payload stack" — primarily refactoring the historical AssumeUTXO validation path to use BlockPayload instead of (Block, Option<Bytes>), adding a witnessed snapshot activation mint (pending_activation_mint), and wiring a VerifiedSnapshotArtifact seed into the load_verified path.

Overall Assessment: The core changes are well-structured. The lifecycle serialization logic in AssumeUtxoManager, the new write_archive<T> generic refactor, and the V4Witness minting path all look correct. No critical logic errors, security vulnerabilities, or crash scenarios were identified that would block merge.

The code correctly handles:

  • The archived early-return in step_historical (durable historical_height is already ≥ the replayed height, so no regression)
  • Lifecycle lock ordering in recover_pending → step_historical
  • pending_activation_mint is only populated after the durable Validating commit succeeds
  • write_archive lock-before-write / unlink-after-rename ordering remains intact after the generic refactor

No blocking issues were found in this review.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.


⚠️ This PR contains more than 30 files. Amazon Q is better at reviewing smaller PRs, and may miss issues in larger changesets.

Comment thread crates/index/src/index/snapshot.rs Outdated
Comment thread crates/mempool/src/gateway.rs Outdated
Stream portable index exports through bounded snapshot pages instead of materializing each family, and probe the restore leftover with one row. Parse each retained RPC body once and cache its transactions.

Replace the observer body-interest callback with registration-time BodyInterest, so commit reads one atomic before the pool write lock and no observer code runs under a gateway lock. Wire every caller to the explicit interest and document the contract.
Comment thread crates/node/src/state/open.rs Outdated
Comment thread crates/node/src/sync.rs
gormes-agent Bot and others added 2 commits October 28, 2026 05:40
Register the ZMQ sequence observer with BodyInterest::Bodies only when the publisher has a rawtx subscriber. Metadata-only notification setups no longer retain accepted transaction bodies.
@metaphoric-dev
metaphoric-dev marked this pull request as ready for review October 28, 2026 09:12
metaphorics added 3 commits October 28, 2026 21:37
Main brings #1684 opt-in Tor/I2P overlay, #1685 public-listener
PeerRemote design, plus #1676 descriptor scan and #1677 compact-scan
bound. Branch brings state-payload plumbing (BlockPayload wire,
BodyInterest admission, index bundle validation).

Resolutions:
- crates/node/src/config.rs: keep both validations; branch
  validate_index_bundle plus main p2p.overlay.validate.
- crates/p2p/src/listener.rs send_block: main PeerRemote
  parameter on branch BlockPayload body; single-conversion entry.
- crates/p2p/src/listener.rs handle_compact_outcome: keep
  branch Option follow-up return (single enqueue_owned_body_fetch
  publisher per branch 5dee503) with main PeerRemote parameter.
  Main header-carried body_fetch_owned mark not restored: branch
  sync/headers.rs and inbound.rs intentionally supersede it with
  one atomic enqueue; restoring would reintroduce the racy
  double-mark 5dee503 deleted.
- aggregate_budget_tests.rs: main PeerEndpoint address with
  branch is_none assertion matching the Option return.
- crates/rpc/tests/core_compat.rs: main ipv4/ipv6/onion/i2p
  networks assertion (branch had dropped the stale len-3 check).
Follow-up to 19344e7: merge origin/main advance to fa187f9
(#1676 ranged/multipath descriptor scan, #1677 compact-scan bound,
ctutils 0.4.5). Clean auto-merge preserving the existing
resolution; no new conflicts.
Main compact-sync tests called record_owned_body_fetch,
which the branch replaced with enqueue_owned_body_fetch.
The NotFoundFixture fields also kept SocketAddr after
current_source and test_addr moved to PeerRemote.

- Add the missing SocketAddr import.
- Store owner and alternate as PeerRemote.
- Mark the owned fetch through enqueue_owned_body_fetch.
@metaphoric-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T15:00:51.328685Z 4b5e6c4 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread crates/index/src/runtime/rollback.rs
Comment thread crates/utxo/src/snapshot.rs Outdated
Comment thread crates/chainstate/src/checkpoint/publisher.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7e0bd884f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/utxo/src/snapshot.rs Outdated
Comment thread crates/index/src/portable/restore.rs Outdated
Comment thread crates/chainstate/src/checkpoint/publisher.rs Outdated
metaphorics added 6 commits October 28, 2026 22:22
…time

Single positions_are_valid in types.rs backed by one
MAX_POSITION_END_BYTES (4 MiB, citing consensus
MAX_BLOCK_SERIALIZED_SIZE). Writer, query fallback, export, and
restore framing all apply it; the writer refuses bodies past the
cap so an admitted row is never corrupt to an exporter.
One stored key can no longer accumulate positions without bound
during restore/import: past 131,072 positions the fold fails
closed with MutationSizeOverflow instead of growing importer RSS.
The bound is twice the transaction capacity of a 4 MiB block, so
no honest bundle trips it.
Skipped locator verification is now an explicit NotChecked
outcome that refuses instead of reporting Verified, so
correctness never depends on gate ordering. stream_import
revalidates that the bundle base is still on the active chain
before the watermark commit; a tip advance past the base stays
valid and backfills above it.
MAX_LIVE_SCRIPT_SIZE is now an alias of
bitcoin_rs_script::MAX_SCRIPT_SIZE instead of a duplicated
literal, removing the stale node-assert comment. History rows
deliberately keep oversized scripts (pinned by
live_predicate_matches_utxo_admission_not_history); the funding
push site now says so with its consensus-block-size bound.
The Accepted-to-body join moves past the pool guard into a
HashMap, keeping admission-lock time out of large-package
publication. A commit-ordering lock spans mutation through
enqueue so the publish queue order stays the commit order;
it drops before the drain so observers can re-enter. A
missing body with capture enabled warns and debug-asserts
instead of silently dropping the envelope entry.
Keeps main's tree alongside the mempool join-outside-the-lock
fix: join_accepted_bodies runs past the pool guard with a
HashMap join and visible missing-body failure, while the
commit_order lock still spans mutation through enqueue so the
publish queue order stays the commit order.
@metaphoric-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 2353fbe5a9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

metaphorics added 2 commits October 28, 2026 23:56
# Conflicts:
#	crates/index/src/portable/export.rs
#	crates/index/src/portable/restore.rs
@metaphoric-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 4b5e6c4245

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

metaphorics added 2 commits October 29, 2026 00:37
seed_from_bundle only checked should_stop at entry, so a stop
landing mid-stream committed the watermark anyway. Thread a
cancelled closure through for_each_coin_raw,
read_raw_snapshot_stream, and seed_script_live_stream, polling
every 4,096 emits/rows plus a pre-commit check. A trip returns
IndexError::Cancelled, mapped from RawSeedError::Cancelled, and
the worker keeps artifact plus lease and stalls so the retry
reuses the same bundle. Focused regression tests at the
traversal and fenced-stream levels.
The validating pass drained the artifact tail with a blocking
io::copy that never polled host.cancelled. Replace it with a
bounded 4,096-byte chunked copy that polls once per chunk and
returns Cancelled at once with no digest comparison, preserving
ArtifactHash precedence over framing faults. Adds a focused
unit test for full drain hashing, entry cancellation, and a
mid-tail trip.
@metaphoric-dev
metaphoric-dev merged commit 03ab65a into main Oct 28, 2026
11 of 16 checks passed
@metaphoric-dev
metaphoric-dev deleted the stack/02-state-payload branch October 28, 2026 15:50
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.

1 participant