block

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: Apache-2.0 Imports: 25 Imported by: 2 modules, 64 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTxRootMismatch      = errors.New("transaction merkle root does not match")
	ErrDeltaStateMismatch  = errors.New("delta state digest doesn't match")
	ErrReceiptRootMismatch = errors.New("receipt root hash does not match")
)

Errors

Functions

func DeserializeBlockStoresPb

func DeserializeBlockStoresPb(buf []byte) (*iotextypes.BlockStores, error)

DeserializeBlockStoresPb decode byte stream into BlockStores pb message

func DeserializeSystemLogPb

func DeserializeSystemLogPb(buf []byte) (*iotextypes.TransactionLogs, error)

DeserializeSystemLogPb parse the byte stream into TransactionLogs Pb message

func GenesisHash

func GenesisHash() hash.Hash256

GenesisHash returns the genesis block's hash

func LoadGenesisHash

func LoadGenesisHash(g *genesis.Genesis)

LoadGenesisHash is done once to compute and save the genesis'es hash

Types

type BlkTransactionLog

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

BlkTransactionLog is transaction log in one block

func (*BlkTransactionLog) Serialize

func (log *BlkTransactionLog) Serialize() []byte

Serialize returns a serialized byte stream for BlkTransactionLog

type Block

type Block struct {
	Header
	Body
	Footer

	// TODO: move receipts out of block struct
	Receipts []*action.Receipt
}

Block defines the struct of block

func CreateTestBlockWithBlob

func CreateTestBlockWithBlob(start, n int) ([]*Block, error)

func GenesisBlock

func GenesisBlock() *Block

GenesisBlock returns the genesis block

func NewBlockDeprecated

func NewBlockDeprecated(
	chainID uint32,
	height uint64,
	prevBlockHash hash.Hash256,
	timestamp time.Time,
	producer crypto.PublicKey,
	actions []*action.SealedEnvelope,
) *Block

NewBlockDeprecated returns a new block This method is deprecated. Only used in old tests.

func (*Block) ActionByHash

func (b *Block) ActionByHash(h hash.Hash256) (*action.SealedEnvelope, uint32, error)

ActionByHash returns the action of a given hash

func (*Block) ConvertToBlockPb

func (b *Block) ConvertToBlockPb() *iotextypes.Block

ConvertToBlockPb converts Block to Block

func (*Block) Finalize

func (b *Block) Finalize(endorsements []*endorsement.Endorsement, ts time.Time) error

Finalize creates a footer for the block

func (*Block) HasBlob

func (b *Block) HasBlob() bool

HasBlob returns whether the block contains blobs

func (*Block) ProtoWithoutSidecar

func (b *Block) ProtoWithoutSidecar() *iotextypes.Block

ProtoWithoutSidecar returns the protobuf without sidecar

func (*Block) RunnableActions

func (b *Block) RunnableActions() RunnableActions

RunnableActions abstructs RunnableActions from a Block.

func (*Block) Serialize

func (b *Block) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block

func (*Block) TransactionLog

func (b *Block) TransactionLog() *BlkTransactionLog

TransactionLog returns transaction logs in the block

func (*Block) VerifyTxRoot

func (b *Block) VerifyTxRoot() error

VerifyTxRoot verifies the transaction root hash

func (*Block) WithBlobSidecars

func (b *Block) WithBlobSidecars(sidecars []*types.BlobTxSidecar, txhash []string, deser *action.Deserializer) (*Block, error)

type Body

type Body struct {
	Actions []*action.SealedEnvelope
}

Body defines the struct of body

func (*Body) CalculateTransferAmount

func (b *Body) CalculateTransferAmount() *big.Int

CalculateTransferAmount returns the calculated transfer amount in this block.

func (*Body) CalculateTxRoot

func (b *Body) CalculateTxRoot() (hash.Hash256, error)

CalculateTxRoot returns the Merkle root of all txs and actions in this block.

func (*Body) Proto

func (b *Body) Proto() *iotextypes.BlockBody

Proto converts Body to Protobuf

func (*Body) Serialize

func (b *Body) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block

type Builder

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

Builder is used to construct Block.

func NewBuilder

func NewBuilder(ra RunnableActions) *Builder

NewBuilder creates a Builder.

func (*Builder) GetCurrentBlockHeader

func (b *Builder) GetCurrentBlockHeader() Header

GetCurrentBlockHeader returns the current hash of Block Header Core

