Documentation ¶
Overview ¶
统一定义状态机对外暴露功能
Index ¶
- Constants
- Variables
- func GetVersion(txIn *protos.TxInputExt) string
- type BlockAgent
- func (t *BlockAgent) GetBlockid() []byte
- func (t *BlockAgent) GetConsensusStorage() ([]byte, error)
- func (t *BlockAgent) GetHeight() int64
- func (t *BlockAgent) GetInTrunk() bool
- func (t *BlockAgent) GetNextHash() []byte
- func (t *BlockAgent) GetPreHash() []byte
- func (t *BlockAgent) GetProposer() []byte
- func (t *BlockAgent) GetPublicKey() string
- func (t *BlockAgent) GetSign() []byte
- func (t *BlockAgent) GetTimestamp() int64
- func (t *BlockAgent) GetTxIDs() []string
- func (t *BlockAgent) MakeBlockId() ([]byte, error)
- func (t *BlockAgent) SetItem(item string, value interface{}) error
- type BlockHeightNotifier
- type ConsensusStorage
- type InvokeRequest
- type State
- func (t *State) BucketCacheDelete(bucket, version string)
- func (t *State) ClearCache()
- func (t *State) Close()
- func (t *State) CreateSnapshot(blkId []byte) (kledger.XMReader, error)
- func (t *State) CreateUtxoReader() contract.UtxoReader
- func (t *State) CreateXMReader() kledger.XMReader
- func (t *State) CreateXMSnapshotReader(blkId []byte) (kledger.XMSnapshotReader, error)
- func (t *State) DiscountTx(FromAddr string, batch kvdb.Batch, Amount string) (*pb.Transaction, error)
- func (t *State) DoTx(tx *pb.Transaction) error
- func (t *State) GenRWSetFromTx(tx *pb.Transaction) ([]*kledger.VersionedData, []*kledger.PureData, error)
- func (t *State) GetAccountAddresses(accountName string) ([]string, error)
- func (t *State) GetAccountContracts(account string) ([]string, error)
- func (t *State) GetBalance(addr string) (*big.Int, error)
- func (t *State) GetBalanceDetail(addr string) ([]*pb.BalanceDetailInfo, error)
- func (t *State) GetContractStatus(contractName string) (*protos.ContractStatus, error)
- func (t *State) GetFrozenBalance(addr string) (*big.Int, error)
- func (t *State) GetLDB() kvdb.Database
- func (t *State) GetLatestBlockid() []byte
- func (t *State) GetMaxBlockSize() int64
- func (t *State) GetMeta() *pb.UtxoMeta
- func (t *State) GetReservedContractRequests(req []*protos.InvokeRequest, isPreExec bool) ([]*protos.InvokeRequest, error)
- func (t *State) GetTimerTx(blockHeight int64) (*pb.Transaction, error)
- func (t *State) GetTipSnapshot() (kledger.XMReader, error)
- func (t *State) GetTipXMSnapshotReader() (kledger.XMSnapshotReader, error)
- func (t *State) GetTotal() *big.Int
- func (t *State) GetUnconfirmedTx(dedup bool, sizeLimit int) ([]*pb.Transaction, error)
- func (t *State) GetUnconfirmedTxFromId(txid []byte) (*pb.Transaction, bool)
- func (t *State) HasTx(txid []byte) (bool, error)
- func (t *State) ImmediateVerifyAutoTx(blockHeight int64, tx *pb.Transaction, isRootTx bool) (bool, error)
- func (t *State) ImmediateVerifyTx(tx *pb.Transaction, isRootTx bool) (bool, error)
- func (t *State) MaxTxSizePerBlock() (int, error)
- func (t *State) NewBatch() kvdb.Batch
- func (t *State) Play(blockid []byte) error
- func (t *State) PlayAndRepost(blockid []byte, needRepost bool, isRootTx bool) error
- func (t *State) PlayForMiner(blockid []byte) error
- func (t *State) QueryAccountACL(accountName string) (*protos.Acl, error)
- func (t *State) QueryAccountContainAK(address string) ([]string, error)
- func (t *State) QueryAccountGovernTokenBalance(accountName string) (*protos.GovernTokenBalance, error)
- func (t *State) QueryBlock(blockid []byte) (kledger.BlockHandle, error)
- func (t *State) QueryContractMethodACL(contractName string, methodName string) (*protos.Acl, error)
- func (t *State) QueryContractStatData() (*protos.ContractStatData, error)
- func (t *State) QueryTransaction(txid []byte) (*pb2.Transaction, error)
- func (t *State) QueryTx(txid []byte) (*pb.Transaction, bool, error)
- func (t *State) QueryUtxoRecord(accountName string, displayCount int64) (*pb.UtxoRecordDetail, error)
- func (t *State) ReverseTx(FromAddr string, batch kvdb.Batch, Amount string) (*pb.Transaction, error)
- func (t *State) RollBackUnconfirmedTx() (map[string]bool, []*pb.Transaction, error)
- func (t *State) SelectUtxos(fromAddr string, totalNeed *big.Int, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
- func (t *State) SelectUtxosBySize(fromAddr string, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
- func (t *State) SetAclMG(aclMgr aclBase.AclManager)
- func (t *State) SetContractMG(contractMgr contract.Manager)
- func (t *State) SetGovernTokenMG(governTokenMgr governToken.GovManager)
- func (t *State) SetProposalMG(proposalMgr propose.ProposeManager)
- func (t *State) SetTimerTaskMG(timerTaskMgr timerTask.TimerManager)
- func (t *State) StochasticApproximationSelectUtxos(fromAddr string, totalNeed *big.Int, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
- func (t *State) VerifyContractOwnerPermission(contractName string, authRequire []string) error
- func (t *State) VerifyContractPermission(initiator string, authRequire []string, contractName, methodName string) (bool, error)
- func (t *State) VerifyReservedContractRequests(reservedReqs, txReqs []*protos.InvokeRequest) bool
- func (t *State) VerifyReservedWhitelist(tx *pb.Transaction) bool
- func (t *State) VerifyTx(tx *pb.Transaction) (bool, error)
- func (t *State) VerifyTxFee(tx *pb.Transaction) bool
- func (t *State) WaitBlockHeight(target int64) int64
- func (t *State) Walk(blockid []byte, ledgerPrune bool) error
- type TxDesc
Constants ¶
const ( LatestBlockKey = "pointer" // BetaTxVersion 为当前代码支持的最高交易版本 BetaTxVersion = 3 RootTxVersion = 0 FeePlaceholder = "$" // TxSizePercent max percent of txs' size in one block TxSizePercent = 0.8 TxWaitTimeout = 5 )
Variables ¶
var ( ErrDoubleSpent = errors.New("utxo can not be spent more than once") ErrAlreadyInUnconfirmed = errors.New("this transaction is in unconfirmed state") ErrPreBlockMissMatch = errors.New("play block failed because pre-hash != latest_block") ErrUnexpected = errors.New("this is a unexpected error") ErrInvalidAutogenTx = errors.New("found invalid autogen-tx") ErrUTXODuplicated = errors.New("found duplicated utxo in same tx") ErrRWSetInvalid = errors.New("RWSet of transaction invalid") ErrACLNotEnough = errors.New("ACL not enough") ErrInvalidSignature = errors.New("the signature is invalid or not match the address") ErrGasNotEnough = errors.New("Gas not enough") ErrVersionInvalid = errors.New("Invalid tx version") ErrInvalidAccount = errors.New("Invalid account") ErrInvalidTxExt = errors.New("Invalid tx ext") ErrTxTooLarge = errors.New("Tx size is too large") ErrParseContractUtxos = errors.New("Parse contract utxos error") ErrContractTxAmout = errors.New("Contract transfer amount error") ErrGetReservedContracts = errors.New("Get reserved contracts error") ErrMempoolIsFull = errors.New("Mempool is full") )
Functions ¶
func GetVersion ¶
func GetVersion(txIn *protos.TxInputExt) string
Types ¶
type BlockAgent ¶
type BlockAgent struct {
// contains filtered or unexported fields
}
func NewBlockAgent ¶
func NewBlockAgent(blk *lpb.InternalBlock) *BlockAgent
func (*BlockAgent) GetBlockid ¶
func (t *BlockAgent) GetBlockid() []byte
func (*BlockAgent) GetConsensusStorage ¶
func (t *BlockAgent) GetConsensusStorage() ([]byte, error)
共识记录信息,xledger账本由于历史原因需要做下转换
func (*BlockAgent) GetHeight ¶
func (t *BlockAgent) GetHeight() int64
func (*BlockAgent) GetInTrunk ¶
func (t *BlockAgent) GetInTrunk() bool
func (*BlockAgent) GetNextHash ¶
func (t *BlockAgent) GetNextHash() []byte
func (*BlockAgent) GetPreHash ¶
func (t *BlockAgent) GetPreHash() []byte
func (*BlockAgent) GetProposer ¶
func (t *BlockAgent) GetProposer() []byte
func (*BlockAgent) GetPublicKey ¶
func (t *BlockAgent) GetPublicKey() string
func (*BlockAgent) GetSign ¶
func (t *BlockAgent) GetSign() []byte
func (*BlockAgent) GetTimestamp ¶
func (t *BlockAgent) GetTimestamp() int64
func (*BlockAgent) GetTxIDs ¶
func (t *BlockAgent) GetTxIDs() []string
func (*BlockAgent) SetItem ¶
func (t *BlockAgent) SetItem(item string, value interface{}) error
用于pow挖矿时需更新nonce
type BlockHeightNotifier ¶
type BlockHeightNotifier struct {
// contains filtered or unexported fields
}
BlockHeightNotifier hold the the latest block's height information of utxovm and notify listeners when information changed
func NewBlockHeightNotifier ¶
func NewBlockHeightNotifier() *BlockHeightNotifier
NewBlockHeightNotifier instances a new BlockHeightNotifier
func (*BlockHeightNotifier) UpdateHeight ¶
func (b *BlockHeightNotifier) UpdateHeight(height int64)
UpdateHeight update the height information and notify all listeners
func (*BlockHeightNotifier) WaitHeight ¶
func (b *BlockHeightNotifier) WaitHeight(target int64) int64
WaitHeight wait util the height of current block >= target
type ConsensusStorage ¶
type ConsensusStorage struct { TargetBits int32 `json:"targetBits,omitempty"` Justify *lpb.QuorumCert `json:"justify,omitempty"` CurTerm int64 `json:"curTerm,omitempty"` CurBlockNum int64 `json:"curBlockNum,omitempty"` }
兼容xledger账本历史原因共识部分字段分开存储在区块中
type InvokeRequest ¶
type InvokeRequest struct { ModuleName string `json:"module_name" mapstructure:"module_name"` ContractName string `json:"contract_name" mapstructure:"contract_name"` MethodName string `json:"method_name" mapstructure:"method_name"` Args map[string]string `json:"args" mapstructure:"args"` }
InvokeRequest define genesis reserved_contracts configure
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) BucketCacheDelete ¶
func (*State) ClearCache ¶
func (t *State) ClearCache()
func (*State) CreateSnapshot ¶
根据指定blockid创建快照(Select方法不可用)
func (*State) CreateUtxoReader ¶
func (t *State) CreateUtxoReader() contract.UtxoReader
func (*State) CreateXMSnapshotReader ¶
func (t *State) CreateXMSnapshotReader(blkId []byte) (kledger.XMSnapshotReader, error)
根据指定blockid创建快照(相比XMReader,只有Get方法,直接返回[]byte)
func (*State) DiscountTx ¶
func (t *State) DiscountTx(FromAddr string, batch kvdb.Batch, Amount string) (*pb.Transaction, error)
分红奖励提现,同ReverseTx,只是奖励不再*10^8
func (*State) GenRWSetFromTx ¶
func (t *State) GenRWSetFromTx(tx *pb.Transaction) ([]*kledger.VersionedData, []*kledger.PureData, error)
func (*State) GetAccountAddresses ¶
func (*State) GetAccountContracts ¶
func (*State) GetBalanceDetail ¶
func (t *State) GetBalanceDetail(addr string) ([]*pb.BalanceDetailInfo, error)
GetFrozenBalance 查询Address的被冻结的余额 / 未冻结的余额
func (*State) GetContractStatus ¶
func (t *State) GetContractStatus(contractName string) (*protos.ContractStatus, error)
查询合约状态
func (*State) GetLatestBlockid ¶
func (*State) GetMaxBlockSize ¶
func (*State) GetReservedContractRequests ¶
func (t *State) GetReservedContractRequests(req []*protos.InvokeRequest, isPreExec bool) ([]*protos.InvokeRequest, error)
geReservedContractRequest get reserved contract requests from system params, it doesn't consume gas.
func (*State) GetTimerTx ¶
func (t *State) GetTimerTx(blockHeight int64) (*pb.Transaction, error)
func (*State) GetTipSnapshot ¶
获取最新确认高度快照(Select方法不可用)
func (*State) GetTipXMSnapshotReader ¶
func (t *State) GetTipXMSnapshotReader() (kledger.XMSnapshotReader, error)
获取状态机最新确认高度快照(相比XMReader,只有Get方法,直接返回[]byte)
func (*State) GetUnconfirmedTx ¶
获取一批未确认交易(用于矿工打包区块)
func (*State) GetUnconfirmedTxFromId ¶ added in v1.0.2
func (t *State) GetUnconfirmedTxFromId(txid []byte) (*pb.Transaction, bool)
func (*State) ImmediateVerifyAutoTx ¶
func (t *State) ImmediateVerifyAutoTx(blockHeight int64, tx *pb.Transaction, isRootTx bool) (bool, error)
ImmediateVerifyTx verify auto tx Immediately Transaction verification workflow:
- 其实可以直接判断二者的txid,相同,则包括读写集在内的内容都相同
- verify transaction ID is the same with data hash
- run contract requests and verify if the RWSet result is the same with preExed RWSet (heavy operation, keep it at last)
func (*State) ImmediateVerifyTx ¶
ImmediateVerifyTx verify tx Immediately Transaction verification workflow:
- verify transaction ID is the same with data hash
- verify all signatures of initiator and auth requires
- verify the utxo input, there are three kinds of input validation 1). PKI technology for transferring from address 2). Account ACL for transferring from account 3). Contract logic transferring from contract
- verify the contract requests' permission
- verify the permission of contract RWSet (WriteSet could including unauthorized data change)
- run contract requests and verify if the RWSet result is the same with preExed RWSet (heavy operation, keep it at last)
func (*State) MaxTxSizePerBlock ¶
func (*State) PlayAndRepost ¶
执行和发送区块 PlayAndRepost 执行一个新收到的block,要求block的pre_hash必须是当前vm的latest_block 执行后会更新latestBlockid
func (*State) PlayForMiner ¶
func (*State) QueryAccountACL ¶
func (*State) QueryAccountContainAK ¶
func (*State) QueryAccountGovernTokenBalance ¶
func (t *State) QueryAccountGovernTokenBalance(accountName string) (*protos.GovernTokenBalance, error)
func (*State) QueryBlock ¶
func (t *State) QueryBlock(blockid []byte) (kledger.BlockHandle, error)
func (*State) QueryContractMethodACL ¶
func (*State) QueryContractStatData ¶
func (t *State) QueryContractStatData() (*protos.ContractStatData, error)
func (*State) QueryTransaction ¶
func (t *State) QueryTransaction(txid []byte) (*pb2.Transaction, error)
func (*State) QueryUtxoRecord ¶
func (*State) ReverseTx ¶
func (t *State) ReverseTx(FromAddr string, batch kvdb.Batch, Amount string) (*pb.Transaction, error)
(目前是凭空产生的,这笔产生的资源不加入系统的总资源)
func (*State) RollBackUnconfirmedTx ¶
回滚全部未确认交易
func (*State) SelectUtxos ¶
func (t *State) SelectUtxos(fromAddr string, totalNeed *big.Int, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
选择足够金额的utxo
func (*State) SelectUtxosBySize ¶
func (*State) SetAclMG ¶
func (t *State) SetAclMG(aclMgr aclBase.AclManager)
func (*State) SetContractMG ¶
func (*State) SetGovernTokenMG ¶
func (t *State) SetGovernTokenMG(governTokenMgr governToken.GovManager)
func (*State) SetProposalMG ¶
func (t *State) SetProposalMG(proposalMgr propose.ProposeManager)
func (*State) SetTimerTaskMG ¶
func (t *State) SetTimerTaskMG(timerTaskMgr timerTask.TimerManager)
func (*State) StochasticApproximationSelectUtxos ¶
func (t *State) StochasticApproximationSelectUtxos(fromAddr string, totalNeed *big.Int, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)
随机逼近法选择utxo
func (*State) VerifyContractOwnerPermission ¶
VerifyContractOwnerPermission implement Contract ChainCore, used to verify contract ownership permisson
func (*State) VerifyContractPermission ¶
func (t *State) VerifyContractPermission(initiator string, authRequire []string, contractName, methodName string) (bool, error)
VerifyContractPermission implement Contract ChainCore, used to verify contract permission while contract running
func (*State) VerifyReservedContractRequests ¶
func (t *State) VerifyReservedContractRequests(reservedReqs, txReqs []*protos.InvokeRequest) bool
func (*State) VerifyReservedWhitelist ¶
func (t *State) VerifyReservedWhitelist(tx *pb.Transaction) bool
It will check whether the transaction in reserved whitelist if the config of chain contains reserved contracts but the transaction does not contains reserved requests.
func (*State) VerifyTx ¶
func (t *State) VerifyTx(tx *pb.Transaction) (bool, error)
校验交易 VerifyTx check the tx signature and permission
func (*State) WaitBlockHeight ¶
WaitBlockHeight wait util the height of current block >= target