Skip to content

Commit

Permalink
lock
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 20, 2023
1 parent 2a8befb commit 67e261d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vms/platformvm/network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/network/p2p/gossip"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/vms/platformvm/block/executor"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"
Expand Down Expand Up @@ -53,6 +54,7 @@ func (t txGossipHandler) AppRequest(

func NewVerifierMempool(
mempool mempool.Mempool,
snowCtx *snow.Context,
verifier executor.Manager,
bloomMaxItems uint64,
bloomFalsePositiveRate float64,
Expand All @@ -68,6 +70,7 @@ func NewVerifierMempool(

return &VerifierMempool{
Mempool: mempool,
snowCtx: snowCtx,
verifier: verifier,
bloomFilter: bloomFilter,
bloomMaxFalsePositiveRate: bloomMaxFalsePositiveRate,
Expand All @@ -77,6 +80,7 @@ func NewVerifierMempool(
// VerifierMempool performs verification before adding something to the mempool
type VerifierMempool struct {
mempool.Mempool
snowCtx *snow.Context
verifier executor.Manager

lock sync.RWMutex
Expand All @@ -85,6 +89,9 @@ type VerifierMempool struct {
}

func (v *VerifierMempool) Add(tx *Tx) error {
v.snowCtx.Lock.Lock()
defer v.snowCtx.Lock.Unlock()

if v.Mempool.Has(tx.ID()) {
err := fmt.Errorf("tx %s dropped: %w", tx.ID(), ErrTxPending)
v.Mempool.MarkDropped(tx.ID(), err)
Expand Down

0 comments on commit 67e261d

Please sign in to comment.