blkmgr

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: ISC Imports: 28 Imported by: 0

Documentation

Overview

Copyright (c) 2020-2021 The bitcoinpay developers Copyright (c) 2016 The btcsuite developers Copyright (c) 2017 The Decred developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	// maxStallDuration is the time after which we will disconnect our
	// current sync peer if we haven't made progress.
	MaxStallDuration = 3 * time.Minute

	// stallSampleInterval the interval at which we will check to see if our
	// sync has stalled.
	StallSampleInterval = 3 * time.Second

	// maxStallDuration is the time after which we will disconnect our
	// current sync peer if we haven't made progress.
	MaxBlockStallDuration = 3 * time.Second
)

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger l.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockManager

type BlockManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BlockManager provides a concurrency safe block manager for handling all incoming blocks.

func NewBlockManager

func NewBlockManager(ntmgr notify.Notify, indexManager blockchain.IndexManager, db database.DB,
	timeSource blockchain.MedianTimeSource, sigCache *txscript.SigCache,
	cfg *config.Config, par *params.Params, blockVersion uint32,
	interrupt <-chan struct{}) (*BlockManager, error)

NewBlockManager returns a new block manager. Use Start to begin processing asynchronous block and inv updates.

func (*BlockManager) API

func (b *BlockManager) API() rpc.API

func (*BlockManager) ChainParams

func (b *BlockManager) ChainParams() *params.Params

Return chain params

func (*BlockManager) Current

func (b *BlockManager) Current() bool

IsCurrent returns whether or not the block manager believes it is synced with the connected peers.

func (*BlockManager) DAGSync

func (b *BlockManager) DAGSync() *blockdag.DAGSync

DAGSync

func (*BlockManager) DonePeer

func (b *BlockManager) DonePeer(sp *peer.ServerPeer)

DonePeer informs the blockmanager that a peer has disconnected.

func (*BlockManager) GetChain

func (b *BlockManager) GetChain() *blockchain.BlockChain

func (*BlockManager) GetCurrentTemplate

func (b *BlockManager) GetCurrentTemplate() *types.BlockTemplate

GetCurrentTemplate gets the current block template for mining.

func (*BlockManager) GetParentTemplate

func (b *BlockManager) GetParentTemplate() *types.BlockTemplate

GetParentTemplate gets the current parent block template for mining.

func (*BlockManager) GetTxManager

func (b *BlockManager) GetTxManager() TxManager

func (*BlockManager) IntellectSyncBlocks

func (b *BlockManager) IntellectSyncBlocks(peer *peer.ServerPeer, refresh bool)

func (*BlockManager) IsCurrent

func (b *BlockManager) IsCurrent() bool

func (*BlockManager) NewPeer

func (b *BlockManager) NewPeer(sp *peer.ServerPeer)

NewPeer informs the block manager of a newly active peer.

func (*BlockManager) ProcessBlock

func (b *BlockManager) ProcessBlock(block *types.SerializedBlock, flags blockchain.BehaviorFlags) (bool, error)

ProcessBlock makes use of ProcessBlock on an internal instance of a block chain. It is funneled through the block manager since blockchain is not safe for concurrent access.

func (*BlockManager) ProcessTransaction

func (b *BlockManager) ProcessTransaction(tx *types.Tx, allowOrphans bool,
	rateLimit bool, allowHighFees bool) ([]*types.TxDesc, error)

ProcessTransaction makes use of ProcessTransaction on an internal instance of a block chain. It is funneled through the block manager since blockchain is not safe for concurrent access.

func (*BlockManager) PushSyncDAGMsg

func (b *BlockManager) PushSyncDAGMsg(peer *peer.ServerPeer)

func (*BlockManager) QueueBlock

func (b *BlockManager) QueueBlock(block *types.SerializedBlock, sp *peer.ServerPeer)

QueueBlock adds the passed block message and peer to the block handling queue.

func (*BlockManager) QueueInv

func (b *BlockManager) QueueInv(inv *message.MsgInv, sp *peer.ServerPeer)

QueueInv adds the passed inv message and peer to the block handling queue.

func (*BlockManager) QueueTx

func (b *BlockManager) QueueTx(tx *types.Tx, sp *peer.ServerPeer)

QueueTx adds the passed transaction message and peer to the block handling queue.

func (*BlockManager) RequestFromPeer

func (b *BlockManager) RequestFromPeer(p *peer.ServerPeer, blocks []*hash.Hash) error

RequestFromPeer allows an outside caller to request blocks or transactions from a peer. The requests are logged in the blockmanager's internal map of requests so they do not later ban the peer for sending the respective data.

func (*BlockManager) SetCurrentTemplate

func (b *BlockManager) SetCurrentTemplate(bt *types.BlockTemplate)

SetCurrentTemplate sets the current block template for mining.

func (*BlockManager) SetParentTemplate

func (b *BlockManager) SetParentTemplate(bt *types.BlockTemplate)

SetParentTemplate sets the current parent block template for mining.

func (*BlockManager) SetTxManager

func (b *BlockManager) SetTxManager(txManager TxManager)

func (*BlockManager) Start

func (b *BlockManager) Start()

Start begins the core block handler which processes block and inv messages.

func (*BlockManager) Stop

func (b *BlockManager) Stop() error

func (*BlockManager) SyncPeerID

func (b *BlockManager) SyncPeerID() int32

SyncPeerID returns the ID of the current sync peer, or 0 if there is none.

func (*BlockManager) TipGeneration

func (b *BlockManager) TipGeneration() ([]hash.Hash, error)

