types

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Index

Constants

View Source
const TestChainID = "test"

TestChainID is a constant used for testing purposes. It represents a mock chain ID.

Variables

View Source
var (
	// ErrNoProposerAddress is returned when the proposer address is not set.
	ErrNoProposerAddress = errors.New("no proposer address")

	// ErrProposerVerificationFailed is returned when the proposer verification fails.
	ErrProposerVerificationFailed = errors.New("proposer verification failed")
)
View Source
var (
	// ErrMaxBytesCannotBeZero indicates that the block's MaxBytes cannot be 0.
	ErrMaxBytesCannotBeZero = errors.New("block.MaxBytes cannot be 0")

	// ErrMaxBytesInvalid indicates that the block's MaxBytes must be either -1 or greater than 0.
	ErrMaxBytesInvalid = errors.New("block.MaxBytes must be -1 or greater than 0")

	// ErrMaxBytesTooBig indicates that the block's MaxBytes exceeds the maximum allowed size.
	// See https://github.com/cometbft/cometbft/blob/2cd0d1a33cdb6a2c76e6e162d892624492c26290/types/params.go#L16
	ErrMaxBytesTooBig = errors.New("block.MaxBytes is bigger than the maximum permitted block size")

	// ErrMaxGasInvalid indicates that the block's MaxGas must be greater than or equal to -1.
	ErrMaxGasInvalid = errors.New("block.MaxGas must be greater or equal to -1")

	// ErrVoteExtensionsEnableHeightNegative indicates that the ABCI.VoteExtensionsEnableHeight cannot be negative.
	ErrVoteExtensionsEnableHeightNegative = errors.New("ABCI.VoteExtensionsEnableHeight cannot be negative")

	// ErrPubKeyTypesEmpty indicates that the Validator.PubKeyTypes length must be greater than 0.
	ErrPubKeyTypesEmpty = errors.New("len(Validator.PubKeyTypes) must be greater than 0")

	// ErrPubKeyTypeUnknown indicates an encounter with an unknown public key type.
	ErrPubKeyTypeUnknown = errors.New("unknown pubkey type")
)
View Source
var (
	// ErrNonAdjacentHeaders is returned when the headers are not adjacent.
	ErrNonAdjacentHeaders = errors.New("non-adjacent headers")

	// ErrLastHeaderHashMismatch is returned when the last header hash doesn't match.
	ErrLastHeaderHashMismatch = errors.New("last header hash mismatch")

	// ErrLastCommitHashMismatch is returned when the last commit hash doesn't match.
	ErrLastCommitHashMismatch = errors.New("last commit hash mismatch")
)
View Source
var (
	// ErrAggregatorSetHashMismatch is returned when the aggregator set hash
	// in the signed header doesn't match the hash of the validator set.
	ErrAggregatorSetHashMismatch = errors.New("aggregator set hash in signed header and hash of validator set do not match")

	// ErrSignatureVerificationFailed is returned when the signature
	// verification fails
	ErrSignatureVerificationFailed = errors.New("signature verification failed")

	// ErrInvalidValidatorSetLengthMismatch is returned when the validator set length is not exactly one
	ErrInvalidValidatorSetLengthMismatch = errors.New("must have exactly one validator (the centralized sequencer)")

	// ErrProposerAddressMismatch is returned when the proposer address in the signed header does not match the proposer address in the validator set
	ErrProposerAddressMismatch = errors.New("proposer address in SignedHeader does not match the proposer address in the validator set")

	// ErrProposerNotInValSet is returned when the proposer address in the validator set is not in the validator set
	ErrProposerNotInValSet = errors.New("proposer address in the validator set is not in the validator set")

	// ErrNoSignatures is returned when there are no signatures
	ErrNoSignatures = errors.New("no signatures")

	// ErrSignatureEmpty is returned when signature is empty
	ErrSignatureEmpty = errors.New("signature is empty")
)
View Source
var (
	// EmptyEvidenceHash is the hash of an empty EvidenceData
	EmptyEvidenceHash = new(cmtypes.EvidenceData).Hash()
)
View Source
var InitStateVersion = cmstate.Version{
	Consensus: cmversion.Consensus{
		Block: version.BlockProtocol,
		App:   0,
	},
	Software: version.TMCoreSemVer,
}

InitStateVersion sets the Consensus.Block and Software versions, but leaves the Consensus.App version blank. The Consensus.App version will be set during the Handshake, once we hear from the app what protocol version it is running.

Functions

func ConsensusParamsFromProto added in v0.11.9

func ConsensusParamsFromProto(pbParams cmproto.ConsensusParams) types.ConsensusParams

