Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 61e65cf

Browse files
Ruteriavalonche
authored andcommitted
More bundle visibility (#42)
Use batch queries for upserting data on built blocks. Include more data on the built blocks - sealing time, orderflow cutoff time, and include data for all bundles considered.
1 parent 6fa73d2 commit 61e65cf

8 files changed

Lines changed: 318 additions & 103 deletions

File tree

builder/builder.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (b *Builder) Stop() error {
9797
return nil
9898
}
9999

100-
func (b *Builder) onSealedBlock(block *types.Block, bundles []types.SimulatedBundle, proposerPubkey boostTypes.PublicKey, proposerFeeRecipient boostTypes.Address, attrs *BuilderPayloadAttributes) error {
100+
func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, sealedAt time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle, proposerPubkey boostTypes.PublicKey, proposerFeeRecipient boostTypes.Address, attrs *BuilderPayloadAttributes) error {
101101
executableData := beacon.BlockToExecutableData(block)
102102
payload, err := executableDataToExecutionPayload(executableData)
103103
if err != nil {
@@ -142,15 +142,15 @@ func (b *Builder) onSealedBlock(block *types.Block, bundles []types.SimulatedBun
142142
log.Error("could not validate block", "err", err)
143143
}
144144
} else {
145-
go b.ds.ConsumeBuiltBlock(block, bundles, &blockBidMsg)
145+
go b.ds.ConsumeBuiltBlock(block, ordersClosedAt, sealedAt, commitedBundles, allBundles, &blockBidMsg)
146146
err = b.relay.SubmitBlock(&blockSubmitReq)
147147
if err != nil {
148-
log.Error("could not submit block", "err", err, "bundles", len(bundles))
148+
log.Error("could not submit block", "err", err, "#commitedBundles", len(commitedBundles))
149149
return err
150150
}
151151
}
152152

153-
log.Info("submitted block", "slot", blockBidMsg.Slot, "value", blockBidMsg.Value.String(), "parent", blockBidMsg.ParentHash, "hash", block.Hash(), "bundles", len(bundles))
153+
log.Info("submitted block", "slot", blockBidMsg.Slot, "value", blockBidMsg.Value.String(), "parent", blockBidMsg.ParentHash, "hash", block.Hash(), "#commitedBundles", len(commitedBundles))
154154

155155
return nil
156156
}
@@ -212,6 +212,14 @@ func (b *Builder) OnPayloadAttribute(attrs *BuilderPayloadAttributes) error {
212212
return nil
213213
}
214214

215+
type blockQueueEntry struct {
216+
block *types.Block
217+
ordersCloseTime time.Time
218+
sealedAt time.Time
219+
commitedBundles []types.SimulatedBundle
220+
allBundles []types.SimulatedBundle
221+
}
222+
215223
func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTypes.PublicKey, feeRecipient boostTypes.Address, attrs *BuilderPayloadAttributes) {
216224
ctx, cancel := context.WithTimeout(slotCtx, 12*time.Second)
217225
defer cancel()
@@ -229,16 +237,16 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
229237
queueMu sync.Mutex
230238
queueLastSubmittedProfit = new(big.Int)
231239
queueBestProfit = new(big.Int)
232-
queueBestBlock *types.Block
233-
queueBestBundles []types.SimulatedBundle
240+
queueBestEntry blockQueueEntry
234241
)
235242

236243
log.Debug("runBuildingJob", "slot", attrs.Slot, "parent", attrs.HeadHash)
237244

