state

package
v0.0.0-...-b124b1e Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LatestBlockKey = "pointer"
	BetaTxVersion  = 3 // 当前支持的最高交易版本
	RootTxVersion  = 0
	FeePlaceholder = "$"
	TxSizePercent  = 0.8 //max percent of txs' size in one block
	TxWaitTimeout  = 5
)

Variables

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

func (t *BlockAgent) GetTimestamp() int64

GetTimestamp 获取区块的时间戳

func (*BlockAgent) GetTxIDs

func (t *BlockAgent) GetTxIDs() []string

GetTxIDs 获取区块中所有交易的id列表

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 NewState

func NewState(sctx *stateBase.StateCtx) (*State, error)

NewState 新建状态机

func (*State) BucketCacheDelete

func (t *State) BucketCacheDelete(bucket, version string)

func (*State) ClearCache

func (t *State) ClearCache()

func (*State) Close

func (t *State) Close()

func (*State) CreateSnapshot

func (t *State) CreateSnapshot(blkId []byte) (ledger.XReader, error)

根据指定blockid创建快照(Select方法不可用)

func (*State) CreateUtxoReader

func (t *State) CreateUtxoReader() contractBase.UtxoReader

func (*State) CreateXMReader

func (t *State) CreateXMReader() ledger.XReader

创建获取最新状态数据XMReader

func (*State) CreateXMSnapshotReader

func (t *State) CreateXMSnapshotReader(blkId []byte) (ledger.SnapshotReader, error)

根据指定blockid创建快照(相比XMReader,只有Get方法,直接返回[]byte)

func (*State) DoTx

func (t *State) DoTx(tx *protos.Transaction) error

执行交易

func (*State) GenRWSetFromTx

func (t *State) GenRWSetFromTx(tx *protos.Transaction) ([]*ledger.VersionedData, []*ledger.PureData, error)

func (*State) GetAccountAddresses

func (t *State) GetAccountAddresses(accountName string) ([]string, error)

func (*State) GetAccountContracts

func (t *State) GetAccountContracts(account string) ([]string, error)

func (*State) GetBalance

func (t *State) GetBalance(addr string) (*big.Int, error)

查询账余额

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

func (t *State) GetFrozenBalance(addr string) (*big.Int, error)

func (*State) GetLDB

func (t *State) GetLDB() storage.Database

func (*State) GetLatestBlockid

func (t *State) GetLatestBlockid() []byte

func (*State) GetMaxBlockSize

func (t *State) GetMaxBlockSize() int64

func (*State) GetMeta

func (t *State) GetMeta() *protos.UtxoMeta

查找状态机meta信息

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

func (t *State) GetTipSnapshot() (ledger.XReader, error)

获取最新确认高度快照(Select方法不可用)

func (*State) GetTipXMSnapshotReader

func (t *State) GetTipXMSnapshotReader() (ledger.SnapshotReader, error)

获取状态机最新确认高度快照(相比XMReader,只有Get方法,直接返回[]byte)

func (*State) GetTotal

func (t *State) GetTotal() *big.Int

GetTotal 返回当前总资产

func (*State) GetUnconfirmedTx

func (t *State) GetUnconfirmedTx(dedup bool, sizeLimit int) ([]*protos.Transaction, error)

获取一批未确认交易(用于矿工打包区块)

func (*State) GetUnconfirmedTxFromId

func (t *State) GetUnconfirmedTxFromId(txid []byte) (*protos.Transaction, bool)

func (*State) HasTx

func (t *State) HasTx(txid []byte) (bool, error)

HasTx 查询一笔交易是否在unconfirm表 这些可能是放在tx对外提供

func (*State) ImmediateVerifyAutoTx

func (t *State) ImmediateVerifyAutoTx(blockHeight int64, tx *protos.Transaction, isRootTx bool) (bool, error)

ImmediateVerifyAutoTx verify auto tx Immediately Transaction verification workflow:

  1. verify transaction ID is the same with data hash
  2. run contract requests and verify if the RWSet result is the same with preExed RWSet (heavy operation, keep it at last)

func (*State) ImmediateVerifyTx

func (t *State) ImmediateVerifyTx(tx *protos.Transaction, isRootTx bool) (bool, error)

ImmediateVerifyTx verify tx Immediately Transaction verification workflow:

  1. verify transaction ID is the same with data hash
  2. verify all signatures of initiator and auth requires
  3. 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
  4. verify the contract requests' permission
  5. verify the permission of contract RWSet (WriteSet could including unauthorized data change)
  6. 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 (t *State) MaxTxSizePerBlock() (int, error)

func (*State) NewBatch

func (t *State) NewBatch() storage.Batch

func (*State) Play

func (t *State) Play(blockid []byte) error

执行区块

func (*State) PlayAndRepost

func (t *State) PlayAndRepost(blockid []byte, needRepost bool, isRootTx bool) error

执行和发送区块 PlayAndRepost 执行一个新收到的block,要求block的pre_hash必须是当前vm的latest_block 执行后会更新latestBlockid

func (*State) PlayForMiner

func (t *State) PlayForMiner(blockid []byte) error

func (*State) QueryAccountACL

func (t *State) QueryAccountACL(accountName string) (*protos.Acl, error)

func (*State) QueryAccountContainAK

func (t *State) QueryAccountContainAK(address string) ([]string, error)

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 (t *State) QueryContractMethodACL(contractName string, methodName string) (*protos.Acl, error)

func (*State) QueryContractStatData

func (t *State) QueryContractStatData() (*protos.ContractStatData, error)

func (*State) QueryTransaction

func (t *State) QueryTransaction(txid []byte) (*protos.Transaction, error)

func (*State) QueryTx

func (t *State) QueryTx(txid []byte) (*protos.Transaction, bool, error)

查询交易

func (*State) QueryUtxoRecord

func (t *State) QueryUtxoRecord(accountName string, displayCount int64) (*protos.UtxoRecordDetail, error)

func (*State) RollBackUnconfirmedTx

func (t *State) RollBackUnconfirmedTx() (map[string]bool, []*protos.Transaction, error)

回滚全部未确认交易

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 (t *State) SelectUtxosBySize(fromAddr string, needLock, excludeUnconfirmed bool) ([]*protos.TxInput, [][]byte, *big.Int, error)

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

func (t *State) VerifyContractOwnerPermission(contractName string, authRequire []string) error

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

func (t *State) WaitBlockHeight(target int64) int64

WaitBlockHeight wait util the height of current block >= target

func (*State) Walk

func (t *State) Walk(blockid []byte, ledgerPrune bool) error

同步账本和状态机

Directories

Path Synopsis
Package utxo is the key part of XuperChain, this module keeps all Unspent Transaction Outputs.
Package utxo is the key part of XuperChain, this module keeps all Unspent Transaction Outputs.

Jump to

Keyboard shortcuts

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