blockchain

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: GPL-2.0 Imports: 19 Imported by: ? modules, 0 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

View Source
const BlockGasTargetDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations

Variables

View Source
var (
	ErrNoBlock              = errors.New("no block data passed in")
	ErrNoBlockHeader        = errors.New("no block header data passed in")
	ErrParentNotFound       = errors.New("parent block not found")
	ErrInvalidParentHash    = errors.New("parent block hash is invalid")
	ErrParentHashMismatch   = errors.New("invalid parent block hash")
	ErrInvalidBlockSequence = errors.New("invalid block sequence")
	ErrInvalidSha3Uncles    = errors.New("invalid block sha3 uncles root")
	ErrInvalidTxRoot        = errors.New("invalid block transactions root")
	ErrInvalidReceiptsSize  = errors.New("invalid number of receipts")
	ErrInvalidStateRoot     = errors.New("invalid block state root")
	ErrInvalidGasUsed       = errors.New("invalid block gas used")
	ErrInvalidReceiptsRoot  = errors.New("invalid block receipts root")
	ErrNilStorageBuilder    = errors.New("nil storage builder")
	ErrClosed               = errors.New("blockchain is closed")
	ErrExistBlock           = errors.New("exist block")
)

Functions

This section is empty.

Types

type BlockResult

type BlockResult struct {
	Root     types.Hash
	Receipts []*types.Receipt
	TotalGas uint64
}

type Blockchain

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

func NewBlockchain

func NewBlockchain(logger hclog.Logger, db ethdb.Database, chain *chain.Chain, executor Executor, state *itrie.State) (*Blockchain, error)

func (*Blockchain) CalculateGasLimit

func (b *Blockchain) CalculateGasLimit(number uint64) (uint64, error)

CalculateGasLimit returns the gas limit of the next block after parent

func (*Blockchain) ChainDB

func (b *Blockchain) ChainDB() ethdb.Database

func (*Blockchain) Close

func (b *Blockchain) Close() error

func (*Blockchain) Config

func (b *Blockchain) Config() *chain.Chain

func (*Blockchain) CurrentTD

func (b *Blockchain) CurrentTD() *big.Int

func (*Blockchain) GetBlockByNumber

func (b *Blockchain) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool)

func (*Blockchain) GetBodyByHash

func (b *Blockchain) GetBodyByHash(hash types.Hash) (*types.Body, bool)

func (*Blockchain) GetHashHelper

func (b *Blockchain) GetHashHelper(header *types.Header) func(i uint64) (res types.Hash)

GetHashHelper is used by the EVM, so that the SC can get the hash of the header number

func (*Blockchain) GetHeaderByHash

func (b *Blockchain) GetHeaderByHash(hash types.Hash) (*types.Header, bool)

func (*Blockchain) GetHeaderByNumber

func (b *Blockchain) GetHeaderByNumber(n uint64) (*types.Header, bool)

func (*Blockchain) GetReceiptsByHash

func (b *Blockchain) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error)

get receitps by block header hash

func (*Blockchain) GetTD

func (b *Blockchain) GetTD(hash types.Hash) (*big.Int, bool)

func (*Blockchain) HandleGenesis

func (b *Blockchain) HandleGenesis() error

func (*Blockchain) Header

func (b *Blockchain) Header() *types.Header

func (*Blockchain) IsSystemTransaction

func (b *Blockchain) IsSystemTransaction(height uint64, coinbase types.Address, tx *types.Transaction) bool

func (*Blockchain) SelfCheck

func (b *Blockchain) SelfCheck()

func (*Blockchain) SubscribeEvents

func (b *Blockchain) SubscribeEvents() Subscription

SubscribeEvents returns a blockchain event subscription

func (*Blockchain) VerifyFinalizedBlock

func (b *Blockchain) VerifyFinalizedBlock(block *types.Block) error

func (*Blockchain) VerifyHeader

func (b *Blockchain) VerifyHeader(header *types.Header) error

func (*Blockchain) WriteBlock

func (b *Blockchain) WriteBlock(block *types.Block) error

func (*Blockchain) WriteHeader

func (b *Blockchain) WriteHeader(header *types.Header) error

type Event

type Event struct {
	// Old chain (removed headers) if there was a reorg
	OldChain []*types.Header

	// New part of the chain (or a fork)
	NewChain []*types.Header

	// Difficulty is the new difficulty created with this event
	Difficulty *big.Int

	// Type is the type of event
	Type EventType

	// Source is the source that generated the blocks for the event
	// right now it can be either the Sealer or the Syncer
	Source string
}

Event is the blockchain event that gets passed to the listeners

func (*Event) AddNewHeader

func (e *Event) AddNewHeader(newHeader *types.Header)

AddNewHeader appends a header to the event's NewChain array

func (*Event) AddOldHeader

func (e *Event) AddOldHeader(oldHeader *types.Header)

AddOldHeader appends a header to the event's OldChain array

func (*Event) Header

func (e *Event) Header() *types.Header

Header returns the latest block header for the event

func (*Event) SetDifficulty

func (e *Event) SetDifficulty(b *big.Int)

SetDifficulty sets the event difficulty

type EventType

type EventType int
const (
	EventHead  EventType = iota // New head event
	EventReorg                  // Chain reorganization event
	EventFork                   // Chain fork event
)

type Executor

type Executor interface {
	BeginTxn(parentRoot types.Hash, header *types.Header, coinbase types.Address) (*state.Transition, error)
	//nolint:lll
	ProcessTransactions(transition *state.Transition, gasLimit uint64, transactions []*types.Transaction) (*state.Transition, error)
	Stop()
}

type IBlockchain

type IBlockchain interface {
	Header() *types.Header
	SubscribeEvents() Subscription
	GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool)
	ChainDB() ethdb.Database
}

type MockSubscription

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

func NewMockSubscription

func NewMockSubscription() *MockSubscription

func (*MockSubscription) Close

func (m *MockSubscription) Close()

func (*MockSubscription) GetEvent

func (m *MockSubscription) GetEvent() *Event

func (*MockSubscription) GetEventCh

func (m *MockSubscription) GetEventCh() chan *Event

func (*MockSubscription) Push

func (m *MockSubscription) Push(e *Event)

type Subscription

type Subscription interface {
	GetEventCh() chan *Event
	GetEvent() *Event
	Close()
}

Subscription is the blockchain subscription interface

Jump to

Keyboard shortcuts

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