chain

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MaxDeputyHostLength  = 128
	StandardNodeIdLength = 128
)
View Source
const MaxExtraDataLen = 256

Variables

View Source
var (
	ErrNoGenesis                     = errors.New("can't get genesis block")
	ErrBlockNotExist                 = errors.New("block not exist in local")
	ErrParentNotExist                = errors.New("parent block not exist in local")
	ErrSaveBlock                     = errors.New("save block to db error")
	ErrSaveAccount                   = errors.New("save account error")
	ErrVerifyHeaderFailed            = errors.New("verify block's header error")
	ErrVerifyBlockFailed             = errors.New("verify block error")
	ErrInvalidConfirmInfo            = errors.New("invalid confirm info")
	ErrInvalidSignedConfirmInfo      = errors.New("invalid signed data of confirm info")
	ErrSetConfirmInfoToDB            = errors.New("set confirm info to db error")
	ErrSetStableBlockToDB            = errors.New("set stable block to db error")
	ErrStableHeightLargerThanCurrent = errors.New("stable block's height is larger than current block")
)
View Source
var (
	ErrGenesisExtraTooLong = errors.New("genesis config's extraData is longer than 256")
	ErrGenesisTimeTooLarge = errors.New("genesis config's time is larger than current time")
	ErrNoDeputyNodes       = errors.New("no deputy nodes in genesis")
	ErrInvalidDeputyNodes  = errors.New("genesis config's deputy nodes are invalid")
)
View Source
var (
	DefaultFounder     = decodeMinerAddress("Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG") // Initial LEMO holder
	DefaultDeputyNodes = deputynode.DeputyNodes{
		&deputynode.DeputyNode{
			MinerAddress: DefaultFounder,
			NodeID:       common.FromHex("0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0"),
			Rank:         0,
			Votes:        new(big.Int).SetInt64(5),
		},
		&deputynode.DeputyNode{
			MinerAddress: decodeMinerAddress("Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY"),
			NodeID:       common.FromHex("0xddb5fc36c415799e4c0cf7046ddde04aad6de8395d777db4f46ebdf258e55ee1d698fdd6f81a950f00b78bb0ea562e4f7de38cb0adf475c5026bb885ce74afb0"),
			Rank:         1,
			Votes:        new(big.Int).SetInt64(4),
		},
		&deputynode.DeputyNode{
			MinerAddress: decodeMinerAddress("Lemo842BJZ4DKCC764C63Y6A943775JH6NQ3Z33Y"),
			NodeID:       common.FromHex("0x7739f34055d3c0808683dbd77a937f8e28f707d5b1e873bbe61f6f2d0347692f36ef736f342fb5ce4710f7e337f062cc2110d134b63a9575f78cb167bfae2f43"),
			Rank:         2,
			Votes:        new(big.Int).SetInt64(3),
		},
		&deputynode.DeputyNode{
			MinerAddress: decodeMinerAddress("Lemo837QGPS3YNTYNF53CD88WA5DR3ABNA95W2DG"),
			NodeID:       common.FromHex("0x34f0df789b46e9bc09f23d5315b951bc77bbfeda653ae6f5aab564c9b4619322fddb3b1f28d1c434250e9d4dd8f51aa8334573d7281e4d63baba913e9fa6908f"),
			Rank:         3,
			Votes:        new(big.Int).SetInt64(2),
		},
		&deputynode.DeputyNode{
			MinerAddress: decodeMinerAddress("Lemo83HKZK68JQZDRGS5PWT2ZBSKR5CRADCSJB9B"),
			NodeID:       common.FromHex("0x5b980ffb1b463fce4773a22ebf376c07c6207023b016b36ccfaba7be1cd1ab4a91737741cd43b7fcb10879e0fcf314d69fa953daec0f02be0f8f9cedb0cb3797"),
			Rank:         4,
			Votes:        new(big.Int).SetInt64(1),
		},
	}
)
View Source
var (
	// ErrInvalidSender is returned if the transaction contains an invalid signature.
	ErrInvalidSender = errors.New("invalid sender")
	ErrTxChainID     = errors.New("Tx chainID unequal to node chainID ")
	ErrNegativeValue = errors.New("negative value")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")
)
View Source
var (
	ErrInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
	ErrInvalidTxInBlock          = errors.New("block contains invalid transaction")
	ErrInvalidGenesis            = errors.New("can't process genesis block")
	ErrInvalidHost               = errors.New("the length of host field in transaction is out of max length limit")
	ErrInvalidAddress            = errors.New("invalid address")
	ErrInvalidNodeId             = errors.New("invalid nodeId")
)
View Source
var TransactionTimeOut = int64(3600)

