block

package
v1.28.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: BSD-3-Clause Imports: 15 Imported by: 8

Documentation

Overview

Package block is a generated GoMock package.

Index

Constants

View Source
const (
	// CodecVersionV0 is the v1.23.x ("Apricot/Banff") wire layout. It is
	// retained as a READ-ONLY decoder so that pre-codec-v1 blocks on
	// disk continue to deserialize and so that v0-derived BlockIDs and
	// TxIDs remain stable. All write paths MUST use CodecVersionV1.
	CodecVersionV0 = txs.CodecVersionV0

	// CodecVersionV1 is the current canonical block-codec wire layout.
	// Every block built by this binary is written at v1.
	CodecVersionV1 = txs.CodecVersionV1

	// CodecVersion is the canonical write version. All Marshal call
	// sites in this package use CodecVersion so that any future bump of
	// the write target updates exactly one symbol.
	CodecVersion = CodecVersionV1
)

Variables

View Source
var (
	// Codec is the standard-size block codec.Manager. It carries ONLY
	// the v1 slot map and so decodes only v1-prefixed block bytes via
	// codec.Manager dispatch. v0 block bytes must go through Parse,
	// which routes prefix==0 to v0Codec for the v0 Block interface.
	//
	// Block-codec dispatch is explicitly two-step (Parse extracts the
	// 2-byte prefix and selects v0Codec or Codec) because v0 blocks
	// implement v0.Block, not block.Block — they cannot be unmarshalled
	// into a block.Block destination. Hence Codec is v1-only by design.
	Codec codec.Manager

	// GenesisCodec is the unbounded-size codec.Manager used by both
	// large-genesis decode AND every P-Chain state-side read of
	// non-block byte values (feeState, L1Validator, NetToL1Conversion,
	// fx.Owner, heightRange, legacy stateBlk). It registers BOTH the
	// v0 (v1.23.x Apricot/Banff) and v1 (current) tx slot maps under
	// CodecVersionV0 and CodecVersionV1 respectively, so a state read
	// of pre-codec-v1 bytes (prefix=0x0000) dispatches into the v0
	// slot map and a v1 read (prefix=0x0001) dispatches into v1.
	//
	// Writes still target CodecVersion (== CodecVersionV1) exclusively —
	// the v0 slot map is a READ-ONLY decoder. This is the same shape
	// that txs.GenesisCodec carries, which is why genesis.Codec aliases
	// txs.GenesisCodec rather than this codec.
	//
	// Note that this codec does NOT register block.Block / v0.Block
	// types directly — block parsing always goes through block.Parse,
	// not GenesisCodec.Unmarshal(b, &Block). The v0 slot map registered
	// here covers the tx + sub-tx slots referenced by serialized state
	// values (e.g. fx.Owner -> secp256k1fx.OutputOwners).
	GenesisCodec codec.Manager
)
View Source
var ErrShortBytes = errors.New("block bytes too short for codec version prefix")

ErrShortBytes is returned when the input is shorter than the 2-byte codec-version prefix.

Functions

func RegisterBlockTypes added in v1.26.35

func RegisterBlockTypes(targetCodec linearcodec.Codec) error

RegisterBlockTypes registers the canonical v1 block type IDs. There is exactly one type per block kind: ProposalBlock, AbortBlock, CommitBlock, StandardBlock. Tx types come from txs.RegisterTypes (which registers the v1 tx slot layout).

func RegisterGenesisType added in v1.16.56

func RegisterGenesisType(val interface{}) error

RegisterGenesisType registers a type with the GenesisCodec at BOTH the v0 and v1 slot positions. Used by other packages (e.g. state) to register types that are encountered in genesis bytes and state-read fallback paths. Registering at both versions keeps the slot ID identical across the codec.Manager dispatch so a v0-prefixed read of a state value (e.g. legacy stateBlk) lands on the same Go type as a v1-prefixed read.

All registrations must succeed atomically: if the v0 registration fails (e.g. duplicate type) the v1 registration is still attempted so the underlying error is surfaced rather than silently leaving the codecs in a divergent state.

Types

type AbortBlock added in v1.26.35

type AbortBlock struct {
	Time        uint64 `serialize:"true" json:"time"`
	CommonBlock `serialize:"true"`
}

AbortBlock is the canonical P-Chain abort outcome of a ProposalBlock.

func NewAbortBlock added in v1.26.35

func NewAbortBlock(
	timestamp time.Time,
	parentID ids.ID,
	height uint64,
) (*AbortBlock, error)

func (*AbortBlock) InitRuntime added in v1.26.35

func (*AbortBlock) InitRuntime(*runtime.Runtime)

func (*AbortBlock) Initialize added in v1.26.35

func (*AbortBlock) Initialize(context.Context) error

func (*AbortBlock) Timestamp added in v1.26.35

func (b *AbortBlock) Timestamp() time.Time

func (*AbortBlock) Txs added in v1.26.35

func (*AbortBlock) Txs() []*txs.Tx

func (*AbortBlock) Visit added in v1.26.35

func (b *AbortBlock) Visit(v Visitor) error

type Block

type Block interface {
	RuntimeInitializable
	ID() ids.ID
	Parent() ids.ID
	Bytes() []byte
	Height() uint64

	// Txs returns list of transactions contained in the block
	Txs() []*txs.Tx

	// Visit calls [visitor] with this block's concrete type
	Visit(visitor Visitor) error
	// contains filtered or unexported methods
}

Block defines the common stateless interface for all blocks

func Parse

func Parse(c codec.Manager, b []byte) (Block, error)

Parse decodes a block byte stream produced by either the v0 (v1.23.x) or v1 (current) block codec. The codec.Manager argument selects the SIZE class — Codec (1 MiB max) or GenesisCodec (unbounded). The actual VERSION is taken from the 2-byte wire prefix and dispatched to the matching slot map.

Parse never re-marshals the input; BlockID = hash(b) verbatim and b is stashed on the returned block's CommonBlock. This is the byte-preserving path that keeps BlockIDs (and inner TxIDs) stable across the v0->v1 migration.

c must be one of block.Codec or block.GenesisCodec. The v0 codec is selected internally based on the size class of c. Other codecs are rejected with codec.ErrUnknownVersion.

type CommitBlock added in v1.26.35

type CommitBlock struct {
	Time        uint64 `serialize:"true" json:"time"`
	CommonBlock `serialize:"true"`
}

CommitBlock is the canonical P-Chain commit outcome of a ProposalBlock.

func NewCommitBlock added in v1.26.35

func NewCommitBlock(
	timestamp time.Time,
	parentID ids.ID,
	height uint64,
) (*CommitBlock, error)

func (*CommitBlock) InitRuntime added in v1.26.35

func (*CommitBlock) InitRuntime(*runtime.Runtime)

func (*CommitBlock) Initialize added in v1.26.35

func (*CommitBlock) Initialize(context.Context) error

func (*CommitBlock) Timestamp added in v1.26.35

func (b *CommitBlock) Timestamp() time.Time

func (*CommitBlock) Txs added in v1.26.35

func (*CommitBlock) Txs() []*txs.Tx

func (*CommitBlock) Visit added in v1.26.35

func (b *CommitBlock) Visit(v Visitor) error

type CommonBlock

type CommonBlock struct {
	// parent's ID
	PrntID ids.ID `serialize:"true" json:"parentID"`

	// This block's height. The genesis block is at height 0.
	Hght uint64 `serialize:"true" json:"height"`

	BlockID ids.ID `json:"id"`
	// contains filtered or unexported fields
}

CommonBlock contains fields and methods common to all blocks in this VM.

func (*CommonBlock) Bytes

func (b *CommonBlock) Bytes() []byte

func (*CommonBlock) Height

func (b *CommonBlock) Height() uint64

func (*CommonBlock) ID

func (b *CommonBlock) ID() ids.ID

func (*CommonBlock) Parent

func (b *CommonBlock) Parent() ids.ID

type MockBlock

type MockBlock struct {
	// contains filtered or unexported fields
}

MockBlock is a mock of Block interface.

func NewMockBlock

func NewMockBlock(ctrl *gomock.Controller) *MockBlock

NewMockBlock creates a new mock instance.

func (*MockBlock) Bytes

func (m *MockBlock) Bytes() []byte

Bytes mocks base method.

func (*MockBlock) EXPECT

func (m *MockBlock) EXPECT() *MockBlockMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBlock) Height

func (m *MockBlock) Height() uint64

Height mocks base method.

func (*MockBlock) ID

func (m *MockBlock) ID() ids.ID

ID mocks base method.

func (*MockBlock) InitRuntime added in v1.22.87

func (m *MockBlock) InitRuntime(rt *runtime.Runtime)

InitRuntime mocks base method.

func (*MockBlock) Parent

func (m *MockBlock) Parent() ids.ID

Parent mocks base method.

func (*MockBlock) Txs

func (m *MockBlock) Txs() []*txs.Tx

Txs mocks base method.

func (*MockBlock) Visit

func (m *MockBlock) Visit(visitor Visitor) error

Visit mocks base method.

type MockBlockMockRecorder

type MockBlockMockRecorder struct {
	// contains filtered or unexported fields
}

MockBlockMockRecorder is the mock recorder for MockBlock.

func (*MockBlockMockRecorder) Bytes

func (mr *MockBlockMockRecorder) Bytes() *gomock.Call

Bytes indicates an expected call of Bytes.

func (*MockBlockMockRecorder) Height

func (mr *MockBlockMockRecorder) Height() *gomock.Call

Height indicates an expected call of Height.

func (*MockBlockMockRecorder) ID

func (mr *MockBlockMockRecorder) ID() *gomock.Call

ID indicates an expected call of ID.

func (*MockBlockMockRecorder) InitRuntime added in v1.22.87

func (mr *MockBlockMockRecorder) InitRuntime(rt any) *gomock.Call

InitRuntime indicates an expected call of InitRuntime.

func (*MockBlockMockRecorder) Parent

func (mr *MockBlockMockRecorder) Parent() *gomock.Call

Parent indicates an expected call of Parent.

func (*MockBlockMockRecorder) Txs

func (mr *MockBlockMockRecorder) Txs() *gomock.Call

Txs indicates an expected call of Txs.

func (*MockBlockMockRecorder) Visit

func (mr *MockBlockMockRecorder) Visit(visitor any) *gomock.Call

Visit indicates an expected call of Visit.

type ProposalBlock added in v1.26.35

type ProposalBlock struct {
	Time         uint64    `serialize:"true" json:"time"`
	Transactions []*txs.Tx `serialize:"true" json:"txs"`
	CommonBlock  `serialize:"true"`
	Tx           *txs.Tx `serialize:"true" json:"tx"`
}

ProposalBlock is the canonical P-Chain proposal block. It carries a per-block timestamp, a single proposal Tx, and a tail of decision Txs that commit atomically with the proposal outcome.

func NewProposalBlock added in v1.26.35

func NewProposalBlock(
	timestamp time.Time,
	parentID ids.ID,
	height uint64,
	proposalTx *txs.Tx,
	decisionTxs []*txs.Tx,
) (*ProposalBlock, error)

func (*ProposalBlock) InitRuntime added in v1.26.35

func (b *ProposalBlock) InitRuntime(rt *runtime.Runtime)

func (*ProposalBlock) Initialize added in v1.26.35

func (*ProposalBlock) Initialize(context.Context) error

func (*ProposalBlock) Timestamp added in v1.26.35

func (b *ProposalBlock) Timestamp() time.Time

func (*ProposalBlock) Txs added in v1.26.35

func (b *ProposalBlock) Txs() []*txs.Tx

func (*ProposalBlock) Visit added in v1.26.35

func (b *ProposalBlock) Visit(v Visitor) error

type RuntimeInitializable added in v1.22.87

type RuntimeInitializable interface {
	InitRuntime(rt *runtime.Runtime)
}

RuntimeInitializable defines the interface for initializing context

type StandardBlock added in v1.26.35

type StandardBlock struct {
	Time         uint64 `serialize:"true" json:"time"`
	CommonBlock  `serialize:"true"`
	Transactions []*txs.Tx `serialize:"true" json:"txs"`
}

StandardBlock is the canonical P-Chain standard block. It carries a per-block timestamp (advance-all-implicitly removed the separate AdvanceTimeTx flow) and an ordered list of decision txs.

func NewStandardBlock added in v1.26.35

func NewStandardBlock(
	timestamp time.Time,
	parentID ids.ID,
	height uint64,
	txs []*txs.Tx,
) (*StandardBlock, error)

func (*StandardBlock) InitRuntime added in v1.26.35

func (b *StandardBlock) InitRuntime(rt *runtime.Runtime)

func (*StandardBlock) Initialize added in v1.26.35

func (*StandardBlock) Initialize(context.Context) error

func (*StandardBlock) Timestamp added in v1.26.35

func (b *StandardBlock) Timestamp() time.Time

func (*StandardBlock) Txs added in v1.26.35

func (b *StandardBlock) Txs() []*txs.Tx

func (*StandardBlock) Visit added in v1.26.35

func (b *StandardBlock) Visit(v Visitor) error

type TimestampedBlock added in v1.26.35

type TimestampedBlock interface {
	Block
	Timestamp() time.Time
}

type Visitor

type Visitor interface {
	AbortBlock(*AbortBlock) error
	CommitBlock(*CommitBlock) error
	ProposalBlock(*ProposalBlock) error
	StandardBlock(*StandardBlock) error
}

Visitor dispatches by the canonical P-Chain block type. Under carries a timestamp and is one of the four canonical kinds.

Directories

Path Synopsis
Package executor is a generated GoMock package.
Package executor is a generated GoMock package.
executormock
Package executormock is a generated GoMock package.
Package executormock is a generated GoMock package.
Package v0 defines the v1.23.x ("Apricot/Banff") P-Chain block layout.
Package v0 defines the v1.23.x ("Apricot/Banff") P-Chain block layout.

Jump to

Keyboard shortcuts

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