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

[REVIEW ONLY] nodereal-op-merge-offcial-v1.1.0 diff official/op-node/v1.1.0 #30

Draft
wants to merge 4 commits into
base: official/op-node/v1.1.0
Choose a base branch
from
Draft
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
48 changes: 48 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Push Docker Images

on:
push:
tags:
- '*'

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push op-node image
uses: docker/build-push-action@v4
with:
context: .
file: ./op-node/Dockerfile
push: true
tags: ghcr.io/node-real/optimism/op-node:${{ github.ref_name }}

- name: Build and push op-batcher image
uses: docker/build-push-action@v4
with:
context: .
file: ./op-batcher/Dockerfile
push: true
tags: ghcr.io/node-real/optimism/op-batcher:${{ github.ref_name }}

- name: Build and push op-proposer image
uses: docker/build-push-action@v4
with:
context: .
file: ./op-proposer/Dockerfile
push: true
tags: ghcr.io/node-real/optimism/op-proposer:${{ github.ref_name }}
6 changes: 4 additions & 2 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"

"github.com/ethereum-optimism/optimism/op-service/feature"
)

var (
Expand Down Expand Up @@ -430,7 +432,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
if block.Number() == nil {
return storage, errors.New("block number not set")
}
if block.BaseFee() == nil {
if feature.CustomizeL1BaseFeeByTransactions(block.BaseFee(), block.Transactions()) == nil {
return storage, errors.New("block base fee not set")
}

Expand All @@ -446,7 +448,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
storage["L1Block"] = state.StorageValues{
"number": block.Number(),
"timestamp": block.Time(),
"basefee": block.BaseFee(),
"basefee": feature.CustomizeL1BaseFeeByTransactions(block.BaseFee(), block.Transactions()),
"hash": block.Hash(),
"sequenceNumber": 0,
"batcherHash": config.BatchSenderAddress.Hash(),
Expand Down
4 changes: 4 additions & 0 deletions op-e2e/actions/l2_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (s *l2VerifierBackend) StopSequencer(ctx context.Context) (common.Hash, err
return common.Hash{}, errors.New("stopping the L2Verifier sequencer is not supported")
}

func (s *l2VerifierBackend) SequencerStopped(ctx context.Context) bool {
return true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return true?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is for integration tests only. And l2VerifierBackend.SequencerStopped() will never be used. I just implement it because of Go interface requirement.

}

func (s *L2Verifier) L2Finalized() eth.L2BlockRef {
return s.derivation.Finalized()
}
Expand Down
5 changes: 5 additions & 0 deletions op-node/node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type driverClient interface {
SyncStatus(ctx context.Context) (*eth.SyncStatus, error)
BlockRefWithStatus(ctx context.Context, num uint64) (eth.L2BlockRef, *eth.SyncStatus, error)
ResetDerivationPipeline(context.Context) error
SequencerStopped(ctx context.Context) bool
StartSequencer(ctx context.Context, blockHash common.Hash) error
StopSequencer(context.Context) (common.Hash, error)
}
Expand Down Expand Up @@ -53,6 +54,10 @@ func (n *adminAPI) ResetDerivationPipeline(ctx context.Context) error {
return n.dr.ResetDerivationPipeline(ctx)
}

func (n *adminAPI) SequencerStopped(ctx context.Context) bool {
return n.dr.SequencerStopped(ctx)
}

func (n *adminAPI) StartSequencer(ctx context.Context, blockHash common.Hash) error {
recordDur := n.m.RecordRPCServerRequest("admin_startSequencer")
defer recordDur()
Expand Down
4 changes: 4 additions & 0 deletions op-node/node/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,7 @@ func (c *mockDriverClient) StartSequencer(ctx context.Context, blockHash common.
func (c *mockDriverClient) StopSequencer(ctx context.Context) (common.Hash, error) {
return c.Mock.MethodCalled("StopSequencer").Get(0).(common.Hash), nil
}

func (c *mockDriverClient) SequencerStopped(ctx context.Context) bool {
return c.Mock.MethodCalled("SequencerStopped").Get(0).(bool)
}
10 changes: 10 additions & 0 deletions op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"

"github.com/ethereum-optimism/optimism/op-service/feature"
)

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

if feature.EnableCustomizeL1BlockBaseFee {
_, receipts, err := ba.l1.FetchReceipts(ctx, epoch.Hash)
if err != nil {
return nil, NewTemporaryError(fmt.Errorf("failed to fetch L1 block receipts: %w", err))
}
l1Info = feature.CustomizeL1BlockInfoByReceipts(l1Info, receipts)
}

l1InfoTx, err := L1InfoDepositBytes(seqNumber, l1Info, sysConfig, ba.cfg.IsRegolith(nextL2Time))
if err != nil {
return nil, NewCriticalError(fmt.Errorf("failed to create l1InfoTx: %w", err))
Expand Down
6 changes: 4 additions & 2 deletions op-node/rollup/derive/l1_block_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ func (info *L1BlockInfo) MarshalBinary() ([]byte, error) {
if err := solabi.WriteUint64(w, info.Time); err != nil {
return nil, err
}
if err := solabi.WriteUint256(w, info.BaseFee); err != nil {
return nil, err
if info.BaseFee != nil {
if err := solabi.WriteUint256(w, info.BaseFee); err != nil {
return nil, err
}
}
if err := solabi.WriteHash(w, info.BlockHash); err != nil {
return nil, err
Expand Down
7 changes: 7 additions & 0 deletions op-node/rollup/driver/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/ethereum-optimism/optimism/op-service/feature"
"time"

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

// Request coordinator for the permission to start building a new block.
// If we are not allowed to build a block, then we wait for the next block time.
if feature.Coordinator != nil && !feature.Coordinator.RequestBuildingBlock() {
return fmt.Errorf("failed to request permission for building block")
}

// If our next L2 block timestamp is beyond the Sequencer drift threshold, then we must produce
// empty blocks (other than the L1 info deposit and any user deposits). We handle this by
// setting NoTxPool to true, which will cause the Sequencer to not include any transactions
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/driver/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func TestSequencerChaosMonkey(t *testing.T) {
}
})

seq := NewSequencer(log, cfg, engControl, attrBuilder, originSelector, metrics.NoopMetrics)
seq := NewSequencer(log, cfg, engControl, nil, attrBuilder, originSelector, metrics.NoopMetrics)
seq.timeNow = clockFn

// try to build 1000 blocks, with 5x as many planning attempts, to handle errors and clock problems
Expand Down
4 changes: 4 additions & 0 deletions op-node/rollup/driver/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ func (s *Driver) ResetDerivationPipeline(ctx context.Context) error {
}
}

func (s *Driver) SequencerStopped(_ctx context.Context) bool {
return s.driverConfig.SequencerStopped
}

func (s *Driver) StartSequencer(ctx context.Context, blockHash common.Hash) error {
if !s.driverConfig.SequencerEnabled {
return errors.New("sequencer is not enabled")
Expand Down
4 changes: 3 additions & 1 deletion op-node/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/sources/caching"

"github.com/ethereum-optimism/optimism/op-service/feature"
)

type L1ClientConfig struct {
Expand Down Expand Up @@ -75,7 +77,7 @@ func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
// L1BlockRefByLabel returns the [eth.L1BlockRef] for the given block label.
// Notice, we cannot cache a block reference by label because labels are not guaranteed to be unique.
func (s *L1Client) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error) {
info, err := s.InfoByLabel(ctx, label)
info, err := feature.CustomizeL1Label(ctx, s.EthClient, label)
if err != nil {
// Both geth and erigon like to serve non-standard errors for the safe and finalized heads, correct that.
// This happens when the chain just started and nothing is marked as safe/finalized yet.
Expand Down
4 changes: 3 additions & 1 deletion op-proposer/proposer/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
oppprof "github.com/ethereum-optimism/optimism/op-service/pprof"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-service/txmgr"

"github.com/ethereum-optimism/optimism/op-service/feature"
)

var supportedL2OutputVersion = eth.Bytes32{}
Expand Down Expand Up @@ -324,7 +326,7 @@ func proposeL2OutputTxData(abi *abi.ABI, output *eth.OutputResponse) ([]byte, er
"proposeL2Output",
output.OutputRoot,
new(big.Int).SetUint64(output.BlockRef.Number),
output.Status.CurrentL1.Hash,
feature.CustomizeProposeL1BlockHash(output.Status.CurrentL1.Hash),
new(big.Int).SetUint64(output.Status.CurrentL1.Number))
}

Expand Down
36 changes: 36 additions & 0 deletions op-service/feature/coordinator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package feature

import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
)

type CoordinatorClient struct {
sequencerId string
rpc *rpc.Client
}

func NewCoordinatorClient(url string, sequencerId string) (*CoordinatorClient, error) {
rpc, err := rpc.Dial(url)
if err != nil {
return nil, err
}
return &CoordinatorClient{
sequencerId: sequencerId,
rpc: rpc,
}, nil
}

func (c *CoordinatorClient) RequestBuildingBlock() bool {
var respErr error
err := c.rpc.Call(respErr, "coordinator_requestBuildingBlock", c.sequencerId)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a pointer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a clue. It just works...

if err != nil {
log.Warn("Failed to call coordinator_requestBuildingBlock", "error", err)
return false
}
if respErr != nil {
log.Warn("coordinator_requestBuildingBlock refused request", "error", respErr)
return false
}
return true
}
Loading