Skip to content

New payload with witness ssz#12048

Merged
LukaszRozmej merged 129 commits into
masterfrom
new-payload-with-witness-ssz
Jul 5, 2026
Merged

New payload with witness ssz#12048
LukaszRozmej merged 129 commits into
masterfrom
new-payload-with-witness-ssz

Conversation

@hudem1

@hudem1 hudem1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Follow up of PR #11623 as this was from a forked repo

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Optional. Remove if not applicable.

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

If yes, fill in the details here. Remove if not applicable.

Remarks

Optional. Remove if not applicable.

Dyslex7c and others added 30 commits May 15, 2026 21:02
WitnessCapturingWorldStateProxy implemented only the explicit IWorldState
methods, leaving IsNonZeroAccount, IsStorageEmpty, HasCode, GetNonce, and
IsDelegatedCode to fall through to the default interface implementations.
Those defaults route via TryGetAccount and see only the committed
AccountStruct, while the real WorldState overrides them to consult the
in-flight persistent storage provider. The mismatch broke EIP-7610 checks
on SELFDESTRUCT-then-CREATE within a single block, causing the Pyspec
test_recreate fixtures on Paris and Shanghai to fail with a header
gas-used mismatch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Restore codeHash-first lookup and the parallel-BAL comment. The proxy
already captures the address via GetCodeHash(Address) earlier in
InternalGetCodeInfo, so the swap is not required for witness capture.

Also drop the verbose comment on the new default-method forwarders and
update the misleading note on GetCode(in ValueHash256).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Spec MAX_REQUEST_BODY_SIZE per execution-apis#764 is 16 MiB; revert the
undocumented bump to 64 MiB.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Witness owns ArrayPoolList buffers. On the JSON-RPC success path the
result is wrapped in ResultWrapper -> JsonRpcSuccessResponse, whose
Dispose() calls Result.TryDispose(). Implementing IDisposable here
routes that into Witness.Dispose() so the pool buffers are returned
instead of GC'd.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When two engine_newPayloadWithWitness calls land for the same blockHash,
ArmCapture cancels the first TCS. The first caller's await captureTask
then throws OperationCanceledException. The block itself executed
successfully, so return VALID with a null witness rather than letting
the cancellation propagate as a 500.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The INVALID_BLOCK_HASH constant and its SSZ byte mapping (4) were added
but no code path produces them; Nethermind returns INVALID with a
descriptive error for block-hash mismatches. Drop both until/unless we
wire the status through the actual mismatch path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
BranchProcessor tracked the witness-capture lifecycle with a pair of
booleans and a manual finally block to disarm on exception. Replace with
a `using` session struct that arms in its factory, drains on success,
and disarms on Dispose if not drained. Removes the inner try/finally
and the ArmWitnessCapture / DrainWitnessCapture helpers; restores the
minor cosmetic edits that crept into the file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the Func<...> indirection the handler used to break the
construction cycle. Now it takes `Lazy<IEngineRpcModule>` directly and
calls `Value.engine_newPayloadV5(...)`, which simplifies the DI wiring
to a plain type registration. Tests substitute IEngineRpcModule on the
builder.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
newPayloadWithWitness already has both a JSON-RPC and SSZ-REST surface
gated on the same fork, so route it through the same Configure(...) helper
the other Amsterdam entries use rather than two parallel dict writes.

Trim the comment in SszWireTypes that explains why
NewPayloadWithWitnessResponseV1 is hand-rolled in SszCodec — keep the
relevant why, drop the prose.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Restore the blank line after the opening brace and the inline body of
engine_getClientVersionV1 — neither was needed for the PR's witness
work.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three near-identical tests differing only in the engine module factory
collapse into a single [TestCaseSource]-driven case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
WitnessGeneratingWorldState.GetWitness and WitnessCapturingWorldStateProxy.BuildWitness
both ran the same per-(address, slots) AccountProofCollector tree-walk loop. Pull the
loop into WitnessProofCollector.CollectAccountProofs so both call sites share it.

Also:
- Swap Arm() order in the proxy to allocate the tracking dictionaries before flipping
  the armed flag; the prior order was safe only on the single-threaded ProcessOne
  path but inverted is a free correctness improvement.
