ethereum

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: GPL-3.0, GPL-3.0 Imports: 38 Imported by: 0

Documentation

Overview

Package ethash implements the ethash proof-of-work consensus engine.

Index

Constants

View Source
const (
	StoreCacheSize = 20
	MaxHeaderLimit = 100000
	SplicingSymbol = "-"
)

Variables

View Source
var ErrInvalidDumpMagic = errors.New("invalid dump magic")

Functions

func CalcBaseFee

func CalcBaseFee(config *ethparams.ChainConfig, parent *Header) *big.Int

CalcBaseFee calculates the basefee of the header.

func MakeGlobalEthash

func MakeGlobalEthash(dir string)

func VerifyEip1559Header

func VerifyEip1559Header(config *ethparams.ChainConfig, parent, header *Header) error

func VerifySeal

func VerifySeal(header *Header) error

Types

type Cache

type Cache struct {
	Cache *golru.Cache
	// contains filtered or unexported fields
}

type Config

type Config struct {
	CacheDir         string
	CachesInMem      int
	CachesOnDisk     int
	CachesLockMmap   bool
	DatasetDir       string
	DatasetsInMem    int
	DatasetsOnDisk   int
	DatasetsLockMmap bool
	PowMode          Mode
	Log              log.Logger `toml:"-"`
}

Config are the configuration parameters of the ethash.

type Ethash

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

Ethash is a consensus engine based on proof-of-work implementing the ethash algorithm.

func New

func New(config Config) *Ethash

New creates a full sized ethash PoW scheme and starts a background thread for remote mining, also optionally notifying a batch of remote services of new work packages.

func (*Ethash) SealHash

