core

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinMinerStake = 500 * common.ZVC // minimal token of miner can stake

	MaxMinerStakeAdjustPeriod = 10000000 // maximal token of miner can stake

)
View Source
const (
	TransactionGasCost     uint64 = 400
	CodeBytePrice                 = 19073 //1.9073486328125
	CodeBytePricePrecision        = 10000
	MaxCastBlockTime              = time.Second * 2
)
View Source
const AddressContract = "zv0000000000000000000000000000000000000000000000000000000000000006"
View Source
const AddressSource = "zv0007"

address manager contract creator

View Source
const (
	GasLimitPerBlock = 2000000 // the max gas limit for a block
)
View Source
const TriesInMemory uint64 = types.EpochLength*4 + 20

Variables

View Source
var (
	ErrorBlockHash  = errors.New("consensus verify fail,block hash error")
	ErrorGroupSign  = errors.New("consensus verify fail,group sign signature error")
	ErrorRandomSign = errors.New("consensus verify fail,random signature error")
	ErrPkNotExists  = errors.New("consensus verify fail,pk not exists")

	ErrPkNil          = errors.New("pk is nil")
	ErrGroupNotExists = errors.New("group not exists")
)
View Source
var (
	ErrBlockExist      = errors.New("block exist")
	ErrPreNotExist     = errors.New("pre block not exist")
	ErrLocalMoreWeight = errors.New("local more weight")
	ErrCommitBlockFail = errors.New("commit block fail")
	ErrBlockSizeLimit  = errors.New("block size exceed the limit")
)
View Source
var (
	ProposerPackageTime = MaxCastBlockTime
	GasLimitForPackage  = uint64(GasLimitPerBlock)
	IgnoreVmCall        = false
)
View Source
var (
	ErrNil             = errors.New("nil transaction")
	ErrHash            = errors.New("invalid transaction hash")
	ErrGasPrice        = errors.New("gas price is too low")
	ErrSign            = errors.New("sign error")
	ErrNonce           = errors.New("nonce error")
	ErrDataSizeTooLong = errors.New("data size too long")
)
View Source
var GroupManagerImpl *group.Manager
View Source
var Logger *logrus.Logger
View Source
var TxSyncer *txSyncer

Functions

func AdminAddr added in v1.0.11

func AdminAddr() common.Address

func CirculatesAddr added in v1.0.11

func CirculatesAddr() common.Address

func DaemonNodeAddress added in v1.0.11

func DaemonNodeAddress() common.Address

func GuardAddress added in v1.0.11

func GuardAddress() []common.Address

func InitBlockSyncer

func InitBlockSyncer(chain *FullBlockChain)

InitBlockSyncer initialize the blockSyncer. Register the ticker for sending and requesting blocks to neighbors timely and also subscribe these events to handle requests from neighbors

func InitCore

func InitCore(helper types.ConsensusHelper, account types.Account) error

InitCore initialize the peerManagerImpl, BlockChainImpl and GroupChainImpl

func IsInExtractGuardNodes added in v1.0.11

func IsInExtractGuardNodes(addr common.Address) bool

func NewFundGuardNode

func NewFundGuardNode() *fundGuardNode

func NewRewardManager

func NewRewardManager() *rewardManager

func StakePlatformAddr added in v1.0.11

func StakePlatformAddr() common.Address

func UserNodeAddress added in v1.0.11

func UserNodeAddress() common.Address

Types

type AddressManager added in v1.0.11

type AddressManager struct {
}

func (*AddressManager) DeployAddressManagerContract added in v1.0.11

func (am *AddressManager) DeployAddressManagerContract(stateDB *account.AccountDB)

type BaseMiner

type BaseMiner struct {
}

type BlockChainConfig

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

BlockChainConfig contains the configuration values of leveldb prefix string

type BlockProvider

type BlockProvider interface {
	Provide(begin, end uint64) []*types.Block
	Height() uint64
}

BlockProvider provides blocks of the given height range [start, end)

func NewLocalBlockProvider

func NewLocalBlockProvider(dir string) (BlockProvider, error)

type FullBlockChain

type FullBlockChain struct {
	types.Account
	// contains filtered or unexported fields
}

FullBlockChain manages chain imports, reverts, chain reorganisations.

var BlockChainImpl *FullBlockChain

func (*FullBlockChain) AccountDBAt

func (chain *FullBlockChain) AccountDBAt(height uint64) (types.AccountDB, error)

AccountDBAt returns account database with specified block height

func (*FullBlockChain) AddBlockOnChain

func (chain *FullBlockChain) AddBlockOnChain(source string, b *types.Block) types.AddBlockResult