- Update WitnessCaptureRegistry xmldoc; the registry tolerates multiple concurrent
  armed entries for distinct block hashes (and cancels-and-replaces on duplicates).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dispatch

SszMiddleware.InvokeAsync (versioned) and DispatchWitnessAsync (non-versioned witness
path) duplicated the entire post-route pipeline: PipeReader body read, request-bytes
metric, handler invocation, status-code bucketing, and the 413/400/500 error mapping.
Pull the shared work into DispatchAsync(handler, version, extra) — the witness path now
adds only the path-specific method/content-type/handler-not-null checks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Use Utf8JsonReader(ReadOnlySequence<byte>) in NewPayloadWithWitnessSszHandler instead
  of `body.ToArray()` on multi-segment bodies — saves an LOH allocation on every
  request.
- Promote the encode-length Debug.Assert in EncodeNewPayloadWithWitnessResponse to a
  runtime check so a future header-size bug fails fast in Release rather than emitting
  silently-wrong bytes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Resolved conflicts from master's long->ulong block-number migration:
- WitnessHeaderRecorder: kept the recorder refactor, adopted ulong types + underflow-safe loop
- EngineRpcModule.Amsterdam: engine_getPayloadBodiesByRangeV2 now takes ulong
- WitnessCapturingTrieStore: kept deleted (removed on this branch)
Rippled ulong fixes: WitnessCapturingHeaderFinder, WitnessCapturingBlockProcessor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@hudem1 hudem1 requested a review from LukaszRozmej June 29, 2026 09:56

@LukaszRozmej LukaszRozmej left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please trim comments and remove the parts that are self-explanatory in code or unnecessary

Comment thread src/Nethermind/Nethermind.Consensus/Processing/CodeInfoRepositoryFactory.cs Outdated
Comment thread src/Nethermind/Nethermind.Consensus/Stateless/WitnessGeneratingWorldState.cs Outdated
Comment thread src/Nethermind/Nethermind.Consensus/Stateless/WitnessGeneratingWorldState.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/Handlers/NewPayloadWithWitnessHandler.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/SszRest/SszCodec.cs
Comment thread src/Nethermind/Nethermind.Merge.Plugin/SszRest/SszCodec.cs
Comment thread src/Nethermind/Nethermind.Merge.Plugin/SszRest/SszMiddleware.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/Handlers/INewPayloadWithWitnessHandler.cs Outdated
hudem1 and others added 7 commits July 1, 2026 15:31
Comment thread src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs Outdated
Comment thread src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin.Test/SszRest/SszMiddlewareTests.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/Handlers/NewPayloadWithWitnessHandler.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/SszRest/SszMiddleware.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/SszRest/SszMiddleware.cs Outdated
Comment thread src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs Outdated

@LukaszRozmej LukaszRozmej left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe merge after #12193 and updating to newest schema.

in test prefer TestCaseData over object[]

@LukaszRozmej

Copy link
Copy Markdown
Member

@claude re-review

@claude

claude Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Claude finished @LukaszRozmej's task in 6m 46s —— View job


Re-review — engine_newPayloadWithWitness (SSZ)

Re-reviewed the current state against origin/master. The architecture has been substantially reworked since the first two review rounds and the prior blocking findings are resolved. No Critical or High issues remain.

Status of prior findings

ID Finding Status
H1 DI lambda anti-pattern in BlockProcessingModule ✅ Resolved — main path is back to .AddScoped<IBlockAccessListManager, BlockAccessListManager>(); the code-repo choice is now a CodeInfoRepositoryFactory delegate (Caching default).
H2 fallbackTrieStore never disposed ✅ Resolved — WitnessCapturingBlockProcessingEnv.Graph.Dispose and WitnessGeneratingBlockProcessingEnvFactory.PooledEntry.Dispose both dispose the trie store.
M1 LINQ on hot path ✅ Resolved — recorder deleted; foreach over plain dictionaries.
M2 Fragile (WitnessCapturingWorldStateProxy) cast ✅ Resolved — new design uses a plain AddDecorator<IBlockProcessor, WitnessCapturingBlockProcessor>() + a separate root-scope witness graph; no cast.
M3 Fragile is NewPayloadWithWitnessSszHandler route exclusion ✅ Resolved — special case gone; routing is fully abstracted behind ISszEndpointHandler (HttpMethod/Resource/Version/AcceptsPathExtra). Handler is now generic NewPayloadWithWitnessSszHandler<TVersion,TWire>.
M4 TryArm memory-ordering comment ✅ Resolved — WitnessRendezvous rewritten as a lock-guarded single hash-validated slot; no CAS, self-cleaning WitnessRequest/using.
L2 node.Keccak null guard ✅ Resolved — file deleted.
L3 No timeout before cancel ✅ Resolved — replaced by using WitnessRequest + non-blocking IsCompletedSuccessfully probe; documented.

