Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate BlobsBundle on build calls #32

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Blo
return b.eth.stateAtTransaction(ctx, block, txIndex, reexec)
}

func (b *EthAPIBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
func (b *EthAPIBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return b.eth.Miner().BuildBlockFromTxs(ctx, buildArgs, txs)
}

func (b *EthAPIBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
func (b *EthAPIBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return b.eth.Miner().BuildBlockFromBundles(ctx, buildArgs, bundles)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,18 +621,18 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match
panic("implement me")
}

func (n *testBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
func (n *testBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
block := types.NewBlock(&types.Header{GasUsed: 1000, BaseFee: big.NewInt(1)}, txs, nil, nil, trie.NewStackTrie(nil))
return block, big.NewInt(11000), nil
return block, big.NewInt(11000), nil, nil
}

func (n *testBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
func (n *testBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
var txs types.Transactions
for _, bundle := range bundles {
txs = append(txs, bundle.Txs...)
}
block := types.NewBlock(&types.Header{GasUsed: 1000, BaseFee: big.NewInt(1)}, txs, nil, nil, trie.NewStackTrie(nil))
return block, big.NewInt(11000), nil
return block, big.NewInt(11000), nil, nil
}

func (n *testBackend) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type Backend interface {
ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)

// SUAVE Execution Methods
BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error)
BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error)
BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error)
BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error)
}

func GetAPIs(apiBackend Backend) []rpc.API {
Expand Down
8 changes: 4 additions & 4 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent)

func (b *backendMock) Engine() consensus.Engine { return nil }

func (n *backendMock) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
return nil, nil, nil
func (n *backendMock) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return nil, nil, nil, nil
}

func (n *backendMock) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
return nil, nil, nil
func (n *backendMock) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return nil, nil, nil, nil
}

func (n *backendMock) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
Expand Down
48 changes: 30 additions & 18 deletions miner/builder_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (miner *Miner) commitPendingTxs(work *environment) error {
return nil
}

func (miner *Miner) buildBlockFromTxs(ctx context.Context, args *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
func (miner *Miner) buildBlockFromTxs(ctx context.Context, args *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
params := &generateParams{
timestamp: args.Timestamp,
forceTime: true,
Expand All @@ -88,36 +88,37 @@ func (miner *Miner) buildBlockFromTxs(ctx context.Context, args *types.BuildBloc

work, err := miner.prepareWork(params)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

profitPre := work.state.GetBalance(args.FeeRecipient)

if err := miner.rawCommitTransactions(work, txs); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
if args.FillPending {
if err := miner.commitPendingTxs(work); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
}

profitPost := work.state.GetBalance(args.FeeRecipient)
// TODO : Is it okay to set Uncle List to nil?
body := types.Body{Transactions: work.txs, Withdrawals: params.withdrawals}
sidecars := envSidecars(work)
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
blockProfit := new(big.Int).Sub(profitPost.ToBig(), profitPre.ToBig())
return block, blockProfit, nil
return block, blockProfit, sidecars, nil
}

func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
// create ephemeral addr and private key for payment txn
ephemeralPrivKey, err := crypto.GenerateKey()
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
ephemeralAddr := crypto.PubkeyToAddress(ephemeralPrivKey.PublicKey)

Expand All @@ -136,7 +137,7 @@ func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.Build

work, err := miner.prepareWork(params)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

// Assume static 28000 gas transfers for both mev-share and proposer payments
Expand All @@ -150,7 +151,7 @@ func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.Build
// apply bundle
profitPreBundle := work.state.GetBalance(params.coinbase)
if err := miner.rawCommitTransactions(work, bundle.Txs); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
profitPostBundle := work.state.GetBalance(params.coinbase)

Expand All @@ -173,7 +174,7 @@ func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.Build
userTx := bundle.Txs[0] // NOTE : assumes first txn is refund recipient
refundAddr, err := types.Sender(types.LatestSignerForChainID(userTx.ChainId()), userTx)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
paymentTx, err := types.SignTx(types.NewTx(&types.LegacyTx{
Nonce: currNonce,
Expand All @@ -184,18 +185,18 @@ func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.Build
}), work.signer, ephemeralPrivKey)

if err != nil {
return nil, nil, err
return nil, nil, nil, err
}

// commit payment txn
if err := miner.rawCommitTransactions(work, types.Transactions{paymentTx}); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
}
}
if args.FillPending {
if err := miner.commitPendingTxs(work); err != nil {
return nil, nil, err
return nil, nil, nil, err
}
}

Expand All @@ -213,20 +214,31 @@ func (miner *Miner) buildBlockFromBundles(ctx context.Context, args *types.Build
GasPrice: work.header.BaseFee,
}), work.signer, ephemeralPrivKey)
if err != nil {
return nil, nil, fmt.Errorf("could not sign proposer payment: %w", err)
return nil, nil, nil, fmt.Errorf("could not sign proposer payment: %w", err)
}

