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

[for review] squash branch diff #20

Draft
wants to merge 27 commits into
base: official-v1.0.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
22779e4
fix optimims port to bsc
s7v7nislands Mar 26, 2023
fbba7ba
Merge pull request #1 from node-real/fix_bsc
s7v7nislands Mar 27, 2023
d75fb80
fix basefee
s7v7nislands Mar 28, 2023
9b95617
Merge pull request #2 from node-real/fix_basefee
keroro520 Mar 28, 2023
2bf1e92
fix gasprice
s7v7nislands Apr 6, 2023
0188575
Merge pull request #4 from node-real/fix_gasprice
s7v7nislands Apr 6, 2023
307353a
add avarage gasprice to l1 block info
s7v7nislands Apr 10, 2023
2f7128c
[beta] new a CI flow to export image to nr ecr
Apr 11, 2023
40a7234
Update and rename ci-with-pr.yml to ci-with-tag.yml
4406arthur Apr 11, 2023
023aa14
Update ci-with-tag.yml
4406arthur Apr 11, 2023
1d83273
Update ci-with-tag.yml
4406arthur Apr 11, 2023
071c9d8
Update ci-with-tag.yml
4406arthur Apr 11, 2023
a7672a5
Update ci-with-tag.yml
4406arthur Apr 11, 2023
4173294
Update ci-with-tag.yml
4406arthur Apr 11, 2023
25954a2
fix(.github): change create trigger to push trigger
keroro520 Apr 11, 2023
f7e1641
Merge pull request #9 from keroro520/cherry-pick-ci-with-tag
keroro520 Apr 12, 2023
a582e6f
filter system trxs which gas price is zero
s7v7nislands Apr 12, 2023
8fa4ea6
update to for_bsc 0.5
s7v7nislands Apr 13, 2023
250fbcb
Merge pull request #11 from node-real/update_to_for_bsc_0.5
keroro520 Apr 13, 2023
372ec73
feat(.github): add docker-build-push.yml
keroro520 Apr 11, 2023
e07e80c
Merge pull request #14 from keroro520/docker-build-push-workflow
keroro520 Apr 17, 2023
6695f82
Merge pull request #17 from node-real/gastrack
keroro520 Apr 19, 2023
19788c8
feat: add API admin_sequencerStopped
keroro520 Apr 28, 2023
4528e1e
Merge pull request #21 from keroro520/feat-sequencer-stopped
keroro520 May 9, 2023
1be46d3
Squashed commit of the following:
s7v7nislands Apr 24, 2023
70ddd71
Merge branch 'nodereal-op' into squash
s7v7nislands May 9, 2023
e2b42dd
Merge branch 'nodereal-op' into squash
s7v7nislands May 9, 2023
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
77 changes: 77 additions & 0 deletions .github/workflows/ci-with-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI-trigger-by-tag

on:
push:
tags:
- '*'
env:
REGION: us-east-1
ECR_REGISTRY_ID: 553885929720

jobs:
ci-lint:
runs-on: [self-hosted,qa-infra-k8s]
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: static check
id: static-check
# TODO: developers need to add static check scripts
run: |
echo "static check"
ci-tests:
runs-on: [self-hosted,qa-infra-k8s]
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: unit tests
id: unit-tests
# TODO: developers need to add unit test scripts
run: |
echo "unit tests"
ci-build:
runs-on: [self-hosted,qa-infra-k8s]
needs: [ci-lint, ci-tests]
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2 # More information on this action can be found below in the 'AWS Credentials' section
with:
role-to-assume: arn:aws:iam::553885929720:role/tf_nodereal_prod_ecr_cicd_deployment_assume_role
aws-region: us-east-1
role-duration-seconds: 1800
- name: Build, tag, and push image to Amazon ECR
env:
OP_NODE_IMAGE_REPO: op-node
OP_BATCHER_IMAGE_REPO: op-batcher
OP_PROPOSER_IMAGE_REPO: op-proposer
run: |

OP_NODE_IMAGE_NAME="${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com/$OP_NODE_IMAGE_REPO:${GITHUB_REF#refs/*/}"
OP_BATCHER_IMAGE_NAME="${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com/$OP_BATCHER_IMAGE_REPO:${GITHUB_REF#refs/*/}"
OP_PROPOSER_IMAGE_NAME="${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com/$OP_PROPOSER_IMAGE_REPO:${GITHUB_REF#refs/*/}"

aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY_ID}.dkr.ecr.${REGION}.amazonaws.com

aws ecr --region $REGION describe-repositories --registry-id $ECR_REGISTRY_ID --repository-names $OP_NODE_IMAGE_REPO || aws ecr --region $REGION create-repository --registry-id $ECR_REGISTRY_ID --repository-name $OP_NODE_IMAGE_REPO
aws ecr --region $REGION set-repository-policy --registry-id $ECR_REGISTRY_ID --repository-name $OP_NODE_IMAGE_REPO --policy-text file:///home/runner/repo-access-permissions.json

