comments - shorten, simplify and make 80cols.
This commit is contained in:
parent
b7622c4e6c
commit
5932cd5385
1 changed files with 13 additions and 20 deletions
33
server.go
33
server.go
|
@ -748,16 +748,12 @@ func (s *server) NetTotals() (uint64, uint64) {
|
||||||
return s.bytesReceived, s.bytesSent
|
return s.bytesReceived, s.bytesSent
|
||||||
}
|
}
|
||||||
|
|
||||||
// rebroadcastHandler is a listener that uses a couple of channels to maintain
|
// rebroadcastHandler keeps track of user submitted inventories that we have
|
||||||
// a list of transactions that need to be rebroadcast. The list of tx is stored
|
// sent out but have not yet made it into a block. We periodically rebroadcast
|
||||||
// in their abstracted P2P form (InvVect) in a map (pendingInvs).
|
// them in case our peers restarted or otherwise lost track of them.
|
||||||
// Why we need this:
|
|
||||||
// We handle user submitted tx, e.g. from a wallet, via the RPC submission
|
|
||||||
// function sendrawtransactions. Because we need to ensure that user-
|
|
||||||
// submitted tx eventually enter a block, we need to retransmit them
|
|
||||||
// periodically until we see them actually enter a block.
|
|
||||||
func (s *server) rebroadcastHandler() {
|
func (s *server) rebroadcastHandler() {
|
||||||
timer := time.NewTimer(5 * time.Minute) // Wait 5 min before first tx rebroadcast.
|
// Wait 5 min before first tx rebroadcast.
|
||||||
|
timer := time.NewTimer(5 * time.Minute)
|
||||||
pendingInvs := make(map[btcwire.InvVect]struct{})
|
pendingInvs := make(map[btcwire.InvVect]struct{})
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -769,29 +765,26 @@ out:
|
||||||
case broadcastInventoryAdd:
|
case broadcastInventoryAdd:
|
||||||
pendingInvs[*msg] = struct{}{}
|
pendingInvs[*msg] = struct{}{}
|
||||||
|
|
||||||
// When an InvVect has been added to a block, we can now remove it;
|
// When an InvVect has been added to a block, we can
|
||||||
// note that we need to check if the iv is actually found in the
|
// now remove it, if it was present.
|
||||||
// map before we try to delete it, as when handleNotifyMsg finds a
|
|
||||||
// new block it cycles through the txs and sends them all
|
|
||||||
// indescriminately to this function. The if loop is cheap, so
|
|
||||||
// this should not be an issue.
|
|
||||||
case broadcastInventoryDel:
|
case broadcastInventoryDel:
|
||||||
if _, ok := pendingInvs[*msg]; ok {
|
if _, ok := pendingInvs[*msg]; ok {
|
||||||
delete(pendingInvs, *msg)
|
delete(pendingInvs, *msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the timer triggers, scan through all the InvVects of RPC-submitted
|
|
||||||
// tx and cause the server to resubmit them to peers, as they have not
|
|
||||||
// been added to incoming blocks.
|
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
|
// Any inventory we have has not made it into a block
|
||||||
|
// yet. We periodically resubmit them until they have.
|
||||||
for iv := range pendingInvs {
|
for iv := range pendingInvs {
|
||||||
ivCopy := iv
|
ivCopy := iv
|
||||||
s.RelayInventory(&ivCopy)
|
s.RelayInventory(&ivCopy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the timer to go off at a random time between 0 and 1799 seconds
|
// Process at a random time up to 30mins (in seconds)
|
||||||
timer.Reset(time.Second * time.Duration(randomUint16Number(1800)))
|
// in the future.
|
||||||
|
timer.Reset(time.Second *
|
||||||
|
time.Duration(randomUint16Number(1800)))
|
||||||
|
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
break out
|
break out
|
||||||
|
|
Loading…
Reference in a new issue