bor

package
v0.0.0-...-ff78b6e Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: GPL-3.0 Imports: 48 Imported by: 0

Documentation

Overview

Package bor is a generated GoMock package.

Package bor is a generated GoMock package.

Index

Constants

View Source
const BorSeparate = "BorSeparate"

Variables

View Source
var (

	// errInvalidSpanValidators is returned if a block contains an
	// invalid list of validators (i.e. non divisible by 40 bytes).
	ErrInvalidSpanValidators = errors.New("invalid validator list on sprint end block")

	// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
	// the previous block's timestamp + the minimum block period.
	ErrInvalidTimestamp = errors.New("invalid timestamp")
)

Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.

View Source
var (

	// MaxCheckpointLength is the maximum number of blocks that can be requested for constructing a checkpoint root hash
	MaxCheckpointLength = uint64(math.Pow(2, 15))
)

Bor protocol constants.

Functions

func AppendBytes32

func AppendBytes32(data ...[]byte) []byte

func BorRLP

func BorRLP(header *types.Header, c *chain.BorConfig) []byte

BorRLP returns the rlp bytes which needs to be signed for the bor sealing. The RLP to sign consists of the entire header apart from the 65 byte signature contained at the end of the extra data.

Note, the method requires the extra data to be at least 65 bytes, otherwise it panics. This is done to avoid accidentally using both forms (signature present or not), which could be abused to produce different hashes for the same header.

func CalcProducerDelay

func CalcProducerDelay(number uint64, succession int, c *chain.BorConfig) uint64

CalcProducerDelay is the block delay algorithm based on block time, period, producerDelay and turn-ness of a signer

func CalculateSprint

func CalculateSprint(config *chain.BorConfig, number uint64) uint64

func CalculateSprintCount

func CalculateSprintCount(config *chain.BorConfig, from, to uint64) int

func Convert

func Convert(input [][32]byte) [][]byte

func ConvertTo32

func ConvertTo32(input []byte) (output [32]byte, err error)

func Ecrecover

func Ecrecover(header *types.Header, sigcache *lru.ARCCache[libcommon.Hash, libcommon.Address], c *chain.BorConfig) (libcommon.Address, error)

ecrecover extracts the Ethereum account address from a signed header.

func GetTxDependency

func GetTxDependency(b *types.Block) [][]uint64

Returns the Block-STM Transaction Dependency from the block header

func GetValidatorBytes

func GetValidatorBytes(h *types.Header, config *chain.BorConfig) []byte

func IsBlockOnTime

func IsBlockOnTime(parent *types.Header, header *types.Header, number uint64, succession int, cfg *chain.BorConfig) bool

func NextPowerOfTwo

func NextPowerOfTwo(n uint64) uint64

func SealHash

func SealHash(header *types.Header, c *chain.BorConfig) (hash libcommon.Hash)

SealHash returns the hash of a block prior to it being sealed.

func ValidateHeaderExtraField

func ValidateHeaderExtraField(extraBytes []byte) error

ValidateHeaderExtraField validates that the extra-data contains both the vanity and signature. header.Extra = header.Vanity + header.ProducerBytes (optional) + header.Seal

Types

type BlockExtraData

type BlockExtraData struct {
	// Validator bytes of bor
	ValidatorBytes []byte

	// length of TxDependency          ->   n (n = number of transactions in the block)
	// length of TxDependency[i]       ->   k (k = a whole number)
	// k elements in TxDependency[i]   ->   transaction indexes on which transaction i is dependent on
	TxDependency [][]uint64
}

In bor, RLP encoding of BlockExtraData will be stored in the Extra field in the header

type BlockTooSoonError

type BlockTooSoonError struct {
	Number     uint64
	Succession int
}

func (*BlockTooSoonError) Error

func (e *BlockTooSoonError) Error() string

type Bor

type Bor struct {
	DB kv.RwDB // Database to store and retrieve snapshot checkpoints

	Recents    *lru.ARCCache[libcommon.Hash, *Snapshot]         // Snapshots for recent block to speed up reorgs
	Signatures *lru.ARCCache[libcommon.Hash, libcommon.Address] // Signatures of recent blocks to speed up mining

	GenesisContractsClient GenesisContract
	HeimdallClient         heimdall.IHeimdallClient
	// contains filtered or unexported fields
}

Bor is the matic-bor consensus engine