Also verified: the witnessMode/_isBuilding parallel gate was replaced with the precise _hasParentReaderPool precondition (per @LukaszRozmej's review), and the witness Witness is disposed on both transports — SSZ via using (result) in WriteSszResultAsync, JSON-RPC via ResultWrapper.DisposePayloads.

Remaining (all Low / non-blocking)

  • DI lambda in the two witness env builders (WitnessCapturingBlockProcessingEnv.cs:87, WitnessGeneratingBlockProcessingEnvFactory.cs:94) — same hand-listed-args pattern as H1, now confined to the specialized witness scopes. Cleanly replaceable by registering CodeInfoRepositoryFactories.Witness in the scope and reverting to the one-liner. See inline comment.
  • validation_error capped at 1024 (SszValidationError = SszList(1024), matching the truncation) — internally consistent and matches the other endpoints, but execution-apis#773 discussion suggests 8192. Already tracked by @LukaszRozmej ("update to newest schema" before merge); no code bug.
  • engine_newPayloadWithWitness hardcodes engine_newPayloadV5 — acknowledged by the author as acceptable until a V6 witness variant exists.
  • Tests — prefer TestCaseData over object[] and dedup where noted; style only, already acknowledged.

Correctness spot-checks (no issues found)

  • Single execution: witnessed block runs only through witness.Processor.ProcessOne; inner is skipped. Recorder wraps the real main world state, so it is imported, not re-executed.
  • PatriciaTrieWitnessGenerator mirrors BulkSet, handles inserts (created accounts/slots → Read), deletes (→ collapse-sibling capture), and the empty-touch root anchor; production walks use parallelize: false with a non-thread-safe sink, as documented. Backed by dedicated tests.
  • Read/Delete classification via post-state AccountExists/Get bypasses the recording overrides (base.*), so it doesn't pollute the accessed set.
  • Rendezvous: block processing is serialized, a second concurrent request is cleanly declined (VALID, no witness), and every exit path releases the slot via the using registration.

Verdict: Mergeable — no Critical/High/Medium findings outstanding. Suggest folding in the small DI-lambda cleanup and confirming the final validation_error limit against the latest schema before merge, per @LukaszRozmej.

The witness block-processing envs hand-built BlockAccessListManager with a
null transactionProcessorFactory, so the block-access list fell back to the
plain Ethereum factory. On AuRa the chain overrides ITransactionProcessorFactory,
and its contract-based withdrawal system calls touch the system-sender account
that the plain factory omits, so the witness-generated BAL diverged from the
main pipeline's and newPayloadWithWitness returned INVALID. Pass the container's
ITransactionProcessorFactory while deliberately leaving the parallel
parent-reader factories out, so the BAL still runs sequentially and every
access is recorded into the witness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LukaszRozmej LukaszRozmej force-pushed the new-payload-with-witness-ssz branch from 40bcb62 to bdbda6a Compare July 3, 2026 14:14
Comment thread src/Nethermind/Nethermind.Consensus/Stateless/WitnessGeneratingWorldState.cs Outdated
@LukaszRozmej LukaszRozmej merged commit ffe4601 into master Jul 5, 2026
555 of 556 checks passed
@LukaszRozmej LukaszRozmej deleted the new-payload-with-witness-ssz branch July 5, 2026 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature rpc state+storage taiko related to the taiko alethia rollup trie

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants