Documentation ¶
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 State
- func (t *State) BucketCacheDelete(bucket, version string)
- func (t *State) ClearCache()
- func (t *State) Close()
- func (t *State) CreateSnapshot(blkId []byte) (ledger.XReader, error)
- func (t *State) CreateUtxoReader() contractBase.UtxoReader
- func (t *State) CreateXMReader() ledger.XReader
- func (t *State) CreateXMSnapshotReader(blkId []byte) (ledger.SnapshotReader, error)
- func (t *State) DoTx(tx *protos.Transaction) error
- func (t *State) GenRWSetFromTx(tx *protos.Transaction) ([]*ledger.VersionedData, []*ledger.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) ([]*protos.BalanceDetailInfo, error)
- func (t *State) GetContractStatus(contractName string) (*protos.ContractStatus, error)
- func (t *State) GetFrozenBalance(addr string) (*big.Int, error)
- func (t *State) GetLDB() storage.Database
- func (t *State) GetLatestBlockid() []byte
- func (t *State) GetMaxBlockSize() int64
- func (t *State) GetMeta() *protos.UtxoMeta
- func (t *State) GetReservedContractRequests(req []*protos.InvokeRequest, isPreExec bool) ([]*protos.InvokeRequest, error)
- func (t *State) GetTimerTx(blockHeight int64) (*protos.Transaction, error)
- func (t *State) GetTipSnapshot() (ledger.XReader, error)
- func (t *State) GetTipXMSnapshotReader() (ledger.SnapshotReader, error)
- func (t *State) GetTotal() *big.Int
- func (t *State) GetUnconfirmedTx(dedup bool, sizeLimit int) ([]*protos.Transaction, error)
- func (t *State) GetUnconfirmedTxFromId(txid []byte) (*protos.Transaction, bool)
- func (t *State) HasTx(txid []byte) (bool, error)
- func (t *State) ImmediateVerifyAutoTx(blockHeight int64, tx *protos.Transaction, isRootTx bool) (bool, error)
- func (t *State) ImmediateVerifyTx(tx *protos.Transaction, isRootTx bool) (bool, error)
- func (t *State) MaxTxSizePerBlock() (int, error)
- func (t *State) NewBatch() storage.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) (ledger.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) (*protos.Transaction, error)
- func (t *State) QueryTx(txid []byte) (*protos.Transaction, bool, error)
- func (t *State) QueryUtxoRecord(accountName string, displayCount int64) (*protos.UtxoRecordDetail, error)
- func (t *State) RollBackUnconfirmedTx() (map[string]bool, []*protos.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 base.AclManager)
- func (t *State) SetContractMG(contractMgr contractBase.Manager)
- func (t *State) SetGovernTokenMG(governTokenMgr govern.GovManager)
- func (t *State) SetProposalMG(proposalMgr propose.ProposeManager)
- func (t *State) SetTimerTaskMG(timerTaskMgr ptimer.TimerManager)
- 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 *protos.Transaction) bool
- func (t *State) VerifyTx(tx *protos.Transaction) (bool, error)
- func (t *State) WaitBlockHeight(target int64) int64
- func (t *State) Walk(blockid []byte, ledgerPrune bool) error
Constants ¶
const ( LatestBlockKey = "pointer" BetaTxVersion = 3 // 当前支持的最高交易版本 RootTxVersion = 0 FeePlaceholder = "$" TxSizePercent = 0.8 //max percent of txs' size in one block 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("TxHandler 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 *protos.InternalBlock) *BlockAgent
func (*BlockAgent) GetBlockid ¶
func (t *BlockAgent) GetBlockid() []byte
func (*BlockAgent) GetConsensusStorage ¶
func (t *BlockAgent) GetConsensusStorage() ([]byte, error)
GetConsensusStorage 获取共识记录信息
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) MakeBlockId ¶
func (t *BlockAgent) MakeBlockId() ([]byte, error)
MakeBlockId 设置并返回BlockId
func (*BlockAgent) SetItem ¶
func (t *BlockAgent) SetItem(item string, value interface{}) error
SetItem 用于pow挖矿时更新nonce,或者设置blockid和sign
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 *protos.QuorumCert `json:"justify,omitempty"` CurTerm int64 `json:"curTerm,omitempty"` CurBlockNum int64 `json:"curBlockNum,omitempty"` }
ConsensusStorage 共识部分字段分开存储在区块中
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() contractBase.UtxoReader
func (*State) CreateXMSnapshotReader ¶
func (t *State) CreateXMSnapshotReader(blkId []byte) (ledger.SnapshotReader, error)
根据指定blockid创建快照(相比XMReader,只有Get方法,直接返回[]byte)
func (*State) GenRWSetFromTx ¶
func (t *State) GenRWSetFromTx(tx *protos.Transaction) ([]*ledger.VersionedData, []*ledger.PureData, error)
func (*State) GetAccountAddresses ¶
func (*State) GetAccountContracts ¶
func (*State) GetBalanceDetail ¶
func (t *State) GetBalanceDetail(addr string) ([]*protos.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)
GetReservedContractRequests get reserved contract requests from system params, it doesn't consume gas.
func (*State) GetTimerTx ¶
func (t *State) GetTimerTx(blockHeight int64) (*protos.Transaction, error)
func (*State) GetTipSnapshot ¶
获取最新确认高度快照(Select方法不可用)
func (*State) GetTipXMSnapshotReader ¶
func (t *State) GetTipXMSnapshotReader() (ledger.SnapshotReader, error)
获取状态机最新确认高度快照(相比XMReader,只有Get方法,直接返回[]byte)
func (*State) GetUnconfirmedTx ¶
获取一批未确认交易(用于矿工打包区块)
func (*State) GetUnconfirmedTxFromId ¶
func (t *State) GetUnconfirmedTxFromId(txid []byte) (*protos.Transaction, bool)
func (*State) ImmediateVerifyAutoTx ¶
func (t *State) ImmediateVerifyAutoTx(blockHeight int64, tx *protos.Transaction, isRootTx bool) (bool, error)
ImmediateVerifyAutoTx verify auto tx Immediately Transaction verification workflow:
- 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) (ledger.BlockHandle, error)
func (*State) QueryContractMethodACL ¶
func (*State) QueryContractStatData ¶
func (t *State) QueryContractStatData() (*protos.ContractStatData, error)
func (*State) QueryTransaction ¶
func (t *State) QueryTransaction(txid []byte) (*protos.Transaction, error)
func (*State) QueryUtxoRecord ¶
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 base.AclManager)
func (*State) SetContractMG ¶
func (t *State) SetContractMG(contractMgr contractBase.Manager)
func (*State) SetGovernTokenMG ¶
func (t *State) SetGovernTokenMG(governTokenMgr govern.GovManager)
func (*State) SetProposalMG ¶
func (t *State) SetProposalMG(proposalMgr propose.ProposeManager)
func (*State) SetTimerTaskMG ¶
func (t *State) SetTimerTaskMG(timerTaskMgr ptimer.TimerManager)
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 *protos.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 *protos.Transaction) (bool, error)
校验交易 VerifyTx check the tx signature and permission
func (*State) WaitBlockHeight ¶
WaitBlockHeight wait util the height of current block >= target