Skip to content

Commit

Permalink
Merge branch 'master' into snapshotter
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Feb 21, 2025
2 parents 6c76c1a + ddd8855 commit 4de083d
Show file tree
Hide file tree
Showing 34 changed files with 724 additions and 243 deletions.
4 changes: 4 additions & 0 deletions .github/buildspec.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 0.2

env:
exported-variables:
- IMAGE_TAG

phases:
pre_build:
commands:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/arbitrator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
id: install-rust-nightly
with:
toolchain: 'nightly-2024-10-06'
targets: 'wasm32-wasi, wasm32-unknown-unknown'
toolchain: 'nightly-2025-02-14'
targets: 'wasm32-wasip1, wasm32-unknown-unknown'
components: 'rust-src, rustfmt, clippy'

- name: Install rust stable
id: install-rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: '1.80.1'
targets: 'wasm32-wasi, wasm32-unknown-unknown'
toolchain: '1.84.1'
targets: 'wasm32-wasip1, wasm32-unknown-unknown'
components: 'llvm-tools-preview, rustfmt, clippy'

- name: Set STYLUS_NIGHTLY_VER environment variable
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ jobs:
uses: dtolnay/rust-toolchain@stable
id: install-rust
with:
toolchain: '1.80.1'
targets: 'wasm32-wasi, wasm32-unknown-unknown'
toolchain: '1.84.1'
targets: 'wasm32-wasip1, wasm32-unknown-unknown'
components: 'llvm-tools-preview, rustfmt, clippy'

- name: Install rust nightly
uses: dtolnay/rust-toolchain@nightly
id: install-rust-nightly
with:
toolchain: 'nightly-2024-10-06'
targets: 'wasm32-wasi, wasm32-unknown-unknown'
toolchain: 'nightly-2025-02-14'
targets: 'wasm32-wasip1, wasm32-unknown-unknown'
components: 'rust-src, rustfmt, clippy'

- name: Set STYLUS_NIGHTLY_VER environment variable
Expand Down
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ FROM wasm-base AS wasm-libs-builder
# clang / lld used by soft-float wasm
RUN apt-get update && \
apt-get install -y clang=1:14.0-55.7~deb12u1 lld=1:14.0-55.7~deb12u1 wabt
# pinned rust 1.80.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.80.1 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasi
# pinned rust 1.84.1
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.84.1 --target x86_64-unknown-linux-gnu wasm32-unknown-unknown wasm32-wasip1
COPY ./Makefile ./
COPY arbitrator/Cargo.* arbitrator/
COPY arbitrator/arbutil arbitrator/arbutil
Expand All @@ -57,6 +57,7 @@ COPY arbitrator/wasm-libraries arbitrator/wasm-libraries
COPY arbitrator/tools/wasmer arbitrator/tools/wasmer
COPY brotli brotli
COPY scripts/build-brotli.sh scripts/
COPY scripts/remove_reference_types.sh scripts/
COPY --from=brotli-wasm-export / target/
RUN apt-get update && apt-get install -y cmake
RUN . ~/.cargo/env && NITRO_BUILD_IGNORE_TIMESTAMPS=1 RUSTFLAGS='-C symbol-mangling-version=v0' make build-wasm-libs
Expand All @@ -65,6 +66,7 @@ FROM scratch AS wasm-libs-export
COPY --from=wasm-libs-builder /workspace/ /

FROM wasm-base AS wasm-bin-builder
RUN apt update && apt install -y wabt
# pinned go version
RUN curl -L https://golang.org/dl/go1.23.1.linux-`dpkg --print-architecture`.tar.gz | tar -C /usr/local -xzf -
COPY ./Makefile ./go.mod ./go.sum ./
Expand All @@ -88,13 +90,14 @@ COPY ./safe-smart-account ./safe-smart-account
COPY ./solgen/gen.go ./solgen/
COPY ./fastcache ./fastcache
COPY ./go-ethereum ./go-ethereum
COPY scripts/remove_reference_types.sh scripts/
COPY --from=brotli-wasm-export / target/
COPY --from=contracts-builder workspace/contracts/build/contracts/src/precompiles/ contracts/build/contracts/src/precompiles/
COPY --from=contracts-builder workspace/contracts/node_modules/@offchainlabs/upgrade-executor/build/contracts/src/UpgradeExecutor.sol/UpgradeExecutor.json contracts/
COPY --from=contracts-builder workspace/.make/ .make/
RUN PATH="$PATH:/usr/local/go/bin" NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-wasm-bin

