Skip to content

Commit

Permalink
Merge pull request #2860 from OffchainLabs/improve-timeboost-code
Browse files Browse the repository at this point in the history
[config change] Improve timeboost implementation
  • Loading branch information
Tristan-Wilson authored Jan 9, 2025
2 parents c9b61ce + 3a1f91c commit be11793
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 437 deletions.
12 changes: 0 additions & 12 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,18 +689,6 @@ func mainImpl() int {
}
}

execNodeConfig := execNode.ConfigFetcher()
if execNodeConfig.Sequencer.Enable && execNodeConfig.Sequencer.Timeboost.Enable {
execNode.Sequencer.StartExpressLane(
ctx,
execNode.Backend.APIBackend(),
execNode.FilterSystem,
common.HexToAddress(execNodeConfig.Sequencer.Timeboost.AuctionContractAddress),
common.HexToAddress(execNodeConfig.Sequencer.Timeboost.AuctioneerAddress),
execNodeConfig.Sequencer.Timeboost.EarlySubmissionGrace,
)
}

err = nil
select {
case err = <-fatalErrChan:
Expand Down
85 changes: 85 additions & 0 deletions execution/gethexec/contract_adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2024-2025, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package gethexec

import (
"context"
"errors"
"math"
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/rpc"
)

// contractAdapter is an impl of bind.ContractBackend with necessary methods defined to work with the ExpressLaneAuction contract
type contractAdapter struct {
*filters.FilterAPI
bind.ContractTransactor // We leave this member unset as it is not used.

apiBackend *arbitrum.APIBackend
}

func (a *contractAdapter) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
logPointers, err := a.GetLogs(ctx, filters.FilterCriteria(q))
if err != nil {
return nil, err
}
logs := make([]types.Log, 0, len(logPointers))
for _, log := range logPointers {
logs = append(logs, *log)
}
return logs, nil
}

func (a *contractAdapter) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
return nil, errors.New("contractAdapter doesn't implement SubscribeFilterLogs - shouldn't be needed")
}

func (a *contractAdapter) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) {
return nil, errors.New("contractAdapter doesn't implement CodeAt - shouldn't be needed")
}

func (a *contractAdapter) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
var num rpc.BlockNumber = rpc.LatestBlockNumber
if blockNumber != nil {
num = rpc.BlockNumber(blockNumber.Int64())
}

state, header, err := a.apiBackend.StateAndHeaderByNumber(ctx, num)
if err != nil {
return nil, err
}

msg := &core.Message{
From: call.From,
To: call.To,
Value: big.NewInt(0),
GasLimit: math.MaxUint64,
GasPrice: big.NewInt(0),
GasFeeCap: big.NewInt(0),
GasTipCap: big.NewInt(0),
Data: call.Data,
AccessList: call.AccessList,
SkipAccountChecks: true,
TxRunMode: core.MessageEthcallMode, // Indicate this is an eth_call
SkipL1Charging: true, // Skip L1 data fees
}

evm := a.apiBackend.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true}, nil)
gp := new(core.GasPool).AddGas(math.MaxUint64)
result, err := core.ApplyMessage(evm, msg, gp)
if err != nil {
return nil, err
}

return result.ReturnData, nil
}
Loading

0 comments on commit be11793

Please sign in to comment.