Functions

func CanTransfer

func CanTransfer(am vm.AccountManager, addr common.Address, amount *big.Int) bool

CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func DivideSalary added in v1.2.0

func DivideSalary(totalSalary *big.Int, am *account.Manager, t *deputynode.TermRecord) []*deputynode.DeputySalary

func GetHashFn

func GetHashFn(ref *types.Header, chain ChainContext) vm.GetHashFunc

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IntrinsicGas

func IntrinsicGas(data []byte, contractCreation bool) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func NewEVMContext

func NewEVMContext(tx *types.Transaction, header *types.Header, txIndex uint, txHash common.Hash, blockHash common.Hash, chain ChainContext) vm.Context

NewEVMContext creates a new context for use in the EVM.

func SetupGenesisBlock

func SetupGenesisBlock(db protocol.ChainDB, genesis *Genesis) *types.Block

SetupGenesisBlock setup genesis block

func Transfer

func Transfer(am vm.AccountManager, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

Types

type BlockChain

type BlockChain struct {
	RecvBlockFeed subscribe.Feed
	// contains filtered or unexported fields
}

func NewBlockChain

func NewBlockChain(chainID uint16, engine Engine, dm *deputynode.Manager, db db.ChainDB, flags flag.CmdFlags) (bc *BlockChain, err error)

func (*BlockChain) AccountManager

func (bc *BlockChain) AccountManager() *account.Manager

func (*BlockChain) ChainID

func (bc *BlockChain) ChainID() uint16

ChainID

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *types.Block

CurrentBlock get latest current block

func (*BlockChain) Db

func (bc *BlockChain) Db() db.ChainDB

func (*BlockChain) DeputyManager added in v1.2.0

func (bc *BlockChain) DeputyManager() *deputynode.Manager

func (*BlockChain) Flags

func (bc *BlockChain) Flags() flag.CmdFlags

func (*BlockChain) Founder added in v1.2.0

func (bc *BlockChain) Founder() common.Address

Founder is LEMO holder in the genesis block

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *types.Block

Genesis genesis block

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block

func (*BlockChain) GetBlockByHeight

func (bc *BlockChain) GetBlockByHeight(height uint32) *types.Block

func (*BlockChain) GetConfirms

func (bc *BlockChain) GetConfirms(query *network.GetConfirmInfo) []types.SignData

GetConfirms get all confirm info of special block

func (*BlockChain) GetNewDeputyNodes added in v1.1.0

func (bc *BlockChain) GetNewDeputyNodes() deputynode.DeputyNodes

GetNewDeputyNodes get next epoch deputy nodes for snapshot block

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash common.Hash) bool

HasBlock has special block in local

func (*BlockChain) InsertChain

func (bc *BlockChain) InsertChain(block *types.Block, isSynchronising bool) (err error)

InsertChain insert block of non-self to chain

func (*BlockChain) Lock added in v1.0.2

func (bc *BlockChain) Lock() *sync.Mutex

Lock call by miner

func (*BlockChain) ReceiveConfirm

func (bc *BlockChain) ReceiveConfirm(info *network.BlockConfirmData) (err error)

ReceiveConfirm

func (*BlockChain) ReceiveConfirms

func (bc *BlockChain) ReceiveConfirms(pack network.BlockConfirms)

ReceiveConfirms receive confirm package from net connection

func (*BlockChain) SetMinedBlock

func (bc *BlockChain) SetMinedBlock(block *types.Block) error

SetMinedBlock 挖到新块

func (*BlockChain) SetStableBlock

func (bc *BlockChain) SetStableBlock(hash common.Hash, height uint32) error

SetStableBlock

func (*BlockChain) StableBlock

func (bc *BlockChain) StableBlock() *types.Block

StableBlock get latest stable block

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

Stop stop block chain

func (*BlockChain) TxProcessor

func (bc *BlockChain) TxProcessor() *TxProcessor

func (*BlockChain) VerifyAndFill added in v1.2.0

func (bc *BlockChain) VerifyAndFill(block *types.Block) (*types.Block, error)

