Stop notifications of duplicate insertions into ethereum type mempool

This commit is contained in:
Martin Boehm 2023-12-20 12:43:50 +01:00
parent e7ee4a95d8
commit e464e16a33
2 changed files with 8 additions and 5 deletions

View File

@ -238,8 +238,10 @@ func (b *EthereumRPC) subscribeEvents() error {
if glog.V(2) {
glog.Info("rpc: new tx ", hex)
}
b.Mempool.AddTransactionToMempool(hex)
b.PushHandler(bchain.NotificationNewTx)
added := b.Mempool.AddTransactionToMempool(hex)
if added {
b.PushHandler(bchain.NotificationNewTx)
}
}
}()

View File

@ -132,8 +132,8 @@ func (m *MempoolEthereumType) Resync() (int, error) {
return entries, nil
}
// AddTransactionToMempool adds transactions to mempool
func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
// 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) bool {
m.mux.Lock()
_, exists := m.txEntries[txid]
m.mux.Unlock()
@ -143,7 +143,7 @@ func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
if !exists {
entry, ok := m.createTxEntry(txid, uint32(time.Now().Unix()))
if !ok {
return
return false
}
m.mux.Lock()
m.txEntries[txid] = entry
@ -152,6 +152,7 @@ func (m *MempoolEthereumType) AddTransactionToMempool(txid string) {
}
m.mux.Unlock()
}
return !exists
}
// RemoveTransactionFromMempool removes transaction from mempool