blockmgr

package
v0.0.0-...-a173fca Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: LGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGasPrice = params.GWei

DefaultGasPrice gets default gas price.

View Source
const (
	MODULENAME = "blockmgr"
)

Variables

View Source
var (
	// DefaultOracleConfig define default config of oracle
	DefaultOracleConfig = OracleConfig{
		Blocks:     20,
		Default:    30000,
		Percentile: 60,
		MaxPrice:   big.NewInt(500 * params.GWei).Uint64(),
	}
	// DefaultChainConfig define default config of chain
	DefaultChainConfig = &BlockMgrConfig{
		GasPrice:    DefaultOracleConfig,
		JournalFile: "txpool/txs",
	}
)
View Source
var (
	// ErrBlockNotFound print error message.
	ErrBlockNotFound = errors.New("block not exist")
	// ErrTxIndexOutOfRange print error message.
	ErrTxIndexOutOfRange = errors.New("transaction index out of range")
	// ErrReachGasLimit print error message.
	ErrReachGasLimit = errors.New("gas limit reached")
	// ErrOverFlowMaxMsgSize print error message.
	ErrOverFlowMaxMsgSize = errors.New("msg exceed max size")
	// ErrEnoughPeer print error message.
	ErrEnoughPeer = errors.New("peer exceed max peers")
	// ErrNotContinueHeader print error message.
	ErrNotContinueHeader = errors.New("non contiguous header")
	// ErrFindAncesstorTimeout print error message.
	ErrFindAncesstorTimeout = errors.New("findAncestor timeout")
	// ErrGetHeaderHashTimeout print error message.
	ErrGetHeaderHashTimeout = errors.New("get header hash timeout")
	// ErrGetBlockTimeout print error message.
	ErrGetBlockTimeout = errors.New("fetch blocks timeout")
	// ErrReqStateTimeout print error message.
	ErrReqStateTimeout = errors.New("req state timeout")
	// ErrDecodeMsg print error message.
	ErrDecodeMsg = errors.New("fail to decode p2p msg")
	// ErrMsgType print error message.
	ErrMsgType = errors.New("not expected msg type")
	// ErrNegativeAmount print error message.
	ErrNegativeAmount = errors.New("negative amount in transaction")
	// ErrExceedGasLimit print error message.
	ErrExceedGasLimit = errors.New("gas limit in transaction has exceed block limit")
	// ErrBalance print error message.
	ErrBalance = errors.New("not enough balance")
	// ErrNotSupportRenameAlias print error message.
	ErrNotSupportRenameAlias = errors.New("not suppport rename alias")
	// ErrNoCommonAncesstor print error message.
	ErrNoCommonAncesstor = errors.New("no common ancesstor")
)

Functions

This section is empty.

Types

type BlockMgr

type BlockMgr struct {
	// ChainService define service interface of chain
	ChainService chain.ChainServiceInterface `service:"chain"`
	// RpcService define service interface of rpc
	RpcService *rpc2.RpcService `service:"rpc"`
	// P2pServer define interface of p2p
	P2pServer p2pService.P2P `service:"p2p"`
	// P2pServer define service interface of database
	DatabaseService *database.DatabaseService `service:"database"`

	Config *BlockMgrConfig
	// contains filtered or unexported fields
}

BlockMgr is an overarching block manager that can communicate with various backends for preducing blocks.

func NewBlockMgr

func NewBlockMgr(config *BlockMgrConfig, homeDir string, cs chain.ChainServiceInterface, p2pservice p2pService.P2P) *BlockMgr

NewBlockMgr init all need of block management

func (*BlockMgr) Api

func (blockMgr *BlockMgr) Api() []app.API

Api return an array of block management api

func (*BlockMgr) BroadcastBlock

func (blockMgr *BlockMgr) BroadcastBlock(msgType int32, block *types.Block, isLocal bool)

BroadcastBlock broadcasts block until receive more than 2/3 of peers.

func (*BlockMgr) BroadcastTx

func (blockMgr *BlockMgr) BroadcastTx(msgType int32, tx *types.Transaction, isLocal bool)

BroadcastTx broadcasts transaction until receive more than 2/3 of peers.

func (*BlockMgr) CommandFlags

func (blockMgr *BlockMgr) CommandFlags() ([]cli.Command, []cli.Flag)

CommandFlags return an array interface of flag

func (*BlockMgr) DefaultConfig

func (blockMgr *BlockMgr) DefaultConfig(netType params.NetType) *BlockMgrConfig

DefaultConfig gets default config of blockchain.

func (*BlockMgr) GenerateTemplate

