Skip to content

Commit

Permalink
Merge branch 'opbnb-devel' into merge-upstream-v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoieh committed Dec 14, 2023
2 parents 5ab6a32 + e62988a commit 56be93a
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
C-Protocol-Critical:
- changed-files:
- any-glob-to-any-file: 'packages/contracts-bedrock/**/*.sol'
13 changes: 13 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: "Pull Request Labeler"
on:
- pull_request_target

jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/labeler.yml
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Changelog

## v0.2.4

This is a minor release and upgrading is optional.

### User Facing Changes

- The op-node is pre-configured with bootnodes for opBNB mainnet and testnet. By default, the op-node will use these pre-configured bootnodes for both networks. If you prefer to use your own bootnodes, you can configure the `p2p.bootnodes` parameter in the command line flag.(#89)

### Partial Changelog

- #87: optimize(op-node): make block produce stable when L1 latency unstable
- #89: feat(op-node): add opBNB bootnodes
- #94: fix(op-node/op-batcher): fallbackClient should ignore ethereum.NotFound error

### Docker Images

- ghcr.io/bnb-chain/op-node:v0.2.4
- ghcr.io/bnb-chain/op-batcher:v0.2.4
- ghcr.io/bnb-chain/op-proposer:v0.2.4

### Full Changelog

https://github.com/bnb-chain/opbnb/compare/v0.2.3...v0.2.4

## v0.2.3

This is a minor release and upgrading is optional.
Expand Down
5 changes: 5 additions & 0 deletions op-batcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM --platform=$BUILDPLATFORM golang:1.21.5-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache build-base libc-dev
RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

# build op-batcher with the shared go.mod & go.sum files
Expand All @@ -22,10 +23,14 @@ RUN go mod download

ARG TARGETOS TARGETARCH

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN make op-batcher VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

FROM alpine:3.18

RUN apk add --no-cache libstdc++

COPY --from=builder /app/op-batcher/bin/op-batcher /usr/local/bin

ENTRYPOINT ["op-batcher"]
7 changes: 5 additions & 2 deletions op-chain-ops/genesis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ type DeployConfig struct {
// FundDevAccounts configures whether or not to fund the dev accounts. Should only be used
// during devnet deployments.
FundDevAccounts bool `json:"fundDevAccounts"`
// opBNB fermat hard fork
Fermat *big.Int `json:"fermat,omitempty"`
// RequiredProtocolVersion indicates the protocol version that
// nodes are required to adopt, to stay in sync with the network.
RequiredProtocolVersion params.ProtocolVersion `json:"requiredProtocolVersion"`
Expand Down Expand Up @@ -519,6 +521,7 @@ func (d *DeployConfig) RollupConfig(l1StartBlock *types.Block, l2GenesisBlockHas
RegolithTime: d.RegolithTime(l1StartBlock.Time()),
CanyonTime: d.CanyonTime(l1StartBlock.Time()),
SpanBatchTime: d.SpanBatchTime(l1StartBlock.Time()),
Fermat: d.Fermat,
}, nil
}

Expand Down Expand Up @@ -760,8 +763,8 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"_symbol": "ETH",
}
storage["WETH9"] = state.StorageValues{
"name": "Wrapped Ether",
"symbol": "WETH",
"name": "Wrapped BNB",
"symbol": "WBNB",
"decimals": 18,
}
if config.EnableGovernance {
Expand Down
1 change: 1 addition & 0 deletions op-chain-ops/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewL2Genesis(config *DeployConfig, block *types.Block) (*core.Genesis, erro
RegolithTime: config.RegolithTime(block.Time()),
CanyonTime: config.CanyonTime(block.Time()),
ShanghaiTime: config.CanyonTime(block.Time()),
Fermat: config.Fermat,
Optimism: &params.OptimismConfig{
EIP1559Denominator: eip1559Denom,
EIP1559Elasticity: eip1559Elasticity,
Expand Down
5 changes: 5 additions & 0 deletions op-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM --platform=$BUILDPLATFORM golang:1.21.5-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache build-base libc-dev
RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

# build op-node with the shared go.mod & go.sum files
Expand All @@ -20,10 +21,14 @@ RUN go mod download

ARG TARGETOS TARGETARCH

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN make op-node VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

FROM alpine:3.18

RUN apk add --no-cache libstdc++

COPY --from=builder /app/op-node/bin/op-node /usr/local/bin

CMD ["op-node"]
15 changes: 12 additions & 3 deletions op-node/p2p/cli/load_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewConfig(ctx *cli.Context, rollupCfg *rollup.Config) (*p2p.Config, error)
return nil, fmt.Errorf("failed to load p2p listen options: %w", err)
}

if err := loadDiscoveryOpts(conf, ctx); err != nil {
if err := loadDiscoveryOpts(conf, ctx, rollupCfg); err != nil {
return nil, fmt.Errorf("failed to load p2p discovery options: %w", err)
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func loadListenOpts(conf *p2p.Config, ctx *cli.Context) error {
return nil
}

func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context, rollupCfg *rollup.Config) error {
if ctx.Bool(flags.NoDiscoveryName) {
conf.NoDiscovery = true
}
Expand Down Expand Up @@ -176,7 +176,16 @@ func loadDiscoveryOpts(conf *p2p.Config, ctx *cli.Context) error {
}

bootnodes := make([]*enode.Node, 0)
records := strings.Split(ctx.String(flags.BootnodesName), ",")
var records []string
if !ctx.IsSet(flags.BootnodesName) {
if rollupCfg.L2ChainID.Cmp(p2p.OpBNBTestnet) == 0 {
records = p2p.OpBNBTestnetBootnodes
} else {
records = p2p.OpBNBMainnetBootnodes
}
} else {
records = strings.Split(ctx.String(flags.BootnodesName), ",")
}
for i, recordB64 := range records {
recordB64 = strings.TrimSpace(recordB64)
if recordB64 == "" { // ignore empty records
Expand Down
19 changes: 19 additions & 0 deletions op-node/p2p/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package p2p
import (
"errors"
"fmt"
"math/big"
"net"
"time"

Expand All @@ -28,6 +29,24 @@ import (
// TODO add values
var DefaultBootnodes = []*enode.Node{}

var OpBNBTestnet = big.NewInt(5611)

// OpBNBMainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the opBNB main network.
var OpBNBMainnetBootnodes = []string{
// op-node
"enr:-J24QIGeBCpZHdaQ5i8fyyK_uzaL1DdgOOZA3_lvjHvirjpgexMGkVeGMxlqauzEX7pWAfztCa9hpEGd_bS2a-1IqB6GAYvRDk5QgmlkgnY0gmlwhDaykUmHb3BzdGFja4PMAQCJc2VjcDI1NmsxoQJ-_5GZKjs7jaB4TILdgC8EwnwyL3Qip89wmjnyjvDDwoN0Y3CCIyuDdWRwgiMs",
"enr:-J24QO_AhXy6stHsVvFWnECRD_1hMccZM6JqJgiXNVIRED1JRAJvIS48Pihku2z30TfizSGUAmeb22RQfPjW99hDu9WGAYvRBDnegmlkgnY0gmlwhDbjSM6Hb3BzdGFja4PMAQCJc2VjcDI1NmsxoQKetGQX7sXd4u8hZr6uayTZgHRDvGm36YaryqZkgnidS4N0Y3CCIyuDdWRwgiMs",
}

// OpBNBTestnetBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the opBNB testnet network.
var OpBNBTestnetBootnodes = []string{
// op-node
"enr:-J24QGQBeMsXOaCCaLWtNFSfb2Gv50DjGOKToH2HUTAIn9yXImowlRoMDNuPNhSBZNQGCCE8eAl5O3dsONuuQp5Qix2GAYjB7KHSgmlkgnY0gmlwhDREiqaHb3BzdGFja4PrKwCJc2VjcDI1NmsxoQL4I9wpEVDcUb8bLWu6V8iPoN5w8E8q-GrS5WUCygYUQ4N0Y3CCIyuDdWRwgiMr",
"enr:-J24QJKXHEkIhy0tmIk2EscMZ2aRrivNsZf_YhgIU51g4ZKHWY0BxW6VedRJ1jxmneW9v7JjldPOPpLkaNSo6cXGFxqGAYpK96oCgmlkgnY0gmlwhANzx96Hb3BzdGFja4PrKwCJc2VjcDI1NmsxoQMOCzUFffz04eyDrmkbaSCrMEvLvn5O4RZaZ5k1GV4wa4N0Y3CCIyuDdWRwgiMr",
}

type HostMetrics interface {
gating.UnbanMetrics
gating.ConnectionGaterMetrics
Expand Down
20 changes: 18 additions & 2 deletions op-node/rollup/driver/origin_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/log"
Expand All @@ -16,6 +17,7 @@ import (
type L1Blocks interface {
derive.L1BlockRefByHashFetcher
derive.L1BlockRefByNumberFetcher
derive.L1ReceiptsFetcher
}

type L1OriginSelector struct {
Expand Down Expand Up @@ -48,14 +50,19 @@ func (los *L1OriginSelector) FindL1Origin(ctx context.Context, l2Head eth.L2Bloc
// If we are past the sequencer depth, we may want to advance the origin, but need to still
// check the time of the next origin.
pastSeqDrift := l2Head.Time+los.cfg.BlockTime > currentOrigin.Time+los.cfg.MaxSequencerDrift
// Limit the time to fetch next origin block by default
refCtx, refCancel := context.WithTimeout(ctx, 100*time.Millisecond)
defer refCancel()
if pastSeqDrift {
log.Warn("Next L2 block time is past the sequencer drift + current origin time")
// Must fetch next L1 block as long as it may take, cause we are pastSeqDrift
refCtx = ctx
}

// Attempt to find the next L1 origin block, where the next origin is the immediate child of
// the current origin block.
// The L1 source can be shimmed to hide new L1 blocks and enforce a sequencer confirmation distance.
nextOrigin, err := los.l1.L1BlockRefByNumber(ctx, currentOrigin.Number+1)
nextOrigin, err := los.l1.L1BlockRefByNumber(refCtx, currentOrigin.Number+1)
if err != nil {
if pastSeqDrift {
return eth.L1BlockRef{}, fmt.Errorf("cannot build next L2 block past current L1 origin %s by more than sequencer time drift, and failed to find next L1 origin: %w", currentOrigin, err)
Expand All @@ -68,12 +75,21 @@ func (los *L1OriginSelector) FindL1Origin(ctx context.Context, l2Head eth.L2Bloc
return currentOrigin, nil
}

receiptsCached := true
receiptsCtx, receiptsCancel := context.WithTimeout(ctx, 10*time.Millisecond)
defer receiptsCancel()
_, _, err = los.l1.FetchReceipts(receiptsCtx, nextOrigin.Hash)
if err != nil {
receiptsCached = false
}

// If the next L2 block time is greater than the next origin block's time, we can choose to
// start building on top of the next origin. Sequencer implementation has some leeway here and
// could decide to continue to build on top of the previous origin until the Sequencer runs out
// of slack. For simplicity, we implement our Sequencer to always start building on the latest
// L1 block when we can.
if l2Head.Time+los.cfg.BlockTime >= nextOrigin.Time {
// If not pastSeqDrift and next origin receipts not cached, fallback to current origin.
if l2Head.Time+los.cfg.BlockTime >= nextOrigin.Time && (pastSeqDrift || receiptsCached) {
return nextOrigin, nil
}

Expand Down
4 changes: 4 additions & 0 deletions op-node/rollup/driver/origin_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestOriginSelectorAdvances(t *testing.T) {

l1.ExpectL1BlockRefByHash(a.Hash, a, nil)
l1.ExpectL1BlockRefByNumber(b.Number, b, nil)
l1.ExpectFetchReceipts(b.Hash, nil, nil, nil)

s := NewL1OriginSelector(log, cfg, l1)
next, err := s.FindL1Origin(context.Background(), l2Head)
Expand Down Expand Up @@ -87,6 +88,7 @@ func TestOriginSelectorRespectsOriginTiming(t *testing.T) {

l1.ExpectL1BlockRefByHash(a.Hash, a, nil)
l1.ExpectL1BlockRefByNumber(b.Number, b, nil)
l1.ExpectFetchReceipts(b.Hash, nil, nil, nil)

s := NewL1OriginSelector(log, cfg, l1)
next, err := s.FindL1Origin(context.Background(), l2Head)
Expand Down Expand Up @@ -208,6 +210,7 @@ func TestOriginSelectorSeqDriftRespectsNextOriginTime(t *testing.T) {

l1.ExpectL1BlockRefByHash(a.Hash, a, nil)
l1.ExpectL1BlockRefByNumber(b.Number, b, nil)
l1.ExpectFetchReceipts(b.Hash, nil, nil, nil)

s := NewL1OriginSelector(log, cfg, l1)
next, err := s.FindL1Origin(context.Background(), l2Head)
Expand Down Expand Up @@ -265,6 +268,7 @@ func TestOriginSelectorHandlesLateL1Blocks(t *testing.T) {
l1.ExpectL1BlockRefByHash(a.Hash, a, nil)
l1.ExpectL1BlockRefByHash(a.Hash, a, nil)
l1.ExpectL1BlockRefByNumber(b.Number, b, nil)
l1.ExpectFetchReceipts(b.Hash, nil, nil, nil)

l1Head := b
confDepthL1 := NewConfDepth(2, func() eth.L1BlockRef { return l1Head }, l1)
Expand Down
8 changes: 7 additions & 1 deletion op-node/rollup/driver/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ func (s *Driver) eventLoop() {
case <-stepReqCh:
s.metrics.SetDerivationIdle(false)
s.log.Debug("Derivation process step", "onto_origin", s.derivation.Origin(), "attempts", stepAttempts)
err := s.derivation.Step(context.Background())
stepCtx := context.Background()
if s.driverConfig.SequencerEnabled && !s.driverConfig.SequencerStopped {
var cancelStep context.CancelFunc
stepCtx, cancelStep = context.WithTimeout(ctx, 3*time.Second)
defer cancelStep()
}
err := s.derivation.Step(stepCtx)
stepAttempts += 1 // count as attempt by default. We reset to 0 if we are making healthy progress.
if err == io.EOF {
s.log.Debug("Derivation process went idle", "progress", s.derivation.Origin(), "err", err)
Expand Down
5 changes: 5 additions & 0 deletions op-proposer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM --platform=$BUILDPLATFORM golang:1.21.5-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache build-base libc-dev
RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

# build op-proposer with the shared go.mod & go.sum files
Expand All @@ -21,10 +22,14 @@ RUN go mod download

ARG TARGETOS TARGETARCH

ENV CGO_CFLAGS="-O -D__BLST_PORTABLE__"
ENV CGO_CFLAGS_ALLOW="-O -D__BLST_PORTABLE__"
RUN make op-proposer VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

FROM alpine:3.18

RUN apk add --no-cache libstdc++

COPY --from=builder /app/op-proposer/bin/op-proposer /usr/local/bin

CMD ["op-proposer"]
Loading

0 comments on commit 56be93a

Please sign in to comment.