AddBlockOnChain add a block on blockchain, there are five cases of return value:

0, successfully add block on blockchain
-1, verification failed
1, the block already exist on the blockchain, then we should discard it
2, the same height block with a larger QN value on the chain, then we should discard it
3, need adjust the blockchain, there will be a fork

func (*FullBlockChain) AddChainSlice

func (chain *FullBlockChain) AddChainSlice(source string, chainSlice []*types.Block, cb batchAddBlockCallback)

func (*FullBlockChain) AddTransactionToPool

func (chain *FullBlockChain) AddTransactionToPool(tx *types.Transaction) (bool, error)

Version of chain Id

func (*FullBlockChain) BatchGetBlockHeadersBetween

func (chain *FullBlockChain) BatchGetBlockHeadersBetween(begin, end uint64) []*types.BlockHeader

BatchGetBlockHeadersBetween query blocks of the height range [start, end)

func (*FullBlockChain) BatchGetBlocksAfterHeight

func (chain *FullBlockChain) BatchGetBlocksAfterHeight(height uint64, limit int) []*types.Block

BatchGetBlocksAfterHeight query blocks after the specified height

func (*FullBlockChain) BatchGetBlocksBetween

func (chain *FullBlockChain) BatchGetBlocksBetween(begin, end uint64) []*types.Block

BatchGetBlocksBetween query blocks of the height range [start, end)

func (*FullBlockChain) CastBlock

func (chain *FullBlockChain) CastBlock(height uint64, proveValue []byte, qn uint64, castor []byte, gSeed common.Hash) *types.Block

CastBlock cast a block, current casters synchronization operation in the group

func (*FullBlockChain) CheckPointAt

func (chain *FullBlockChain) CheckPointAt(h uint64) *types.BlockHeader

func (*FullBlockChain) Clear

func (chain *FullBlockChain) Clear() error

Clear clear blockchain all data. Not used now, should remove it latter

func (*FullBlockChain) Close

func (chain *FullBlockChain) Close()

Close the open levelDb files

func (*FullBlockChain) CountBlocksInRange

func (chain *FullBlockChain) CountBlocksInRange(startHeight uint64, endHeight uint64) uint64

CountBlocksInRange returns the count of block in a range of block height. the block with startHeight and endHeight will be included

func (*FullBlockChain) DeleteSmallDbByHeight

func (chain *FullBlockChain) DeleteSmallDbByHeight(heightLimit uint64) error

from last delete small db height to current height's data can be deleted

func (*FullBlockChain) GetAccountDBByHash

func (chain *FullBlockChain) GetAccountDBByHash(hash common.Hash) (types.AccountDB, error)

GetAccountDBByHash returns account database with specified block hash

func (*FullBlockChain) GetBalance

func (chain *FullBlockChain) GetBalance(address common.Address) *big.Int

GetBalance return the balance of specified address

func (*FullBlockChain) GetConsensusHelper

func (chain *FullBlockChain) GetConsensusHelper() types.ConsensusHelper

GetConsensusHelper returns consensus helper reference

func (*FullBlockChain) GetNonce

func (chain *FullBlockChain) GetNonce(address common.Address) uint64

GetBalance returns the nonce of specified address

func (*FullBlockChain) GetRewardManager

func (chain *FullBlockChain) GetRewardManager() types.RewardManager

GetRewardManager returns the reward manager

func (*FullBlockChain) GetTransactionByHash

func (chain *FullBlockChain) GetTransactionByHash(onlyReward bool, h common.Hash) *types.Transaction

GetTransactionByHash get a transaction by hash

func (*FullBlockChain) GetTransactionPool

func (chain *FullBlockChain) GetTransactionPool() types.TransactionPool

GetTransactionPool return the transaction pool waiting for the block

func (*FullBlockChain) HasBlock

func (chain *FullBlockChain) HasBlock(hash common.Hash) bool

HasBlock returns whether the chain has a block with specific hash

func (*FullBlockChain) HasHeight

func (chain *FullBlockChain) HasHeight(height uint64) bool

HasBlock returns whether the chain has a block with specific height

func (*FullBlockChain) Height

func (chain *FullBlockChain) Height() uint64

Height of chain

func (*FullBlockChain) IsAdjusting

func (chain *FullBlockChain) IsAdjusting() bool

IsAdjusting means whether need to adjust blockchain, which means there may be a fork

func (*FullBlockChain) IsPruneMode

func (chain *FullBlockChain) IsPruneMode() bool

func (*FullBlockChain) IsSyncing

func (chain *FullBlockChain) IsSyncing() bool

func (*FullBlockChain) LatestAccountDB

func (chain *FullBlockChain) LatestAccountDB() (types.AccountDB, error)

