block

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyExtraValidators is key that identifies the `ValidatorsExtra` object
	// serialized in `ExtraData`.
	KeyExtraValidators = "EXTRA_VALIDATORS"

	// KeyFraudProofOf is key that identifies the fraudproof objected malicious
	// block hash in `ExtraData` of the fraudproof block header.
	KeyFraudProofOf = "FRAUD_PROOF_OF"

	// KeyBeginDisputeResolutionOf used to understand which tx from the txpool we need to pick
	// when writing fraud slash block
	KeyBeginDisputeResolutionOf = "BEGIN_DISPUTE_RESOLUTION_OF"

	// KeyEndDisputeResolutionOf used to understand which block hash was used to slash the node
	// in order to end dispute resolution on all of the nodes
	KeyEndDisputeResolutionOf = "END_DISPUTE_RESOLUTION_OF"
)
View Source
const (
	SourceAvail      = "Avail"
	SourceWatchTower = "WatchTower"
)

Constants defining different block sources

Variables

View Source
var ErrInvalidHash = errors.New("invalid hash")

ErrInvalidHash represents an error indicating an invalid hash.

View Source
var ErrSignKeyMissing = errors.New("signing key missing")

ErrSignKeyMissing represents an error indicating a missing signing key.

Functions

func AddressRecoverFromHeader

func AddressRecoverFromHeader(h *types.Header) (types.Address, error)

AddressRecoverFromHeader recovers the address from the header seal. It takes the header and returns the recovered address and an error if there is an issue.

func AssignExtraValidators

func AssignExtraValidators(h *types.Header, validators []types.Address) error

AssignExtraValidators adds the validators to the extra data field in the header. It takes the header and a slice of validator addresses and modifies the header's extra data field accordingly. Returns an error if there is an issue decoding or encoding the extra data field.

func DecodeExtraDataFields

func DecodeExtraDataFields(data []byte) (map[string][]byte, error)

DecodeExtraDataFields decodes the byte slice into a map of extra data fields. It takes a byte slice representing the encoded data and returns a map of string keys to byte slice values.

func EncodeExtraDataFields

func EncodeExtraDataFields(data map[string][]byte) []byte

EncodeExtraDataFields encodes the given map of extra data fields into a byte slice. It takes a map of string keys to byte slice values and returns a byte slice representation of the encoded data.

func GetExtraDataBeginDisputeResolutionTarget

func GetExtraDataBeginDisputeResolutionTarget(h *types.Header) (types.Hash, bool)

GetExtraDataBeginDisputeResolutionTarget returns the begin dispute resolution target from the extra data field in the header. It takes the header and returns the begin dispute resolution target as a Hash value. Returns the begin dispute resolution target and a boolean indicating if it was found in the extra data field.

func GetExtraDataEndDisputeResolutionTarget

func GetExtraDataEndDisputeResolutionTarget(h *types.Header) (types.Hash, bool)

GetExtraDataEndDisputeResolutionTarget returns the end dispute resolution target from the extra data field in the header. It takes the header and returns the end dispute resolution target as a Hash value. Returns the end dispute resolution target and a boolean indicating if it was found in the extra data field.

func GetExtraDataFraudProofTarget

func GetExtraDataFraudProofTarget(h *types.Header) (types.Hash, bool)

GetExtraDataFraudProofTarget returns the fraudproof target from the extra data field in the header. It takes the header and returns the fraudproof target as a Hash value. Returns the fraudproof target and a boolean indicating if it was found in the extra data field.

func PutValidatorExtra

func PutValidatorExtra(h *types.Header, istanbulExtra *ValidatorExtra) error

PutValidatorExtra sets the extra data field in the header to the given ValidatorExtra. It takes the header and a ValidatorExtra struct and modifies the header's extra data field accordingly. Returns an error if there is an issue decoding or encoding the extra data field.

func WriteSeal

func WriteSeal(prv *ecdsa.PrivateKey, h *types.Header) (*types.Header, error)

WriteSeal signs the block and writes serialized `ValidatorExtra` into the block's `ExtraData`. It takes the private key and the header, and returns the updated header with the seal and an error if there is an issue.

Types

type BlockBuilderFactory

type BlockBuilderFactory interface {
	// FromParentHash creates a block builder using the parent block's hash.
	FromParentHash(parent types.Hash) (Builder, error)

	// FromBlockchainHead creates a block builder using the blockchain's head.
	FromBlockchainHead() (Builder, error)
}

BlockBuilderFactory is a factory interface for creating block builders.

func NewBlockBuilderFactory

func NewBlockBuilderFactory(blockchain blockchain, executor *state.Executor, logger hclog.Logger) BlockBuilderFactory

NewBlockBuilderFactory creates a new block builder factory.

type Builder

type Builder interface {
	// SetBlockNumber sets the block number and returns the builder.
	SetBlockNumber(number uint64) Builder

	// SetCoinbaseAddress sets the coinbase address and returns the builder.
	SetCoinbaseAddress(coinbaseAddr types.Address) Builder

	// SetDifficulty sets the block difficulty and returns the builder.
	SetDifficulty(d uint64) Builder

	// SetExtraDataField sets an extra data field with a key-value pair and returns the builder.
	SetExtraDataField(key string, value []byte) Builder

	// SetGasLimit sets the gas limit and returns the builder.
	SetGasLimit(limit uint64) Builder

	// SetParentStateRoot sets the parent state root and returns the builder.
	SetParentStateRoot(parentRoot types.Hash) Builder

	// AddTransactions adds transactions to the block and returns the builder.
	AddTransactions(txs ...*types.Transaction) Builder

	// SignWith signs the block with the provided private key and returns the builder.
	SignWith(signKey *ecdsa.PrivateKey) Builder

	// Build constructs and returns the built block.
	Build() (*types.Block, error)

	// Write writes the built block to the specified source.
	Write(src string) error
}

Builder provides a builder interface for constructing blocks.

type ValidatorExtra

type ValidatorExtra struct {
	Validators    []types.Address
	Seal          []byte
	CommittedSeal [][]byte
}

ValidatorExtra defines the structure of the extra data field for validators.

func (*ValidatorExtra) MarshalRLPTo

func (i *ValidatorExtra) MarshalRLPTo(dst []byte) []byte

MarshalRLPTo marshals the ValidatorExtra struct to an RLP-encoded byte slice. It takes the ValidatorExtra struct and a destination byte slice, and returns the marshaled byte slice.

func (*ValidatorExtra) MarshalRLPWith

func (i *ValidatorExtra) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith marshals the ValidatorExtra struct to an RLP value using the given RLP arena. It takes the ValidatorExtra struct and an RLP arena, and returns the RLP value.

func (*ValidatorExtra) UnmarshalRLP

func (i *ValidatorExtra) UnmarshalRLP(input []byte) error

UnmarshalRLP unmarshals the ValidatorExtra struct from an RLP-encoded byte slice. It takes the input byte slice and returns an error if there is an issue unmarshaling the data.

func (*ValidatorExtra) UnmarshalRLPFrom

func (i *ValidatorExtra) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLPFrom unmarshals the ValidatorExtra struct from an RLP value using the given RLP parser and value. It takes the RLP parser, RLP value, and returns an error if there is an issue unmarshaling the data.

Jump to

Keyboard shortcuts

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