238245
submitBestBlock := func() {
239246
queueMu.Lock()
240247
if queueLastSubmittedProfit.Cmp(queueBestProfit) < 0 {
241-
err := b.onSealedBlock(queueBestBlock, queueBestBundles, proposerPubkey, feeRecipient, attrs)
248+
err := b.onSealedBlock(queueBestEntry.block, queueBestEntry.ordersCloseTime, queueBestEntry.sealedAt, queueBestEntry.commitedBundles, queueBestEntry.allBundles, proposerPubkey, feeRecipient, attrs)
249+
242250
if err != nil {
243251
log.Error("could not run sealed block hook", "err", err)
244252
} else {
@@ -252,16 +260,23 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey boostTy
252260
go runResubmitLoop(ctx, b.limiter, queueSignal, submitBestBlock)
253261

254262
// Populates queue with submissions that increase block profit
255-
blockHook := func(block *types.Block, bundles []types.SimulatedBundle) {
263+
blockHook := func(block *types.Block, ordersCloseTime time.Time, commitedBundles []types.SimulatedBundle, allBundles []types.SimulatedBundle) {
256264
if ctx.Err() != nil {
257265
return
258266
}
259267

268+
sealedAt := time.Now()
269+
260270
queueMu.Lock()
261271
defer queueMu.Unlock()
262272
if block.Profit.Cmp(queueBestProfit) > 0 {
263-
queueBestBlock = block
264-
queueBestBundles = bundles
273+
queueBestEntry = blockQueueEntry{
274+
block: block,
275+
ordersCloseTime: ordersCloseTime,
276+
sealedAt: sealedAt,
277+
commitedBundles: commitedBundles,
278+
allBundles: allBundles,
279+
}
265280
queueBestProfit.Set(block.Profit)
266281

267282
select {

builder/eth_service.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
"github.com/ethereum/go-ethereum/core/types"
1010
"github.com/ethereum/go-ethereum/eth"
1111
"github.com/ethereum/go-ethereum/log"
12+
"github.com/ethereum/go-ethereum/miner"
1213
)
1314

1415
type IEthereumService interface {
15-
BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback func(*types.Block, []types.SimulatedBundle)) error
16+
BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback miner.BlockHookFn) error
1617
GetBlockByHash(hash common.Hash) *types.Block
1718
Synced() bool
1819
}
@@ -22,10 +23,11 @@ type testEthereumService struct {
2223
testExecutableData *beacon.ExecutableDataV1
2324
testBlock *types.Block
2425
testBundlesMerged []types.SimulatedBundle
26+
testAllBundles []types.SimulatedBundle
2527
}
2628

27-
func (t *testEthereumService) BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback func(*types.Block, []types.SimulatedBundle)) error {
28-
sealedBlockCallback(t.testBlock, t.testBundlesMerged)
29+
func (t *testEthereumService) BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback miner.BlockHookFn) error {
30+
sealedBlockCallback(t.testBlock, time.Now(), t.testBundlesMerged, t.testAllBundles)
2931
return nil
3032
}
3133

@@ -41,7 +43,7 @@ func NewEthereumService(eth *eth.Ethereum) *EthereumService {
4143
return &EthereumService{eth: eth}
4244
}
4345

44-
func (s *EthereumService) BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback func(*types.Block, []types.SimulatedBundle)) error {
46+
func (s *EthereumService) BuildBlock(attrs *BuilderPayloadAttributes, sealedBlockCallback miner.BlockHookFn) error {
4547
// Send a request to generate a full block in the background.
4648
// The result can be obtained via the returned channel.
4749
resCh, err := s.eth.Miner().GetSealingBlockAsync(attrs.HeadHash, uint64(attrs.Timestamp), attrs.SuggestedFeeRecipient, attrs.GasLimit, attrs.Random, false, sealedBlockCallback)

builder/eth_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestBuildBlock(t *testing.T) {
9393
service := NewEthereumService(ethservice)
9494
service.eth.APIBackend.Miner().SetEtherbase(common.Address{0x05, 0x11})
9595

96-
err := service.BuildBlock(testPayloadAttributes, func(block *types.Block, _ []types.SimulatedBundle) {
96+
err := service.BuildBlock(testPayloadAttributes, func(block *types.Block, _ time.Time, _ []types.SimulatedBundle, _ []types.SimulatedBundle) {
9797
executableData := beacon.BlockToExecutableData(block)
9898
require.Equal(t, common.Address{0x05, 0x11}, executableData.FeeRecipient)
9999
require.Equal(t, common.Hash{0x05, 0x10}, executableData.Random)

0 commit comments

Comments
 (0)