LatestAccountDB returns chain's last account database

func (*FullBlockChain) LatestCheckPoint

func (chain *FullBlockChain) LatestCheckPoint() *types.BlockHeader

func (*FullBlockChain) LogDbStats

func (chain *FullBlockChain) LogDbStats()

func (*FullBlockChain) PersistentState

func (chain *FullBlockChain) PersistentState()

PersistentState when shut down it will be run Take last prune height's next height block state to commit big db

func (*FullBlockChain) QueryBlockByHash

func (chain *FullBlockChain) QueryBlockByHash(hash common.Hash) *types.Block

QueryBlockByHash query the block by block hash

func (*FullBlockChain) QueryBlockByHeight

func (chain *FullBlockChain) QueryBlockByHeight(height uint64) *types.Block

QueryBlockByHeight query the block by height

func (*FullBlockChain) QueryBlockCeil

func (chain *FullBlockChain) QueryBlockCeil(height uint64) *types.Block

QueryBlockCeil query first block whose height >= height

func (*FullBlockChain) QueryBlockFloor

func (chain *FullBlockChain) QueryBlockFloor(height uint64) *types.Block

QueryBlockFloor query first block whose height <= height

func (*FullBlockChain) QueryBlockHeaderByHash

func (chain *FullBlockChain) QueryBlockHeaderByHash(hash common.Hash) *types.BlockHeader

QueryBlockHeaderByHash query block header according to the specified hash

func (*FullBlockChain) QueryBlockHeaderByHeight

func (chain *FullBlockChain) QueryBlockHeaderByHeight(height uint64) *types.BlockHeader

QueryBlockHeaderByHeight returns the block header query by height, first query LRU, if there's not exist, then query db

func (*FullBlockChain) QueryBlockHeaderCeil

func (chain *FullBlockChain) QueryBlockHeaderCeil(height uint64) *types.BlockHeader

QueryBlockHeaderCeil query first block header whose height >= height

func (*FullBlockChain) QueryBlockHeaderFloor

func (chain *FullBlockChain) QueryBlockHeaderFloor(height uint64) *types.BlockHeader

QueryBlockHeaderFloor query first block header whose height <= height

func (*FullBlockChain) QueryTopBlock

func (chain *FullBlockChain) QueryTopBlock() *types.BlockHeader

QueryTopBlock returns the latest block header

func (*FullBlockChain) Remove

func (chain *FullBlockChain) Remove(block *types.Block) bool

Remove removes the block and blocks after it from the chain. Only used in a debug file, should be removed later

func (*FullBlockChain) ResetNear

func (chain *FullBlockChain) ResetNear(bh *types.BlockHeader) (restartBh *types.BlockHeader, err error)

ResetNear reset the current top block with parameter bh,if parameter bh state not exists,then find last restart point

func (*FullBlockChain) ResetTop

func (chain *FullBlockChain) ResetTop(bh *types.BlockHeader) error

ResetTop reset the current top block with parameter bh

func (*FullBlockChain) ScanBlockHeightsInRange

func (chain *FullBlockChain) ScanBlockHeightsInRange(startHeight uint64, endHeight uint64) []uint64

func (*FullBlockChain) TotalQN

func (chain *FullBlockChain) TotalQN() uint64

TotalQN of chain

func (*FullBlockChain) Traverse

func (chain *FullBlockChain) Traverse(height uint64, config *account.TraverseConfig) (bool, error)

func (*FullBlockChain) Version

func (chain *FullBlockChain) Version() int

Version of chain Id

type FundGuardType

type FundGuardType byte

type GuardProposalMiner

type GuardProposalMiner struct {
	*BaseMiner
}

type InvalidProposalMiner

type InvalidProposalMiner struct {
	*BaseMiner
}

type MessageBase

type MessageBase struct {
}

type MinerManager

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

MinerManager manage all the miner related actions

var MinerManagerImpl *MinerManager

func (*MinerManager) ClearTicker

func (mm *MinerManager) ClearTicker()

ClearTicker clear the ticker routine

func (*MinerManager) ExecuteOperation

func (mm *MinerManager) ExecuteOperation(accountDB types.AccountDB, msg types.TxMessage, height uint64) (success bool, err error)

ExecuteOperation execute the miner operation

func (*MinerManager) FullStakeGuardNodesCheck

func (mm *MinerManager) FullStakeGuardNodesCheck(db types.AccountDB, height uint64) ([]common.Address, error)

func (*MinerManager) FundGuardExpiredCheck

func (mm *MinerManager) FundGuardExpiredCheck(accountDB types.AccountDB, height uint64) ([]common.Address, error)

