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 ad50676 commit 0d3edb8
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions modules/transactionpool/accept.go
Expand Up @@ -331,35 +331,38 @@ 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 {
tp.log.Println("Beginning broadcast of transaction set")
tp.log.Println("Beginning broadcast of transaction set")
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 {
tp.log.Println("Transaction set broadcast has failed")
return err
}
// Notify subscribers of an accepted transaction set
tp.updateSubscribersTransactions()
tp.log.Println("Transaction set broadcast appears to have succeeded")
return nil
})
// 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())
tp.log.Println("Transaction set broadcast appears to have succeeded")
} else {
tp.log.Println("Transaction set broadcast has failed")
}
return err
}

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

0 comments on commit 0d3edb8

Please sign in to comment.