func New

func New(
	chainConfig *chain.Config,
	db kv.RwDB,
	blockReader services.FullBlockReader,
	spanner Spanner,
	heimdallClient heimdall.IHeimdallClient,
	genesisContracts GenesisContract,
	logger log.Logger,
) *Bor

New creates a Matic Bor consensus engine.

func NewRo

func NewRo(chainConfig *chain.Config, db kv.RoDB, blockReader services.FullBlockReader, spanner Spanner,
	genesisContracts GenesisContract, logger log.Logger) *Bor

This is used by the rpcdaemon and tests which need read only access to the provided data services

func (*Bor) APIs

func (c *Bor) APIs(chain consensus.ChainHeaderReader) []rpc.API

Depricated: To get the API use jsonrpc.APIList

func (*Bor) Author

func (c *Bor) Author(header *types.Header) (libcommon.Address, error)

Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section. This is thread-safe (only access the header and config (which is never updated), as well as signatures, which are lru.ARCCache, which is thread-safe)

func (*Bor) Authorize

func (c *Bor) Authorize(currentSigner libcommon.Address, signFn SignerFn)

Authorize injects a private key into the consensus engine to mint new blocks with.

func (*Bor) CalcDifficulty

func (c *Bor) CalcDifficulty(chain consensus.ChainHeaderReader, _, _ uint64, _ *big.Int, parentNumber uint64, parentHash, _ libcommon.Hash, _ uint64) *big.Int

CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.

func (*Bor) CalculateRewards

func (c *Bor) CalculateRewards(config *chain.Config, header *types.Header, uncles []*types.Header, syscall consensus.SystemCall,
) ([]consensus.Reward, error)

func (*Bor) Close

func (c *Bor) Close() error

func (*Bor) CommitStates

func (c *Bor) CommitStates(
	state *state.IntraBlockState,
	header *types.Header,
	chain statefull.ChainContext,
	syscall consensus.SystemCall,
) error

CommitStates commit states

func (*Bor) Finalize

func (c *Bor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
	txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
	chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, error)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.

func (*Bor) FinalizeAndAssemble

func (c *Bor) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState,
	txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal,
	chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, error)

FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.

func (*Bor) GenerateSeal

func (c *Bor) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *types.Header, call consensus.Call) []byte

func (*Bor) GetRootHash

func (c *Bor) GetRootHash(ctx context.Context, tx kv.Tx, start, end uint64) (string, error)

func (*Bor) HeaderProgress

func (c *Bor) HeaderProgress(p HeaderProgress)

func (*Bor) Initialize

func (c *Bor) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header,
	state *state.IntraBlockState, syscall consensus.SysCallCustom, logger log.Logger)

func (*Bor) IsProposer

func (c *Bor) IsProposer(header *types.Header) (bool, error)

IsProposer returns true if this instance is the proposer for this block

func (*Bor) IsServiceTransaction

func (c *Bor) IsServiceTransaction(sender libcommon.Address, syscall consensus.SystemCall) bool

func (*Bor) IsValidator

func (c *Bor) IsValidator(header *types.Header) (bool, error)

IsValidator returns true if this instance is the validator for this block

func (*Bor) Prepare

func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header, state *state.IntraBlockState) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*Bor) Seal

func (c *Bor) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.

func (*Bor) SealHash

func (c *Bor) SealHash(header *types.Header) libcommon.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*Bor) SetHeimdallClient

func (c *Bor) SetHeimdallClient(h heimdall.IHeimdallClient)

func (*Bor) Start

func (c *Bor) Start(chainDB kv.RwDB)

func (*Bor) Type

func (c *Bor) Type() chain.ConsensusName

Type returns underlying consensus engine

func (*Bor) VerifyHeader

func (c *Bor) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Bor) VerifyHeaders

func (c *Bor) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, _ []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).

func (*Bor) VerifySeal

func (c *Bor) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*Bor) VerifyUncles

func (c *Bor) VerifyUncles(_ consensus.ChainReader, _ *types.Header, uncles []*types.Header) error

VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.

type FakeBor

type FakeBor struct {
	*ethash.FakeEthash
}

func NewFaker

func NewFaker() *FakeBor

NewFaker creates a bor consensus engine with a FakeEthash

func (*FakeBor) Finalize

func (f *FakeBor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
	txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
	chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, error)