ConsensusParamsFromProto converts protobuf consensus parameters to consensus parameters

func ConsensusParamsValidateBasic added in v0.11.9

func ConsensusParamsValidateBasic(params cmtypes.ConsensusParams) error

ConsensusParamsValidateBasic validates the ConsensusParams to ensure all values are within their allowed limits, and returns an error if they are not.

func GetGenesisWithPrivkey added in v0.11.8

func GetGenesisWithPrivkey() (*cmtypes.GenesisDoc, ed25519.PrivKey)

GetGenesisWithPrivkey returns a genesis doc with a single validator and a signing key

func GetNodeKey added in v0.10.7

func GetNodeKey(nodeKey *p2p.NodeKey) (crypto.PrivKey, error)

GetNodeKey creates libp2p private key from Tendermints NodeKey.

func GetRandomBytes added in v0.9.0

func GetRandomBytes(n uint) []byte

GetRandomBytes returns a byte slice of random bytes of length n. It uses crypto/rand for cryptographically secure random number generation.

func GetRandomValidatorSet added in v0.9.0

func GetRandomValidatorSet() *cmtypes.ValidatorSet

GetRandomValidatorSet creates a validatorConfig with a randomly generated privateKey and votingPower set to 1, then calls GetValidatorSetCustom to return a new validator set along with the validatorConfig.

func GetValidatorSetCustom added in v0.13.0

func GetValidatorSetCustom(config ValidatorConfig) *cmtypes.ValidatorSet

GetValidatorSetCustom returns a validator set based on the provided validatorConfig.

func GetValidatorSetFromGenesis added in v0.11.8

func GetValidatorSetFromGenesis(g *cmtypes.GenesisDoc) cmtypes.ValidatorSet

GetValidatorSetFromGenesis returns a ValidatorSet from a GenesisDoc, for usage with the centralized sequencer scheme.

func PostableBytesToShares added in v0.10.5

func PostableBytesToShares(postableData []byte) (txShares []shares.Share, err error)

PostableBytesToShares converts a slice of bytes that can be posted to the blockchain to a slice of shares

func PrivKeyToSigningKey added in v0.11.13

func PrivKeyToSigningKey(privKey ed25519.PrivKey) (crypto.PrivKey, error)

PrivKeyToSigningKey converts a privKey to a signing key

func SharesToPostableBytes added in v0.10.5

func SharesToPostableBytes(txShares []shares.Share) (postableData []byte, err error)

SharesToPostableBytes converts a slice of shares to a slice of bytes that can be posted to the blockchain.

func SharesToTxsWithISRs added in v0.10.5

func SharesToTxsWithISRs(txShares []shares.Share) (txsWithISRs []pb.TxWithISRs, err error)

SharesToTxsWithISRs converts a slice of shares to a slice of TxWithISRs.

func TxsWithISRsToShares added in v0.10.5

func TxsWithISRsToShares(txsWithISRs []pb.TxWithISRs) (txShares []shares.Share, err error)

TxsWithISRsToShares converts a slice of TxWithISRs to a slice of shares.

Types

type BaseHeader

type BaseHeader struct {
	// Height represents the block height (aka block number) of a given header
	Height uint64
	// Time contains Unix nanotime of a block
	Time uint64
	// The Chain ID
	ChainID string
}

BaseHeader contains the most basic data of a header

type Block

type Block struct {
	SignedHeader SignedHeader
	Data         Data
}

Block defines the structure of Rollkit block.

func GenerateRandomBlockCustom added in v0.13.0

func GenerateRandomBlockCustom(config *BlockConfig) (*Block, ed25519.PrivKey)

GenerateRandomBlockCustom returns a block with random data and the given height, transactions, privateKey and proposer address.

func GetRandomBlock added in v0.10.7

func GetRandomBlock(height uint64, nTxs int) *Block

GetRandomBlock creates a block with a given height and number of transactions, intended for testing. It's tailored for simplicity, primarily used in test setups where additional outputs are not needed.

func GetRandomNextBlock added in v0.11.8

func GetRandomNextBlock(block *Block, privKey ed25519.PrivKey, appHash header.Hash, nTxs int) *Block

GetRandomNextBlock returns a block with random data and height of +1 from the provided block

func (*Block) ChainID added in v0.9.0

func (b *Block) ChainID() string

ChainID returns chain ID of the block.

func (*Block) FromProto

func (b *Block) FromProto(other *pb.Block) error

FromProto fills Block with data from its protobuf representation.

func (*Block) Hash

func (b *Block) Hash() Hash

Hash returns ABCI-compatible hash of a block.

func (*Block) Height added in v0.9.0

func (b *Block) Height() uint64