aws ecr --region $REGION describe-repositories --registry-id $ECR_REGISTRY_ID --repository-names $OP_BATCHER_IMAGE_REPO || aws ecr --region $REGION create-repository --registry-id $ECR_REGISTRY_ID --repository-name $OP_BATCHER_IMAGE_REPO
aws ecr --region $REGION set-repository-policy --registry-id $ECR_REGISTRY_ID --repository-name $OP_BATCHER_IMAGE_REPO --policy-text file:///home/runner/repo-access-permissions.json

aws ecr --region $REGION describe-repositories --registry-id $ECR_REGISTRY_ID --repository-names $OP_PROPOSER_IMAGE_REPO || aws ecr --region $REGION create-repository --registry-id $ECR_REGISTRY_ID --repository-name $OP_PROPOSER_IMAGE_REPO
aws ecr --region $REGION set-repository-policy --registry-id $ECR_REGISTRY_ID --repository-name $OP_PROPOSER_IMAGE_REPO --policy-text file:///home/runner/repo-access-permissions.json

docker build --build-arg GIT_TOKEN=${{ secrets.GO_MODULES_TOKEN }} -t $OP_NODE_IMAGE_NAME -f op-node/Dockerfile .
docker push $OP_NODE_IMAGE_NAME

docker build --build-arg GIT_TOKEN=${{ secrets.GO_MODULES_TOKEN }} -t $OP_BATCHER_IMAGE_NAME -f op-batcher/Dockerfile .
docker push $OP_BATCHER_IMAGE_NAME

docker build --build-arg GIT_TOKEN=${{ secrets.GO_MODULES_TOKEN }} -t $OP_PROPOSER_IMAGE_NAME -f op-proposer/Dockerfile .
docker push $OP_PROPOSER_IMAGE_NAME

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 }}
2 changes: 1 addition & 1 deletion op-bindings/bindings/erc20.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/optimismportal.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/optimismportal_more.go

Large diffs are not rendered by default.

15 changes: 11 additions & 4 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-node/rollup/derive"
opservice "github.com/ethereum-optimism/optimism/op-service"
)

