Stop notifications of duplicate insertions into ethereum type mempool
This commit is contained in:
parent
e7ee4a95d8
commit
e464e16a33
@ -238,8 +238,10 @@ func (b *EthereumRPC) subscribeEvents() error {
|
|||||||
if glog.V(2) {
|
if glog.V(2) {
|
||||||
glog.Info("rpc: new tx ", hex)
|
glog.Info("rpc: new tx ", hex)
|
||||||
}
|
}
|
||||||
b.Mempool.AddTransactionToMempool(hex)
|
added := b.Mempool.AddTransactionToMempool(hex)
|
||||||
b.PushHandler(bchain.NotificationNewTx)
|
if added {
|
||||||
|
b.PushHandler(bchain.NotificationNewTx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@ -132,8 +132,8 @@ func (m *MempoolEthereumType) Resync() (int, error) {
|
|||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTransactionToMempool adds transactions to mempool
|
// AddTransactionToMempool adds transactions to mempool, returns true if tx added to mempool, false if not added (for example duplicate call)
|
||||||
func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
|
func (m *MempoolEthereumType) AddTransactionToMempool(txid string) bool {
|
||||||
m.mux.Lock()
|
m.mux.Lock()
|
||||||
_, exists := m.txEntries[txid]
|
_, exists := m.txEntries[txid]
|
||||||
m.mux.Unlock()
|
m.mux.Unlock()
|
||||||
@ -143,7 +143,7 @@ func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
|
|||||||
if !exists {
|
if !exists {
|
||||||
entry, ok := m.createTxEntry(txid, uint32(time.Now().Unix()))
|
entry, ok := m.createTxEntry(txid, uint32(time.Now().Unix()))
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
m.mux.Lock()
|
m.mux.Lock()
|
||||||
m.txEntries[txid] = entry
|
m.txEntries[txid] = entry
|
||||||
@ -152,6 +152,7 @@ func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
|
|||||||
}
|
}
|
||||||
m.mux.Unlock()
|
m.mux.Unlock()
|
||||||
}
|
}
|
||||||
|
return !exists
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveTransactionFromMempool removes transaction from mempool
|
// RemoveTransactionFromMempool removes transaction from mempool
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user