Skip to content

docs(stateless): add mega_getBlockWitness RPC reference page#45

Merged
flyq merged 11 commits intomainfrom
liquan/witness_doc
Apr 29, 2026
Merged

docs(stateless): add mega_getBlockWitness RPC reference page#45
flyq merged 11 commits intomainfrom
liquan/witness_doc

Conversation

@flyq
Copy link
Copy Markdown
Member

@flyq flyq commented Apr 28, 2026

Summary

  • Adds docs/stateless/get-block-witness.md documenting the mega_getBlockWitness JSON-RPC method served at mainnet.megaeth.com/rpc: endpoint, request schema with the three lookup modes (blockNumber + blockHash preferred / blockNumber + parentHash + attributesHash for OP-stack derivation / blockNumber-only with an explicit warning that the backend prefix-lists keys and may return a non-canonical witness), response envelope (v0:<base64>), decoding pipeline (base64 → zstd → bincode-legacy), and error code reference.
  • Documents the witness data structure: SaltWitness, SaltKey (24-bit bucket / 40-bit slot bit layout + unpack formula), SaltValue (94-byte length-prefixed encoding with Account / Storage / BucketMeta flavors), SaltProof, and MptWitness — each shown as the upstream Rust struct with a file:line source link.
  • Wires the page into navigation: nested under Stateless Validation in docs/SUMMARY.md, with a back-link from docs/stateless/stateless-validator.md's Related pages section.