type FinalityAPI

type FinalityAPI interface {
	GetRootHash(start uint64, end uint64) (string, error)
}

type FinalityAPIFunc

type FinalityAPIFunc func(start uint64, end uint64) (string, error)

func (FinalityAPIFunc) GetRootHash

func (f FinalityAPIFunc) GetRootHash(start uint64, end uint64) (string, error)

type GenesisContract

type GenesisContract interface {
	CommitState(event rlp.RawValue, syscall consensus.SystemCall) error
	LastStateId(syscall consensus.SystemCall) (*big.Int, error)
}

type HeaderProgress

type HeaderProgress interface {
	Progress() uint64
}

type InvalidStateReceivedError

type InvalidStateReceivedError struct {
	Number      uint64
	LastStateID uint64
	To          *time.Time
	Event       *clerk.EventRecordWithTime
}

func (*InvalidStateReceivedError) Error

func (e *InvalidStateReceivedError) Error() string

type MaxCheckpointLengthExceededError

type MaxCheckpointLengthExceededError struct {
	Start uint64
	End   uint64
}

func (*MaxCheckpointLengthExceededError) Error

type MismatchingValidatorsError

type MismatchingValidatorsError struct {
	Number             uint64
	ValidatorSetSnap   []byte
	ValidatorSetHeader []byte
}

MismatchingValidatorsError is returned if a last block in sprint contains a list of validators different from the one that local node calculated

func (*MismatchingValidatorsError) Error

type MockGenesisContract

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

MockGenesisContract is a mock of GenesisContract interface.

func NewMockGenesisContract

func NewMockGenesisContract(ctrl *gomock.Controller) *MockGenesisContract

NewMockGenesisContract creates a new mock instance.

func (*MockGenesisContract) CommitState

CommitState mocks base method.

func (*MockGenesisContract) EXPECT

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

func (*MockGenesisContract) LastStateId

func (m *MockGenesisContract) LastStateId(arg0 consensus.SystemCall) (*big.Int, error)

LastStateId mocks base method.

type MockGenesisContractMockRecorder

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

MockGenesisContractMockRecorder is the mock recorder for MockGenesisContract.

func (*MockGenesisContractMockRecorder) CommitState

func (mr *MockGenesisContractMockRecorder) CommitState(arg0, arg1 interface{}) *gomock.Call

CommitState indicates an expected call of CommitState.

func (*MockGenesisContractMockRecorder) LastStateId

func (mr *MockGenesisContractMockRecorder) LastStateId(arg0 interface{}) *gomock.Call

LastStateId indicates an expected call of LastStateId.

type MockSpanner

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

MockSpanner is a mock of Spanner interface.

func NewMockSpanner

func NewMockSpanner(ctrl *gomock.Controller) *MockSpanner

NewMockSpanner creates a new mock instance.

func (*MockSpanner) CommitSpan

func (m *MockSpanner) CommitSpan(arg0 span.HeimdallSpan, arg1 consensus.SystemCall) error

CommitSpan mocks base method.

func (*MockSpanner) EXPECT

func (m *MockSpanner) EXPECT() *MockSpannerMockRecorder

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

func (*MockSpanner) GetCurrentProducers

func (m *MockSpanner) GetCurrentProducers(arg0 uint64, arg1 common.Address, arg2 func(uint64) (*span.HeimdallSpan, error)) ([]*valset.Validator, error)

GetCurrentProducers mocks base method.

func (*MockSpanner) GetCurrentSpan

func (m *MockSpanner) GetCurrentSpan(arg0 consensus.SystemCall) (*span.Span, error)

GetCurrentSpan mocks base method.

func (*MockSpanner) GetCurrentValidators

func (m *MockSpanner) GetCurrentValidators(arg0 uint64, arg1 common.Address, arg2 func(uint64) (*span.HeimdallSpan, error)) ([]*valset.Validator, error)

GetCurrentValidators mocks base method.

type MockSpannerMockRecorder

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

MockSpannerMockRecorder is the mock recorder for MockSpanner.

func (*MockSpannerMockRecorder) CommitSpan

func (mr *MockSpannerMockRecorder) CommitSpan(arg0, arg1 interface{}) *gomock.Call

CommitSpan indicates an expected call of CommitSpan.

func (*MockSpannerMockRecorder) GetCurrentProducers