func (ethash *Ethash) SealHash(header *Header) (hash common.Hash)
type Header struct {
	ParentHash  common.Hash      `json:"parentHash"       gencodec:"required"`
	UncleHash   common.Hash      `json:"sha3Uncles"       gencodec:"required"`
	Coinbase    common.Address   `json:"miner"            gencodec:"required"`
	Root        common.Hash      `json:"stateRoot"        gencodec:"required"`
	TxHash      common.Hash      `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash common.Hash      `json:"receiptsRoot"     gencodec:"required"`
	Bloom       types.Bloom      `json:"logsBloom"        gencodec:"required"`
	Difficulty  *big.Int         `json:"difficulty"       gencodec:"required"`
	Number      *big.Int         `json:"number"           gencodec:"required"`
	GasLimit    uint64           `json:"gasLimit"         gencodec:"required"`
	GasUsed     uint64           `json:"gasUsed"          gencodec:"required"`
	Time        uint64           `json:"timestamp"        gencodec:"required"`
	Extra       []byte           `json:"extraData"        gencodec:"required"`
	MixDigest   common.Hash      `json:"mixHash"`
	Nonce       types.BlockNonce `json:"nonce"`

	// BaseFee was added by EIP-1559 and is ignored in legacy headers.
	BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
}

func (*Header) Hash

func (eh *Header) Hash() common.Hash

type HeaderStore

type HeaderStore struct {
	CurNumber uint64
	CurHash   common.Hash
}

func NewHeaderStore

func NewHeaderStore() *HeaderStore

func (*HeaderStore) CurrentHash

func (hs *HeaderStore) CurrentHash() common.Hash

func (*HeaderStore) CurrentNumber

func (hs *HeaderStore) CurrentNumber() uint64

func (*HeaderStore) DeleteCanonicalHash

func (hs *HeaderStore) DeleteCanonicalHash(number uint64, db types.StateDB)

func (*HeaderStore) GetCurrentNumberAndHash

func (hs *HeaderStore) GetCurrentNumberAndHash(db types.StateDB) (uint64, common.Hash, error)

func (*HeaderStore) GetHashByNumber

func (hs *HeaderStore) GetHashByNumber(db types.StateDB, number uint64) (common.Hash, error)

func (*HeaderStore) GetHeader

func (hs *HeaderStore) GetHeader(hash common.Hash, number uint64, db types.StateDB) *Header

func (*HeaderStore) GetHeaderByNumber

func (hs *HeaderStore) GetHeaderByNumber(number uint64, db types.StateDB) *Header

func (*HeaderStore) GetTd

func (hs *HeaderStore) GetTd(hash common.Hash, number uint64, db types.StateDB) *big.Int

func (*HeaderStore) HasHeader

func (hs *HeaderStore) HasHeader(hash common.Hash, number uint64, db types.StateDB) bool

func (*HeaderStore) InsertHeaders

func (hs *HeaderStore) InsertHeaders(db types.StateDB, ethHeaders []byte) ([]*params.NumberHash, error)

func (*HeaderStore) Load

func (hs *HeaderStore) Load(state types.StateDB) (err error)

func (*HeaderStore) LoadCanonicalHash

func (hs *HeaderStore) LoadCanonicalHash(number uint64, db types.StateDB) (lh common.Hash, err error)

func (*HeaderStore) LoadHeader

func (hs *HeaderStore) LoadHeader(number uint64, db types.StateDB) (lh *LightHeader, err error)

func (*HeaderStore) ReadCanonicalHash

func (hs *HeaderStore) ReadCanonicalHash(number uint64, db types.StateDB) common.Hash

func (*HeaderStore) ResetHeaderStore

func (hs *HeaderStore) ResetHeaderStore(state types.StateDB, ethHeaders []byte, td *big.Int) error

func (*HeaderStore) Store

func (hs *HeaderStore) Store(state types.StateDB) error

func (*HeaderStore) StoreCanonicalHash

func (hs *HeaderStore) StoreCanonicalHash(state types.StateDB, number uint64, hash *common.Hash) error

func (*HeaderStore) StoreHeader

func (hs *HeaderStore) StoreHeader(state types.StateDB, number uint64, header *LightHeader) error

func (*HeaderStore) WriteCanonicalHash

func (hs *HeaderStore) WriteCanonicalHash(hash common.Hash, number uint64, db types.StateDB)

func (*HeaderStore) WriteHeaderAndTd

func (hs *HeaderStore) WriteHeaderAndTd(hash common.Hash, number uint64, td *big.Int, header *Header, db types.StateDB) error

func (*HeaderStore) WriteHeaders

func (hs *HeaderStore) WriteHeaders(db types.StateDB, ethHeaders []byte) (*headerWriteResult, error)

type LightHeader

type LightHeader struct {
	Headers map[string][]byte
	TDs     map[string]*big.Int
}

func (*LightHeader) DecodeRLP

func (lh *LightHeader) DecodeRLP(s *rlp.Stream) error

func (*LightHeader) EncodeRLP

func (lh *LightHeader) EncodeRLP(w io.Writer) error

type Mode

type Mode uint

Mode defines the type and amount of PoW verification an ethash engine makes.

const (
	ModeNormal Mode = iota
	ModeTest
)

type TxProve

type TxProve struct {
	Receipt     *ethtypes.Receipt
	Prove       light.NodeList
	BlockNumber uint64
	TxIndex     uint
}

type Validate

type Validate struct{}

func (*Validate) ValidateHeaderChain

func (v *Validate) ValidateHeaderChain(db types.StateDB, headers []byte, chainType chains.ChainType) (int, error)

func (*Validate) VerifyHeaders

func (v *Validate) VerifyHeaders(hs *HeaderStore, headers []*Header, chainType chains.ChainType, db types.StateDB) (chan<- struct{}, <-chan error)

type Verify

type Verify struct {
}

func (*Verify) Verify

func (v *Verify) Verify(db types.StateDB, routerContractAddr common.Address, txProveBytes []byte) (logs []byte, err error)

type WriteStatus

type WriteStatus byte

WriteStatus status of write

const (
	NonStatTy WriteStatus = iota
	CanonStatTy
	SideStatTy
)

Jump to

Keyboard shortcuts

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