Height returns height of the block.

func (*Block) IsZero added in v0.9.0

func (b *Block) IsZero() bool

IsZero returns true if the block is nil.

func (*Block) LastHeader added in v0.9.0

func (b *Block) LastHeader() Hash

LastHeader returns last header hash of the block.

func (*Block) MarshalBinary

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

MarshalBinary encodes Block into binary form and returns it.

func (*Block) New added in v0.9.0

func (b *Block) New() *Block

New returns a new Block.

func (*Block) Size added in v0.11.19

func (b *Block) Size() int

Size returns size of the block in bytes.

func (*Block) Time added in v0.9.0

func (b *Block) Time() time.Time

Time returns time of the block.

func (*Block) ToProto

func (b *Block) ToProto() (*pb.Block, error)

ToProto converts Block into protobuf representation and returns it.

func (*Block) UnmarshalBinary

func (b *Block) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes binary form of Block into object.

func (*Block) Validate added in v0.9.0

func (b *Block) Validate() error

Validate performs basic validation of a block.

func (*Block) ValidateBasic

func (b *Block) ValidateBasic() error

ValidateBasic performs basic validation of a block.

func (*Block) Verify added in v0.9.0

func (b *Block) Verify(untrustedBlock *Block) error

Verify Verifies a new, untrusted block against a trusted block.

type BlockConfig added in v0.13.0

type BlockConfig struct {
	Height       uint64
	NTxs         int
	PrivKey      ed25519.PrivKey // Input and Output option
	ProposerAddr []byte          // Input option
}

BlockConfig carries all necessary state for block generation

type Commit

type Commit struct {
	Signatures []Signature // most of the time this is a single signature
}

Commit contains evidence of block creation.

func GetCommit added in v0.11.13

func GetCommit(header Header, privKey ed25519.PrivKey) (*Commit, error)

GetCommit returns a commit with a signature from the given private key over the given header

func (*Commit) FromProto

func (c *Commit) FromProto(other *pb.Commit) error

FromProto fills Commit with data from its protobuf representation.

func (*Commit) GetCommitHash added in v0.9.0

func (c *Commit) GetCommitHash(header *Header, proposerAddress []byte) []byte

GetCommitHash returns hash of the commit.

func (*Commit) MarshalBinary

func (c *Commit) MarshalBinary() ([]byte, error)

MarshalBinary encodes Commit into binary form and returns it.

func (*Commit) ToABCICommit added in v0.9.0

func (c *Commit) ToABCICommit(height uint64, hash Hash, val cmtypes.Address, time time.Time) *cmtypes.Commit

ToABCICommit converts Rollkit commit into commit format defined by ABCI. This function only converts fields that are available in Rollkit commit. Other fields (especially ValidatorAddress and Timestamp of Signature) has to be filled by caller.

func (*Commit) ToProto

func (c *Commit) ToProto() *pb.Commit

ToProto converts Commit into protobuf representation and returns it.

func (*Commit) UnmarshalBinary

func (c *Commit) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes binary form of Commit into object.

func (*Commit) ValidateBasic

func (c *Commit) ValidateBasic() error

ValidateBasic performs basic validation of a commit.

type Data

type Data struct {
	Txs Txs
}

Data defines Rollkit block data.

func (*Data) FromProto added in v0.10.2

func (d *Data) FromProto(other *pb.Data) error

FromProto fills the Data with data from its protobuf representation

func (*Data) Hash added in v0.10.5

func (d *Data) Hash() (Hash, error)

Hash returns hash of the Data

func (*Data) MarshalBinary

func (d *Data) MarshalBinary() ([]byte, error)

MarshalBinary encodes Data into binary form and returns it.

func (*Data) ToProto

func (d *Data) ToProto() *pb.Data

ToProto converts Data into protobuf representation and returns it.

func (*Data) UnmarshalBinary added in v0.10.2

func (d *Data) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes binary form of Data into object.

func (*Data) ValidateBasic

func (d *Data) ValidateBasic() error

ValidateBasic performs basic validation of block data. Actually it's a placeholder, because nothing is checked.

type EvidenceData

type EvidenceData struct {
	Evidence []cmtypes.Evidence
}

EvidenceData defines how evidence is stored in block.

type Hash

type Hash = header.Hash

Hash is a 32-byte array which is used to represent a hash result.

