Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
move broadcast out of lockedTryTransactionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jan 16, 2018
1 parent 657921f commit f26934a
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions modules/transactionpool/accept.go
Expand Up @@ -331,32 +331,33 @@ func (tp *TransactionPool) AcceptTransactionSet(ts []types.Transaction) error {
return errors.New("consensus set does not support LockedTryTransactionSet method")
}

return cs.LockedTryTransactionSet(func(txnFn func(txns []types.Transaction) (modules.ConsensusChange, error)) error {
err := cs.LockedTryTransactionSet(func(txnFn func(txns []types.Transaction) (modules.ConsensusChange, error)) error {
tp.mu.Lock()
defer tp.mu.Unlock()
err := tp.acceptTransactionSet(ts, txnFn)
// In case of certain errors we still want to broadcast the set
broadcast := err == nil || err == modules.ErrDuplicateTransactionSet
if broadcast {
// This set was broadcasted before if err != nil. We need to update
// it's seen txn height when we rebroadcast it. If we don't do
// that, the transaction will be pruned from the tpool and they
// might no longer show up in the wallet while still beingt
// tracked.
if err != nil {
for _, txn := range ts {
tp.transactionHeights[txn.ID()] = tp.blockHeight
}
}
go tp.gateway.Broadcast("RelayTransactionSet", ts, tp.gateway.Peers())
}
if err != nil {
return err
// Notify subscribers of an accepted transaction set
tp.updateSubscribersTransactions()
}
// Notify subscribers of an accepted transaction set
tp.updateSubscribersTransactions()
return nil
return err
})
// In case of certain errors we still want to broadcast the set
if err == nil || err == modules.ErrDuplicateTransactionSet || err == errLowMinerFees {
// This set was broadcasted before if err != nil. We need to update
// it's seen txn height when we rebroadcast it. If we don't do
// that, the transaction will be pruned from the tpool and they
// might no longer show up in the wallet while still beingt
// tracked.
if err != nil {
tp.mu.Lock()
for _, txn := range ts {
tp.transactionHeights[txn.ID()] = tp.blockHeight
}
tp.mu.Unlock()
}
go tp.gateway.Broadcast("RelayTransactionSet", ts, tp.gateway.Peers())
}
return err
}

// relayTransactionSet is an RPC that accepts a transaction set from a peer. If
Expand Down

0 comments on commit f26934a

Please sign in to comment.