func (*MinerManager) GetAllFullStakeGuardNodes

func (mm *MinerManager) GetAllFullStakeGuardNodes(accountDB types.AccountDB) []common.Address

func (*MinerManager) GetAllFundStakeGuardNodes

func (mm *MinerManager) GetAllFundStakeGuardNodes(accountDB types.AccountDB) ([]*fundGuardNodeDetail, error)

func (*MinerManager) GetAllGuardNodeAddrs added in v1.0.8

func (mm *MinerManager) GetAllGuardNodeAddrs(accountDB types.AccountDB) ([]common.Address, error)

GetAllGuardNodeAddrs return all guard node addresses,contains fund guard addresses and full stake addresses

func (*MinerManager) GetAllMiners

func (mm *MinerManager) GetAllMiners(mType types.MinerType, height uint64) []*types.Miner

GetAllMiners returns all miners of the the specified type at the given height

func (*MinerManager) GetAllStakeDetails

func (mm *MinerManager) GetAllStakeDetails(address common.Address) map[string][]*types.StakeDetail

GetAllStakeDetails returns all stake details of the given account

func (*MinerManager) GetFullMinerPoolStake

func (mm *MinerManager) GetFullMinerPoolStake(height uint64) uint64

func (*MinerManager) GetFundGuard

func (mm *MinerManager) GetFundGuard(addr string) (*fundGuardNode, error)

func (*MinerManager) GetLatestMiner

func (mm *MinerManager) GetLatestMiner(address common.Address, mType types.MinerType) *types.Miner

GetMiner return the latest miner info stored in db of the given address and the miner type

func (*MinerManager) GetMiner

func (mm *MinerManager) GetMiner(address common.Address, mType types.MinerType, height uint64) *types.Miner

GetMiner return miner info stored in db of the given address and the miner type at the given height

func (*MinerManager) GetProposalTotalStake

func (mm *MinerManager) GetProposalTotalStake(height uint64) uint64

GetProposalTotalStake returns the chain's total staked value of proposals at the specific block height

func (*MinerManager) GetStakeDetails

func (mm *MinerManager) GetStakeDetails(address common.Address, source common.Address) []*types.StakeDetail

GetStakeDetails returns all the stake details of the given address pairs

func (*MinerManager) GetTickets

func (mm *MinerManager) GetTickets(db types.AccountDB, address common.Address) uint64

func (*MinerManager) GetValidTicketsByHeight

func (mm *MinerManager) GetValidTicketsByHeight(height uint64) uint64

func (*MinerManager) GuardNodesCheck

func (mm *MinerManager) GuardNodesCheck(accountDB types.AccountDB, bh *types.BlockHeader)

GuardNodesCheck check guard nodes is expired

func (*MinerManager) MinerFrozen

func (mm *MinerManager) MinerFrozen(accountDB types.AccountDB, miner common.Address, height uint64) (success bool, err error)

FreezeMiner execute the miner frozen operation

func (*MinerManager) MinerPenalty

func (mm *MinerManager) MinerPenalty(accountDB types.AccountDB, penalty types.PunishmentMsg, height uint64) (success bool, err error)

func (*MinerManager) ValidateStakeAdd

func (mm *MinerManager) ValidateStakeAdd(tx *types.Transaction) error

type MinerPoolProposalMiner

type MinerPoolProposalMiner struct {
	*BaseMiner
}

type NormalProposalMiner

type NormalProposalMiner struct {
	*BaseMiner
}

type OfflineTailor

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

func NewOfflineTailor

func NewOfflineTailor(genesisGroup *types.GenesisInfo, dbDir string, sdbDir string, mem int, cacheDir string, out string, onlyVerify bool, maxOpenFiles int) (*OfflineTailor, error)

func (*OfflineTailor) Compaction

func (t *OfflineTailor) Compaction()

func (*OfflineTailor) Pruning

func (t *OfflineTailor) Pruning()

func (*OfflineTailor) Verify

func (t *OfflineTailor) Verify() error

type PruneConfig

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

type Replayer

type Replayer interface {
	Replay(provider BlockProvider, out io.Writer) error
}

func NewFastReplayer

func NewFastReplayer(bp BlockProvider, chain *FullBlockChain, out io.Writer) Replayer

type SyncCandidateInfo

type SyncCandidateInfo struct {
	Candidate       string // Candidate's ID
	CandidateHeight uint64 // Candidate's current block/group height
	ReqHeight       uint64 // Candidate's current request block/group height
}

type TransactionWithTime

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

type UnSupportMiner

type UnSupportMiner struct {
}

type VerifyMiner

type VerifyMiner struct {
	*BaseMiner
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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