-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first pass * Feature/immediate last payloads 3 (#56) * add auctioneer to datastore tests fail * fix main * fix max bid calculation * fix max bid calculation * move auctioneer from datastore to relay * refactored main * fix max profit calculation * fix max block calculation add slot check on block submission * fix max block calculation * fix tests * fix max block calculation * fix max block calculation * add log for auctioneer not having block * add log for auctioneer not having block * change dabug to trace * check slot is not older than current slot * add logs to auctioneer * refactor acutioneer * changed debug to trace log level * fix max profit calculation * fix max profit calculation * add block to auctioneer, after writing payload to storage * put back memory check on GetMaxProfitHeader * fix tests * remove log from datastore * removed log from auctioner * add tiomer to auctioneer * dd slot -1 to auctioneer * revert logs test Co-authored-by: Aratz M. Lasa <[email protected]> Co-authored-by: Aratz M. Lasa <[email protected]>
- Loading branch information
1 parent
d888e78
commit 9e63784
Showing
16 changed files
with
454 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package auction | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/blocknative/dreamboat/pkg/structs" | ||
"github.com/flashbots/go-boost-utils/types" | ||
) | ||
|
||
type Auctioneer struct { | ||
auctions [3]*Auction | ||
} | ||
|
||
type Auction struct { | ||
mu sync.RWMutex | ||
maxProfit *structs.CompleteBlockstruct | ||
latestBlockByBuilder map[types.PublicKey]*structs.CompleteBlockstruct | ||
} | ||
|
||
func NewAuctioneer() *Auctioneer { | ||
return &Auctioneer{ | ||
auctions: [3]*Auction{ | ||
{latestBlockByBuilder: make(map[types.PublicKey]*structs.CompleteBlockstruct)}, // slot - 1 | ||
{latestBlockByBuilder: make(map[types.PublicKey]*structs.CompleteBlockstruct)}, // slot | ||
{latestBlockByBuilder: make(map[types.PublicKey]*structs.CompleteBlockstruct)}, // slot + 1 | ||
}, | ||
} | ||
} | ||
|
||
func (a *Auctioneer) AddBlock(block *structs.CompleteBlockstruct) bool { | ||
auction := a.auctions[block.Header.Trace.Slot%3] | ||
|
||
auction.mu.Lock() | ||
defer auction.mu.Unlock() | ||
|
||
auction.latestBlockByBuilder[block.Payload.Trace.Message.BuilderPubkey] = block | ||
|
||
// always set new value and bigger slot | ||
if auction.maxProfit == nil || auction.maxProfit.Header.Trace.Slot < block.Header.Trace.Slot { | ||
auction.maxProfit = block | ||
return true | ||
} | ||
|
||
// always discard submissions lower than latest slot | ||
if auction.maxProfit.Header.Trace.Slot > block.Header.Trace.Slot { | ||
return false | ||
} | ||
|
||
// accept bigger bid | ||
if auction.maxProfit.Header.Trace.Value.Cmp(&block.Header.Trace.Value) <= 0 { | ||
auction.maxProfit = block | ||
return true | ||
} | ||
|
||
// reassign biggest for resubmission from the same builder with lower bid | ||
if auction.maxProfit.Header.Trace.BuilderPubkey == block.Header.Trace.BuilderPubkey && | ||
auction.maxProfit.Header.Trace.Value.Cmp(&block.Header.Trace.Value) > 0 { | ||
auction.maxProfit = block | ||
for _, b := range auction.latestBlockByBuilder { | ||
if auction.maxProfit.Header.Trace.Slot == b.Header.Trace.Slot && // Only check the current slot | ||
auction.maxProfit.Header.Trace.Value.Cmp(&b.Header.Trace.Value) <= 0 { | ||
auction.maxProfit = b | ||
} | ||
} | ||
} | ||
|
||
return block == auction.maxProfit | ||
} | ||
|
||
func (a *Auctioneer) MaxProfitBlock(slot structs.Slot) (*structs.CompleteBlockstruct, bool) { | ||
auction := a.auctions[slot%3] | ||
|
||
auction.mu.RLock() | ||
defer auction.mu.RUnlock() | ||
|
||
if auction.maxProfit != nil && structs.Slot(auction.maxProfit.Header.Trace.Slot) == slot { | ||
return auction.maxProfit, true | ||
} | ||
|
||
return nil, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.