Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import (
"github.com/ethereum-optimism/optimism/op-devstack/dsl"
"github.com/ethereum-optimism/optimism/op-devstack/presets"
"github.com/ethereum-optimism/optimism/op-devstack/sysgo"
"github.com/ethereum-optimism/optimism/op-service/bigs"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/txplan"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm/program"
)

const (
Expand Down Expand Up @@ -99,27 +96,6 @@ func newProofsHistorySystem(t devtest.T, c proofsHistoryCase) *proofsHistorySyst
}
}

// deployBlockRecorder deploys a contract that writes the block number to slot 0 and the block
// timestamp to slot 1 on every call, so every call changes its storage.
func deployBlockRecorder(t devtest.T, deployer *dsl.EOA) common.Address {
runtimeCode := program.New().
Op(vm.NUMBER).Push(0).Op(vm.SSTORE).
Op(vm.TIMESTAMP).Push(1).Op(vm.SSTORE).
Bytes()
initCode := program.New().ReturnViaCodeCopy(runtimeCode).Bytes()

tx := deployer.Transact(deployer.Plan(), txplan.WithData(initCode))
receipt, err := tx.Included.Eval(t.Ctx())
t.Require().NoError(err, "block recorder deployment must be included")
return receipt.ContractAddress
}

func includedBlock(t devtest.T, tx *txplan.PlannedTx) uint64 {
receipt, err := tx.Included.Eval(t.Ctx())
t.Require().NoError(err, "transaction must be included")
return bigs.Uint64Strict(receipt.BlockNumber)
}

