Skip to content

Commit 5034a0b

Browse files
committed
feat: apply customized features
1 parent 9f1167f commit 5034a0b

File tree

13 files changed

+60
-17
lines changed

13 files changed

+60
-17
lines changed

op-chain-ops/genesis/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/ethereum-optimism/optimism/op-chain-ops/state"
2121
"github.com/ethereum-optimism/optimism/op-node/eth"
2222
"github.com/ethereum-optimism/optimism/op-node/rollup"
23+
24+
"github.com/ethereum-optimism/optimism/op-service/feature"
2325
)
2426

2527
var (
@@ -430,7 +432,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
430432
if block.Number() == nil {
431433
return storage, errors.New("block number not set")
432434
}
433-
if block.BaseFee() == nil {
435+
if feature.CustomizeL1BaseFeeByTransactions(block.BaseFee(), block.Transactions()) == nil {
434436
return storage, errors.New("block base fee not set")
435437
}
436438

@@ -446,7 +448,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
446448
storage["L1Block"] = state.StorageValues{
447449
"number": block.Number(),
448450
"timestamp": block.Time(),
449-
"basefee": block.BaseFee(),
451+
"basefee": feature.CustomizeL1BaseFeeByTransactions(block.BaseFee(), block.Transactions()),
450452
"hash": block.Hash(),
451453
"sequenceNumber": 0,
452454
"batcherHash": config.BatchSenderAddress.Hash(),

op-e2e/actions/l2_verifier.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ func (s *l2VerifierBackend) StopSequencer(ctx context.Context) (common.Hash, err
121121
return common.Hash{}, errors.New("stopping the L2Verifier sequencer is not supported")
122122
}
123123

124+
func (s *l2VerifierBackend) SequencerStopped(ctx context.Context) bool {
125+
return true
126+
}
127+
124128
func (s *L2Verifier) L2Finalized() eth.L2BlockRef {
125129
return s.derivation.Finalized()
126130
}

op-node/node/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type driverClient interface {
2727
SyncStatus(ctx context.Context) (*eth.SyncStatus, error)
2828
BlockRefWithStatus(ctx context.Context, num uint64) (eth.L2BlockRef, *eth.SyncStatus, error)
2929
ResetDerivationPipeline(context.Context) error
30+
SequencerStopped(ctx context.Context) bool
3031
StartSequencer(ctx context.Context, blockHash common.Hash) error
3132
StopSequencer(context.Context) (common.Hash, error)
3233
}
@@ -54,6 +55,10 @@ func (n *adminAPI) ResetDerivationPipeline(ctx context.Context) error {
5455
return n.dr.ResetDerivationPipeline(ctx)
5556
}
5657

58+
func (n *adminAPI) SequencerStopped(ctx context.Context) bool {
59+
return n.dr.SequencerStopped(ctx)
60+
}
61+
5762
func (n *adminAPI) StartSequencer(ctx context.Context, blockHash common.Hash) error {
5863
recordDur := n.m.RecordRPCServerRequest("admin_startSequencer")
5964
defer recordDur()

op-node/node/server_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,7 @@ func (c *mockDriverClient) StartSequencer(ctx context.Context, blockHash common.
227227
func (c *mockDriverClient) StopSequencer(ctx context.Context) (common.Hash, error) {
228228
return c.Mock.MethodCalled("StopSequencer").Get(0).(common.Hash), nil
229229
}
230+
231+
func (c *mockDriverClient) SequencerStopped(ctx context.Context) bool {
232+
return c.Mock.MethodCalled("SequencerStopped").Get(0).(bool)
233+
}

op-node/rollup/derive/attributes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
1212
"github.com/ethereum-optimism/optimism/op-node/eth"
1313
"github.com/ethereum-optimism/optimism/op-node/rollup"
14+
15+
"github.com/ethereum-optimism/optimism/op-service/feature"
1416
)
1517

1618
// L1ReceiptsFetcher fetches L1 header info and receipts for the payload attributes derivation (the info tx and deposits)
@@ -100,6 +102,14 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
100102
l2Parent, nextL2Time, eth.ToBlockID(l1Info), l1Info.Time()))
101103
}
102104

105+
if feature.EnableCustomizeL1BlockBaseFee {
106+
_, receipts, err := ba.l1.FetchReceipts(ctx, epoch.Hash)
107+
if err != nil {
108+
return nil, NewTemporaryError(fmt.Errorf("failed to fetch L1 block receipts: %w", err))
109+
}
110+
l1Info = feature.CustomizeL1BlockInfoByReceipts(l1Info, receipts)
111+
}
112+
103113
l1InfoTx, err := L1InfoDepositBytes(seqNumber, l1Info, sysConfig, ba.cfg.IsRegolith(nextL2Time))
104114
if err != nil {
105115
return nil, NewCriticalError(fmt.Errorf("failed to create l1InfoTx: %w", err))

op-node/rollup/derive/l1_block_info.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ func (info *L1BlockInfo) MarshalBinary() ([]byte, error) {
5454
offset += 32
5555
binary.BigEndian.PutUint64(data[offset+24:offset+32], info.Time)
5656
offset += 32
57-
// Ensure that the baseFee is not too large.
58-
if info.BaseFee.BitLen() > 256 {
59-
return nil, fmt.Errorf("base fee exceeds 256 bits: %d", info.BaseFee)
57+
if info.BaseFee != nil {
58+
// Ensure that the baseFee is not too large.
59+
if info.BaseFee.BitLen() > 256 {
60+
return nil, fmt.Errorf("base fee exceeds 256 bits: %d", info.BaseFee)
61+
}
62+
info.BaseFee.FillBytes(data[offset : offset+32])
6063
}
61-
info.BaseFee.FillBytes(data[offset : offset+32])
6264
offset += 32
6365
copy(data[offset:offset+32], info.BlockHash.Bytes())
6466
offset += 32

op-node/rollup/driver/sequencer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"github.com/ethereum-optimism/optimism/op-service/feature"
78
"time"
89

910
"github.com/ethereum/go-ethereum/common"
@@ -85,6 +86,12 @@ func (d *Sequencer) StartBuildingBlock(ctx context.Context) error {
8586
return err
8687
}
8788

89+
// Request coordinator for the permission to start building a new block.
90+
// If we are not allowed to build a block, then we wait for the next block time.
91+
if feature.Coordinator != nil && !feature.Coordinator.RequestBuildingBlock() {
92+
return fmt.Errorf("failed to request permission for building block")
93+
}
94+
8895
// If our next L2 block timestamp is beyond the Sequencer drift threshold, then we must produce
8996
// empty blocks (other than the L1 info deposit and any user deposits). We handle this by
9097
// setting NoTxPool to true, which will cause the Sequencer to not include any transactions

op-node/rollup/driver/sequencer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func TestSequencerChaosMonkey(t *testing.T) {
302302
}
303303
})
304304

305-
seq := NewSequencer(log, cfg, engControl, attrBuilder, originSelector, metrics.NoopMetrics)
305+
seq := NewSequencer(log, cfg, engControl, nil, attrBuilder, originSelector, metrics.NoopMetrics)
306306
seq.timeNow = clockFn
307307

308308
// try to build 1000 blocks, with 5x as many planning attempts, to handle errors and clock problems

op-node/rollup/driver/state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ func (s *Driver) ResetDerivationPipeline(ctx context.Context) error {
371371
}
372372
}
373373

374+
func (s *Driver) SequencerStopped(_ctx context.Context) bool {
375+
return s.driverConfig.SequencerStopped
376+
}
377+
374378
func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) error {
375379
if !s.driverConfig.SequencerEnabled {
376380
return errors.New("sequencer is not enabled")

op-node/sources/l1_client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/ethereum-optimism/optimism/op-node/eth"
1515
"github.com/ethereum-optimism/optimism/op-node/rollup"
1616
"github.com/ethereum-optimism/optimism/op-node/sources/caching"
17+
18+
"github.com/ethereum-optimism/optimism/op-service/feature"
1719
)
1820

1921
type L1ClientConfig struct {
@@ -75,7 +77,7 @@ func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
7577
// L1BlockRefByLabel returns the [eth.L1BlockRef] for the given block label.
7678
// Notice, we cannot cache a block reference by label because labels are not guaranteed to be unique.
7779
func (s *L1Client) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error) {
78-
info, err := s.InfoByLabel(ctx, label)
80+
info, err := feature.CustomizeL1Label(ctx, s.EthClient, label)
7981
if err != nil {
8082
// Both geth and erigon like to serve non-standard errors for the safe and finalized heads, correct that.
8183
// This happens when the chain just started and nothing is marked as safe/finalized yet.

0 commit comments

Comments
 (0)