func (blockMgr *BlockMgr) GenerateTemplate(trieStore chainStore.StoreInterface, leaderAddr crypto.CommonAddress, blockInterval int) (*types.Block, *big.Int, error)

GenerateTemplate blockchain t

func (*BlockMgr) GetBestPeerInfo

func (blockMgr *BlockMgr) GetBestPeerInfo() types.PeerInfoInterface

func (*BlockMgr) GetPoolMiniPendingNonce

func (blockMgr *BlockMgr) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64

GetPoolMiniPendingNonce gets the smallest nonce in the Pending queue

func (*BlockMgr) GetPoolTransactions

func (blockMgr *BlockMgr) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions

GetPoolTransactions gets all the trades in the current pool.

func (*BlockMgr) GetTransactionCount

func (blockMgr *BlockMgr) GetTransactionCount(addr *crypto.CommonAddress) uint64

GetTransactionCount gets the total number of transactions, that is, the nonce corresponding to the address.

func (*BlockMgr) GetTxInPool

func (blockMgr *BlockMgr) GetTxInPool(hash string) (*types.Transaction, error)

GetTxInPool gets transactions in the trading pool.

func (*BlockMgr) HandleBlockReqMsg

func (blockMgr *BlockMgr) HandleBlockReqMsg(peer types.PeerInfoInterface, req *types.BlockReq)

func (*BlockMgr) HandleBlockRespMsg

func (blockMgr *BlockMgr) HandleBlockRespMsg(peer types.PeerInfoInterface, rsp *types.BlockResp)

func (*BlockMgr) Init

func (blockMgr *BlockMgr) Init(executeContext *app.ExecuteContext) error

Init function init block from initial config.

func (*BlockMgr) Name

func (blockMgr *BlockMgr) Name() string

Name return package name

func (*BlockMgr) NewTxFeed

func (blockMgr *BlockMgr) NewTxFeed() *event.Feed

NewTxFeed gets transaction feed in the trading pool.

func (*BlockMgr) SendTransaction

func (blockMgr *BlockMgr) SendTransaction(tx *types.Transaction, islocal bool) error

SendTransaction adds local signed transaction and broadcast it.

func (*BlockMgr) Start

func (blockMgr *BlockMgr) Start(executeContext *app.ExecuteContext) error

Start syn block and transactions.

func (*BlockMgr) Stop

func (blockMgr *BlockMgr) Stop(executeContext *app.ExecuteContext) error

Stop blockchain.

func (*BlockMgr) SubscribeSyncBlockEvent

func (blockMgr *BlockMgr) SubscribeSyncBlockEvent(subchan chan event.SyncBlockEvent) event.Subscription

SubscribeSyncBlockEvent gets a channel from the feed.

type BlockMgrAPI

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

name: Block management usage: For processing block chain partial upper logic prefix:blockMgr

func (*BlockMgrAPI) GasPrice

func (blockMgrApi *BlockMgrAPI) GasPrice() (*big.Int, error)
 name: gasPrice
 usage: Get the recommended value of gasprice given by the system
 params:
	1. Query address
 return: Price and error message
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_gasPrice","params":[], "id": 3}' -H "Content-Type:application/json"
 response:

func (*BlockMgrAPI) GetPoolMiniPendingNonce

func (blockMgrApi *BlockMgrAPI) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
 name: GetPoolMiniPendingNonce
 usage: Get the smallest Nonce in the pending queue
 params:
	1. Query address
 return: The smallest nonce in the pending queue
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_getPoolMiniPendingNonce","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:

func (*BlockMgrAPI) GetPoolTransactions

func (blockMgrApi *BlockMgrAPI) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
 name: GetPoolTransactions
 usage: Get trading information in the trading pool.
 params:
	1. Query address
 return: All transactions in the pool
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_getPoolTransactions","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:

func (*BlockMgrAPI) GetTransactionCount

func (blockMgrApi *BlockMgrAPI) GetTransactionCount(addr *crypto.CommonAddress) uint64
 name: GetTransactionCount
 usage: Gets the total number of transactions issued by the address
 params:
	1. Query address
 return: All transactions in the pool
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_getTransactionCount","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:

func (*BlockMgrAPI) GetTxInPool