type Header struct {
	BaseHeader
	// Block and App version
	Version Version

	// prev block info
	LastHeaderHash Hash

	// hashes of block data
	LastCommitHash Hash // commit from aggregator(s) from the last block
	DataHash       Hash // Block.Data root aka Transactions
	ConsensusHash  Hash // consensus params for current block
	AppHash        Hash // state after applying txs from the current block

	// Root hash of all results from the txs from the previous block.
	// This is ABCI specific but smart-contract chains require some way of committing
	// to transaction receipts/results.
	LastResultsHash Hash

	// compatibility with tendermint light client
	ValidatorHash Hash

	// Note that the address can be derived from the pubkey which can be derived
	// from the signature when using secp256k.
	// We keep this in case users choose another signature format where the
	// pubkey can't be recovered by the signature (e.g. ed25519).
	ProposerAddress []byte // original proposer of the block
}

Header defines the structure of Rollkit block header.

func GetRandomHeader added in v0.10.7

func GetRandomHeader() Header

GetRandomHeader returns a header with random fields and current time

func GetRandomNextHeader added in v0.10.7

func GetRandomNextHeader(header Header) Header

GetRandomNextHeader returns a header with random data and height of +1 from the provided Header

func (*Header) ChainID

func (h *Header) ChainID() string

ChainID returns chain ID of the header.

func (*Header) FromProto

func (h *Header) FromProto(other *pb.Header) error

FromProto fills Header with data from its protobuf representation.

func (*Header) Hash

func (h *Header) Hash() Hash

Hash returns ABCI-compatible hash of a header.

func (*Header) Height

func (h *Header) Height() uint64

Height returns height of the header.

func (*Header) IsZero

func (h *Header) IsZero() bool

IsZero returns true if the header is nil.

func (*Header) LastHeader

func (h *Header) LastHeader() Hash

LastHeader returns last header hash of the header.

func (*Header) MakeCometBFTVote added in v0.13.0

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

MakeCometBFTVote make a cometBFT consensus vote for the sequencer to commit we have the sequencer signs cometBFT consensus vote for compatibility with cometBFT client

func (*Header) MarshalBinary

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

MarshalBinary encodes Header into binary form and returns it.

func (*Header) New

func (h *Header) New() *Header

New creates a new Header.

func (*Header) Time

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

Time returns timestamp as unix time with nanosecond precision

func (*Header) ToProto

func (h *Header) ToProto() *pb.Header

ToProto converts Header into protobuf representation and returns it.

func (*Header) UnmarshalBinary

func (h *Header) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes binary form of Header into object.

func (*Header) Validate

func (h *Header) Validate() error

Validate performs basic validation of a header.

func (*Header) ValidateBasic

func (h *Header) ValidateBasic() error

ValidateBasic performs basic validation of a header.

func (*Header) Verify added in v0.7.2

func (h *Header) Verify(untrstH *Header) error

Verify verifies the header.

type HeaderConfig added in v0.13.0

type HeaderConfig struct {
	Height      uint64
	DataHash    header.Hash
	PrivKey     ed25519.PrivKey
	VotingPower int64
}

HeaderConfig carries all necessary state for header generation

type IntermediateStateRoots

type IntermediateStateRoots struct {
	RawRootsList [][]byte
}

IntermediateStateRoots describes the state between transactions. They are required for fraud proofs.

type Signature

type Signature []byte

Signature represents signature of block creator.

type SignedHeader

type SignedHeader struct {
	Header
	Commit     Commit
	Validators *cmtypes.ValidatorSet
}

SignedHeader combines Header and its Commit.

Used mostly for gossiping.

func GetFirstSignedHeader added in v0.11.8

func GetFirstSignedHeader(privkey ed25519.PrivKey, valSet *cmtypes.ValidatorSet) (*SignedHeader, error)

GetFirstSignedHeader creates a 1st signed header for a chain, given a valset and signing key.

func GetRandomNextSignedHeader added in v0.10.7

func GetRandomNextSignedHeader(signedHeader *SignedHeader, privKey ed25519.PrivKey) (*SignedHeader, error)

GetRandomNextSignedHeader returns a signed header with random data and height of +1 from the provided signed header

func GetRandomSignedHeader added in v0.9.0

func GetRandomSignedHeader() (*SignedHeader, ed25519.PrivKey, error)

GetRandomSignedHeader generates a signed header with random data and returns it.

func GetRandomSignedHeaderCustom added in v0.13.0

func GetRandomSignedHeaderCustom(config *HeaderConfig) (*SignedHeader, error)

GetRandomSignedHeaderCustom creates a signed header based on the provided HeaderConfig.

func (*SignedHeader) FromProto

func (sh *SignedHeader) FromProto(other *pb.SignedHeader) error

FromProto fills SignedHeader with data from protobuf representation.

func (*SignedHeader) IsZero added in v0.7.0

func (sh *SignedHeader) IsZero() bool

IsZero returns true if the SignedHeader is nil

