Documentation ¶
Index ¶
- Constants
- Variables
- func HandlerLedgerError(err error) pb.AChainErrorEnum
- func HandlerUtxoError(err error) pb.AChainErrorEnum
- type AChainCore
- func (xc *AChainCore) BroadCastGetBlock(bid *pb.BlockID) *pb.Block
- func (xc *AChainCore) ConfirmTipBlockChainStatus(in *pb.BCStatus) *pb.BCTipStatus
- func (xc *AChainCore) GenerateTx(in *pb.TxData, hd *global.XContext) *pb.TxStatus
- func (xc *AChainCore) GetAccountContractsStatus(account string) ([]*pb.ContractStatus, error)
- func (xc *AChainCore) GetBalance(addr string) (string, error)
- func (xc *AChainCore) GetBlock(in *pb.BlockID) *pb.Block
- func (xc *AChainCore) GetBlockByHeight(in *pb.BlockHeight) *pb.Block
- func (xc *AChainCore) GetBlockChainStatus(in *pb.BCStatus) *pb.BCStatus
- func (xc *AChainCore) GetCheckResults(term int64) ([]string, error)
- func (xc *AChainCore) GetConsStatus() *cons_base.ConsensusStatus
- func (xc *AChainCore) GetConsType() string
- func (xc *AChainCore) GetDposCandidates() ([]string, error)
- func (xc *AChainCore) GetDposNominateRecords(addr string) ([]*pb.DposNominateInfo, error)
- func (xc *AChainCore) GetDposNominatedRecords(addr string) (string, error)
- func (xc *AChainCore) GetDposVoteRecords(addr string) ([]*pb.VoteRecord, error)
- func (xc *AChainCore) GetDposVotedRecords(addr string) ([]*pb.VotedRecord, error)
- func (xc *AChainCore) GetFrozenBalance(addr string) (string, error)
- func (xc *AChainCore) GetNodeMode() string
- func (xc *AChainCore) Init(bcname string, xlog log.Logger, cfg *config.NodeConfig, p2p p2pv2.P2PServer, ...) error
- func (xc *AChainCore) IsCoreMiner() bool
- func (xc *AChainCore) Miner() int
- func (xc *AChainCore) NeedCoreConnection() bool
- func (xc *AChainCore) PostTx(in *pb.TxStatus, hd *global.XContext) (*pb.CommonReply, bool)
- func (xc *AChainCore) PreExec(req *pb.InvokeRPCRequest, hd *global.XContext) (*pb.InvokeResponse, error)
- func (xc *AChainCore) QueryAccountACL(accountName string) (*pb.Acl, bool, error)
- func (xc *AChainCore) QueryAccountContainAK(address string) ([]string, error)
- func (xc *AChainCore) QueryContractMethodACL(contractName string, methodName string) (*pb.Acl, bool, error)
- func (xc *AChainCore) QueryTx(in *pb.TxStatus) *pb.TxStatus
- func (xc *AChainCore) QueryTxFromForbidden(txid []byte) bool
- func (xc *AChainCore) SendBlock(in *pb.Block, hd *global.XContext) error
- func (xc *AChainCore) Status() int
- func (xc *AChainCore) Stop()
- func (xc *AChainCore) SyncBlocks()
- type AChainMG
- func (xm *AChainMG) CreateBlockChain(name string, data []byte) (*AChainCore, error)
- func (xm *AChainMG) Get(name string) *AChainCore
- func (xm *AChainMG) GetAll() []string
- func (xm *AChainMG) HandleSendBlock(msg *amper_p2p.AmperMessage)
- func (xm *AChainMG) Init(log log.Logger, cfg *config.NodeConfig, p2pV2 p2pv2.P2PServer) error
- func (xm *AChainMG) ProcessBatchTx(batchTx *pb.BatchTxs) (*pb.BatchTxs, error)
- func (xm *AChainMG) ProcessBlock(block *pb.Block) error
- func (xm *AChainMG) ProcessTx(in *pb.TxStatus) (*pb.CommonReply, bool, error)
- func (xm *AChainMG) RegisterBlockChain(name string) error
- func (xm *AChainMG) RegisterSubscriber() error
- func (xm *AChainMG) Set(name string, xc *AChainCore)
- func (xm *AChainMG) Start()
- func (xm *AChainMG) StartLoop()
- func (xm *AChainMG) Stop()
- func (xm *AChainMG) UnloadBlockChain(name string) error
Constants ¶
const ( // MaxReposting max repost times for broadcats MaxReposting = 300 // tx重试广播的最大并发,过多容易打爆对方的grpc连接数 // RepostingInterval repost retry interval, ms RepostingInterval = 50 // 重试广播间隔ms )
const ( // MaxSyncTimes SyncBlocks 最大次数 MaxSyncTimes = 5 // MaxSleepMilSecond ... MaxSleepMilSecond = 500 )
Variables ¶
var ( // ErrCannotSyncBlock used to return the error while sync block error ErrCannotSyncBlock = errors.New("get block error when sync block") // ErrConfirmBlock used to return the error while confirm block error ErrConfirmBlock = errors.New("Confirm block error") // ErrUTXOVMPlay used to return the error while utxovm play error ErrUTXOVMPlay = errors.New("Utxovm play error") // ErrWalk used to return the error while Walk error ErrWalk = errors.New("Walk error") // ErrWalkCheckMinerMatch used to return check miner match while walk error ErrWalkCheckMinerMatch = errors.New("Walk error check miner match") // ErrNotReady used to return the error while blockchain not ready error ErrNotReady = errors.New("BlockChain is not ready") // ErrBlockExist used to return the error while block already exit ErrBlockExist = errors.New("Block is exist") // ErrServiceRefused used to return the error while service refused ErrServiceRefused = errors.New("Service refused") // ErrInvalidBlock is returned when found an invalid block ErrInvalidBlock = errors.New("invalid block") // ErrProposeBlockMoreThanConfig is returned when propose block not match config ErrProposeBlockMoreThanConfig = errors.New("Error propose block more than config") // ErrBlockChainNotExist is returned when process a block for non-existent blockchain ErrBlockChainNotExist = errors.New("Error block chain is not exist") // ErrBlockChainIsExist is returned when find out blockachin has been loaded ErrBlockChainIsExist = errors.New("Error block chain is exist already") // ErrBlockTooLarge is returned when its size greater than the max block size defined ErrBlockTooLarge = errors.New("block is too large") )
var ( // ErrBlockChainNameEmpty is returned when blockchain name is empty ErrBlockChainNameEmpty = errors.New("validation error: validatePostTx TxStatus.Bcname can't be null") // ErrTxNil is returned when tx is nil ErrTxNil = errors.New("validation error: validatePostTx TxStatus.Tx can't be null") // ErrBlockIDNil is returned when blockid is nil ErrBlockIDNil = errors.New("validation error: validateSendBlock Block.Blockid can't be null") // ErrBlockNil is returned when block is nil ErrBlockNil = errors.New("validation error: validateSendBlock Block.Block can't be null") )
Functions ¶
func HandlerLedgerError ¶
func HandlerLedgerError(err error) pb.AChainErrorEnum
HandlerLedgerError used to handle error of ledger
func HandlerUtxoError ¶
func HandlerUtxoError(err error) pb.AChainErrorEnum
HandlerUtxoError used to handle error of utxo
Types ¶
type AChainCore ¶
type AChainCore struct { Ledger *ledger.Ledger Utxovm *utxo.UtxoVM P2pv2 p2pv2.P2PServer CryptoClient crypto_base.CryptoClient Speed *probe.SpeedCalc NativeCodeMgr *native.GeneralSCFramework // contains filtered or unexported fields }
AChainCore is the core struct of a chain
func (*AChainCore) BroadCastGetBlock ¶
func (xc *AChainCore) BroadCastGetBlock(bid *pb.BlockID) *pb.Block
BroadCastGetBlock get block from p2p network nodes
func (*AChainCore) ConfirmTipBlockChainStatus ¶
func (xc *AChainCore) ConfirmTipBlockChainStatus(in *pb.BCStatus) *pb.BCTipStatus
ConfirmTipBlockChainStatus check tip block status
func (*AChainCore) GenerateTx ¶
GenerateTx generate transaction from tx data
func (*AChainCore) GetAccountContractsStatus ¶
func (xc *AChainCore) GetAccountContractsStatus(account string) ([]*pb.ContractStatus, error)
GetAccountContractsStatus query account contracts
func (*AChainCore) GetBalance ¶
func (xc *AChainCore) GetBalance(addr string) (string, error)
GetBalance get balance from utxo
func (*AChainCore) GetBlock ¶
func (xc *AChainCore) GetBlock(in *pb.BlockID) *pb.Block
GetBlock get block from ledger
func (*AChainCore) GetBlockByHeight ¶
func (xc *AChainCore) GetBlockByHeight(in *pb.BlockHeight) *pb.Block
GetBlockByHeight get block from ledger on trunk, by Block Height
func (*AChainCore) GetBlockChainStatus ¶
func (xc *AChainCore) GetBlockChainStatus(in *pb.BCStatus) *pb.BCStatus
GetBlockChainStatus get block status from ledger
func (*AChainCore) GetCheckResults ¶
func (xc *AChainCore) GetCheckResults(term int64) ([]string, error)
GetCheckResults get all proposers for specific term
func (*AChainCore) GetConsStatus ¶
func (xc *AChainCore) GetConsStatus() *cons_base.ConsensusStatus
GetConsStatus get current consensus status
func (*AChainCore) GetConsType ¶
func (xc *AChainCore) GetConsType() string
GetConsType get consensus type for specific block chain
func (*AChainCore) GetDposCandidates ¶
func (xc *AChainCore) GetDposCandidates() ([]string, error)
GetDposCandidates get all candidates
func (*AChainCore) GetDposNominateRecords ¶
func (xc *AChainCore) GetDposNominateRecords(addr string) ([]*pb.DposNominateInfo, error)
GetDposNominateRecords get nominate(positively) record infos for specific address
func (*AChainCore) GetDposNominatedRecords ¶
func (xc *AChainCore) GetDposNominatedRecords(addr string) (string, error)
GetDposNominatedRecords get nominated(passively) record infos for specific address
func (*AChainCore) GetDposVoteRecords ¶
func (xc *AChainCore) GetDposVoteRecords(addr string) ([]*pb.VoteRecord, error)
GetDposVoteRecords get vote(positively) record infos for specific address
func (*AChainCore) GetDposVotedRecords ¶
func (xc *AChainCore) GetDposVotedRecords(addr string) ([]*pb.VotedRecord, error)
GetDposVotedRecords get voted(passively) record infos for specific address
func (*AChainCore) GetFrozenBalance ¶
func (xc *AChainCore) GetFrozenBalance(addr string) (string, error)
GetFrozenBalance get balance that still be frozen from utxo
func (*AChainCore) GetNodeMode ¶
func (xc *AChainCore) GetNodeMode() string
GetNodeMode get node running mode, such as Normal mode, FastSync mode
func (*AChainCore) Init ¶
func (xc *AChainCore) Init(bcname string, xlog log.Logger, cfg *config.NodeConfig, p2p p2pv2.P2PServer, ker *kernel.Kernel, nodeMode string) error
Init init the chain
func (*AChainCore) IsCoreMiner ¶
func (xc *AChainCore) IsCoreMiner() bool
IsCoreMiner return true if current node is one of the current core miners Note that is could be a little delay since it updated at each CompeteMaster.
func (*AChainCore) NeedCoreConnection ¶
func (xc *AChainCore) NeedCoreConnection() bool
NeedCoreConnection return true if current node is one of the core miners and coreConnection configure to true. True means block and batch tx messages need to send to core peers using p2p core peer connections
func (*AChainCore) PostTx ¶
func (xc *AChainCore) PostTx(in *pb.TxStatus, hd *global.XContext) (*pb.CommonReply, bool)
PostTx post transaction to utxo and broad cast the transaction
func (*AChainCore) PreExec ¶
func (xc *AChainCore) PreExec(req *pb.InvokeRPCRequest, hd *global.XContext) (*pb.InvokeResponse, error)
PreExec get read/write set for smart contract could be run in parallel
func (*AChainCore) QueryAccountACL ¶
QueryAccountACL get ACL for an account
func (*AChainCore) QueryAccountContainAK ¶
func (xc *AChainCore) QueryAccountContainAK(address string) ([]string, error)
QueryAccountContainAK get all accounts contain a specific address
func (*AChainCore) QueryContractMethodACL ¶
func (xc *AChainCore) QueryContractMethodACL(contractName string, methodName string) (*pb.Acl, bool, error)
QueryContractMethodACL get ACL for a contract method
func (*AChainCore) QueryTx ¶
func (xc *AChainCore) QueryTx(in *pb.TxStatus) *pb.TxStatus
QueryTx query transaction from ledger
func (*AChainCore) QueryTxFromForbidden ¶
func (xc *AChainCore) QueryTxFromForbidden(txid []byte) bool
QueryTxFromForbidden query if the tx has been forbidden
func (*AChainCore) Status ¶
func (xc *AChainCore) Status() int
Status return the status of the chain
func (*AChainCore) SyncBlocks ¶
func (xc *AChainCore) SyncBlocks()
SyncBlocks sync block while start to miner
type AChainMG ¶
type AChainMG struct { Log log.Logger Cfg *config.NodeConfig P2pv2 p2pv2.P2PServer Ukeys *sync.Map //address -> scrkey Speed *probe.SpeedCalc Quit chan struct{} // contains filtered or unexported fields }
AChainMG manage all chains
func (*AChainMG) CreateBlockChain ¶
func (xm *AChainMG) CreateBlockChain(name string, data []byte) (*AChainCore, error)
CreateBlockChain create an instance of blockchain
func (*AChainMG) Get ¶
func (xm *AChainMG) Get(name string) *AChainCore
Get return specific instance of blockchain by blockchain name from map
func (*AChainMG) HandleSendBlock ¶
func (xm *AChainMG) HandleSendBlock(msg *amper_p2p.AmperMessage)
HandleSendBlock handle SENDBLOCK type msg
func (*AChainMG) ProcessBatchTx ¶
ProcessBatchTx process batch tx
func (*AChainMG) ProcessBlock ¶
ProcessBlock process block
func (*AChainMG) RegisterBlockChain ¶
RegisterBlockChain load an instance of blockchain and start it dynamically
func (*AChainMG) RegisterSubscriber ¶
RegisterSubscriber register p2pv2 msg type
func (*AChainMG) Set ¶
func (xm *AChainMG) Set(name string, xc *AChainCore)
Set put <blockname, blockchain instance> into map
func (*AChainMG) UnloadBlockChain ¶
UnloadBlockChain unload an instance of blockchain and stop it dynamically