Propagate known transactions to new peers on connect
This commit is contained in:
@ -46,6 +46,7 @@ type ethProtocol struct {
|
||||
// used as an argument to EthProtocol
|
||||
type txPool interface {
|
||||
AddTransactions([]*types.Transaction)
|
||||
GetTransactions() types.Transactions
|
||||
}
|
||||
|
||||
type chainManager interface {
|
||||
@ -101,6 +102,7 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
|
||||
}
|
||||
err = self.handleStatus()
|
||||
if err == nil {
|
||||
self.propagateTxs()
|
||||
for {
|
||||
err = self.handle()
|
||||
if err != nil {
|
||||
@ -324,3 +326,13 @@ func (self *ethProtocol) protoErrorDisconnect(code int, format string, params ..
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (self *ethProtocol) propagateTxs() {
|
||||
transactions := self.txPool.GetTransactions()
|
||||
iface := make([]interface{}, len(transactions))
|
||||
for i, transaction := range transactions {
|
||||
iface[i] = transaction
|
||||
}
|
||||
|
||||
self.rw.WriteMsg(p2p.NewMsg(TxMsg, iface...))
|
||||
}
|
||||
|
Reference in New Issue
Block a user