var (
Expand Down Expand Up @@ -430,8 +432,10 @@ 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 {
return storage, errors.New("block base fee not set")
if !opservice.ForBSC {
if block.BaseFee() == nil {
return storage, errors.New("block base fee not set")
}
}

storage["L2ToL1MessagePasser"] = state.StorageValues{
Expand All @@ -444,15 +448,18 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"msgNonce": 0,
}
storage["L1Block"] = state.StorageValues{
"number": block.Number(),
"timestamp": block.Time(),
"number": block.Number(),
"timestamp": block.Time(),
"basefee": block.BaseFee(),
"hash": block.Hash(),
"sequenceNumber": 0,
"batcherHash": config.BatchSenderAddress.Hash(),
"l1FeeOverhead": config.GasPriceOracleOverhead,
"l1FeeScalar": config.GasPriceOracleScalar,
}
if opservice.ForBSC {
storage["L1Block"]["basefee"] = derive.BSCFakeBaseFee
}
storage["LegacyERC20ETH"] = state.StorageValues{
"_name": "Ether",
"_symbol": "ETH",
Expand Down
2 changes: 2 additions & 0 deletions op-e2e/actions/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
opservice "github.com/ethereum-optimism/optimism/op-service"
)

var enableParallelTesting bool = true
Expand All @@ -13,6 +14,7 @@ func init() {
if os.Getenv("OP_E2E_DISABLE_PARALLEL") == "true" {
enableParallelTesting = false
}
opservice.ForBSC = false
}

func parallel(t e2eutils.TestingBase) {
Expand Down
2 changes: 2 additions & 0 deletions op-e2e/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/sources"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/withdrawals"
opservice "github.com/ethereum-optimism/optimism/op-service"
oppprof "github.com/ethereum-optimism/optimism/op-service/pprof"
)

Expand All @@ -55,6 +56,7 @@ func init() {
if os.Getenv("OP_E2E_DISABLE_PARALLEL") == "true" {
enableParallelTesting = false
}
opservice.ForBSC = false
}

func parallel(t *testing.T) {
Expand Down
27 changes: 26 additions & 1 deletion op-node/eth/heads.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"

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

// HeadSignalFn is used as callback function to accept head-signals
Expand Down Expand Up @@ -48,8 +50,11 @@ func WatchHeadChanges(ctx context.Context, src NewHeadSource, fn HeadSignalFn) (

type L1BlockRefsSource interface {
L1BlockRefByLabel(ctx context.Context, label BlockLabel) (L1BlockRef, error)
L1BlockRefByNumber(ctx context.Context, num uint64) (L1BlockRef, error)
}

var finalizedBlockNumberForBSC uint64 = 15

// PollBlockChanges opens a polling loop to fetch the L1 block reference with the given label,
// on provided interval and with request timeout. Results are returned with provided callback fn,
// which may block to pause/back-pressure polling.
Expand All @@ -67,12 +72,32 @@ func PollBlockChanges(ctx context.Context, log log.Logger, src L1BlockRefsSource
select {
case <-ticker.C:
reqCtx, reqCancel := context.WithTimeout(ctx, timeout)
if opservice.ForBSC {
label = Unsafe
}
ref, err := src.L1BlockRefByLabel(reqCtx, label)
reqCancel()
if err != nil {
log.Warn("failed to poll L1 block", "label", label, "err", err)
} else {
fn(ctx, ref)
if opservice.ForBSC {
reqCtx, reqCancel := context.WithTimeout(ctx, timeout)
number := ref.Number
if number < finalizedBlockNumberForBSC {
number = 0
} else {
number -= finalizedBlockNumberForBSC
}
ref, err := src.L1BlockRefByNumber(reqCtx, number)
reqCancel()
if err != nil {
log.Warn("failed to poll L1 block", "number", number, "err", err)
} else {
fn(ctx, ref)
}
} else {
fn(ctx, ref)
}
}
case <-ctx.Done():
return ctx.Err()
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 @@ -27,6 +27,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 @@ -54,6 +55,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
58 changes: 57 additions & 1 deletion op-node/rollup/derive/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package derive
import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -11,12 +12,14 @@ 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"
opservice "github.com/ethereum-optimism/optimism/op-service"
)

// L1ReceiptsFetcher fetches L1 header info and receipts for the payload attributes derivation (the info tx and deposits)
type L1ReceiptsFetcher interface {
InfoByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, error)
FetchReceipts(ctx context.Context, blockHash common.Hash) (eth.BlockInfo, types.Receipts, error)
InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error)
}

type SystemConfigL2Fetcher interface {
Expand Down Expand Up @@ -53,6 +56,14 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
return nil, NewTemporaryError(fmt.Errorf("failed to retrieve L2 parent block: %w", err))
}

var gasPrice *big.Int
if opservice.ForBSC {
gasPrice, err = ba.prepareAverageGasPrice(ctx, epoch)
if err != nil {
return nil, NewTemporaryError(fmt.Errorf("failed to prepare average gas price: %w", err))
}
}

// If the L1 origin changed this block, then we are in the first block of the epoch. In this
// case we need to fetch all transaction receipts from the L1 origin block so we can scan for
// user deposits.
Expand All @@ -76,7 +87,9 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
if err := UpdateSystemConfigWithL1Receipts(&sysConfig, receipts, ba.cfg); err != nil {
return nil, NewCriticalError(fmt.Errorf("failed to apply derived L1 sysCfg updates: %w", err))
}

if opservice.ForBSC {
info = newGasPriceWrapper(info, gasPrice)
}
l1Info = info
depositTxs = deposits
seqNumber = 0
Expand All @@ -88,6 +101,9 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
if err != nil {
return nil, NewTemporaryError(fmt.Errorf("failed to fetch L1 block info: %w", err))
}
if opservice.ForBSC {
info = newGasPriceWrapper(info, gasPrice)
}
l1Info = info
depositTxs = nil
seqNumber = l2Parent.SequenceNumber + 1
Expand Down Expand Up @@ -118,3 +134,43 @@ func (ba *FetchingAttributesBuilder) PreparePayloadAttributes(ctx context.Contex
GasLimit: (*eth.Uint64Quantity)(&sysConfig.GasLimit),
}, nil
}

var bscDefaultGasPrice = big.NewInt(5000000000)

func (ba *FetchingAttributesBuilder) prepareAverageGasPrice(ctx context.Context, epoch eth.BlockID) (*big.Int, error) {
_, txs, err := ba.l1.InfoAndTxsByHash(ctx, epoch.Hash)
if err != nil {
return nil, err
}
count := 0
var sum big.Int
for _, tx := range txs {
if tx.GasPrice().Cmp(common.Big0) <= 0 {
continue
}
sum.Add(&sum, tx.GasPrice())
count += 1
}
if count == 0 {
return bscDefaultGasPrice, nil
}
return sum.Div(&sum, big.NewInt(int64(count))), nil
}

type gasPriceWrapper struct {
eth.BlockInfo
gasprice *big.Int
}

var _ (eth.BlockInfo) = (*gasPriceWrapper)(nil)

func newGasPriceWrapper(info eth.BlockInfo, gasprice *big.Int) *gasPriceWrapper {
return &gasPriceWrapper{
BlockInfo: info,
gasprice: gasprice,
}
}

func (w *gasPriceWrapper) BaseFee() *big.Int {
return w.gasprice
}
2 changes: 2 additions & 0 deletions op-node/rollup/derive/attributes_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
opservice "github.com/ethereum-optimism/optimism/op-service"
)

// TestAttributesQueue checks that it properly uses the PreparePayloadAttributes function
// (which is well tested) and that it properly sets NoTxPool and adds in the candidate
// transactions.
func TestAttributesQueue(t *testing.T) {
opservice.ForBSC = false
// test config, only init the necessary fields
cfg := &rollup.Config{
BlockTime: 2,
Expand Down
Loading