FROM rust:1.80.1-slim-bookworm AS prover-header-builder
FROM rust:1.84.1-slim-bookworm AS prover-header-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand All @@ -120,7 +123,7 @@ RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-prover-header
FROM scratch AS prover-header-export
COPY --from=prover-header-builder /workspace/target/ /

FROM rust:1.80.1-slim-bookworm AS prover-builder
FROM rust:1.84.1-slim-bookworm AS prover-builder
WORKDIR /workspace
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand Down
67 changes: 31 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ arbitrator_cases=arbitrator/prover/test-cases
arbitrator_tests_wat=$(wildcard $(arbitrator_cases)/*.wat)
arbitrator_tests_rust=$(wildcard $(arbitrator_cases)/rust/src/bin/*.rs)

arbitrator_test_wasms=$(patsubst %.wat,%.wasm, $(arbitrator_tests_wat)) $(patsubst $(arbitrator_cases)/rust/src/bin/%.rs,$(arbitrator_cases)/rust/target/wasm32-wasi/release/%.wasm, $(arbitrator_tests_rust)) $(arbitrator_cases)/go/testcase.wasm
arbitrator_test_wasms=$(patsubst %.wat,%.wasm, $(arbitrator_tests_wat)) $(patsubst $(arbitrator_cases)/rust/src/bin/%.rs,$(arbitrator_cases)/rust/target/wasm32-wasip1/release/%.wasm, $(arbitrator_tests_rust)) $(arbitrator_cases)/go/testcase.wasm

arbitrator_tests_link_info = $(shell cat $(arbitrator_cases)/link.txt | xargs)
arbitrator_tests_link_deps = $(patsubst %,$(arbitrator_cases)/%.wasm, $(arbitrator_tests_link_info))
Expand Down Expand Up @@ -103,7 +103,7 @@ stylus_files = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(wasm_li
jit_dir = arbitrator/jit
jit_files = $(wildcard $(jit_dir)/*.toml $(jit_dir)/*.rs $(jit_dir)/src/*.rs $(jit_dir)/src/*/*.rs) $(stylus_files)

wasm32_wasi = target/wasm32-wasi/release
wasm32_wasi = target/wasm32-wasip1/release
wasm32_unknown = target/wasm32-unknown-unknown/release

stylus_dir = arbitrator/stylus
Expand Down Expand Up @@ -339,6 +339,7 @@ $(output_root)/bin/dbconv: $(DEP_PREDICATE) build-node-deps
$(replay_wasm): $(DEP_PREDICATE) $(go_source) .make/solgen
mkdir -p `dirname $(replay_wasm)`
GOOS=wasip1 GOARCH=wasm go build -o $@ ./cmd/replay/...
./scripts/remove_reference_types.sh $@

$(prover_bin): $(DEP_PREDICATE) $(rust_prover_files)
mkdir -p `dirname $(prover_bin)`
Expand All @@ -356,7 +357,8 @@ $(arbitrator_jit): $(DEP_PREDICATE) $(jit_files)
install arbitrator/target/release/jit $@