func (mr *MockSpannerMockRecorder) GetCurrentProducers(arg0, arg1, arg2 interface{}) *gomock.Call

GetCurrentProducers indicates an expected call of GetCurrentProducers.

func (*MockSpannerMockRecorder) GetCurrentSpan

func (mr *MockSpannerMockRecorder) GetCurrentSpan(arg0 interface{}) *gomock.Call

GetCurrentSpan indicates an expected call of GetCurrentSpan.

func (*MockSpannerMockRecorder) GetCurrentValidators

func (mr *MockSpannerMockRecorder) GetCurrentValidators(arg0, arg1, arg2 interface{}) *gomock.Call

GetCurrentValidators indicates an expected call of GetCurrentValidators.

type SignerFn

type SignerFn func(signer libcommon.Address, mimeType string, message []byte) ([]byte, error)

SignerFn is a signer callback function to request a header to be signed by a backing account.

type Snapshot

type Snapshot struct {
	Number       uint64                    `json:"number"`       // Block number where the snapshot was created
	Hash         common.Hash               `json:"hash"`         // Block hash where the snapshot was created
	ValidatorSet *valset.ValidatorSet      `json:"validatorSet"` // Validator set at this moment
	Recents      map[uint64]common.Address `json:"recents"`      // Set of recent signers for spam protections
	// contains filtered or unexported fields
}

Snapshot is the state of the authorization voting at a given point in time.

func LoadSnapshot

func LoadSnapshot(config *chain.BorConfig, sigcache *lru.ARCCache[common.Hash, common.Address], db kv.RwDB, hash common.Hash) (*Snapshot, error)

loadSnapshot loads an existing snapshot from the database.

func NewSnapshot

func NewSnapshot(
	config *chain.BorConfig,
	sigcache *lru.ARCCache[common.Hash, common.Address],
	number uint64,
	hash common.Hash,
	validators []*valset.Validator,
	logger log.Logger,
) *Snapshot

newSnapshot creates a new snapshot with the specified startup parameters. This method does not initialize the set of recent signers, so only ever use if for the genesis block.

func (*Snapshot) Apply

func (s *Snapshot) Apply(parent *types.Header, headers []*types.Header, logger log.Logger) (*Snapshot, error)

func (*Snapshot) Difficulty

func (s *Snapshot) Difficulty(signer common.Address) uint64

Difficulty returns the difficulty for a particular signer at the current snapshot number

func (*Snapshot) GetSignerSuccessionNumber

func (s *Snapshot) GetSignerSuccessionNumber(signer common.Address) (int, error)

GetSignerSuccessionNumber returns the relative position of signer in terms of the in-turn proposer

func (*Snapshot) Store

func (s *Snapshot) Store(db kv.RwDB) error

store inserts the snapshot into the database.

type Spanner

type Spanner interface {
	GetCurrentSpan(syscall consensus.SystemCall) (*span.Span, error)
	GetCurrentValidators(spanId uint64, signer libcommon.Address, chain consensus.ChainHeaderReader) ([]*valset.Validator, error)
	GetCurrentProducers(spanId uint64, signer libcommon.Address, chain consensus.ChainHeaderReader) ([]*valset.Validator, error)
	CommitSpan(heimdallSpan span.HeimdallSpan, syscall consensus.SystemCall) error
}

type UnauthorizedProposerError

type UnauthorizedProposerError struct {
	Number   uint64
	Proposer []byte
}

UnauthorizedProposerError is returned if a header is [being] signed by an unauthorized entity.

func (*UnauthorizedProposerError) Error

func (e *UnauthorizedProposerError) Error() string

type UnauthorizedSignerError

type UnauthorizedSignerError struct {
	Number uint64
	Signer []byte
}

UnauthorizedSignerError is returned if a header is [being] signed by an unauthorized entity.

func (*UnauthorizedSignerError) Error

func (e *UnauthorizedSignerError) Error() string

type WrongDifficultyError

type WrongDifficultyError struct {
	Number   uint64
	Expected uint64
	Actual   uint64
	Signer   []byte
}

WrongDifficultyError is returned if the difficulty of a block doesn't match the turn of the signer.

func (*WrongDifficultyError) Error

func (e *WrongDifficultyError) Error() string

Directories

Path Synopsis
nolint
nolint
rawdb
nolint
nolint

Jump to

Keyboard shortcuts

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