btcd: github.com/btcsuite/btcd/netsync Index | Files

package netsync

import "github.com/btcsuite/btcd/netsync"

Package netsync implements a concurrency safe block syncing protocol. The SyncManager communicates with connected peers to perform an initial block download, keep the chain and unconfirmed transaction pool in sync, and announce new blocks connected to the chain. Currently the sync manager selects a single sync peer that it downloads all blocks from until it is up to date with the longest chain the sync peer is aware of.

Index

Package Files

blocklogger.go doc.go interface.go log.go manager.go

func DisableLog Uses

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger Uses

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

type Config Uses

type Config struct {
    PeerNotifier PeerNotifier
    Chain        *blockchain.BlockChain
    TxMemPool    *mempool.TxPool
    ChainParams  *chaincfg.Params

    DisableCheckpoints bool
    MaxPeers           int

    FeeEstimator *mempool.FeeEstimator
}

Config is a configuration struct used to initialize a new SyncManager.

type PeerNotifier Uses

type PeerNotifier interface {
    AnnounceNewTransactions(newTxs []*mempool.TxDesc)

    UpdatePeerHeights(latestBlkHash *chainhash.Hash, latestHeight int32, updateSource *peer.Peer)

    RelayInventory(invVect *wire.InvVect, data interface{})

    TransactionConfirmed(tx *btcutil.Tx)
}

PeerNotifier exposes methods to notify peers of status changes to transactions, blocks, etc. Currently server (in the main package) implements this interface.

type SyncManager Uses

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

SyncManager is used to communicate block related messages with peers. The SyncManager is started as by executing Start() in a goroutine. Once started, it selects peers to sync from and starts the initial block download. Once the chain is in sync, the SyncManager handles incoming block and header notifications and relays announcements of new blocks to peers.

func New Uses

func New(config *Config) (*SyncManager, error)

New constructs a new SyncManager. Use Start to begin processing asynchronous block, tx, and inv updates.

func (*SyncManager) DonePeer Uses

func (sm *SyncManager) DonePeer(peer *peerpkg.Peer)

DonePeer informs the blockmanager that a peer has disconnected.

func (*SyncManager) IsCurrent Uses

func (sm *SyncManager) IsCurrent() bool

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

func (*SyncManager) NewPeer Uses

func (sm *SyncManager) NewPeer(peer *peerpkg.Peer)

NewPeer informs the sync manager of a newly active peer.

func (*SyncManager) Pause Uses

func (sm *SyncManager) Pause() chan<- struct{}

Pause pauses the sync manager until the returned channel is closed.

Note that while paused, all peer and block processing is halted. The message sender should avoid pausing the sync manager for long durations.

func (*SyncManager) ProcessBlock Uses

func (sm *SyncManager) ProcessBlock(block *btcutil.Block, flags blockchain.BehaviorFlags) (bool, error)

ProcessBlock makes use of ProcessBlock on an internal instance of a block chain.

func (*SyncManager) QueueBlock Uses

func (sm *SyncManager) QueueBlock(block *btcutil.Block, peer *peerpkg.Peer, done chan struct{})

QueueBlock adds the passed block message and peer to the block handling queue. Responds to the done channel argument after the block message is processed.

func (*SyncManager) QueueHeaders Uses

func (sm *SyncManager) QueueHeaders(headers *wire.MsgHeaders, peer *peerpkg.Peer)

QueueHeaders adds the passed headers message and peer to the block handling queue.

func (*SyncManager) QueueInv Uses

func (sm *SyncManager) QueueInv(inv *wire.MsgInv, peer *peerpkg.Peer)

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

func (*SyncManager) QueueTx Uses

func (sm *SyncManager) QueueTx(tx *btcutil.Tx, peer *peerpkg.Peer, done chan struct{})

QueueTx adds the passed transaction message and peer to the block handling queue. Responds to the done channel argument after the tx message is processed.

func (*SyncManager) Start Uses

func (sm *SyncManager) Start()

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

func (*SyncManager) Stop Uses

func (sm *SyncManager) Stop() error

Stop gracefully shuts down the sync manager by stopping all asynchronous handlers and waiting for them to finish.

func (*SyncManager) SyncPeerID Uses

func (sm *SyncManager) SyncPeerID() int32

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

Package netsync imports 15 packages (graph) and is imported by 38 packages. Updated 2019-04-29. Refresh now. Tools for package owners.