flowcontext

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: ISC Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const TransactionIDPropagationInterval = 500 * time.Millisecond

TransactionIDPropagationInterval is the interval between transaction IDs propagations

Variables

View Source
var (
	// ErrPingTimeout signifies that a ping operation timed out.
	ErrPingTimeout = protocolerrors.New(false, "timeout expired on ping")
)

Functions

This section is empty.

Types

type FlowContext

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

FlowContext holds state that is relevant to more than one flow or one peer, and allows communication between different flows that can be associated to different peers.

func New

func New(cfg *config.Config, domain domain.Domain, addressManager *addressmanager.AddressManager,
	netAdapter *netadapter.NetAdapter, connectionManager *connmanager.ConnectionManager) *FlowContext

New returns a new instance of FlowContext.

func (*FlowContext) AddBlock

func (f *FlowContext) AddBlock(block *externalapi.DomainBlock) error

AddBlock adds the given block to the DAG and propagates it.

func (*FlowContext) AddOrphan

func (f *FlowContext) AddOrphan(orphanBlock *externalapi.DomainBlock)

AddOrphan adds the block to the orphan set

func (*FlowContext) AddToPeers

func (f *FlowContext) AddToPeers(peer *peerpkg.Peer) error

AddToPeers marks this peer as ready and adds it to the ready peers list.

func (*FlowContext) AddTransaction

func (f *FlowContext) AddTransaction(tx *externalapi.DomainTransaction, allowOrphan bool) error

AddTransaction adds transaction to the mempool and propagates it.

func (*FlowContext) AddressManager

func (f *FlowContext) AddressManager() *addressmanager.AddressManager

AddressManager returns the address manager associated to the flow context.

func (*FlowContext) Broadcast

func (f *FlowContext) Broadcast(message appmessage.Message) error

Broadcast broadcast the given message to all the ready peers.

func (*FlowContext) Close

func (f *FlowContext) Close()

Close signals to all flows the the protocol manager is closed.

func (*FlowContext) Config

func (f *FlowContext) Config() *config.Config

Config returns an instance of *config.Config associated to the flow context.

func (*FlowContext) ConnectionManager

func (f *FlowContext) ConnectionManager() *connmanager.ConnectionManager

ConnectionManager returns the connection manager that is associated to the flow context.

func (*FlowContext) Domain

func (f *FlowContext) Domain() domain.Domain

Domain returns the Domain object associated to the flow context.

func (*FlowContext) EnqueueTransactionIDsForPropagation

func (f *FlowContext) EnqueueTransactionIDsForPropagation(transactionIDs []*externalapi.DomainTransactionID) error

EnqueueTransactionIDsForPropagation add the given transactions IDs to a set of IDs to propagate. The IDs will be broadcast to all peers within a single transaction Inv message. The broadcast itself may happen only during a subsequent call to this method

func (*FlowContext) GetOrphanRoots

func (f *FlowContext) GetOrphanRoots(orphan *externalapi.DomainHash) ([]*externalapi.DomainHash, bool, error)

GetOrphanRoots returns the roots of the missing ancestors DAG of the given orphan

func (*FlowContext) HandleError

func (*FlowContext) HandleError(err error, flowName string, isStopping *uint32, errChan chan<- error)

HandleError handles an error from a flow, It sends the error to errChan if isStopping == 0 and increments isStopping

If this is ErrRouteClosed - forward it to errChan If this is ProtocolError - logs the error, and forward it to errChan Otherwise - panics

func (*FlowContext) HasPeers

func (f *FlowContext) HasPeers() bool

HasPeers returns whether there are currently active peers

func (*FlowContext) IBDPeer

func (f *FlowContext) IBDPeer() *peerpkg.Peer

IBDPeer returns the current IBD peer or null if the node is not in IBD

func (*FlowContext) IsIBDRunning

func (f *FlowContext) IsIBDRunning() bool

IsIBDRunning returns true if IBD is currently marked as running

func (*FlowContext) IsNearlySynced

func (f *FlowContext) IsNearlySynced() (bool, error)

IsNearlySynced returns whether current consensus is considered synced or close to being synced.

func (*FlowContext) IsOrphan

func (f *FlowContext) IsOrphan(blockHash *externalapi.DomainHash) bool

IsOrphan returns whether the given blockHash belongs to an orphan block

func (*FlowContext) IsRecoverableError

func (*FlowContext) IsRecoverableError(err error) bool

IsRecoverableError returns whether the error is recoverable

func (*FlowContext) NetAdapter

func (f *FlowContext) NetAdapter() *netadapter.NetAdapter

NetAdapter returns the net adapter that is associated to the flow context.

func (*FlowContext) OnNewBlock

func (f *FlowContext) OnNewBlock(block *externalapi.DomainBlock) error

OnNewBlock updates the mempool after a new block arrival, and relays newly unorphaned transactions and possibly rebroadcast manually added transactions when not in IBD.

func (*FlowContext) OnNewBlockTemplate

func (f *FlowContext) OnNewBlockTemplate() error

OnNewBlockTemplate calls the handler function whenever a new block template is available for miners.

func (*FlowContext) OnPruningPointUTXOSetOverride

func (f *FlowContext) OnPruningPointUTXOSetOverride() error

OnPruningPointUTXOSetOverride calls the handler function whenever the UTXO set resets due to pruning point change via IBD.