func (*Builder) SetBaseFee

func (b *Builder) SetBaseFee(fee *big.Int) *Builder

SetBaseFee sets the base fee

func (*Builder) SetBlobGasUsed

func (b *Builder) SetBlobGasUsed(g uint64) *Builder

SetBlobGasUsed sets the blob gas used

func (*Builder) SetDeltaStateDigest

func (b *Builder) SetDeltaStateDigest(h hash.Hash256) *Builder

SetDeltaStateDigest sets the new delta state digest after running actions included in this building block

func (*Builder) SetExcessBlobGas

func (b *Builder) SetExcessBlobGas(g uint64) *Builder

SetExcessBlobGas sets the excess blob gas

func (*Builder) SetGasUsed

func (b *Builder) SetGasUsed(g uint64) *Builder

SetGasUsed sets the used gas

func (*Builder) SetHeight

func (b *Builder) SetHeight(h uint64) *Builder

SetHeight sets the block height

func (*Builder) SetLogsBloom

func (b *Builder) SetLogsBloom(f bloom.BloomFilter) *Builder

SetLogsBloom sets the logs bloom filter value after running actions included in this building block.

func (*Builder) SetPrevBlockHash

func (b *Builder) SetPrevBlockHash(h hash.Hash256) *Builder

SetPrevBlockHash sets the previous block hash for block which is building.

func (*Builder) SetReceiptRoot

func (b *Builder) SetReceiptRoot(h hash.Hash256) *Builder

SetReceiptRoot sets the receipt root after running actions included in this building block.

func (*Builder) SetReceipts

func (b *Builder) SetReceipts(receipts []*action.Receipt) *Builder

SetReceipts sets the receipts after running actions included in this building block.

func (*Builder) SetTimestamp

func (b *Builder) SetTimestamp(ts time.Time) *Builder

SetTimestamp sets the block timestamp

func (*Builder) SetVersion

func (b *Builder) SetVersion(v uint32) *Builder

SetVersion sets the protocol version for block which is building.

func (*Builder) SignAndBuild