func (*SignedHeader) MarshalBinary

func (sh *SignedHeader) MarshalBinary() ([]byte, error)

MarshalBinary encodes SignedHeader into binary form and returns it.

func (*SignedHeader) New added in v0.7.0

func (sh *SignedHeader) New() *SignedHeader

New creates a new SignedHeader.

func (*SignedHeader) ToProto

func (sh *SignedHeader) ToProto() (*pb.SignedHeader, error)

ToProto converts SignedHeader into protobuf representation and returns it.

func (*SignedHeader) UnmarshalBinary

func (sh *SignedHeader) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes binary form of SignedHeader into object.

func (*SignedHeader) ValidateBasic

func (sh *SignedHeader) ValidateBasic() error

ValidateBasic performs basic validation of a signed header.

func (*SignedHeader) Verify added in v0.7.2

func (sh *SignedHeader) Verify(untrstH *SignedHeader) error

Verify verifies the signed header.

type State

type State struct {
	Version cmstate.Version

	// immutable
	ChainID       string
	InitialHeight uint64 // should be 1, not 0, when starting from height 1

	// LastBlockHeight=0 at genesis (ie. block(H=0) does not exist)
	LastBlockHeight uint64
	LastBlockID     types.BlockID
	LastBlockTime   time.Time

	// DAHeight identifies DA block containing the latest applied Rollkit block.
	DAHeight uint64

	// Consensus parameters used for validating blocks.
	// Changes returned by EndBlock and updated after Commit.
	ConsensusParams                  cmproto.ConsensusParams
	LastHeightConsensusParamsChanged uint64

	// Merkle root of the results from executing prev block
	LastResultsHash Hash

	// the latest AppHash we've received from calling abci.Commit()
	AppHash Hash
}

State contains information about current state of the blockchain.

func NewFromGenesisDoc

func NewFromGenesisDoc(genDoc *types.GenesisDoc) (State, error)

NewFromGenesisDoc reads blockchain State from genesis.

func (*State) FromProto

func (s *State) FromProto(other *pb.State) error

FromProto fills State with data from its protobuf representation.

func (*State) ToProto

func (s *State) ToProto() (*pb.State, error)

ToProto converts State into protobuf representation and returns it.

type ThreadManager added in v0.11.14

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

ThreadManager is a simple wrapper around sync.WaitGroup to make it easier to manage threads

func NewThreadManager added in v0.11.14

func NewThreadManager() *ThreadManager

NewThreadManager creates a new ThreadManager

func (*ThreadManager) Go added in v0.11.14

func (tm *ThreadManager) Go(f func())

Go launches a goroutine and adds it to the WaitGroup

func (*ThreadManager) Wait added in v0.11.14

func (tm *ThreadManager) Wait()

Wait blocks until all goroutines have called Done on the WaitGroup

type Tx

type Tx []byte

Tx represents transaction.

func GetRandomTx added in v0.9.0

func GetRandomTx() Tx

GetRandomTx returns a tx with random data

func (Tx) Hash

func (tx Tx) Hash() []byte

Hash computes the TMHASH hash of the wire encoded transaction.

type TxProof

type TxProof struct {
	RootHash cmbytes.HexBytes `json:"root_hash"`
	Data     Tx               `json:"data"`
	Proof    merkle.Proof     `json:"proof"`
}

TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.

type Txs

type Txs []Tx

Txs represents a slice of transactions.

func (Txs) Proof

func (txs Txs) Proof(i int) TxProof

Proof returns a simple merkle proof for this node. Panics if i < 0 or i >= len(txs) TODO: optimize this!

func (Txs) ToSliceOfBytes added in v0.11.2

func (txs Txs) ToSliceOfBytes() [][]byte

ToSliceOfBytes converts a Txs to slice of byte slices.

func (Txs) ToTxsWithISRs added in v0.8.0

func (txs Txs) ToTxsWithISRs(intermediateStateRoots IntermediateStateRoots) ([]pb.TxWithISRs, error)

ToTxsWithISRs converts a slice of transactions and a list of intermediate state roots to a slice of TxWithISRs. Note that the length of intermediateStateRoots is equal to the length of txs + 1.

type ValidatorConfig added in v0.13.0

type ValidatorConfig struct {
	PrivKey     ed25519.PrivKey
	VotingPower int64
}

ValidatorConfig carries all necessary state for generating a Validator

type Version

type Version struct {
	Block uint64
	App   uint64
}

Version captures the consensus rules for processing a block in the blockchain, including all blockchain data structures and the rules of the application's state transition machine. This is equivalent to the tmversion.Consensus type in Tendermint.

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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