Commit 6cb07ee6 authored by protolambda's avatar protolambda Committed by GitHub

op-node: optimize case to handle proposer requests (#11262)

* op-node: optimize case to handle proposer requests

* op-e2e: modify withdrawals test to trigger BlockRefWithStatus finalized hot-path
parent a61e4674
......@@ -22,7 +22,7 @@ import (
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
)
func InitL1(chainID uint64, blockTime uint64, genesis *core.Genesis, c clock.Clock, blobPoolDir string, beaconSrv Beacon, opts ...GethOption) (*node.Node, *eth.Ethereum, error) {
func InitL1(chainID uint64, blockTime uint64, finalizedDistance uint64, genesis *core.Genesis, c clock.Clock, blobPoolDir string, beaconSrv Beacon, opts ...GethOption) (*node.Node, *eth.Ethereum, error) {
ethConfig := &ethconfig.Config{
NetworkId: chainID,
Genesis: genesis,
......@@ -51,12 +51,11 @@ func InitL1(chainID uint64, blockTime uint64, genesis *core.Genesis, c clock.Clo
// Instead of running a whole beacon node, we run this fake-proof-of-stake sidecar that sequences L1 blocks using the Engine API.
l1Node.RegisterLifecycle(&fakePoS{
clock: c,
eth: l1Eth,
log: log.Root(), // geth logger is global anyway. Would be nice to replace with a local logger though.
blockTime: blockTime,
// for testing purposes we make it really fast, otherwise we don't see it finalize in short tests
finalizedDistance: 8,
clock: c,
eth: l1Eth,
log: log.Root(), // geth logger is global anyway. Would be nice to replace with a local logger though.
blockTime: blockTime,
finalizedDistance: finalizedDistance,
safeDistance: 4,
engineAPI: catalyst.NewConsensusAPI(l1Eth),
beacon: beaconSrv,
......
......@@ -124,6 +124,7 @@ func DefaultSystemConfig(t testing.TB) SystemConfig {
L1InfoPredeployAddress: predeploys.L1BlockAddr,
JWTFilePath: writeDefaultJWT(t),
JWTSecret: testingJWTSecret,
L1FinalizedDistance: 8, // Short, for faster tests.
BlobsPath: t.TempDir(),
Nodes: map[string]*rollupNode.Config{
RoleSeq: {
......@@ -239,6 +240,9 @@ type SystemConfig struct {
BlobsPath string
// L1FinalizedDistance is the distance from the L1 head that L1 blocks will be artificially finalized on.
L1FinalizedDistance uint64
Premine map[common.Address]*big.Int
Nodes map[string]*rollupNode.Config // Per node config. Don't use populate rollup.Config
Loggers map[string]log.Logger
......@@ -614,7 +618,8 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
sys.L1BeaconAPIAddr = beaconApiAddr
// Initialize nodes
l1Node, l1Backend, err := geth.InitL1(cfg.DeployConfig.L1ChainID, cfg.DeployConfig.L1BlockTime, l1Genesis, c,
l1Node, l1Backend, err := geth.InitL1(cfg.DeployConfig.L1ChainID,
cfg.DeployConfig.L1BlockTime, cfg.L1FinalizedDistance, l1Genesis, c,
path.Join(cfg.BlobsPath, "l1_el"), bcn, cfg.GethOptions[RoleL1]...)
if err != nil {
return nil, err
......
......@@ -1045,6 +1045,7 @@ func TestWithdrawals(t *testing.T) {
cfg := DefaultSystemConfig(t)
cfg.DeployConfig.FinalizationPeriodSeconds = 2 // 2s finalization period
cfg.L1FinalizedDistance = 2 // Finalize quick, don't make the proposer wait too long
sys, err := cfg.Start(t)
require.NoError(t, err, "Error starting up system")
......
......@@ -518,6 +518,11 @@ func (s *Driver) SyncStatus(ctx context.Context) (*eth.SyncStatus, error) {
// along with an L2 block reference by number consistent with that same status.
// If the event loop is too busy and the context expires, a context error is returned.
func (s *Driver) BlockRefWithStatus(ctx context.Context, num uint64) (eth.L2BlockRef, *eth.SyncStatus, error) {
resp := s.statusTracker.SyncStatus()
if resp.FinalizedL2.Number >= num { // If finalized, we are certain it does not reorg, and don't have to lock.
ref, err := s.L2.L2BlockRefByNumber(ctx, num)
return ref, resp, err
}
wait := make(chan struct{})
select {
case s.stateReq <- wait:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment