Skip to content

Commit

Permalink
Merge pull request #99 from ethpandaops/feat/add-ttl
Browse files Browse the repository at this point in the history
feat(mimicry): add ttl to shared cache
  • Loading branch information
Savid authored Mar 9, 2023
2 parents b73f580 + b8d3508 commit bb571db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/mimicry/p2p/execution/event_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/savid/ttlcache/v3"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -133,7 +132,7 @@ func (p *Peer) ExportTransactions(ctx context.Context, items []*TransactionHashI

if txs != nil {
for _, tx := range txs.PooledTransactionsPacket {
_, retrieved := p.sharedCache.Transaction.GetOrSet(tx.Hash().String(), true, ttlcache.DefaultTTL)
_, retrieved := p.sharedCache.Transaction.GetOrSet(tx.Hash().String(), true, 1*time.Hour)
// transaction was just set in shared cache, so we need to handle it
if !retrieved {
seen := seenMap[tx.Hash()]
Expand Down
9 changes: 3 additions & 6 deletions pkg/mimicry/p2p/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"
"time"

"github.com/savid/ttlcache/v3"
"github.com/sirupsen/logrus"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -240,11 +239,9 @@ func (p *Peer) Start(ctx context.Context) (<-chan error, error) {
if p.handlers.DecoratedEvent != nil && txs != nil {
now := time.Now()
for _, tx := range *txs {
// only process transactions we haven't seen before across all peers
exists := p.sharedCache.Transaction.Get(tx.Hash().String())
if exists == nil {
p.sharedCache.Transaction.Set(tx.Hash().String(), true, ttlcache.DefaultTTL)

_, retrieved := p.sharedCache.Transaction.GetOrSet(tx.Hash().String(), true, 1*time.Hour)
// transaction was just set in shared cache, so we need to handle it
if !retrieved {
event, errT := p.handleTransaction(ctx, now, tx)
if errT != nil {
p.log.WithError(errT).Error("failed handling transaction")
Expand Down

0 comments on commit bb571db

Please sign in to comment.