$(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm: $(arbitrator_cases)/rust/src/bin/%.rs $(arbitrator_cases)/rust/src/lib.rs $(arbitrator_cases)/rust/.cargo/config.toml
cargo build --manifest-path $(arbitrator_cases)/rust/Cargo.toml --release --target wasm32-wasi --config $(arbitrator_cases)/rust/.cargo/config.toml --bin $(patsubst $(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm,%, $@)
cargo build --manifest-path $(arbitrator_cases)/rust/Cargo.toml --release --target wasm32-wasip1 --config $(arbitrator_cases)/rust/.cargo/config.toml --bin $(patsubst $(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm,%, $@)
./scripts/remove_reference_types.sh $@

$(arbitrator_cases)/go/testcase.wasm: $(arbitrator_cases)/go/*.go .make/solgen
cd $(arbitrator_cases)/go && GOOS=wasip1 GOARCH=wasm go build -o testcase.wasm
Expand All @@ -370,6 +372,7 @@ $(arbitrator_generated_header): $(DEP_PREDICATE) $(stylus_files)
$(output_latest)/wasi_stub.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,wasi-stub)
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-unknown-unknown --config $(wasm_lib_cargo) --package wasi-stub
install arbitrator/wasm-libraries/$(wasm32_unknown)/wasi_stub.wasm $@
./scripts/remove_reference_types.sh $@

arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/softfloat.a: $(DEP_PREDICATE) \
arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/Makefile \
Expand All @@ -381,10 +384,10 @@ arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/softfloat.a: $(D
cd arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang && make $(MAKEFLAGS)

arbitrator/wasm-libraries/soft-float/bindings32.o: $(DEP_PREDICATE) arbitrator/wasm-libraries/soft-float/bindings32.c
clang arbitrator/wasm-libraries/soft-float/bindings32.c --sysroot $(WASI_SYSROOT) -I arbitrator/wasm-libraries/soft-float/SoftFloat/source/include -target wasm32-wasi -Wconversion -c -o $@
clang arbitrator/wasm-libraries/soft-float/bindings32.c --sysroot $(WASI_SYSROOT) -I arbitrator/wasm-libraries/soft-float/SoftFloat/source/include -target wasm32-wasip1 -Wconversion -c -o $@

arbitrator/wasm-libraries/soft-float/bindings64.o: $(DEP_PREDICATE) arbitrator/wasm-libraries/soft-float/bindings64.c
clang arbitrator/wasm-libraries/soft-float/bindings64.c --sysroot $(WASI_SYSROOT) -I arbitrator/wasm-libraries/soft-float/SoftFloat/source/include -target wasm32-wasi -Wconversion -c -o $@
clang arbitrator/wasm-libraries/soft-float/bindings64.c --sysroot $(WASI_SYSROOT) -I arbitrator/wasm-libraries/soft-float/SoftFloat/source/include -target wasm32-wasip1 -Wconversion -c -o $@

$(output_latest)/soft-float.wasm: $(DEP_PREDICATE) \
arbitrator/wasm-libraries/soft-float/bindings32.o \
Expand All @@ -410,24 +413,29 @@ $(output_latest)/soft-float.wasm: $(DEP_PREDICATE) \
--export wavm__f64_promote_f32

$(output_latest)/host_io.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,host-io) $(wasm_lib_go_abi)
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package host-io
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasip1 --config $(wasm_lib_cargo) --package host-io
install arbitrator/wasm-libraries/$(wasm32_wasi)/host_io.wasm $@
./scripts/remove_reference_types.sh $@

$(output_latest)/user_host.wasm: $(DEP_PREDICATE) $(wasm_lib_user_host) $(rust_prover_files) $(output_latest)/forward_stub.wasm .make/machines
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package user-host
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasip1 --config $(wasm_lib_cargo) --package user-host
install arbitrator/wasm-libraries/$(wasm32_wasi)/user_host.wasm $@
./scripts/remove_reference_types.sh $@

$(output_latest)/program_exec.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,program-exec) $(rust_prover_files) .make/machines
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package program-exec
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasip1 --config $(wasm_lib_cargo) --package program-exec
install arbitrator/wasm-libraries/$(wasm32_wasi)/program_exec.wasm $@
./scripts/remove_reference_types.sh $@

$(output_latest)/user_test.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,user-test) $(rust_prover_files) .make/machines
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package user-test
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasip1 --config $(wasm_lib_cargo) --package user-test
install arbitrator/wasm-libraries/$(wasm32_wasi)/user_test.wasm $@
./scripts/remove_reference_types.sh $@

$(output_latest)/arbcompress.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,brotli) $(wasm_lib_go_abi)
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package arbcompress
cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasip1 --config $(wasm_lib_cargo) --package arbcompress
install arbitrator/wasm-libraries/$(wasm32_wasi)/arbcompress.wasm $@
./scripts/remove_reference_types.sh $@

$(output_latest)/forward.wasm: $(DEP_PREDICATE) $(wasm_lib_forward) .make/machines
cargo run --manifest-path $(forward_dir)/Cargo.toml -- --path $(forward_dir)/forward.wat
Expand All @@ -449,80 +457,67 @@ $(stylus_test_dir)/%.wasm: $(stylus_test_dir)/%.b $(stylus_lang_bf)

$(stylus_test_keccak_wasm): $(stylus_test_keccak_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_keccak-100_wasm): $(stylus_test_keccak-100_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_fallible_wasm): $(stylus_test_fallible_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_storage_wasm): $(stylus_test_storage_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_multicall_wasm): $(stylus_test_multicall_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_log_wasm): $(stylus_test_log_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_create_wasm): $(stylus_test_create_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_math_wasm): $(stylus_test_math_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_evm-data_wasm): $(stylus_test_evm-data_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_read-return-data_wasm): $(stylus_test_read-return-data_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_sdk-storage_wasm): $(stylus_test_sdk-storage_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_erc20_wasm): $(stylus_test_erc20_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

$(stylus_test_hostio-test_wasm): $(stylus_test_hostio-test_src)
$(cargo_nightly) --manifest-path $< --release --config $(stylus_cargo)
wasm2wat $@ > $@.wat #removing reference types
wat2wasm $@.wat -o $@
./scripts/remove_reference_types.sh $@
@touch -c $@ # cargo might decide to not rebuild the binary

contracts/test/prover/proofs/float%.json: $(arbitrator_cases)/float%.wasm $(prover_bin) $(output_latest)/soft-float.wasm
Expand Down
101 changes: 101 additions & 0 deletions arbnode/consensus_execution_syncer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2021-2025, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package arbnode

import (
"context"
"errors"
"time"

flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/execution"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/util/stopwaiter"
)

type ConsensusExecutionSyncerConfig struct {
SyncInterval time.Duration `koanf:"sync-interval"`
}

var DefaultConsensusExecutionSyncerConfig = ConsensusExecutionSyncerConfig{
SyncInterval: 1 * time.Second,
}

func ConsensusExecutionSyncerConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Duration(prefix+".sync-interval", DefaultConsensusExecutionSyncerConfig.SyncInterval, "Interval in which finality data is pushed from consensus to execution")
}

type ConsensusExecutionSyncer struct {
stopwaiter.StopWaiter

config func() *ConsensusExecutionSyncerConfig

inboxReader *InboxReader
execClient execution.ExecutionClient
blockValidator *staker.BlockValidator
}

func NewConsensusExecutionSyncer(
config func() *ConsensusExecutionSyncerConfig,
inboxReader *InboxReader,
execClient execution.ExecutionClient,
blockValidator *staker.BlockValidator,
) *ConsensusExecutionSyncer {
return &ConsensusExecutionSyncer{
config: config,
inboxReader: inboxReader,
execClient: execClient,
blockValidator: blockValidator,
}
}

func (c *ConsensusExecutionSyncer) Start(ctx_in context.Context) {
c.StopWaiter.Start(ctx_in, c)
c.CallIteratively(c.pushFinalityDataFromConsensusToExecution)
}

func (c *ConsensusExecutionSyncer) pushFinalityDataFromConsensusToExecution(ctx context.Context) time.Duration {
safeMsgCount, err := c.inboxReader.GetSafeMsgCount(ctx)
if errors.Is(err, headerreader.ErrBlockNumberNotSupported) {
log.Warn("Finality not supported, not pushing finality data to execution")
return c.config().SyncInterval
} else if err != nil {
log.Error("Error getting safe message count", "err", err)
return c.config().SyncInterval
}

finalizedMsgCount, err := c.inboxReader.GetFinalizedMsgCount(ctx)
if errors.Is(err, headerreader.ErrBlockNumberNotSupported) {
log.Warn("Finality not supported, not pushing finality data to execution")
return c.config().SyncInterval
} else if err != nil {
log.Error("Error getting finalized message count", "err", err)
return c.config().SyncInterval
}

var validatedMsgCount arbutil.MessageIndex
if c.blockValidator != nil {
validatedMsgCount = c.blockValidator.GetValidated()
}

finalityData := &arbutil.FinalityData{
SafeMsgCount: safeMsgCount,
FinalizedMsgCount: finalizedMsgCount,
ValidatedMsgCount: &validatedMsgCount,
}

err = c.execClient.SetFinalityData(ctx, finalityData)
if err != nil {
log.Error("Error pushing finality data from consensus to execution", "err", err)
} else {
log.Info("Pushed finality data from consensus to execution", "finalityData", finalityData)
}

return c.config().SyncInterval
}
Loading

0 comments on commit 4de083d

Please sign in to comment.