VerifyAndFill verify block then create a new block

type ChainContext

type ChainContext interface {
	// GetBlockByHash returns the hash corresponding to their hash.
	GetBlockByHash(hash common.Hash) *types.Block
}

ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type Dpovp

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

func NewDpovp

func NewDpovp(timeout int64, dm *deputynode.Manager, db protocol.ChainDB) *Dpovp

func (*Dpovp) Finalize

func (d *Dpovp) Finalize(height uint32, am *account.Manager) error

Finalize increases miners' balance and fix all account changes

func (*Dpovp) Seal

func (d *Dpovp) Seal(header *types.Header, txProduct *account.TxsProduct, confirms []types.SignData, dNodes deputynode.DeputyNodes) (*types.Block, error)

Seal packages all products into a block

func (*Dpovp) VerifyDeputyRoot added in v1.1.0

func (d *Dpovp) VerifyDeputyRoot(block *types.Block) error

VerifyDeputyRoot verify deputy root

func (*Dpovp) VerifyHeader

func (d *Dpovp) VerifyHeader(block *types.Block) error

VerifyHeader verify block header

type Engine

type Engine interface {
	VerifyHeader(block *types.Block) error

	Finalize(height uint32, am *account.Manager) error

	Seal(header *types.Header, txProduct *account.TxsProduct, confirms []types.SignData, dNodes deputynode.DeputyNodes) (*types.Block, error)
}

type Genesis

type Genesis struct {
	Time        uint32                 `json:"timestamp"     gencodec:"required"`
	ExtraData   []byte                 `json:"extraData"`
	GasLimit    uint64                 `json:"gasLimit"      gencodec:"required"`
	Founder     common.Address         `json:"founder"       gencodec:"required"`
	DeputyNodes deputynode.DeputyNodes `json:"deputyNodes"   gencodec:"required"`
}

func DefaultGenesisBlock

func DefaultGenesisBlock() *Genesis

DefaultGenesisBlock default genesis block

func (Genesis) MarshalJSON

func (g Genesis) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Genesis) ToBlock

func (g *Genesis) ToBlock(am *account.Manager) (*types.Block, error)

ToBlock

func (*Genesis) UnmarshalJSON

func (g *Genesis) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type TransactionWithTime

type TransactionWithTime struct {
	Tx      *types.Transaction
	RecTime int64
	DelFlg  bool
}

type TxPool

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

func NewTxPool

func NewTxPool(chainID uint16) *TxPool

func (*TxPool) AddKey

func (pool *TxPool) AddKey(hash common.Hash)

func (*TxPool) AddTx

func (pool *TxPool) AddTx(tx *types.Transaction) error

func (*TxPool) AddTxs

func (pool *TxPool) AddTxs(txs []*types.Transaction) error

func (*TxPool) Pending

func (pool *TxPool) Pending(size int) []*types.Transaction

func (*TxPool) Remove

func (pool *TxPool) Remove(keys []common.Hash)

type TxProcessor

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

func NewTxProcessor

func NewTxProcessor(bc *BlockChain) *TxProcessor

func (*TxProcessor) ApplyTxs

func (p *TxProcessor) ApplyTxs(header *types.Header, txs types.Transactions, outTime int64) (types.Transactions, types.Transactions, uint64)

ApplyTxs picks and processes transactions from miner's tx pool.

func (*TxProcessor) CallTx added in v1.0.2

func (p *TxProcessor) CallTx(ctx context.Context, header *types.Header, to *common.Address, txType uint16, data hexutil.Bytes, blockHash common.Hash, timeout time.Duration) ([]byte, uint64, error)

CallTx pre-execute transactions and contracts.

func (*TxProcessor) Process

func (p *TxProcessor) Process(header *types.Header, txs types.Transactions) (uint64, error)

Process processes all transactions in a block. Change accounts' data and execute contract codes.

type TxsRecent

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

func NewRecent

func NewRecent() *TxsRecent

type TxsSort

type TxsSort interface {
	// contains filtered or unexported methods
}

func NewTxsSortByTime

func NewTxsSortByTime() TxsSort

type TxsSortByTime

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

Directories

Path Synopsis
vm
abi
Package abi implements the Lemochain ABI (Application Binary Interface).
Package abi implements the Lemochain ABI (Application Binary Interface).
runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.

Jump to

Keyboard shortcuts

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