func (b *Builder) SignAndBuild(signerPrvKey crypto.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

type Deserializer

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

Deserializer de-serializes a block

It's a wrapper to set certain parameters in order to correctly de-serialize a block Currently the parameter is EVM network ID for tx in web3 format, it is called like

blk, err := (&Deserializer{}).SetEvmNetworkID(id).FromBlockProto(pbBlock) blk, err := (&Deserializer{}).SetEvmNetworkID(id).DeserializeBlock(buf)

func NewDeserializer

func NewDeserializer(evmNetworkID uint32) *Deserializer

NewDeserializer creates a new deserializer

func (*Deserializer) BlockFromBlockStoreProto

func (bd *Deserializer) BlockFromBlockStoreProto(pb *iotextypes.BlockStore) (*Block, error)

func (*Deserializer) DeserializeBlock

func (bd *Deserializer) DeserializeBlock(buf []byte) (*Block, error)

DeserializeBlock de-serializes a block

func (*Deserializer) DeserializeBlockStore

func (bd *Deserializer) DeserializeBlockStore(buf []byte) (*Store, error)

DeserializeBlockStore de-serializes a block store

func (*Deserializer) DeserializeBody

func (bd *Deserializer) DeserializeBody(buf []byte) (*Body, error)

DeserializeBody de-serializes a block body

func (*Deserializer) EvmNetworkID

func (bd *Deserializer) EvmNetworkID() uint32

EvmNetworkID get evm network ID

func (*Deserializer) FromBlockProto

func (bd *Deserializer) FromBlockProto(pbBlock *iotextypes.Block) (*Block, error)

FromBlockProto converts protobuf to block

func (*Deserializer) ReceiptsFromBlockStoreProto

func (bd *Deserializer) ReceiptsFromBlockStoreProto(pb *iotextypes.BlockStore) ([]*action.Receipt, error)

func (*Deserializer) SetEvmNetworkID

func (bd *Deserializer) SetEvmNetworkID(id uint32) *Deserializer

SetEvmNetworkID sets the evm network ID for web3 actions

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

Footer defines a set of proof of this block

func (*Footer) CommitTime

func (f *Footer) CommitTime() time.Time

CommitTime returns the timestamp the block was committed

func (*Footer) ConvertFromBlockFooterPb

func (f *Footer) ConvertFromBlockFooterPb(pb *iotextypes.BlockFooter) error

ConvertFromBlockFooterPb converts BlockFooter to BlockFooter

func (*Footer) Deserialize

func (f *Footer) Deserialize(buf []byte) error

Deserialize loads from the serialized byte stream

func (*Footer) Endorsements

func (f *Footer) Endorsements() []*endorsement.Endorsement

Endorsements returns the number of commit endorsements froms delegates

func (*Footer) Proto added in v2.2.0

func (f *Footer) Proto() *iotextypes.BlockFooter

Proto converts BlockFooter

func (*Footer) Serialize

func (f *Footer) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block footer

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

Header defines the struct of block header make sure the variable type and order of this struct is same as "BlockHeaderPb" in blockchain.pb.go

func (*Header) BaseFee

func (h *Header) BaseFee() *big.Int

BaseFee returns the baseFee of the block

func (*Header) BlobGasUsed

func (h *Header) BlobGasUsed() uint64

BlobGasUsed returns the blob gas used in this block

func (*Header) BlockHeaderCoreProto

func (h *Header) BlockHeaderCoreProto() *iotextypes.BlockHeaderCore

BlockHeaderCoreProto returns BlockHeaderCore proto.

func (*Header) DeltaStateDigest

func (h *Header) DeltaStateDigest() hash.Hash256

DeltaStateDigest returns the delta sate digest after applying this block.

func (*Header) Deserialize

func (h *Header) Deserialize(buf []byte) error

Deserialize loads from the serialized byte stream

func (*Header) ExcessBlobGas

func (h *Header) ExcessBlobGas() uint64

ExcessBlobGas returns the excess blob gas in this block

func (*Header) GasUsed

func (h *Header) GasUsed() uint64

GasUsed returns the gas used in this block.

func (*Header) HashBlock

func (h *Header) HashBlock() hash.Hash256

HashBlock return the hash of this block (actually hash of block header)

func (*Header) HashHeader

func (h *Header) HashHeader() hash.Hash256

HashHeader hashes the header

func (*Header) HashHeaderCore

func (h *Header) HashHeaderCore() hash.Hash256

HashHeaderCore hahes the header core.

func (*Header) HeaderLogger

func (h *Header) HeaderLogger(l *zap.Logger) *zap.Logger

HeaderLogger returns a new logger with block header fields' value.

func (*Header) Height

func (h *Header) Height() uint64

Height returns the height of this block.

func (*Header) LoadFromBlockHeaderProto

func (h *Header) LoadFromBlockHeaderProto(pb *iotextypes.BlockHeader) error

LoadFromBlockHeaderProto loads from protobuf

func (*Header) LogsBloomfilter

func (h *Header) LogsBloomfilter() bloom.BloomFilter

LogsBloomfilter return the bloom filter for all contract log events

func (*Header) PrevHash

func (h *Header) PrevHash() hash.Hash256

PrevHash returns the hash of prev block.

func (*Header) ProducerAddress

func (h *Header) ProducerAddress() string

ProducerAddress returns the address of producer

func (*Header) Proto

func (h *Header) Proto() *iotextypes.BlockHeader

Proto returns BlockHeader proto.

func (*Header) PublicKey

func (h *Header) PublicKey() crypto.PublicKey

PublicKey returns the public key of this header.

func (*Header) ReceiptRoot

func (h *Header) ReceiptRoot() hash.Hash256

ReceiptRoot returns the receipt root after apply this block

func (*Header) Serialize

func (h *Header) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of the block header

func (*Header) SerializeCore

func (h *Header) SerializeCore() []byte

SerializeCore returns byte stream for header core.

func (*Header) Timestamp

func (h *Header) Timestamp() time.Time

Timestamp returns the Timestamp of this block.

func (*Header) TxRoot

func (h *Header) TxRoot() hash.Hash256

TxRoot returns the hash of all actions in this block.

func (*Header) VerifyDeltaStateDigest

func (h *Header) VerifyDeltaStateDigest(digest hash.Hash256) bool

VerifyDeltaStateDigest verifies the delta state digest in header

func (*Header) VerifyReceiptRoot

func (h *Header) VerifyReceiptRoot(root hash.Hash256) bool

VerifyReceiptRoot verifies the receipt root in header

func (*Header) VerifySignature

func (h *Header) VerifySignature() bool

VerifySignature verifies the signature saved in block header

func (*Header) VerifyTransactionRoot

func (h *Header) VerifyTransactionRoot(root hash.Hash256) bool

VerifyTransactionRoot verifies the delta state digest in header

func (*Header) Version

func (h *Header) Version() uint32

Version returns the version of this block.

type RunnableActions

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

RunnableActions is abstructed from block which contains information to execute all actions in a block.

func (RunnableActions) Actions

func (ra RunnableActions) Actions() []*action.SealedEnvelope

Actions returns Actions.

func (RunnableActions) TxHash

func (ra RunnableActions) TxHash() hash.Hash256

TxHash returns TxHash.

type RunnableActionsBuilder

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

RunnableActionsBuilder is used to construct RunnableActions.

func NewRunnableActionsBuilder

func NewRunnableActionsBuilder() *RunnableActionsBuilder

NewRunnableActionsBuilder creates a RunnableActionsBuilder.

func (*RunnableActionsBuilder) AddActions

AddActions adds actions for block which is building.

func (*RunnableActionsBuilder) Build

Build signs and then builds a block.

type Store

type Store struct {
	Block    *Block
	Receipts []*action.Receipt
}

Store defines block storage schema

func (*Store) Serialize

func (in *Store) Serialize() ([]byte, error)

Serialize returns the serialized byte stream of Store

func (*Store) ToProto

func (in *Store) ToProto() *iotextypes.BlockStore

ToProto converts to proto message

func (*Store) ToProtoWithoutSidecar

func (in *Store) ToProtoWithoutSidecar() *iotextypes.BlockStore

ToProtoWithoutSidecar converts to proto message excluding sidecar data

type TestingBuilder

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

TestingBuilder is used to construct Block.

func NewTestingBuilder

func NewTestingBuilder() *TestingBuilder

NewTestingBuilder creates a Builder.

func (*TestingBuilder) AddActions

func (b *TestingBuilder) AddActions(acts ...*action.SealedEnvelope) *TestingBuilder

AddActions adds actions for block which is building.

func (*TestingBuilder) SetHeight

func (b *TestingBuilder) SetHeight(h uint64) *TestingBuilder

SetHeight sets the block height for block which is building.

func (*TestingBuilder) SetPrevBlockHash

func (b *TestingBuilder) SetPrevBlockHash(h hash.Hash256) *TestingBuilder

SetPrevBlockHash sets the previous block hash for block which is building.

func (*TestingBuilder) SetReceipts

func (b *TestingBuilder) SetReceipts(receipts []*action.Receipt) *TestingBuilder

SetReceipts sets the receipts after running actions included in this building block.

func (*TestingBuilder) SetTimeStamp

func (b *TestingBuilder) SetTimeStamp(ts time.Time) *TestingBuilder

SetTimeStamp sets the time stamp for block which is building.

func (*TestingBuilder) SetVersion

func (b *TestingBuilder) SetVersion(v uint32) *TestingBuilder

SetVersion sets the protocol version for block which is building.

func (*TestingBuilder) SignAndBuild

func (b *TestingBuilder) SignAndBuild(signerPrvKey crypto.PrivateKey) (Block, error)

SignAndBuild signs and then builds a block.

type TokenTxRecord

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

TokenTxRecord is a token transaction record

func LogTokenTxRecord

func LogTokenTxRecord(l *action.TransactionLog) *TokenTxRecord

LogTokenTxRecord generates token transaction record from log

func NewTokenTxRecord

func NewTokenTxRecord(typ iotextypes.TransactionLogType, amount, sender, recipient string) *TokenTxRecord

NewTokenTxRecord creates a new TokenTxRecord

type TransactionLog

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

TransactionLog is transaction log in one action

func NewTransactionLog

func NewTransactionLog(actHash hash.Hash256, records []*TokenTxRecord) *TransactionLog

NewTransactionLog creates a new TransactionLog

func ReceiptTransactionLog

func ReceiptTransactionLog(r *action.Receipt) *TransactionLog

ReceiptTransactionLog generates transaction log from receipt

func (*TransactionLog) Proto

Proto returns the pb message

type Validator

type Validator interface {
	// Validate validates the given block's content
	Validate(ctx context.Context, block *Block) error
}

Validator is the interface of validator

func NewValidator

func NewValidator(subsequenceValidator Validator, validators ...action.SealedEnvelopeValidator) Validator

NewValidator creates a validator with a set of sealed envelope validators

Jump to

Keyboard shortcuts

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