Documentation
¶
Index ¶
Constants ¶
const ( // DefaultRebroadcastInterval is the default period that we'll wait // between blocks to attempt another rebroadcast. DefaultRebroadcastInterval = 10 * time.Second )
Variables ¶
var ( // RejUnknown is the code used when a transaction has been rejected by some // unknown reason by a peer. RejUnknown = Err.Code("RejUnknown") // RejInvalid is the code used when a transaction has been deemed invalid // by a peer. RejInvalid = Err.Code("RejInvalid") // RejInsufficientFee is the code used when a transaction has been deemed // as having an insufficient fee by a peer. RejInsufficientFee = Err.Code("RejInsufficientFee") // RejMempool is the code used when a transaction already exists in a // peer's mempool. RejMempool = Err.Code("RejMempool") // RejConfirmed is the code used when a transaction has been deemed as // already existing in the chain by a peer. RejConfirmed = Err.Code("RejConfirmed") )
var Err er.ErrorType = er.NewErrorType("pushtx.Err")
var ( // ErrBroadcasterStopped is an error returned when we attempt to process a // request to broadcast a transaction but the Broadcaster has already // been stopped. ErrBroadcasterStopped = er.GenericErrorType.CodeWithDetail("pushtx.ErrBroadcasterStopped", "broadcaster has been stopped") )
Functions ¶
func ParseBroadcastError ¶
ParseBroadcastError maps a peer's reject message for a transaction to a BroadcastError. TODO(cjd): We're parsing reject messages here which is a bad idea.
The text is not guaranteed to be relevant and bitcoind has already gotten rid of the reject message because nodes cannot be trusted to send a reject honestly. Furthermore we are parsing text of the messages because the error codes are not clear enough alone.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster is a subsystem responsible for reliably broadcasting transactions to the network. Each transaction will be rebroadcast upon every new block being connected/disconnected to/from the chain.
func NewBroadcaster ¶
func NewBroadcaster(cfg *Config) *Broadcaster
NewBroadcaster creates a new Broadcaster backed by the given config.
func (*Broadcaster) Broadcast ¶
func (b *Broadcaster) Broadcast(tx *wire.MsgTx) er.R
Broadcast submits a request to the Broadcaster to reliably broadcast the given transaction. An error won't be returned if the transaction already exists within the mempool. Any transaction broadcast through this method will be rebroadcast upon every change of the tip of the chain.
func (*Broadcaster) Start ¶
func (b *Broadcaster) Start() er.R
Start starts all of the necessary steps for the Broadcaster to begin properly carrying out its duties.
func (*Broadcaster) Stop ¶
func (b *Broadcaster) Stop()
Stop halts the Broadcaster from rebroadcasting pending transactions.
type Config ¶
type Config struct { // Broadcast broadcasts a transaction to the network. We expect certain // BroadcastError's to be returned to handle special cases, namely // errors with the codes Mempool and Confirmed. Broadcast func(*wire.MsgTx) er.R // SubscribeBlocks returns a block subscription that delivers block // notifications in order. This will be used to rebroadcast all // transactions once a new block arrives. SubscribeBlocks func() (*blockntfns.Subscription, er.R) // RebroadcastInterval is the interval that we'll continually try to // re-broadcast transactions in-between new block arrival. RebroadcastInterval time.Duration }
Config contains all of the external dependencies required for the Broadcaster to properly carry out its duties.