func (blockMgrApi *BlockMgrAPI) GetTxInPool(hash string) (*types.Transaction, error)
 name: GetTxInPool
 usage: Checks whether the transaction is in the trading pool and, if so, return the transaction
 params:
	1. The address at which the transfer was initiated

 return: Complete transaction information
 example: curl -H "Content-Type: application/json" -X post --data '{"jsonrpc":"2.0","method":"blockmgr_getTxInPool","params":["0x3ebcbe7cb440dd8c52940a2963472380afbb56c5"],"id":1}' http://127.0.0.1:10085
 response:
   {
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "Hash": "0xfa5c34114ff459b4c97e7cd268c507c0ccfcfc89d3ccdcf71e96402f9899d040",
    "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a",
    "Version": 1,
    "Nonce": 15632,
    "Type": 0,
    "To": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a",
    "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "Amount": "0x111",
    "GasPrice": "0x110",
    "GasLimit": "0x30000",
    "Timestamp": 1559322808,
    "Data": null,
    "Sig": "0x20f25b86c4bf73aa4fa0bcb01e2f5731de3a3917c8861d1ce0574a8d8331aedcf001e678000f6afc95d35a53ef623a2055fce687f85c2fd752dc455ab6db802b1f"
  }
}

func (*BlockMgrAPI) SendRawTransaction

func (blockMgrApi *BlockMgrAPI) SendRawTransaction(txbytes common.Bytes) (string, error)
 name: sendRawTransaction
 usage: Send signed transactions
 params:
	1. A signed transaction
 return: transaction hash
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_sendRawTransaction","params":["0x40a287b6d30b05313131317a4120dd8c23c40910d038fa43b2f8932d3681cbe5ee3079b6e9de0bea6e8e6b2a867a561aa26e1cd6b62aa0422a043186b593b784bf80845c3fd5a7fbfe62e61d8564"], "id": 3}' -H "Content-Type:application/json"
 response:
	{"jsonrpc":"2.0","id":1,"result":"0xf30e858667fa63bc57ae395c3f57ede9bb3ad4969d12f4bce51d900fb5931538"}

type BlockMgrConfig

type BlockMgrConfig struct {
	GasPrice    OracleConfig `json:"gasprice"`
	JournalFile string       `json:"journalFile"`
}

BlockMgrConfig defines gasprice & journal file type.

type IBlockBlockGenerator

type IBlockBlockGenerator interface {
	//generate block template
	GenerateTemplate(trieStore chainStore.StoreInterface, leaderAddr crypto.CommonAddress, blockInterval int) (*types.Block, *big.Int, error)
}

IBlockBlockGenerator interface

type IBlockMgr

IBlockMgr interface

type IBlockMgrPool

type IBlockMgrPool interface {
	//query tx pool message
	GetTransactionCount(addr *crypto.CommonAddress) uint64
	GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
	GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
	GetTxInPool(hash string) (*types.Transaction, error)
}

IBlockMgrPool interface

type IBlockNotify

type IBlockNotify interface {
	//notify
	SubscribeSyncBlockEvent(subchan chan event.SyncBlockEvent) event.Subscription
	NewTxFeed() *event.Feed
}

IBlockNotify interface

type ISendMessage

type ISendMessage interface {
	// send
	SendTransaction(tx *types.Transaction, islocal bool) error
	BroadcastBlock(msgType int32, block *types.Block, isLocal bool)
	BroadcastTx(msgType int32, tx *types.Transaction, isLocal bool)
}

ISendMessage interface

type Oracle

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

Oracle recommends gas prices based on the content of recent blocks. Suitable for both light and full clients.

func NewOracle

func NewOracle(chainService xxx.ChainServiceInterface, params OracleConfig) *Oracle

NewOracle returns a new oracle.

func (*Oracle) SuggestPrice

func (gpo *Oracle) SuggestPrice() (*big.Int, error)

SuggestPrice returns the recommended gas price.

type OracleConfig

type OracleConfig struct {
	Blocks     int    `json:"blocks"`
	Percentile int    `json:"percentile"`
	Default    uint64 `json:"default"`
	MaxPrice   uint64 `json:"maxPrice"`
}

OracleConfig manages gas price of block.

type TemplateBlockValidator

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

func NewTemplateBlockValidator

func NewTemplateBlockValidator(chain chain.ChainServiceInterface) *TemplateBlockValidator

func (*TemplateBlockValidator) ExecuteBlock

func (chainBlockValidator *TemplateBlockValidator) ExecuteBlock(context *block.BlockExecuteContext, blockInterval int) error

func (*TemplateBlockValidator) RouteTransaction

func (chainBlockValidator *TemplateBlockValidator) RouteTransaction(context *block.BlockExecuteContext, gasPool *utils.GasPool, tx *types.Transaction) (*types.Receipt, uint64, error)

func (*TemplateBlockValidator) VerifyBody

func (chainBlockValidator *TemplateBlockValidator) VerifyBody(block *types.Block) error

func (*TemplateBlockValidator) VerifyHeader

func (chainBlockValidator *TemplateBlockValidator) VerifyHeader(header, parent *types.BlockHeader) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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