// commit payment txn
if err := miner.rawCommitTransactions(work, types.Transactions{paymentTx}); err != nil {
return nil, nil, fmt.Errorf("could not sign proposer payment: %w", err)
return nil, nil, nil, fmt.Errorf("could not sign proposer payment: %w", err)
}

log.Info("buildBlockFromBundles", "num_bundles", len(bundles), "num_txns", len(work.txs), "profit", proposerProfit)
// TODO : Is it okay to set Uncle List to nil?
body := types.Body{Transactions: work.txs, Withdrawals: params.withdrawals}
sidecars := envSidecars(work)
block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
return block, proposerProfit, nil
return block, proposerProfit, sidecars, nil
}

func envSidecars(env *environment) []*types.BlobTxSidecar {
sidecars := []*types.BlobTxSidecar{}
for _, tx := range env.txs {
if tx.Type() == 0x03 {
sidecars = append(sidecars, env.sidecars[len(sidecars)])
}
}
return sidecars
}
4 changes: 2 additions & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ func (miner *Miner) getPending() *newPayloadResult {
return ret
}

func (miner *Miner) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
func (miner *Miner) BuildBlockFromTxs(ctx context.Context, buildArgs *types.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return miner.buildBlockFromTxs(ctx, buildArgs, txs)
}

func (miner *Miner) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
func (miner *Miner) BuildBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
return miner.buildBlockFromBundles(ctx, buildArgs, bundles)
}
14 changes: 6 additions & 8 deletions suave/backends/eth_backend_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var _ EthBackend = &EthBackendServer{}
// to resolve the EthBackend server queries
type EthBackendServerBackend interface {
CurrentHeader() *types.Header
BuildBlockFromTxs(ctx context.Context, buildArgs *suave.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error)
BuildBlockFromBundles(ctx context.Context, buildArgs *suave.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error)
BuildBlockFromTxs(ctx context.Context, buildArgs *suave.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error)
BuildBlockFromBundles(ctx context.Context, buildArgs *suave.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error)
Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error)
}

Expand All @@ -51,13 +51,12 @@ func (e *EthBackendServer) BuildEthBlock(ctx context.Context, buildArgs *types.B
}
}

block, profit, err := e.b.BuildBlockFromTxs(ctx, buildArgs, txs)
block, profit, scs, err := e.b.BuildBlockFromTxs(ctx, buildArgs, txs)
if err != nil {
return nil, err
}

// TODO: we're not adding blobs, but this is not where you would do it anyways
return engine.BlockToExecutableData(block, profit, nil), nil
return engine.BlockToExecutableData(block, profit, scs), nil
}

func (e *EthBackendServer) BuildEthBlockFromBundles(ctx context.Context, buildArgs *types.BuildBlockArgs, bundles []types.SBundle) (*engine.ExecutionPayloadEnvelope, error) {
Expand All @@ -75,13 +74,12 @@ func (e *EthBackendServer) BuildEthBlockFromBundles(ctx context.Context, buildAr
}
}

block, profit, err := e.b.BuildBlockFromBundles(ctx, buildArgs, bundles)
block, profit, scs, err := e.b.BuildBlockFromBundles(ctx, buildArgs, bundles)
if err != nil {
return nil, err
}

// TODO: we're not adding blobs, but this is not where you would do it anyways
return engine.BlockToExecutableData(block, profit, nil), nil
return engine.BlockToExecutableData(block, profit, scs), nil
}

func (e *EthBackendServer) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
Expand Down
8 changes: 4 additions & 4 deletions suave/backends/eth_backend_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ func (n *mockBackend) CurrentHeader() *types.Header {
return &types.Header{}
}

func (n *mockBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *suave.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, error) {
func (n *mockBackend) BuildBlockFromTxs(ctx context.Context, buildArgs *suave.BuildBlockArgs, txs types.Transactions) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
block := types.NewBlock(&types.Header{GasUsed: 1000, BaseFee: big.NewInt(1)}, txs, nil, nil, trie.NewStackTrie(nil))
return block, big.NewInt(11000), nil
return block, big.NewInt(11000), nil, nil
}

func (n *mockBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *suave.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, error) {
func (n *mockBackend) BuildBlockFromBundles(ctx context.Context, buildArgs *suave.BuildBlockArgs, bundles []types.SBundle) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
var txs types.Transactions
for _, bundle := range bundles {
txs = append(txs, bundle.Txs...)
}
block := types.NewBlock(&types.Header{GasUsed: 1000, BaseFee: big.NewInt(1)}, txs, nil, nil, trie.NewStackTrie(nil))
return block, big.NewInt(11000), nil
return block, big.NewInt(11000), nil, nil
}

func (n *mockBackend) Call(ctx context.Context, contractAddr common.Address, input []byte) ([]byte, error) {
Expand Down
Loading