tx

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: 17 Imported by: 0

Documentation

Overview

package txn deals with tx data

Index

Constants

View Source
const (
	TxVersion                = 1
	RootTxVersion            = 0
	DefaultMaxConfirmedDelay = 300
)

Variables

View Source
var (
	ErrNegativeAmount = errors.New("amount in transaction can not be negative number")
	ErrTxNotFound     = errors.New("transaction not found")
	ErrUnexpected     = errors.New("this is a unexpected error")
)
View Source
var (
	// ErrTxExist tx already in mempool when put tx.
	ErrTxExist = errors.New("tx already in mempool")
)

Functions

func GenerateAutoTxWithRWSets

func GenerateAutoTxWithRWSets(inputs []*protos.TxInputExt, outputs []*protos.TxOutputExt) (*protos.Transaction, error)

生成只有读写集的空交易

func GenerateAwardTx

func GenerateAwardTx(address, awardAmount string, desc []byte) (*protos.Transaction, error)

生成奖励TX

func GenerateEmptyTx

func GenerateEmptyTx(desc []byte) (*protos.Transaction, error)

生成只有Desc的空交易

func GenerateRootTx

func GenerateRootTx(js []byte) (*protos.Transaction, error)

通过创世块配置生成创世区块交易

func ParseContractTransferRequest

func ParseContractTransferRequest(requests []*protos.InvokeRequest) (string, *big.Int, error)

func SplitToDags

func SplitToDags(block *protos.InternalBlock) [][]*protos.Transaction

func TopSortDFS

func TopSortDFS(g TxGraph) (order []string, cyclic bool, childDAGSize []int)

TopSortDFS 对依赖关系图进行拓扑排序 输入:TxGraph: 依赖关系图 输出: order: 排序后的有序数组,依赖者排在前面,被依赖的排在后面

cyclic: 如果发现有环形依赖关系则输出这个数组

实现参考: https://rosettacode.org/wiki/Topological_sort#Go

Types

type Mempool

type Mempool struct {
	Tx *TxHandler
	// contains filtered or unexported fields
}

Mempool tx mempool.

func NewMempool

func NewMempool(tx *TxHandler, log logger.Logger, txLimit int) *Mempool

NewMempool new mempool.

func (*Mempool) BatchConfirmTx

func (m *Mempool) BatchConfirmTx(txs []*protos.Transaction)

BatchConfirmTx 批量确认交易

func (*Mempool) BatchConfirmTxID

func (m *Mempool) BatchConfirmTxID(txids []string)

BatchConfirmTxID 批量确认交易ID

func (*Mempool) BatchDeleteTx

func (m *Mempool) BatchDeleteTx(txs []*protos.Transaction)

BatchDeleteTx 从 mempool 删除所有 txs。

func (*Mempool) ConfirmTx

func (m *Mempool) ConfirmTx(tx *protos.Transaction) error

ConfirmTx confirm tx. 将 tx 从未确认交易表放入确认交易表,或者删除。

func (*Mempool) ConfirmTxID

func (m *Mempool) ConfirmTxID(txid string)

ConfirmTxID txid

func (*Mempool) DeleteTxAndChildren

func (m *Mempool) DeleteTxAndChildren(txid string) []*protos.Transaction

DeleteTxAndChildren delete tx from mempool. 返回交易是从子交易到父交易顺序。

func (*Mempool) FindConflictByTx

func (m *Mempool) FindConflictByTx(tx *protos.Transaction) []*protos.Transaction

FindConflictByTx 找出所有与 tx 冲突的交易。返回数组中,前面是子交易,后面是父交易。 保证事物原子性,此接口不删除交易,只返回交易列表。

func (*Mempool) Full

func (m *Mempool) Full() bool

func (*Mempool) GetTx

func (m *Mempool) GetTx(txid string) (*protos.Transaction, bool)

GetTx 从 mempool 中查询一笔交易,先查未确认交易表,然后是孤儿交易表。

func (*Mempool) GetTxCounnt

func (m *Mempool) GetTxCounnt() int

GetTxCounnt get 获取未确认交易与孤儿交易总数

func (*Mempool) HasTx

func (m *Mempool) HasTx(txid string) bool

HasTx has tx in mempool.

func (*Mempool) PutTx

func (m *Mempool) PutTx(tx *protos.Transaction) error

PutTx put tx.

func (*Mempool) Range

func (m *Mempool) Range(f func(tx *protos.Transaction) bool)

Range 按照拓扑排序遍历节点交易。

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node tx wrapper.

func NewNode

func NewNode(txid string, tx *protos.Transaction) *Node

NewNode new node.

type RootJSON

type RootJSON struct {
	Version   string `json:"version"`
	Consensus struct {
		Miner string `json:"miner"`
	} `json:"consensus"`
	Predistribution []struct {
		Address string `json:"address"`
		Quota   string `json:"quota"`
	} `json:"predistribution"`
}

RootJSON xuper.json对应的struct,目前先只写了utxovm关注的字段

type TxGraph

type TxGraph map[string][]string

交易依赖关系图

type TxHandler

type TxHandler struct {
	UnconfirmTxAmount int64
	// UnconfirmTxInMem  *sync.Map // 使用新版 mempool 就不用这个字段了。
	AvgDelay int64

	Mempool *Mempool
	// contains filtered or unexported fields
}

func NewTxHandler

func NewTxHandler(sctx *base.StateCtx, stateDB storage.Database) (*TxHandler, error)

func (*TxHandler) GetDelayedTxs

func (t *TxHandler) GetDelayedTxs() []*protos.Transaction

GetDelayedTxs 获取当前 mempool 中超时的交易。

func (*TxHandler) GetUnconfirmedTx

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

GetUnconfirmedTx 挖掘一批unconfirmed的交易打包,返回的结果要保证是按照交易执行的先后顺序 maxSize: 打包交易最大的长度(in byte), -1(小于0) 表示不限制

func (*TxHandler) LoadUnconfirmedTxFromDisk

func (t *TxHandler) LoadUnconfirmedTxFromDisk() error

从disk还原unconfirm表到内存, 初始化的时候

func (*TxHandler) QueryTx

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

QueryTx 查询一笔交易,从unconfirm表中查询

func (*TxHandler) SetMaxConfirmedDelay

func (t *TxHandler) SetMaxConfirmedDelay(seconds uint32)

func (*TxHandler) SortUnconfirmedTx

func (t *TxHandler) SortUnconfirmedTx(sizeLimit int) ([]*protos.Transaction, []*protos.Transaction, error)

SortUnconfirmedTx 返回未确认交易列表以及延迟时间过长交易。

Jump to

Keyboard shortcuts

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