Skip to content

Commit

Permalink
clean old maps
Browse files Browse the repository at this point in the history
  • Loading branch information
lukanus committed May 31, 2023
1 parent 6b7338e commit dfabce5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions auction/auctioneer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Auctioneer struct {

type Auction struct {
mu sync.RWMutex
Slot uint64
maxProfit map[types.Hash]structs.BuilderBidExtended
latestBlockByBuilder map[LatestKey]structs.BuilderBidExtended
}
Expand All @@ -26,6 +27,7 @@ func NewAuctioneer() *Auctioneer {
a := &Auctioneer{}
for i := 0; i < structs.NumberOfSlotsInState; i++ {
a.auctions[i] = &Auction{
Slot: uint64(i),
latestBlockByBuilder: make(map[LatestKey]structs.BuilderBidExtended),
maxProfit: make(map[types.Hash]structs.BuilderBidExtended),
}
Expand All @@ -43,21 +45,28 @@ func (a *Auctioneer) AddBlock(bid structs.BuilderBidExtended) bool {
auction.mu.Lock()
defer auction.mu.Unlock()


//auction.latestBlockByBuilder[block.Payload.Trace.Message.BuilderPubkey] = block
//auction.latestBlockByBuilder[bid.BuilderBid().Pubkey()] = bid
auction.latestBlockByBuilder[LatestKey{ParentHash: parent, Pk: bbid.Pubkey()}] = bid
mp, ok := auction.maxProfit[parent]
// always discard submissions lower than latest slot
if auction.Slot > bid.Slot() {
return false
}

// always set new value and bigger slot
if !ok || mp.Slot() < bid.Slot() {
if auction.Slot < bid.Slot() {
a.auctions[bid.Slot()%structs.NumberOfSlotsInState] = &Auction{
Slot: bid.Slot(),
latestBlockByBuilder: make(map[LatestKey]structs.BuilderBidExtended),
maxProfit: make(map[types.Hash]structs.BuilderBidExtended),
}
auction.maxProfit[parent] = bid
auction.latestBlockByBuilder[LatestKey{ParentHash: parent, Pk: bbid.Pubkey()}] = bid
return true
}

// always discard submissions lower than latest slot
if mp.Slot() > bid.Slot() {
return false
auction.latestBlockByBuilder[LatestKey{ParentHash: parent, Pk: bbid.Pubkey()}] = bid
mp, ok := auction.maxProfit[parent]
if !ok {
auction.maxProfit[parent] = bid
return true
}

// accept bigger bid
Expand Down

0 comments on commit dfabce5

Please sign in to comment.