AmpChaincore

package
v0.0.0-...-d9e9996 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxReposting max repost times for broadcats
	MaxReposting = 300 // tx重试广播的最大并发,过多容易打爆对方的grpc连接数
	// RepostingInterval repost retry interval, ms
	RepostingInterval = 50 // 重试广播间隔ms
)
View Source
const (
	// MaxSyncTimes SyncBlocks 最大次数
	MaxSyncTimes = 5
	// MaxSleepMilSecond ...
	MaxSleepMilSecond = 500
)

Variables

View Source
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")
)
View Source
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

func (xc *AChainCore) GenerateTx(in *pb.TxData, hd *global.XContext) *pb.TxStatus

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) Miner

func (xc *AChainCore) Miner() int

Miner start to miner

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

func (xc *AChainCore) QueryAccountACL(accountName string) (*pb.Acl, bool, error)

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) SendBlock

func (xc *AChainCore) SendBlock(in *pb.Block, hd *global.XContext) error

SendBlock send block

func (*AChainCore) Status

func (xc *AChainCore) Status() int

Status return the status of the chain

func (*AChainCore) Stop

func (xc *AChainCore) Stop()

Stop stop one AmpChain instance

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) GetAll

func (xm *AChainMG) GetAll() []string

GetAll returns all blockchains name

func (*AChainMG) HandleSendBlock

func (xm *AChainMG) HandleSendBlock(msg *amper_p2p.AmperMessage)

HandleSendBlock handle SENDBLOCK type msg

func (*AChainMG) Init

func (xm *AChainMG) Init(log log.Logger, cfg *config.NodeConfig,
	p2pV2 p2pv2.P2PServer) error

Init init instance of AChainMG

func (*AChainMG) ProcessBatchTx

func (xm *AChainMG) ProcessBatchTx(batchTx *pb.BatchTxs) (*pb.BatchTxs, error)

ProcessBatchTx process batch tx

func (*AChainMG) ProcessBlock

func (xm *AChainMG) ProcessBlock(block *pb.Block) error

ProcessBlock process block

func (*AChainMG) ProcessTx

func (xm *AChainMG) ProcessTx(in *pb.TxStatus) (*pb.CommonReply, bool, error)

ProcessTx process tx, move from server/server.go

func (*AChainMG) RegisterBlockChain

func (xm *AChainMG) RegisterBlockChain(name string) error

RegisterBlockChain load an instance of blockchain and start it dynamically

func (*AChainMG) RegisterSubscriber

func (xm *AChainMG) RegisterSubscriber() error

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) Start

func (xm *AChainMG) Start()

Start start all blockchain instances

func (*AChainMG) StartLoop

func (xm *AChainMG) StartLoop()

StartLoop dispatch msg received

func (*AChainMG) Stop

func (xm *AChainMG) Stop()

Stop stop all blockchain instances

func (*AChainMG) UnloadBlockChain

func (xm *AChainMG) UnloadBlockChain(name string) error

UnloadBlockChain unload an instance of blockchain and stop it dynamically

Jump to

Keyboard shortcuts

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