Skip to content

Commit

Permalink
check the auction is over when submitting a bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jj1980a committed Apr 30, 2024
1 parent 1de32f8 commit 1eb3f4d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions auction/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func NewAuction(duration time.Duration, maxSolutions uint64, userOp *operation.U
return auction
}

func (a *Auction) isOpen() bool {
a.mu.Lock()
defer a.mu.Unlock()
return a.open
}

func (a *Auction) close() {
a.mu.Lock()
defer a.mu.Unlock()
Expand Down
9 changes: 8 additions & 1 deletion auction/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (am *Manager) auctionsCleaner() {
for range time.Tick(10 * time.Minute) {
am.mu.Lock()
for userOpHash, auction := range am.auctions {
if !auction.open && time.Since(auction.createdAt) > time.Hour {
if !auction.isOpen() && time.Since(auction.createdAt) > time.Hour {
delete(am.auctions, userOpHash)
}
}
Expand Down Expand Up @@ -160,6 +160,13 @@ func (am *Manager) GetSolverOperations(userOpHash common.Hash, completionChan ch
return auction.getSolverOps(completionChan)
}

func (am *Manager) IsAuctionOngoing(userOpHash common.Hash) bool {
am.mu.RLock()
defer am.mu.RUnlock()
auction, ok := am.auctions[userOpHash]
return ok && auction.isOpen()
}

func (am *Manager) getAuction(userOpHash common.Hash) *Auction {
am.mu.RLock()
defer am.mu.RUnlock()
Expand Down
13 changes: 11 additions & 2 deletions bundle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"
"time"

"github.com/FastLane-Labs/atlas-operations-relay/auction"
"github.com/FastLane-Labs/atlas-operations-relay/config"
"github.com/FastLane-Labs/atlas-operations-relay/contract"
"github.com/FastLane-Labs/atlas-operations-relay/contract/dAppControl"
Expand All @@ -24,6 +25,7 @@ var (
)

type getDAppConfigFn func(common.Address, *operation.UserOperation) (*dAppControl.DAppConfig, *relayerror.Error)
type isAuctionOngoingFn func(common.Hash) bool

type Manager struct {
ethClient *ethclient.Client
Expand All @@ -34,18 +36,20 @@ type Manager struct {

atlasDomainSeparator common.Hash

getDAppConfig getDAppConfigFn
getDAppConfig getDAppConfigFn
isAuctionOngoing isAuctionOngoingFn

mu sync.RWMutex
}

func NewManager(ethClient *ethclient.Client, config *config.Config, atlasDomainSeparator common.Hash, getDAppConfig getDAppConfigFn) *Manager {
func NewManager(ethClient *ethclient.Client, config *config.Config, atlasDomainSeparator common.Hash, getDAppConfig getDAppConfigFn, isAuctionOngoing isAuctionOngoingFn) *Manager {
bm := &Manager{
ethClient: ethClient,
config: config,
bundles: make(map[common.Hash]*Bundle),
atlasDomainSeparator: atlasDomainSeparator,
getDAppConfig: getDAppConfig,
isAuctionOngoing: isAuctionOngoing,
}

go bm.bundlesCleaner()
Expand Down Expand Up @@ -77,6 +81,11 @@ func (bm *Manager) NewBundle(bundleOps *operation.BundleOperations) (common.Hash
return common.Hash{}, nil, relayErr
}

if bm.isAuctionOngoing(userOpHash) {
log.Info("auction is ongoing", "userOpHash", userOpHash.Hex())
return common.Hash{}, nil, auction.ErrAuctionOngoing
}

relayErr = bundleOps.Validate(bm.ethClient, userOpHash, bm.config.Contracts.Atlas, bm.atlasDomainSeparator, bm.config.Relay.Gas.MaxPerUserOperation, bm.config.Relay.Gas.MaxPerDAppOperation, dAppConfig)
if relayErr != nil {
log.Info("invalid dapp operation", "err", relayErr.Message, "userOpHash", userOpHash.Hex())
Expand Down
2 changes: 1 addition & 1 deletion core/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewRelay(ethClient *ethclient.Client, config *config.Config) *Relay {
}

r.auctionManager = auction.NewManager(ethClient, config, atlasDomainSeparator, r.solverGasLimit, r.balanceOfBonded, r.reputationScore, r.getDAppConfig)
r.bundleManager = bundle.NewManager(ethClient, config, atlasDomainSeparator, r.getDAppConfig)
r.bundleManager = bundle.NewManager(ethClient, config, atlasDomainSeparator, r.getDAppConfig, r.auctionManager.IsAuctionOngoing)
r.server = NewServer(NewRouter(NewApi(r)), r.auctionManager.NewSolverOperation, r.auctionManager.GetSolverOperationStatus, r.getDAppSignatories)

return r
Expand Down

0 comments on commit 1eb3f4d

Please sign in to comment.