exec

package
v0.0.0-...-8cea40f Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

本包应当使用/ds内的函数和结构体

Index

Constants

View Source
const MAX_POOL_SIZE = 10

MAX_POOL_SIZE PoolSize fixed

Variables

This section is empty.

Functions

func ExamineNewBlock

func ExamineNewBlock(newBlock *ds.Block) bool

验证来自其他节点的区块是否合法

func MiningNewBlock

func MiningNewBlock(txs []entity.Transaction) ds.Block

打包多个交易并生成新区块,生成过程中应不断调整区块nonce值以满足PoW约束

func VerifyNonce

func VerifyNonce(lastNonce uint64, nonce uint64) bool

Types

type AbstractController

type AbstractController interface {
	AddTransaction(entity.Transaction)
	AddBlock(ds.Block)
	QueryAccount([]byte) entity.Account
}

type AbstractTxPool

type AbstractTxPool interface {
	Insert(entity.Transaction)
	Poll() entity.Transaction
	Length() int
	IsFull() bool
}

type Controller

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

用于核心控制的结构体,上层包应当直接调用这里的函数,其他地方的函数不对包外公开

func NewController

func NewController() *Controller

func (*Controller) AddBlock

func (c *Controller) AddBlock(block ds.Block)

加入由其他节点挖出来的新区块。应当先进行验证再加入到本地区块链中,注意加入区块链时是直接对ds进行操作。 验证流程:1.满足PoW约束 2.MPT证明通过

func (*Controller) AddTransaction

func (c *Controller) AddTransaction(tx entity.Transaction)

加入新交易。在交易池未满时放入交易池,交易池已满则进行挖矿,挖矿完成则将新区块返回到Communicator来发布

func (*Controller) QueryAccount

func (c *Controller) QueryAccount(key []byte) entity.Account

询问账号信息,从/ds中得到账号信息并返回

type DefualtTxPool

type DefualtTxPool struct {
	StatDB   *ds.MPT
	Pendings map[string]TxsBlks // map to store pending transactions grouped by nonce
	Queues   map[string]Txs     // queue for out-of-order nonce transactions
	MiniPool Txs                // in order to poll one by one
}

func (*DefualtTxPool) AllSortedByGas

func (pool *DefualtTxPool) AllSortedByGas()

func (*DefualtTxPool) CreateTxsBlk

func (pool *DefualtTxPool) CreateTxsBlk(tx entity.Transaction, address string)

CreateTxsBlk Create Blk and append the first new transaction

func (*DefualtTxPool) DeleteFromPending

func (pool *DefualtTxPool) DeleteFromPending(tx entity.Transaction)

DeleteFromPending Delete the transaction from the pending list

func (*DefualtTxPool) DeleteQueueRow

func (pool *DefualtTxPool) DeleteQueueRow(address string)

func (DefualtTxPool) GetPendingLastNonce

func (pool DefualtTxPool) GetPendingLastNonce(address string) uint64

func (*DefualtTxPool) Insert

func (pool *DefualtTxPool) Insert(tx entity.Transaction)

Insert 向合约池放入新的交易数据

func (*DefualtTxPool) IsFull

func (pool *DefualtTxPool) IsFull() bool

func (*DefualtTxPool) Length

func (pool *DefualtTxPool) Length() int

func (*DefualtTxPool) Poll

func (pool *DefualtTxPool) Poll() entity.Transaction

Poll 从合约池中取出第一个交易,并从合约池中弹出该交易

func (*DefualtTxPool) PollFromQueueToPending

func (pool *DefualtTxPool) PollFromQueueToPending(address string)

PollFromQueueToPending Put the transactions to pending

func (*DefualtTxPool) QueueInsertToPending

func (pool *DefualtTxPool) QueueInsertToPending(tx entity.Transaction, address string)

type SortedTxsBlk

type SortedTxsBlk struct {
	Txs      []entity.Transaction
	GasPrice uint64 // equal to Gas in the transaction struct
	// contains filtered or unexported fields
}

type TxPool

type TxPool interface {
	Insert(tx entity.Transaction)
	Poll() entity.Transaction
	IsFull() bool
	Length() int
}

func NewTxPool

func NewTxPool() TxPool

type Txs

type Txs []entity.Transaction

func (Txs) Len

func (td Txs) Len() int

func (Txs) Less

func (td Txs) Less(i, j int) bool

func (Txs) Swap

func (td Txs) Swap(i, j int)

type TxsBlks

type TxsBlks []SortedTxsBlk

func (TxsBlks) Len

func (td TxsBlks) Len() int

func (TxsBlks) Less

func (td TxsBlks) Less(i, j int) bool

func (TxsBlks) Swap

func (td TxsBlks) Swap(i, j int)

Jump to

Keyboard shortcuts

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