// TestProofsHistoryFollowerServesMatchingHistoricalProofs runs transfers, withdrawals and contract
// writes against a sequencer that serves eth_getProof from its own historical state, then sweeps a
// proofs-history follower from its window's first block to the last workload block: each of the
Expand All @@ -132,7 +108,7 @@ func TestProofsHistoryFollowerServesMatchingHistoricalProofs(gt *testing.T) {

alice := sys.FunderL2.NewFundedEOA(eth.OneEther)
bob := sys.FunderL2.NewFundedEOA(eth.OneEther)
recorder := deployBlockRecorder(t, alice)
recorder := alice.DeployBlockRecorder()
var lastWorkloadBlock uint64
for round := range workloadRounds {
if round == workloadRounds-1 {
Expand All @@ -144,7 +120,7 @@ func TestProofsHistoryFollowerServesMatchingHistoricalProofs(gt *testing.T) {
alice.Transfer(bob.Address(), eth.OneHundredthEther)
bob.Transfer(alice.Address(), eth.OneHundredthEther)
sys.Bridge.InitiateWithdrawal(eth.OneHundredthEther, bob)
lastWorkloadBlock = includedBlock(t, alice.Transact(alice.Plan(), txplan.WithTo(&recorder)))
lastWorkloadBlock = dsl.IncludedBlockNumber(t, alice.Transact(alice.Plan(), txplan.WithTo(&recorder)))
}

sys.ProofsFollower.VerifyHistoricalProofsMatch(sys.Reference, func(opts *dsl.HistoricalProofsOpts) {
Expand Down

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions op-devstack/dsl/block_recorder_workload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package dsl

import (
"time"

"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum-optimism/optimism/op-service/txplan"
"github.com/ethereum/go-ethereum/common"
)

// BlockRecorderWorkload changes state in nearly every block: a writer and a counterparty transfer
// back and forth and the writer calls a block recorder contract, so every block it fills carries
// balance and storage changes that a rebuilt block would not repeat.
type BlockRecorderWorkload struct {
commonImpl

counterparty *EOA
inclusionPoll txplan.Option
recorder common.Address
// setupBlock is the block that completed the funding and the contract deployment; a chain that
// lacks it lacks the workload's accounts.
setupBlock uint64
writer *EOA
}

// NewBlockRecorderWorkload funds two senders, deploys a block recorder and calls it once.
func NewBlockRecorderWorkload(t devtest.T, funder *FunderEOA) *BlockRecorderWorkload {
w := &BlockRecorderWorkload{
commonImpl: commonFromT(t),
counterparty: funder.NewFundedEOA(eth.OneEther),
inclusionPoll: txplan.Combine(),
writer: funder.NewFundedEOA(eth.OneEther),
}
w.recorder = w.writer.DeployBlockRecorder()
w.setupBlock = IncludedBlockNumber(t, w.writer.Transact(w.writer.Plan(), txplan.WithTo(&w.recorder)))
w.log.Info("Block recorder workload set up", "recorder", w.recorder, "setup_block", w.setupBlock)
return w
}

// WithFreshSenders returns a workload that writes to the same contract from two newly funded
// accounts. A node that reorgs puts the transactions of the blocks it drops back into its pool, so
// new transactions from the original senders could race those for the same nonces.
func (w *BlockRecorderWorkload) WithFreshSenders(funder *FunderEOA) *BlockRecorderWorkload {
fresh := *w
fresh.counterparty = funder.NewFundedEOA(eth.OneEther)
fresh.writer = funder.NewFundedEOA(eth.OneEther)
return &fresh
}

// WithInclusionPoll returns a workload that polls el for its transactions' receipts every
// interval, up to maxAttempts times, so DriveUntilBlock returns within about interval of the block
// that held its last write rather than after the default exponential backoff.
func (w *BlockRecorderWorkload) WithInclusionPoll(el *L2ELNode, interval time.Duration, maxAttempts int) *BlockRecorderWorkload {
polled := *w
polled.inclusionPoll = txplan.WithRetryInclusion(el.EthClient(), maxAttempts, retry.Fixed(interval))
return &polled
}

// Accounts are the senders and the recorder with the storage slots it writes.
func (w *BlockRecorderWorkload) Accounts() []ProofAccount {
return append(w.SenderAccounts(),
ProofAccount{Address: w.recorder, StorageKeys: []common.Hash{common.HexToHash("0x0"), common.HexToHash("0x1")}})
}

func (w *BlockRecorderWorkload) SenderAccounts() []ProofAccount {
return []ProofAccount{{Address: w.counterparty.Address()}, {Address: w.writer.Address()}}
}

func (w *BlockRecorderWorkload) SetupBlock() uint64 {
return w.setupBlock
}

// DriveUntilBlock sends transactions one after another until a contract write lands in a block at
// or past target, and returns that block.
func (w *BlockRecorderWorkload) DriveUntilBlock(target uint64) uint64 {
w.log.Info("Driving the block recorder workload", "target", target)
for {
w.counterparty.Transact(w.counterparty.PlanTransfer(w.writer.Address(), eth.OneHundredthEther), w.inclusionPoll)
w.writer.Transact(w.writer.PlanTransfer(w.counterparty.Address(), eth.OneHundredthEther), w.inclusionPoll)
write := w.writer.Transact(w.writer.Plan(), txplan.WithTo(&w.recorder), w.inclusionPoll)
block := IncludedBlockNumber(w.t, write)
if block >= target {
w.log.Info("Block recorder workload reached target", "target", target, "last_write_block", block)
return block
}
}
}
27 changes: 27 additions & 0 deletions op-devstack/dsl/eoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum-optimism/optimism/op-acceptance-tests/tests/interop"
messages "github.com/ethereum-optimism/optimism/op-core/interop/messages"
"github.com/ethereum-optimism/optimism/op-core/predeploys"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
e2eBindings "github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-service/bigs"
"github.com/ethereum-optimism/optimism/op-service/eth"
Expand All @@ -22,6 +23,8 @@ import (
"github.com/ethereum-optimism/optimism/op-service/txplan"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm/program"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down Expand Up @@ -252,6 +255,30 @@ func (u *EOA) DeployEventLogger() common.Address {
return eventLoggerAddress
}

// DeployBlockRecorder deploys a contract that writes the block number to storage slot 0 and the
// block timestamp to slot 1 on every call, so every call to it changes its storage.
func (u *EOA) DeployBlockRecorder() common.Address {
runtimeCode := program.New().
Op(vm.NUMBER).Push(0).Op(vm.SSTORE).
Op(vm.TIMESTAMP).Push(1).Op(vm.SSTORE).
Bytes()
initCode := program.New().ReturnViaCodeCopy(runtimeCode).Bytes()
tx := txplan.NewPlannedTx(u.Plan(), txplan.WithData(initCode))
_, err := tx.Success.Eval(u.ctx)
u.t.Require().NoError(err, "block recorder deployment must succeed")
res, err := tx.Included.Eval(u.ctx)
u.t.Require().NoError(err, "failed to read the block recorder deployment receipt")
u.log.Info("deployed block recorder", "chainID", tx.ChainID.Value(), "address", res.ContractAddress)
return res.ContractAddress
}

// IncludedBlockNumber waits for tx to be included and returns the number of the block holding it.
func IncludedBlockNumber(t devtest.T, tx *txplan.PlannedTx) uint64 {
receipt, err := tx.Included.Eval(t.Ctx())
t.Require().NoError(err, "transaction must be included")
return bigs.Uint64Strict(receipt.BlockNumber)
}

func (u *EOA) DeployWETH() common.Address {
// Use the e2e bindings which contain the WETH bytecode
tx := txplan.NewPlannedTx(u.Plan(), txplan.WithData(common.FromHex(e2eBindings.WETHBin)))
Expand Down
26 changes: 26 additions & 0 deletions op-devstack/dsl/l2_el.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
safety "github.com/ethereum-optimism/optimism/op-service/eth/safety"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/p2p"
)

var emptyHash = common.Hash{}
Expand Down Expand Up @@ -525,6 +526,15 @@ func (el *L2ELNode) Stop() {
lifecycle.Stop()
}

// StopUngracefully ends the node's process without a shutdown, the way a crash would, so state
// it held only in memory is lost. Start brings the node back.
func (el *L2ELNode) StopUngracefully() {
el.log.Info("Stopping ungracefully", "name", el.inner.Name())
lifecycle, ok := el.inner.(stack.UngracefulLifecycle)
el.require.Truef(ok, "L2EL node %s cannot be stopped ungracefully", el.inner.Name())
lifecycle.StopUngracefully()
}

func (el *L2ELNode) Start() {
lifecycle, ok := el.inner.(stack.Lifecycle)
el.require.Truef(ok, "L2EL node %s is not lifecycle-controllable", el.inner.Name())
Expand All @@ -539,6 +549,22 @@ func (el *L2ELNode) DisconnectPeerWith(peer *L2ELNode) {
sysgo.DisconnectP2P(el.ctx, el.require, el.inner.L2EthClient().RPC(), peer.inner.L2EthClient().RPC())
}

// Enode returns the node's enode URL, which identifies it to its peers across restarts.
func (el *L2ELNode) Enode() string {
var info p2p.NodeInfo
el.require.NoErrorf(el.inner.L2EthClient().RPC().CallContext(el.ctx, &info, "admin_nodeInfo"),
"admin_nodeInfo on %s failed", el)
return info.Enode
}

// ForgetPeer drops this node's peer entry for peerEnode, trusted status included, and waits until
// the peer is no longer connected. The peer may be down.
func (el *L2ELNode) ForgetPeer(peerEnode string) {
el.log.Info("Forgetting peer", "node", el, "peer_enode", peerEnode)
sysgo.ForgetP2PPeer(el.ctx, el.require, el.inner.L2EthClient().RPC(), peerEnode)
el.log.Info("Forgot peer", "node", el, "peer_enode", peerEnode)
}

func (el *L2ELNode) PayloadByNumber(number uint64) *eth.ExecutionPayloadEnvelope {
payload, err := el.inner.L2EthClient().PayloadByNumber(el.ctx, number)
el.require.NoError(err, "failed to get payload")
Expand Down
2 changes: 2 additions & 0 deletions op-devstack/presets/proofs_history_follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const proofsHistoryReferenceEthProofWindow = 1_000_000
// starts.
type ProofsHistoryFollowerConfig struct {
DeployerOptions []sysgo.DeployerOption
FollowerL2CLOpts []sysgo.L2CLOption
FollowerOpRethOpts []sysgo.OpRethOption
// SequencerOpRethOpts apply after the options that turn the sequencer's proofs history off and
// open its eth_getProof window.
Expand Down Expand Up @@ -57,6 +58,7 @@ func NewProofsHistoryFollowerSystem(t devtest.T, configure ...func(*ProofsHistor
CLKind: clKind,
ELKey: "proofs-follower",
ELKind: sysgo.MixedL2ELOpReth,
L2CLOpts: cfg.FollowerL2CLOpts,
OpRethOpts: cfg.FollowerOpRethOpts,
},
},
Expand Down
11 changes: 10 additions & 1 deletion op-devstack/presets/rpc_frontends.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ type l2ELFrontend struct {
l2EngineClient *sources.EngineClient
lifecycle stack.Lifecycle
control stack.ControlledLifecycle
ungraceful stack.UngracefulLifecycle
}

var _ stack.L2ELNode = (*l2ELFrontend)(nil)
var (
_ stack.L2ELNode = (*l2ELFrontend)(nil)
_ stack.UngracefulLifecycle = (*l2ELFrontend)(nil)
)

func newPresetL2ELNode(t devtest.T, name string, chainID eth.ChainID, userRPCCl opclient.RPC, userRPC string, engineRPCCl opclient.RPC, rollupCfg *rollup.Config) *l2ELFrontend {
t.Require().NotNil(rollupCfg, "rollup config must be configured")
Expand Down Expand Up @@ -193,6 +197,11 @@ func (r *l2ELFrontend) Stop() {
r.lifecycle.Stop()
}

func (r *l2ELFrontend) StopUngracefully() {
r.require().NotNil(r.ungraceful, "L2EL node %s cannot be stopped ungracefully", r.Name())
r.ungraceful.StopUngracefully()
}

func (r *l2ELFrontend) StartControlled(ctx context.Context) error {
if r.control == nil {
return fmt.Errorf("L2EL node %s is not controllable", r.Name())
Expand Down
3 changes: 3 additions & 0 deletions op-devstack/presets/sysgo_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func newL2ELFrontend(t devtest.T, name string, chainID eth.ChainID, userRPC stri
if control, ok := lifecycle[0].(stack.ControlledLifecycle); ok {
l2EL.control = control
}
if ungraceful, ok := lifecycle[0].(stack.UngracefulLifecycle); ok {
l2EL.ungraceful = ungraceful
}
}
return l2EL
}
Expand Down
7 changes: 7 additions & 0 deletions op-devstack/stack/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ type ControlledLifecycle interface {
StopControlled(ctx context.Context) error
Running() bool
}

// UngracefulLifecycle is implemented by components that can be stopped the way a process crash
// would stop them: no shutdown runs, so state held only in process memory is lost. Writes already
// handed to the OS survive, so this does not model a power loss.
type UngracefulLifecycle interface {
StopUngracefully()
}
22 changes: 22 additions & 0 deletions op-devstack/sysgo/l2_cl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type L2CLConfig struct {

// OffsetELSafe retracts safe and finalized from the EL-sync tip by floor(OffsetELSafe / L2BlockTime) blocks.
OffsetELSafe time.Duration
// SupportsPostFinalizationELSync lets an op-node in EL sync mode EL-sync even when its EL
// already has a finalized block past genesis. When false, such a node goes straight to CL sync.
// It is off unless set, whatever the EL, while production op-node turns it on for op-reth.
SupportsPostFinalizationELSync bool

// AltDAServerURL is the DA server the node reads alt-DA inputs from. Empty disables alt-DA.
AltDAServerURL string
Expand All @@ -57,6 +61,24 @@ func L2CLFollowSource(source string) L2CLOption {
})
}

// L2CLVerifierSyncMode sets the sync mode a verifier runs: CL sync has op-node fill unsafe gaps
// from its peers, EL sync hands the forkchoice target to the EL and lets it sync from its own
// peers.
func L2CLVerifierSyncMode(mode nodeSync.Mode) L2CLOption {
return L2CLOptionFn(func(p devtest.T, _ ComponentTarget, cfg *L2CLConfig) {
cfg.VerifierSyncMode = mode
})
}

// L2CLPostFinalizationELSync sets whether an op-node in EL sync mode EL-syncs a restart even though
// its EL has a finalized block past genesis. Production op-node enables it for an op-reth or
// op-erigon EL and disables it for op-geth.
func L2CLPostFinalizationELSync(enabled bool) L2CLOption {
return L2CLOptionFn(func(p devtest.T, _ ComponentTarget, cfg *L2CLConfig) {
cfg.SupportsPostFinalizationELSync = enabled
})
}

func DefaultL2CLConfig() *L2CLConfig {
return &L2CLConfig{
SequencerSyncMode: nodeSync.CLSync,
Expand Down
1 change: 1 addition & 0 deletions op-devstack/sysgo/l2_cl_kona_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestKonaL2CLConfigRejectsUnsupportedOptions(t *testing.T) {
{"role override", true, func(cfg *L2CLConfig) { cfg.IsSequencer = false }, "unsupported L2CL option"},
{"sequencer sync", true, func(cfg *L2CLConfig) { cfg.SequencerSyncMode = nodeSync.Mode(99) }, "unknown effective sync mode"},
{"verifier sync", false, func(cfg *L2CLConfig) { cfg.VerifierSyncMode = nodeSync.Mode(99) }, "unknown effective sync mode"},
{"post-finalization EL sync", false, func(cfg *L2CLConfig) { cfg.SupportsPostFinalizationELSync = true }, "unsupported L2CL option"},
{"verifier conductor", false, func(cfg *L2CLConfig) { cfg.ConductorRPC = "http://conductor:8547" }, "unsupported L2CL option"},
{"zero conductor timeout", true, func(cfg *L2CLConfig) { cfg.ConductorRPC = "http://conductor:8547" }, "timeout must be positive"},
{"fractional conductor timeout", true, func(cfg *L2CLConfig) {
Expand Down
30 changes: 30 additions & 0 deletions op-devstack/sysgo/l2_cl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sysgo

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

nodeSync "github.com/ethereum-optimism/optimism/op-node/rollup/sync"
)

func TestL2CLVerifierSyncMode(t *testing.T) {
cfg := &L2CLConfig{SequencerSyncMode: nodeSync.CLSync, VerifierSyncMode: nodeSync.CLSync}
L2CLVerifierSyncMode(nodeSync.ELSync).Apply(nil, ComponentTarget{}, cfg)

require.Equal(t, nodeSync.ELSync, cfg.VerifierSyncMode)
require.Equal(t, nodeSync.CLSync, cfg.SequencerSyncMode, "the sequencer keeps its own sync mode")
}

func TestL2CLPostFinalizationELSync(t *testing.T) {
require.False(t, DefaultL2CLConfig().SupportsPostFinalizationELSync, "op-node skips EL sync past finality by default")
for _, enabled := range []bool{false, true} {
t.Run(fmt.Sprintf("enabled=%t", enabled), func(t *testing.T) {
cfg := &L2CLConfig{SupportsPostFinalizationELSync: !enabled}
L2CLPostFinalizationELSync(enabled).Apply(nil, ComponentTarget{}, cfg)

require.Equal(t, enabled, cfg.SupportsPostFinalizationELSync)
})
}
}
Loading
Loading