Skip to content

Commit

Permalink
make pool sync
Browse files Browse the repository at this point in the history
  • Loading branch information
devbugging committed Jun 13, 2024
1 parent 59b83ff commit 6d825c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions services/requester/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"fmt"
"regexp"
"strconv"
"sync"
"time"

"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go/fvm/evm/types"
gethCommon "github.com/onflow/go-ethereum/common"
gethTypes "github.com/onflow/go-ethereum/core/types"
"github.com/rs/zerolog"

Expand All @@ -27,7 +27,7 @@ const evmErrorRegex = `evm_error=(\d+)`
type TxPool struct {
logger zerolog.Logger
client *CrossSporkClient
pool map[gethCommon.Hash]*gethTypes.Transaction
pool *sync.Map
// todo add a broadcaster for pending transaction streaming
// todo add methods to inspect transaction pool state
}
Expand All @@ -36,7 +36,7 @@ func NewTxPool(client *CrossSporkClient, logger zerolog.Logger) *TxPool {
return &TxPool{
logger: logger.With().Str("component", "tx-pool").Logger(),
client: client,
pool: make(map[gethCommon.Hash]*gethTypes.Transaction),
pool: &sync.Map{},
}
}

Expand All @@ -54,15 +54,15 @@ func (t *TxPool) Send(
}

// add to pool
t.pool[evmTx.Hash()] = evmTx
t.pool.Store(evmTx.Hash(), evmTx)

const fetchInterval = time.Millisecond * 500
const fetchTimeout = time.Minute * 3
ticker := time.NewTicker(fetchInterval)
timeout := time.NewTimer(fetchTimeout)

defer func() {
delete(t.pool, evmTx.Hash())
t.pool.Delete(evmTx.Hash())
timeout.Stop()
ticker.Stop()
}()
Expand Down

0 comments on commit 6d825c4

Please sign in to comment.