TipGeneration returns the hashes of all the children of the current best chain tip. It is funneled through the block manager since blockchain is not safe for concurrent access.

func (*BlockManager) WaitForStop

func (b *BlockManager) WaitForStop()

type PublicBlockAPI

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

func NewPublicBlockAPI

func NewPublicBlockAPI(bm *BlockManager) *PublicBlockAPI

func (*PublicBlockAPI) GetBestBlockHash

func (api *PublicBlockAPI) GetBestBlockHash() (interface{}, error)

func (*PublicBlockAPI) GetBlock

func (api *PublicBlockAPI) GetBlock(h hash.Hash, verbose *bool, inclTx *bool, fullTx *bool) (interface{}, error)

func (*PublicBlockAPI) GetBlockByID

func (api *PublicBlockAPI) GetBlockByID(id uint64, verbose *bool, inclTx *bool, fullTx *bool) (interface{}, error)

Obsoleted GetBlockByID Method, since the confused naming, replaced by GetBlockByNum method

func (*PublicBlockAPI) GetBlockByNum

func (api *PublicBlockAPI) GetBlockByNum(num uint64, verbose *bool, inclTx *bool, fullTx *bool) (interface{}, error)

GetBlockByNum works like GetBlockByOrder, the different is the GetBlockByNum is return the order result from the current node's DAG directly instead of according to the consensus of BlockDAG algorithm.

func (*PublicBlockAPI) GetBlockByOrder

func (api *PublicBlockAPI) GetBlockByOrder(order uint64, verbose *bool, inclTx *bool, fullTx *bool) (interface{}, error)

func (*PublicBlockAPI) GetBlockCount

func (api *PublicBlockAPI) GetBlockCount() (interface{}, error)

The total ordered Block count

func (*PublicBlockAPI) GetBlockHeader

func (api *PublicBlockAPI) GetBlockHeader(hash hash.Hash, verbose bool) (interface{}, error)

GetBlockHeader implements the getblockheader command.

func (*PublicBlockAPI) GetBlockTotal

func (api *PublicBlockAPI) GetBlockTotal() (interface{}, error)

The total Block count, included possible blocks have not ordered by BlockDAG consensus yet at the moments.

func (*PublicBlockAPI) GetBlockV2

func (api *PublicBlockAPI) GetBlockV2(h hash.Hash, verbose *bool, inclTx *bool, fullTx *bool) (interface{}, error)

func (*PublicBlockAPI) GetBlockWeight

func (api *PublicBlockAPI) GetBlockWeight(h hash.Hash) (interface{}, error)

Return the weight of block

func (*PublicBlockAPI) GetBlockhash

func (api *PublicBlockAPI) GetBlockhash(order uint) (string, error)

TODO, refactor BlkMgr API

func (*PublicBlockAPI) GetBlockhashByRange

func (api *PublicBlockAPI) GetBlockhashByRange(start uint, end uint) ([]string, error)

Return the hash range of block from 'start' to 'end'(exclude self) if 'end' is equal to zero, 'start' is the number that from the last block to the Gen if 'start' is greater than or equal to 'end', it will just return the hash of 'start'

func (*PublicBlockAPI) GetCoinbase

func (api *PublicBlockAPI) GetCoinbase(h hash.Hash, verbose *bool) (interface{}, error)

GetCoinbase

func (*PublicBlockAPI) GetFees

func (api *PublicBlockAPI) GetFees(h hash.Hash) (interface{}, error)

GetCoinbase

func (*PublicBlockAPI) GetMainChainHeight

func (api *PublicBlockAPI) GetMainChainHeight() (interface{}, error)

Return the current height of DAG main chain

func (*PublicBlockAPI) GetOrphansTotal

func (api *PublicBlockAPI) GetOrphansTotal() (interface{}, error)

Return the total number of orphan blocks, orphan block are the blocks have not been included into the DAG at this moment.

func (*PublicBlockAPI) IsBlue

func (api *PublicBlockAPI) IsBlue(h hash.Hash) (interface{}, error)

IsBlue:0:not blue; 1:blue 2:Cannot confirm

func (*PublicBlockAPI) IsCurrent

func (api *PublicBlockAPI) IsCurrent() (interface{}, error)

Return IsCurrent

func (*PublicBlockAPI) IsOnMainChain

func (api *PublicBlockAPI) IsOnMainChain(h hash.Hash) (interface{}, error)

Query whether a given block is on the main chain. Note that some DAG protocols may not support this feature.

func (*PublicBlockAPI) Tips

func (api *PublicBlockAPI) Tips() (interface{}, error)

Return a list hash of the tip blocks of the DAG at this moment.

type TxManager

type TxManager interface {
	MemPool() TxPool
}

type TxPool

type TxPool interface {
	AddTransaction(utxoView *blockchain.UtxoViewpoint,
		tx *types.Tx, height uint64, fee int64)

	RemoveTransaction(tx *types.Tx, removeRedeemers bool)

	RemoveDoubleSpends(tx *types.Tx)

	RemoveOrphan(txHash *hash.Hash)

	ProcessOrphans(hash *hash.Hash) []*types.TxDesc

	MaybeAcceptTransaction(tx *types.Tx, isNew, rateLimit bool) ([]*hash.Hash, error)

	HaveTransaction(hash *hash.Hash) bool

	PruneExpiredTx()

	ProcessTransaction(tx *types.Tx, allowOrphan, rateLimit, allowHighFees bool) ([]*types.TxDesc, error)
}

Jump to

Keyboard shortcuts

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