Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
iterating over slice of txs, instead of map
Browse files Browse the repository at this point in the history
itzmeanjan committed Mar 31, 2021
1 parent 3905ff3 commit 1fc6e68
Showing 2 changed files with 16 additions and 40 deletions.
28 changes: 8 additions & 20 deletions app/data/pending.go
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ func (p *PendingPool) DuplicateTxs(hash common.Hash) []*MemPoolTx {

result := make([]*MemPoolTx, 0, p.Count())

for _, tx := range p.Transactions {
for _, tx := range p.DescTxsByGasPrice.get() {

// First checking if tx under radar is the one for which
// we're finding duplicate tx(s). If yes, we will move to next one
@@ -94,9 +94,7 @@ func (p *PendingPool) DuplicateTxs(hash common.Hash) []*MemPoolTx {
// If yes, we'll include it considerable duplicate tx list, for given
// txHash
if tx.IsDuplicateOf(targetTx) {

result = append(result, tx)

}

}
@@ -111,13 +109,7 @@ func (p *PendingPool) ListTxs() []*MemPoolTx {
p.Lock.RLock()
defer p.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(p.Transactions))

for _, v := range p.Transactions {
result = append(result, v)
}

return result
return p.DescTxsByGasPrice.get()

}

@@ -150,7 +142,7 @@ func (p *PendingPool) SentFrom(address common.Address) []*MemPoolTx {
p.Lock.RLock()
defer p.Lock.RUnlock()

result := make([]*MemPoolTx, 0, p.DescTxsByGasPrice.len())
result := make([]*MemPoolTx, 0, p.Count())

for _, tx := range p.DescTxsByGasPrice.get() {

@@ -171,7 +163,7 @@ func (p *PendingPool) SentTo(address common.Address) []*MemPoolTx {
p.Lock.RLock()
defer p.Lock.RUnlock()

result := make([]*MemPoolTx, 0, p.DescTxsByGasPrice.len())
result := make([]*MemPoolTx, 0, p.Count())

for _, tx := range p.DescTxsByGasPrice.get() {

@@ -192,9 +184,9 @@ func (p *PendingPool) OlderThanX(x time.Duration) []*MemPoolTx {
p.Lock.RLock()
defer p.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(p.Transactions))
result := make([]*MemPoolTx, 0, p.Count())

for _, tx := range p.Transactions {
for _, tx := range p.DescTxsByGasPrice.get() {

if tx.IsPendingForGTE(x) {
result = append(result, tx)
@@ -213,9 +205,9 @@ func (p *PendingPool) FresherThanX(x time.Duration) []*MemPoolTx {
p.Lock.RLock()
defer p.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(p.Transactions))
result := make([]*MemPoolTx, 0, p.Count())

for _, tx := range p.Transactions {
for _, tx := range p.DescTxsByGasPrice.get() {

if tx.IsPendingForLTE(x) {
result = append(result, tx)
@@ -273,9 +265,7 @@ func (p *PendingPool) PublishAdded(ctx context.Context, pubsub *redis.Client, ms
}

if err := pubsub.Publish(ctx, config.GetPendingTxEntryPublishTopic(), _msg).Err(); err != nil {

log.Printf("[❗️] Failed to publish new pending tx : %s\n", err.Error())

}

}
@@ -332,9 +322,7 @@ func (p *PendingPool) PublishRemoved(ctx context.Context, pubsub *redis.Client,
}

if err := pubsub.Publish(ctx, config.GetPendingTxExitPublishTopic(), _msg).Err(); err != nil {

log.Printf("[❗️] Failed to publish confirmed tx : %s\n", err.Error())

}

}
28 changes: 8 additions & 20 deletions app/data/queued.go
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ func (q *QueuedPool) DuplicateTxs(hash common.Hash) []*MemPoolTx {

result := make([]*MemPoolTx, 0, q.Count())

for _, tx := range q.Transactions {
for _, tx := range q.DescTxsByGasPrice.get() {

// First checking if tx under radar is the one for which
// we're finding duplicate tx(s). If yes, we will move to next one
@@ -98,9 +98,7 @@ func (q *QueuedPool) DuplicateTxs(hash common.Hash) []*MemPoolTx {
// If yes, we'll include it considerable duplicate tx list, for given
// txHash
if tx.IsDuplicateOf(targetTx) {

result = append(result, tx)

}

}
@@ -115,13 +113,7 @@ func (q *QueuedPool) ListTxs() []*MemPoolTx {
q.Lock.RLock()
defer q.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(q.Transactions))

for _, v := range q.Transactions {
result = append(result, v)
}

return result
return q.DescTxsByGasPrice.get()

}

@@ -154,7 +146,7 @@ func (q *QueuedPool) SentFrom(address common.Address) []*MemPoolTx {
q.Lock.RLock()
defer q.Lock.RUnlock()

result := make([]*MemPoolTx, 0, q.DescTxsByGasPrice.len())
result := make([]*MemPoolTx, 0, q.Count())

for _, tx := range q.DescTxsByGasPrice.get() {

@@ -175,7 +167,7 @@ func (q *QueuedPool) SentTo(address common.Address) []*MemPoolTx {
q.Lock.RLock()
defer q.Lock.RUnlock()

result := make([]*MemPoolTx, 0, q.DescTxsByGasPrice.len())
result := make([]*MemPoolTx, 0, q.Count())

for _, tx := range q.DescTxsByGasPrice.get() {

@@ -196,9 +188,9 @@ func (q *QueuedPool) OlderThanX(x time.Duration) []*MemPoolTx {
q.Lock.RLock()
defer q.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(q.Transactions))
result := make([]*MemPoolTx, 0, q.Count())

for _, tx := range q.Transactions {
for _, tx := range q.DescTxsByGasPrice.get() {

if tx.IsQueuedForGTE(x) {
result = append(result, tx)
@@ -217,9 +209,9 @@ func (q *QueuedPool) FresherThanX(x time.Duration) []*MemPoolTx {
q.Lock.RLock()
defer q.Lock.RUnlock()

result := make([]*MemPoolTx, 0, len(q.Transactions))
result := make([]*MemPoolTx, 0, q.Count())

for _, tx := range q.Transactions {
for _, tx := range q.DescTxsByGasPrice.get() {

if tx.IsQueuedForLTE(x) {
result = append(result, tx)
@@ -277,9 +269,7 @@ func (q *QueuedPool) PublishAdded(ctx context.Context, pubsub *redis.Client, msg
}

if err := pubsub.Publish(ctx, config.GetQueuedTxEntryPublishTopic(), _msg).Err(); err != nil {

log.Printf("[❗️] Failed to publish new queued tx : %s\n", err.Error())

}

}
@@ -329,9 +319,7 @@ func (q *QueuedPool) PublishRemoved(ctx context.Context, pubsub *redis.Client, m
}

if err := pubsub.Publish(ctx, config.GetQueuedTxExitPublishTopic(), _msg).Err(); err != nil {

log.Printf("[❗️] Failed to publish unstuck tx : %s\n", err.Error())

}

}

0 comments on commit 1fc6e68

Please sign in to comment.