Test plan

  • Render the new page in GitBook preview and confirm tables, hint blocks, and code fences display correctly.
  • Click through the upstream source links (salt/src/proof/salt_witness.rs#L46, salt/src/types.rs#L198, salt/src/types.rs#L274, salt/src/proof/prover.rs#L103, stateless-core/src/withdrawals.rs#L49) and verify they land on the expected struct definitions.
  • Run the curl ... | jq | base64 -d | zstd -d > witness.bincode example against a real mainnet block and confirm the resulting file decodes into (SaltWitness, MptWitness) via bincode-legacy.
  • Verify "Get Block Witness" appears under "Stateless Validation" in the rendered sidebar.

@flyq flyq requested review from Troublor and nnsgmsone as code owners April 28, 2026 03:33
Comment thread docs/stateless/get-block-witness.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Good addition — technically thorough, well-structured reference page. One nit flagged inline (two sentences on one line at the lookup-modes intro paragraph). Everything else looks correct: frontmatter present, SUMMARY.md updated, relative links use .md extensions, placeholder format matches the stateless layer convention (<BLOCK_NUMBER_HEX>), decoding pipeline matches the upstream Rust implementation, and SaltValue byte-layout arithmetic checks out.

Comment thread docs/stateless/get-block-witness.md Outdated
Comment thread docs/stateless/get-block-witness.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Good reference page overall — the lookup mode table, decoding pipeline, and struct field breakdowns are exactly the right level of detail for this audience.

Three style fixes needed before merge:

  1. H1 heading case (inline) — # Get Block Witness# Get block witness per the sentence-case rule.
  2. Passive voice in Errors section (inline) — two sentences name no actor; suggestions provided.
  3. Existing unresolved thread (line 40) — two sentences on one line still not addressed: **Always pass a hash...** The \blockNumber`-only mode...` needs to be split onto separate lines per the one-sentence-per-line rule.

Comment thread docs/stateless/get-block-witness.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Reviewed. Three previously open threads are resolved — the heading is sentence case, the bold sentence and the following sentence are on separate lines, and the errors-section prose is active voice.

One new issue filed inline: base64 -d on line 276 of get-block-witness.md is Linux-only (macOS BSD base64 requires -D). The brew-install note above that line implies macOS users may run the command, so base64 --decode (or a clarifying note) is safer.

Content quality is solid: frontmatter is present, page is wired into SUMMARY.md and back-linked from stateless-validator.md, all fenced code blocks carry language identifiers, GitBook hint blocks are correctly closed, internal links use relative .md paths, and the three lookup modes are documented with appropriate safety warnings.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Reviewed. Three earlier threads have been resolved (heading case, one-sentence-per-line, active voice) and the base64 -d--decode change was applied.

One remaining issue: base64 --decode still fails on macOS. BSD base64 (the macOS built-in) uses -D for decode — --decode is GNU coreutils only. The brew-install line (brew install jq zstd) doesn't pull in GNU coreutils, so macOS users following the example will hit base64: illegal option. Fix options:

  • Add a note that the command targets Linux/GNU coreutils, or
  • Replace the pipeline with python3 -m base64 -d (works cross-platform), or
  • Note that macOS users need brew install coreutils && gbase64 --decode.

Content, structure, and formatting otherwise look good — detailed reference with correct struct layouts, accurate source links, and proper GitBook syntax.

@flyq
Copy link
Copy Markdown
Member Author

flyq commented Apr 28, 2026

@claude I tried in mac book M4, it works with base64 -d or --decode both

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Claude finished @flyq's task in 41s —— View job


Tasks

  • Gather context and understand request
  • Verify base64 compatibility claim
  • Update review status

Thanks for testing that, @flyq — good to know. On modern macOS (Apple Silicon / recent OS versions), base64 has been updated to accept both -d and --decode, so this is a non-issue on current hardware.

The current file already uses --decode (the more explicit form), which is fine. My concern was based on older macOS BSD behavior where only -D was supported for decode — that's not relevant for anyone running a recent macOS version.

All previous concerns are now resolved:

  • H1 heading sentence case
  • One-sentence-per-line rule
  • Active voice in Errors section
  • base64 --decode — works on modern macOS (confirmed by author)

The PR looks good to merge. Content is technically accurate, well-structured, and follows the stateless layer conventions.


· Branch: liquan/witness_doc

- Rename docs/stateless/ -> docs/node/ to broaden the layer for node-operator content
- Rename stateless-validator.md -> stateless-validation.md
- Rename get-block-witness.md -> witness.md
- Hide internal OP-stack lookup mode (parentHash, attributesHash) from public docs
- Wrap request examples in GitBook tabs
- Anchor-link payload tuple to SaltWitness/MptWitness sections
- Add use statements + crate-attribution hint to decoding snippet
- Reorder Errors before Decoding pipeline under Response
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

The PR description lists three lookup modes, but the page only documents two. The parentHash + attributesHash OP-stack derivation mode is missing entirely — it does not appear in the request fields table, the Lookup modes table, or the Examples section.

Concretely, these fields need to be added to the request schema:

Field Type Required Description
parentHash Data (32 bytes) No Hash of the parent block. Used together with attributesHash for OP-stack derivation — the backend can resolve the block without a canonical block hash.
attributesHash Data (32 bytes) No Hash of the PayloadAttributes used to build this block. Paired with parentHash to uniquely identify a derived block on OP-stack.

The Lookup modes table should gain a third row, and the Examples section should include a parentHash + attributesHash tab. This mode is the correct one for OP-stack derivers that have those hashes available but have not yet committed a canonical block hash.

Comment thread docs/node/witness.md Outdated
Copy link
Copy Markdown
Collaborator

@Troublor Troublor left a comment

Choose a reason for hiding this comment

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

I directly edited the files.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 28, 2026

Review

Directory rename (stateless/node/) and file rename (stateless-validator.mdstateless-validation.md) — correctly propagated to AGENTS.md, docs/AGENTS.md, docs/SUMMARY.md, and the back-link in the renamed page. Clean.

New page docs/node/witness.md — well-structured reference. Frontmatter has description, the page is in SUMMARY.md, internal links use .md extensions, GitBook blocks are correctly opened/closed, headings use sentence case, and the earlier review issues (one-sentence-per-line, passive voice, base64 --decode) are all addressed.

One outstanding issue — the existing unresolved thread on the opening line:

MegaETH defines \mega_getBlockWitness` RPC method to return…`

Missing indefinite article — should be "defines a mega_getBlockWitness RPC method". Nothing else blocking.

Comment thread docs/node/witness.md
@flyq
Copy link
Copy Markdown
Member Author

flyq commented Apr 29, 2026

@claude blockNumber + parentHash + attributesHash is not supported public

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

Claude finished @flyq's task in 33s —— View job


Tasks

  • Gather context and understand the clarification
  • Check current state of docs/node/witness.md
  • Update review status

Thanks for clarifying, @flyq — understood, parentHash + attributesHash is an internal/non-public lookup mode, so it's correct to omit it from the public RPC reference.

That resolves the last open thread. All review concerns are now closed:

  • H1 heading sentence case
  • One-sentence-per-line rule
  • Active voice in Errors section
  • base64 --decode — confirmed working on modern macOS
  • Missing article ("defines a mega_getBlockWitness") — present on line 7
  • parentHash + attributesHash lookup mode — intentionally omitted (not publicly supported)

The PR is ready to merge.

--- · Branch: liquan/witness_doc

@nnsgmsone
Copy link
Copy Markdown
Contributor

@claude Witnesses are immutable once written: the upstream RPC layer sets Cache-Control: public, max-age=31536000, immutable, so clients can cache successful responses
indefinitely. 这个帮忙校验一下,为什么我测试下来的结果是 POST https://mainnet.megaeth.com/rpc 对 mega_getBlockWitness 返回的是 cache-control: no-store。

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

Claude finished @nnsgmsone's task in 52s —— View job


Tasks

  • Gather context and understand request
  • Read current docs/node/witness.md to find the Cache-Control claim
  • Test the endpoint to verify actual Cache-Control headers
  • Fix the documentation — claim was incorrect
  • Commit and push changes

你说得对。POST https://mainnet.megaeth.com/rpcmega_getBlockWitness 实际返回的是 Cache-Control: no-store,与文档中声称的 public, max-age=31536000, immutable 不符。

该声明是之前 review 中 Claude 建议的,但这个建议是错误的——它假设了一个不存在的上游缓存行为。

Fix applied to docs/node/witness.md line 102:

- Witnesses are immutable once written: the upstream RPC layer sets `Cache-Control: public, max-age=31536000, immutable`, so clients can cache successful responses indefinitely.
+ Witnesses are immutable once written: the same block number and hash will always return the same witness.
+ Do not rely on HTTP caching — the endpoint currently returns `Cache-Control: no-store`.

The immutability of the witness data itself is still true (same block + hash → same witness), but the HTTP caching behavior is now accurately documented.
· Branch: liquan/witness_doc

The endpoint returns Cache-Control: no-store, not the immutable
public cache headers previously documented.

Co-authored-by: nnsgmsone <nnsgmsone@users.noreply.github.com>
@nnsgmsone
Copy link
Copy Markdown
Contributor

@claude Witnesses are immutable once written: the upstream RPC layer sets Cache-Control: public, max-age=31536000, immutable, so clients can cache successful responses indefinitely. 这个帮忙校验一下,为什么我测试下来的结果是 POST https://mainnet.megaeth.com/rpc 对 mega_getBlockWitness 返回的是 cache-control: no-store。

@flyq 这个是不是不符合你的预期呢?你的预期是要cache吗?

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

Claude finished @nnsgmsone's task in 29s —— View job


Tasks

  • Gather context and understand request
  • Check current state of docs/node/witness.md
  • Clarify the situation for @flyq

@flyq — the earlier fix (from the previous job run) already corrected the documentation to match the observed behavior:

Current doc (line ~102 of docs/node/witness.md):

Witnesses are immutable once written: the same block number and hash will always return the same witness.
Do not rely on HTTP caching — the endpoint currently returns Cache-Control: no-store.

@nnsgmsone's question is whether the no-store behavior is intentional on your end, or whether you planned to add caching support (e.g. public, max-age=31536000, immutable) at some point.

  • If no-store is the intended long-term behavior → current docs are correct, no further changes needed.
  • If caching support is planned or already available on some environments → the documentation should be updated to reflect that, and the commit from the previous job run should be revised.

No code changes were made in this task — this is a clarifying question for @flyq to confirm the intended caching behavior.

--- · Branch: liquan/witness_doc

@flyq
Copy link
Copy Markdown
Member Author

flyq commented Apr 29, 2026

@claude Witnesses are immutable once written: the upstream RPC layer sets Cache-Control: public, max-age=31536000, immutable, so clients can cache successful responses indefinitely. 这个帮忙校验一下,为什么我测试下来的结果是 POST https://mainnet.megaeth.com/rpc 对 mega_getBlockWitness 返回的是 cache-control: no-store。

@flyq 这个是不是不符合你的预期呢?你的预期是要cache吗?

@nnsgmsone 赞,这个确实之前是参考文档写的,但是不符合后来 mega-rpc 对这个方法对实现。我更新一下。实际情况是没有基于 POST 的缓存(也不应该有)

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

Claude finished @flyq's task in 1m 3s —— View job


Tasks

  • Gather context and understand request
  • Read current docs/node/witness.md to verify the Cache-Control section
  • Refine wording to reflect intended permanent behavior

The previous job had already corrected the false Cache-Control: public, max-age=31536000, immutable claim. Since you've confirmed that no-store is the intended permanent behavior (not a temporary limitation), I made one further small fix:

- Do not rely on HTTP caching — the endpoint currently returns `Cache-Control: no-store`.
+ Do not rely on HTTP caching — the endpoint returns `Cache-Control: no-store`.

Dropping "currently" removes the implication that HTTP caching might be added later. The sentence now reads as the stable, intended design.
· Branch: liquan/witness_doc

github-actions Bot and others added 2 commits April 29, 2026 02:28
Cache-Control: no-store is the intended permanent behavior for POST
endpoints, not a temporary state.

Co-authored-by: liquan.eth <flyq@users.noreply.github.com>
Comment thread docs/node/witness.md Outdated
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

All six previous threads are resolved. One remaining issue flagged inline: the ## Request table uses a transposed layout that puts a meta-label (Field) alongside actual field names (Method, Params) as column headers, making the row with Value ambiguous. Suggested a conventional vertical two-column table instead.

Otherwise the PR looks good — the stateless/ → node/ rename is properly propagated across AGENTS.md, docs/AGENTS.md, SUMMARY.md, and the page itself; the new witness.md is thorough and well-structured with correct GitBook syntax, sentence-case headings, and one-sentence-per-line formatting.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 29, 2026

All prior review threads have been addressed and resolved.

Summary of changes:

  • docs/stateless/ renamed to docs/node/ (with stateless-validator.mdstateless-validation.md) — clean rename, no stale cross-references remain anywhere in the docs tree.
  • AGENTS.md and docs/AGENTS.md updated to reflect the new path.
  • docs/SUMMARY.md wired correctly — Get Block Witness nests under Stateless Validation at the right depth, consistent with other sections.
  • New docs/node/witness.md is thorough and accurate: one-sentence-per-line rule followed, all headings in sentence case, hint/tab blocks used correctly, base64 --decode (cross-platform) in the example, and all upstream source links are pinned to specific file/line locations.

The page intentionally documents two lookup modes (not three as the PR description originally stated); that was discussed and the thread resolved.

LGTM.

Copy link
Copy Markdown
Contributor

@nnsgmsone nnsgmsone left a comment

Choose a reason for hiding this comment

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

lgtm

@flyq flyq merged commit 305b9d6 into main Apr 29, 2026
7 checks passed
@flyq flyq deleted the liquan/witness_doc branch April 29, 2026 03:04
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.

3 participants