func (*FlowContext) OnTransactionAddedToMempool

func (f *FlowContext) OnTransactionAddedToMempool()

OnTransactionAddedToMempool notifies the handler function that a transaction has been added to the mempool

func (*FlowContext) Peers

func (f *FlowContext) Peers() []*peerpkg.Peer

Peers returns the currently active peers

func (*FlowContext) RemoveFromPeers

func (f *FlowContext) RemoveFromPeers(peer *peerpkg.Peer)

RemoveFromPeers remove this peer from the peers list.

func (*FlowContext) SetOnNewBlockTemplateHandler

func (f *FlowContext) SetOnNewBlockTemplateHandler(onNewBlockTemplateHandler OnNewBlockTemplateHandler)

SetOnNewBlockTemplateHandler sets the onNewBlockTemplateHandler handler

func (*FlowContext) SetOnPruningPointUTXOSetOverrideHandler

func (f *FlowContext) SetOnPruningPointUTXOSetOverrideHandler(onPruningPointUTXOSetOverrideHandler OnPruningPointUTXOSetOverrideHandler)

SetOnPruningPointUTXOSetOverrideHandler sets the onPruningPointUTXOSetOverrideHandler handler

func (*FlowContext) SetOnTransactionAddedToMempoolHandler

func (f *FlowContext) SetOnTransactionAddedToMempoolHandler(onTransactionAddedToMempoolHandler OnTransactionAddedToMempoolHandler)

SetOnTransactionAddedToMempoolHandler sets the onTransactionAddedToMempool handler

func (*FlowContext) SharedRequestedBlocks

func (f *FlowContext) SharedRequestedBlocks() *SharedRequestedBlocks

SharedRequestedBlocks returns a *blockrelay.SharedRequestedBlocks for sharing data about requested blocks between different peers.

func (*FlowContext) SharedRequestedTransactions

func (f *FlowContext) SharedRequestedTransactions() *SharedRequestedTransactions

SharedRequestedTransactions returns a *transactionrelay.SharedRequestedTransactions for sharing data about requested transactions between different peers.

func (*FlowContext) ShutdownChan

func (f *FlowContext) ShutdownChan() <-chan struct{}

ShutdownChan is a chan where flows can subscribe to shutdown event.

func (*FlowContext) TrySetIBDRunning

func (f *FlowContext) TrySetIBDRunning(ibdPeer *peerpkg.Peer) bool

TrySetIBDRunning attempts to set `isInIBD`. Returns false if it is already set

func (*FlowContext) UnorphanBlocks

func (f *FlowContext) UnorphanBlocks(rootBlock *externalapi.DomainBlock) ([]*externalapi.DomainBlock, error)

UnorphanBlocks removes the block from the orphan set, and remove all of the blocks that are not orphans anymore.

func (*FlowContext) UnsetIBDRunning

func (f *FlowContext) UnsetIBDRunning()

UnsetIBDRunning unsets isInIBD

type OnNewBlockTemplateHandler

type OnNewBlockTemplateHandler func() error

OnNewBlockTemplateHandler is a handler function that's triggered when a new block template is available

type OnPruningPointUTXOSetOverrideHandler

type OnPruningPointUTXOSetOverrideHandler func() error

OnPruningPointUTXOSetOverrideHandler is a handle function that's triggered whenever the UTXO set resets due to pruning point change via IBD.

type OnTransactionAddedToMempoolHandler

type OnTransactionAddedToMempoolHandler func()

OnTransactionAddedToMempoolHandler is a handler function that's triggered when a transaction is added to the mempool

type SharedRequestedBlocks

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

SharedRequestedBlocks is a data structure that is shared between peers that holds the hashes of all the requested blocks to prevent redundant requests.

func NewSharedRequestedBlocks

func NewSharedRequestedBlocks() *SharedRequestedBlocks

NewSharedRequestedBlocks returns a new instance of SharedRequestedBlocks.

func (*SharedRequestedBlocks) AddIfNotExists

func (s *SharedRequestedBlocks) AddIfNotExists(hash *externalapi.DomainHash) (exists bool)

AddIfNotExists adds a block to the set if it doesn't exist yet.

func (*SharedRequestedBlocks) Remove

func (s *SharedRequestedBlocks) Remove(hash *externalapi.DomainHash)

Remove removes a block from the set.

func (*SharedRequestedBlocks) RemoveSet

func (s *SharedRequestedBlocks) RemoveSet(blockHashes map[externalapi.DomainHash]struct{})

RemoveSet removes a set of blocks from the set.

type SharedRequestedTransactions

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

SharedRequestedTransactions is a data structure that is shared between peers that holds the IDs of all the requested transactions to prevent redundant requests.

func NewSharedRequestedTransactions

func NewSharedRequestedTransactions() *SharedRequestedTransactions

NewSharedRequestedTransactions returns a new instance of SharedRequestedTransactions.

func (*SharedRequestedTransactions) AddIfNotExists

func (s *SharedRequestedTransactions) AddIfNotExists(txID *externalapi.DomainTransactionID) (exists bool)

AddIfNotExists adds a transaction to the set if it doesn't exist yet.

func (*SharedRequestedTransactions) Remove

Remove removes a transaction from the set.

func (*SharedRequestedTransactions) RemoveMany

RemoveMany removes a set of transactions from the set.

Jump to

Keyboard shortcuts

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