chain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: LGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VerifierAddress []common.Address

the verifier address to generate the first twenty blocks

Functions

func SetupGenesisBlock

func SetupGenesisBlock(genesis *Genesis) (*chain_config.ChainConfig, common.Hash, error)

SetupGenesisBlock writes or updates the genesis block in db. The block that will be used is:

                     genesis == nil       genesis != nil
                  +------------------------------------------
db has no genesis |  main-net default  |  genesis
db has genesis    |  from DB           |  genesis (if compatible)

The stored chain configuration will be updated if it is compatible (i.e. does not specify a fork block below the local head block). In case of a conflict, the error is a *params.ConfigCompatError and the new, unwritten config is returned.

The returned chain configuration is never nil.

Types

type AccountDBChainReader

type AccountDBChainReader interface {
	CurrentBlock() model.AbstractBlock
	GetBlockByNumber(number uint64) model.AbstractBlock
	GetVerifiers(round uint64) []common.Address
	StateAtByBlockNumber(num uint64) (*state_processor.AccountStateDB, error)

	IsChangePoint(block model.AbstractBlock, isProcessPackageBlock bool) bool
	GetLastChangePoint(block model.AbstractBlock) *uint64
	GetSlot(block model.AbstractBlock) *uint64
}

type BlockProcessor

type BlockProcessor struct {
	*state_processor.AccountStateDB
	// contains filtered or unexported fields
}

process chain state before insert a block

func NewBlockProcessor

func NewBlockProcessor(fullChain AccountDBChainReader, preStateRoot common.Hash, db state_processor.StateStorage) (*BlockProcessor, error)

func (*BlockProcessor) Process

func (state *BlockProcessor) Process(block model.AbstractBlock, economyModel economy_model.EconomyModel) (err error)

func (*BlockProcessor) ProcessExceptTxs

func (state *BlockProcessor) ProcessExceptTxs(block model.AbstractBlock, economyModel economy_model.EconomyModel, isProcessPackageBlock bool) (err error)

func (*BlockProcessor) RewardByzantiumVerifier

func (state *BlockProcessor) RewardByzantiumVerifier(Block model.AbstractBlock, earlyContract *contract.EarlyRewardContract) (err error)

Reward Verifiers, current block reward previous block

func (*BlockProcessor) RewardCoinBase

func (state *BlockProcessor) RewardCoinBase(block model.AbstractBlock, earlyContract *contract.EarlyRewardContract) (err error)

type Chain

type Chain interface {
	GetBlockByNumber(number uint64) model.AbstractBlock
	CurrentBlock() model.AbstractBlock
	Genesis() model.AbstractBlock
	GetCurrVerifiers() []common.Address
	GetNextVerifiers() []common.Address
	GetHeaderByHash(hash common.Hash) model.AbstractHeader
	GetHeaderByNumber(number uint64) model.AbstractHeader
	IsChangePoint(block model.AbstractBlock, isProcessPackageBlock bool) bool
}

type Genesis

type Genesis struct {
	Config    *chain_config.ChainConfig `json:"config"`
	Nonce     uint64                    `json:"nonce"`
	Timestamp *big.Int                  `json:"timestamp"`
	ExtraData []byte                    `json:"extraData"`
	//GasLimit   uint64              `json:"gasLimit"   gencodec:"required"`
	//Difficulty *big.Int            `json:"difficulty" gencodec:"required"`
	Difficulty common.Difficulty `json:"difficulty" gencodec:"required"`
	Mixhash    common.Hash       `json:"mixHash"`
	Coinbase   common.Address    `json:"coinbase"`
	Alloc      GenesisAlloc      `json:"alloc"      gencodec:"required"`

	//add verifiers
	Verifiers []common.Address

	// These fields are used for consensus tests. Please don't use them
	// in actual genesis blocks.
	Number uint64 `json:"number"`
	//GasUsed    uint64      `json:"gasUsed"`
	ParentHash common.Hash `json:"parentHash"`

	ChainDB               chaindb.Database
	AccountStateProcessor state_processor.AccountStateProcessor
	RegisterProcessor     registerdb.RegisterProcessor
	// contains filtered or unexported fields
}

Genesis specifies the header fields, state of a genesis block. It also defines hard fork switch-over blocks through the chain configuration.

func DefaultGenesisBlock

func DefaultGenesisBlock(chainDB chaindb.Database, accountStateProcessor state_processor.AccountStateProcessor, registerProcessor registerdb.RegisterProcessor, chainConf *chain_config.ChainConfig) *Genesis

DefaultGenesisBlock returns the Ethereum main net genesis block.

func GenesisBlockFromFile

func GenesisBlockFromFile(chainDB chaindb.Database, accountStateProcessor state_processor.AccountStateProcessor) *Genesis

func (*Genesis) Commit

func (g *Genesis) Commit(block model.AbstractBlock) error

func (*Genesis) Prepare

func (g *Genesis) Prepare() (model.AbstractBlock, error)

Commit writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.

func (*Genesis) SetAccountStateProcessor

func (g *Genesis) SetAccountStateProcessor(p state_processor.AccountStateProcessor)

func (*Genesis) SetChainDB

func (g *Genesis) SetChainDB(db chaindb.Database)

func (*Genesis) SetEarlyTokenContract

func (g *Genesis) SetEarlyTokenContract() error

func (*Genesis) SetVerifiers

func (g *Genesis) SetVerifiers(v []common.Address)

func (*Genesis) ToBlock

func (g *Genesis) ToBlock() *model.Block

ToBlock creates the genesis block and writes state of a genesis specification to the given database (or discards it if nil).

func (*Genesis) Valid

func (g *Genesis) Valid() bool

type GenesisAlloc

type GenesisAlloc map[common.Address]*big.Int

GenesisAlloc specifies the initial state that is part of the genesis block.

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New common.Hash
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

type VerifiersReader

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

func MakeVerifiersReader

func MakeVerifiersReader(fullChain Chain) *VerifiersReader

func (*VerifiersReader) CurrentVerifiers

func (verifier *VerifiersReader) CurrentVerifiers() []common.Address

func (*VerifiersReader) GetPBFTPrimaryNode

func (verifier *VerifiersReader) GetPBFTPrimaryNode() common.Address

To get the PBFT master node, use the next considering the situation of 9.

func (*VerifiersReader) NextVerifiers

func (verifier *VerifiersReader) NextVerifiers() []common.Address

func (*VerifiersReader) PrimaryNode

func (verifier *VerifiersReader) PrimaryNode() common.Address

Get the main node of the current block, not considering the situation of 9

func (*VerifiersReader) ShouldChangeVerifier

func (verifier *VerifiersReader) ShouldChangeVerifier() bool

func (*VerifiersReader) VerifiersTotalCount

func (verifier *VerifiersReader) VerifiersTotalCount() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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