amt

package
v1.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Legacy (v2) AMT support.

Filecoin's block message AMTs (MsgMeta.BlsMessages / SecpkMessages) and the per-tipset ParentMessageReceipts AMT are encoded with the ORIGINAL go-amt-ipld v2 format: a 3-field root [Height, Count, Node] with an implicit fixed width of 8 (bitWidth 3) that is NOT stored in the root.

FEVM contract-state AMTs and most modern actor sub-AMTs use the v4 format (4-field root [BitWidth, Height, Count, Node]). Loading a v2 root with the v4 loader fails with "cbor input had wrong number of fields" because the v4 internal.Root decoder expects 4 fields and the bytes carry 3.

This file provides v2-format Lookup / ForEach over the same path-recording store the rest of state/amt uses, so message-search (chain/msgsearch) can resolve receipts locally with zero external trust.

Package amt is Lantern's proof-recording AMT walker.

Filecoin uses Array-Mapped Tries (AMTs) for indexed arrays in actor state: message receipts, miner sectors, partition expirations, market deal proposals, etc. The on-disk encoding is documented in github.com/filecoin-project/go-amt-ipld/v4.

We delegate the actual node decoding and traversal to that library (pure Go, no CGo) and wrap it with a BlockGetter abstraction + proof-path recorder, mirroring the state/hamt design.

Index

Constants

View Source
const FilBitWidth = 3

FilBitWidth is the default Filecoin AMT bit-width. Most actor sub-AMTs use width = 3 (8 entries per node); see go-amt-ipld/v4 docs.

Variables

View Source
var ErrNotFound = fmt.Errorf("index not found in AMT")

ErrNotFound is returned by Lookup when the index is not in the AMT.

Functions

func ForEachRaw

func ForEachRaw(ctx context.Context, root cid.Cid, bg hamt.BlockGetter, opts *LookupOptions, fn func(i uint64, val []byte) error) ([]cid.Cid, error)

ForEachRaw walks a v4 AMT in index order, invoking fn with each entry's index and raw value bytes. Used to enumerate small per-receipt AMTs like the EventsRoot events AMT (lantern#73). Returns the proof path (node CIDs fetched). fn must not retain the value slice past the call.

func ForEachV2CIDs

func ForEachV2CIDs(ctx context.Context, root cid.Cid, bg hamt.BlockGetter) ([]cid.Cid, error)

ForEachV2CIDs walks a legacy (v2) AMT-of-CIDs in index order, returning the CIDs. This is the canonical way to enumerate a block's message AMT (each leaf value is a CBOR-tagged CID).

func Lookup

func Lookup(ctx context.Context, root cid.Cid, i uint64, bg hamt.BlockGetter, opts *LookupOptions) ([]byte, []cid.Cid, error)

Lookup walks the AMT rooted at `root`, fetching nodes via `bg`. It returns the raw value bytes at index `i`, the proof path (list of node CIDs in fetch order), and an error.

func LookupCBOR

func LookupCBOR(ctx context.Context, root cid.Cid, i uint64, bg hamt.BlockGetter, out cbg.CBORUnmarshaler, opts *LookupOptions) ([]cid.Cid, error)

LookupCBOR is a convenience wrapper that decodes the leaf bytes via cbor-gen into `out`.

func LookupV2

func LookupV2(ctx context.Context, root cid.Cid, i uint64, bg hamt.BlockGetter) ([]byte, []cid.Cid, error)

LookupV2 reads the raw value bytes at index `i` from a legacy (v2) AMT rooted at `root`, returning the value bytes and the proof path (node CIDs fetched in order). Use this for block message AMTs and ParentMessageReceipts.

func VerifyProof

func VerifyProof(ctx context.Context, root cid.Cid, i uint64, value []byte, proof []cid.Cid, bg hamt.BlockGetter, opts *LookupOptions) error

VerifyProof independently re-verifies an AMT lookup proof. See state/hamt.VerifyProof for the design rationale.

Types

type LookupOptions

type LookupOptions struct {
	BitWidth uint // default FilBitWidth (3)
}

LookupOptions on a single Lookup call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL