From 0e7f612eb03bc03743b2e175eaadc8eea1678357 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Thu, 5 Sep 2024 03:04:02 -0400 Subject: [PATCH 01/67] chore: Fix typos in validator/server_jit/spawner.go --- validator/server_jit/spawner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/server_jit/spawner.go b/validator/server_jit/spawner.go index d77317d218..0e16978fc0 100644 --- a/validator/server_jit/spawner.go +++ b/validator/server_jit/spawner.go @@ -30,7 +30,7 @@ type JitSpawnerConfigFecher func() *JitSpawnerConfig var DefaultJitSpawnerConfig = JitSpawnerConfig{ Workers: 0, Cranelift: true, - WasmMemoryUsageLimit: 4294967296, // 2^32 WASM memeory limit + WasmMemoryUsageLimit: 4294967296, // 2^32 WASM memory limit } func JitSpawnerConfigAddOptions(prefix string, f *flag.FlagSet) { @@ -82,7 +82,7 @@ func (v *JitSpawner) execute( ) (validator.GoGlobalState, error) { machine, err := v.machineLoader.GetMachine(ctx, moduleRoot) if err != nil { - return validator.GoGlobalState{}, fmt.Errorf("unabled to get WASM machine: %w", err) + return validator.GoGlobalState{}, fmt.Errorf("unable to get WASM machine: %w", err) } state, err := machine.prove(ctx, entry) From 1bb666593d668fd93f38ffa39f71712be06d36b6 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Tue, 15 Oct 2024 22:19:57 +0200 Subject: [PATCH 02/67] compile module only when activating or in targets list --- arbos/programs/native.go | 165 +++++++++++++++++++++--------- arbos/programs/programs.go | 4 +- arbos/programs/wasmstorehelper.go | 3 +- execution/gethexec/node.go | 3 - 4 files changed, 123 insertions(+), 52 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 725b302ac0..7fc3500e2e 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -70,7 +70,9 @@ func activateProgram( debug bool, burner burn.Burner, ) (*activationInfo, error) { - info, asmMap, err := activateProgramInternal(db, program, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, burner.GasLeft()) + targets := db.Database().WasmTargets() + moduleActivationMandatory := true + info, asmMap, err := activateProgramInternal(program, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, burner.GasLeft(), targets, moduleActivationMandatory) if err != nil { return nil, err } @@ -78,8 +80,7 @@ func activateProgram( return info, nil } -func activateProgramInternal( - db vm.StateDB, +func activateModule( addressForLogging common.Address, codehash common.Hash, wasm []byte, @@ -88,7 +89,7 @@ func activateProgramInternal( arbosVersionForGas uint64, debug bool, gasLeft *uint64, -) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { +) (*activationInfo, []byte, error) { output := &rustBytes{} moduleHash := &bytes32{} stylusData := &C.StylusData{} @@ -106,7 +107,6 @@ func activateProgramInternal( stylusData, (*u64)(gasLeft), )) - module, msg, err := status_mod.toResult(output.intoBytes(), debug) if err != nil { if debug { @@ -114,72 +114,143 @@ func activateProgramInternal( } if errors.Is(err, vm.ErrExecutionReverted) { return nil, nil, fmt.Errorf("%w: %s", ErrProgramActivation, msg) + } else { + return nil, nil, err + } + } + info := &activationInfo{ + moduleHash: moduleHash.toHash(), + initGas: uint16(stylusData.init_cost), + cachedInitGas: uint16(stylusData.cached_init_cost), + asmEstimate: uint32(stylusData.asm_estimate), + footprint: uint16(stylusData.footprint), + } + return info, module, nil +} + +func compileNative( + wasm []byte, + stylusVersion uint16, + debug bool, + target ethdb.WasmTarget, +) ([]byte, error) { + output := &rustBytes{} + status_asm := C.stylus_compile( + goSlice(wasm), + u16(stylusVersion), + cbool(debug), + goSlice([]byte(target)), + output, + ) + asm := output.intoBytes() + if status_asm != 0 { + return nil, fmt.Errorf("%w: %s", ErrProgramActivation, string(asm)) + } + return asm, nil +} + +func activateProgramInternal( + addressForLogging common.Address, + codehash common.Hash, + wasm []byte, + page_limit uint16, + stylusVersion uint16, + arbosVersionForGas uint64, + debug bool, + gasLeft *uint64, + targets []ethdb.WasmTarget, + moduleActivationMandatory bool, +) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { + var wavmFound bool + for _, target := range targets { + if target == rawdb.TargetWavm { + wavmFound = true + break } - return nil, nil, err } - hash := moduleHash.toHash() - targets := db.Database().WasmTargets() type result struct { target ethdb.WasmTarget asm []byte err error } + asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) + + // info can be set in separate thread, make sure to wait before reading + var info *activationInfo + var moduleActivationStarted bool + if moduleActivationMandatory { + moduleActivationStarted = true + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + if err != nil { + return nil, nil, err + } + if wavmFound { + asmMap[rawdb.TargetWavm] = module + } + } + results := make(chan result, len(targets)) for _, target := range targets { target := target if target == rawdb.TargetWavm { - results <- result{target, module, nil} + if moduleActivationStarted { + // skip if already started or activated because of moduleActivationMandatory + results <- result{target, nil, nil} + continue + } + go func() { + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + results <- result{target, module, err} + }() + moduleActivationStarted = true } else { go func() { - output := &rustBytes{} - status_asm := C.stylus_compile( - goSlice(wasm), - u16(stylusVersion), - cbool(debug), - goSlice([]byte(target)), - output, - ) - asm := output.intoBytes() - if status_asm != 0 { - results <- result{target, nil, fmt.Errorf("%w: %s", ErrProgramActivation, string(asm))} - return - } - results <- result{target, asm, nil} + asm, err := compileNative(wasm, stylusVersion, debug, target) + results <- result{target, asm, err} }() } } - asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) + var err error for range targets { res := <-results - if res.err != nil { - err = errors.Join(res.err, err) + if res.asm == nil { + continue + } else if res.err != nil { + err = errors.Join(res.err, fmt.Errorf("%s:%w", res.target, err)) } else { asmMap[res.target] = res.asm } } - if err != nil { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codeHash", codeHash, - "moduleHash", hash, - "targets", targets, - "err", err, - ) + if err != nil && moduleActivationMandatory { + if info != nil { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "moduleHash", info.moduleHash, + "targets", targets, + "err", err, + ) + } else { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "targets", targets, + "err", err, + ) + } panic(fmt.Sprintf("Compilation of %v failed for one or more targets despite activation succeeding: %v", addressForLogging, err)) } - info := &activationInfo{ - moduleHash: hash, - initGas: uint16(stylusData.init_cost), - cachedInitGas: uint16(stylusData.cached_init_cost), - asmEstimate: uint32(stylusData.asm_estimate), - footprint: uint16(stylusData.footprint), - } return info, asmMap, err } -func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging common.Address, code []byte, codeHash common.Hash, pagelimit uint16, time uint64, debugMode bool, program Program) ([]byte, error) { +func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging common.Address, code []byte, codehash common.Hash, pagelimit uint16, time uint64, debugMode bool, program Program) ([]byte, error) { localTarget := rawdb.LocalTarget() localAsm, err := statedb.TryGetActivatedAsm(localTarget, moduleHash) if err == nil && len(localAsm) > 0 { @@ -197,8 +268,10 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c zeroArbosVersion := uint64(0) zeroGas := uint64(0) + targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - info, asmMap, err := activateProgramInternal(statedb, addressForLogging, codeHash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas) + moduleActivationMandatory := false + info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) return nil, fmt.Errorf("failed to reactivate program address: %v err: %w", addressForLogging, err) @@ -300,10 +373,10 @@ func handleReqImpl(apiId usize, req_type u32, data *rustSlice, costPtr *u64, out // Caches a program in Rust. We write a record so that we can undo on revert. // For gas estimation and eth_call, we ignore permanent updates and rely on Rust's LRU. -func cacheProgram(db vm.StateDB, module common.Hash, program Program, addressForLogging common.Address, code []byte, codeHash common.Hash, params *StylusParams, debug bool, time uint64, runMode core.MessageRunMode) { +func cacheProgram(db vm.StateDB, module common.Hash, program Program, addressForLogging common.Address, code []byte, codehash common.Hash, params *StylusParams, debug bool, time uint64, runMode core.MessageRunMode) { if runMode == core.MessageCommitMode { // address is only used for logging - asm, err := getLocalAsm(db, module, addressForLogging, code, codeHash, params.PageLimit, time, debug, program) + asm, err := getLocalAsm(db, module, addressForLogging, code, codehash, params.PageLimit, time, debug, program) if err != nil { panic("unable to recreate wasm") } diff --git a/arbos/programs/programs.go b/arbos/programs/programs.go index 06ff4137da..5861181bff 100644 --- a/arbos/programs/programs.go +++ b/arbos/programs/programs.go @@ -170,7 +170,7 @@ func (p Programs) CallProgram( tracingInfo *util.TracingInfo, calldata []byte, reentrant bool, - runmode core.MessageRunMode, + runMode core.MessageRunMode, ) ([]byte, error) { evm := interpreter.Evm() contract := scope.Contract @@ -246,7 +246,7 @@ func (p Programs) CallProgram( address = *contract.CodeAddr } var arbos_tag uint32 - if runmode == core.MessageCommitMode { + if runMode == core.MessageCommitMode { arbos_tag = statedb.Database().WasmCacheTag() } ret, err := callProgram(address, moduleHash, localAsm, scope, interpreter, tracingInfo, calldata, evmData, goParams, model, arbos_tag) diff --git a/arbos/programs/wasmstorehelper.go b/arbos/programs/wasmstorehelper.go index c2d1aa65b0..1393752b72 100644 --- a/arbos/programs/wasmstorehelper.go +++ b/arbos/programs/wasmstorehelper.go @@ -62,7 +62,8 @@ func (p Programs) SaveActiveProgramToWasmStore(statedb *state.StateDB, codeHash // We know program is activated, so it must be in correct version and not use too much memory // Empty program address is supplied because we dont have access to this during rebuilding of wasm store - info, asmMap, err := activateProgramInternal(statedb, common.Address{}, codeHash, wasm, progParams.PageLimit, program.version, zeroArbosVersion, debugMode, &zeroGas) + moduleActivationMandatory := false + info, asmMap, err := activateProgramInternal(common.Address{}, codeHash, wasm, progParams.PageLimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program while rebuilding wasm store", "expected moduleHash", moduleHash, "err", err) return fmt.Errorf("failed to reactivate program while rebuilding wasm store: %w", err) diff --git a/execution/gethexec/node.go b/execution/gethexec/node.go index 499a13164e..79c5c8896e 100644 --- a/execution/gethexec/node.go +++ b/execution/gethexec/node.go @@ -53,9 +53,6 @@ func (c *StylusTargetConfig) Validate() error { } targetsSet[target] = true } - if !targetsSet[rawdb.TargetWavm] { - return fmt.Errorf("%s target not found in archs list, archs: %v", rawdb.TargetWavm, c.ExtraArchs) - } targetsSet[rawdb.LocalTarget()] = true targets := make([]ethdb.WasmTarget, 0, len(c.ExtraArchs)+1) for target := range targetsSet { From 17bdb495fb1f2b068b61cc3ccb27105834379edc Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 16 Oct 2024 17:41:09 -0600 Subject: [PATCH 03/67] update wasmer pin tp merge 4.3.7 --- arbitrator/tools/wasmer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/tools/wasmer b/arbitrator/tools/wasmer index 6b15433d83..84aec79c13 160000 --- a/arbitrator/tools/wasmer +++ b/arbitrator/tools/wasmer @@ -1 +1 @@ -Subproject commit 6b15433d83f951555c24f0c56dc05e4751b0cc76 +Subproject commit 84aec79c13888bf3fb324ddbd69b3fecc22d4a8c From 0dca996a58e829253817c4284330d2708c3cec19 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Wed, 16 Oct 2024 17:42:25 -0600 Subject: [PATCH 04/67] update cargo.lock for new wasmer --- arbitrator/Cargo.lock | 61 +++++++++++++++++----------- arbitrator/wasm-libraries/Cargo.lock | 14 ++++++- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/arbitrator/Cargo.lock b/arbitrator/Cargo.lock index 2b437968fa..9688d07229 100644 --- a/arbitrator/Cargo.lock +++ b/arbitrator/Cargo.lock @@ -747,11 +747,12 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.5.3" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" dependencies = [ "cfg-if 1.0.0", + "crossbeam-utils", "hashbrown 0.14.5", "lock_api", "once_cell", @@ -974,8 +975,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1312,15 +1315,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - [[package]] name = "mach2" version = "0.4.2" @@ -2558,7 +2552,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytes", "cfg-if 1.0.0", @@ -2580,12 +2574,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wat", - "winapi", + "windows-sys 0.59.0", ] [[package]] name = "wasmer-compiler" -version = "4.2.8" +version = "4.3.7" dependencies = [ "backtrace", "bytes", @@ -2594,6 +2588,7 @@ dependencies = [ "enumset", "lazy_static", "leb128", + "libc", "memmap2 0.5.10", "more-asserts", "region", @@ -2605,12 +2600,13 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser", - "winapi", + "windows-sys 0.59.0", + "xxhash-rust", ] [[package]] name = "wasmer-compiler-cranelift" -version = "4.2.8" +version = "4.3.7" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -2627,7 +2623,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-llvm" -version = "4.2.8" +version = "4.3.7" dependencies = [ "byteorder", "cc", @@ -2649,7 +2645,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.2.8" +version = "4.3.7" dependencies = [ "byteorder", "dynasm", @@ -2666,7 +2662,7 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.2.8" +version = "4.3.7" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2676,21 +2672,25 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", + "getrandom", + "hex", "indexmap 1.9.3", "more-asserts", "rkyv", + "sha2 0.10.8", "target-lexicon", "thiserror", + "xxhash-rust", ] [[package]] name = "wasmer-vm" -version = "4.2.8" +version = "4.3.7" dependencies = [ "backtrace", "cc", @@ -2704,14 +2704,14 @@ dependencies = [ "indexmap 1.9.3", "lazy_static", "libc", - "mach", + "mach2", "memoffset", "more-asserts", "region", "scopeguard", "thiserror", "wasmer-types", - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -2830,6 +2830,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -2942,6 +2951,12 @@ dependencies = [ "tap", ] +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + [[package]] name = "zerocopy" version = "0.6.6" diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index a5a066e5c9..e62acf43a6 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -518,8 +518,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1633,16 +1635,20 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.8" +version = "4.3.7" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", + "getrandom", + "hex", "indexmap 1.9.3", "more-asserts", "rkyv", + "sha2 0.10.8", "target-lexicon", "thiserror", + "xxhash-rust", ] [[package]] @@ -1803,6 +1809,12 @@ dependencies = [ "tap", ] +[[package]] +name = "xxhash-rust" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" + [[package]] name = "zerocopy" version = "0.7.35" From 81155d85bee23c6a0783a7f24bff5bbca67c058a Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 16:44:58 +0200 Subject: [PATCH 05/67] system_tests: fix checkWasmStoreContent helper --- system_tests/common_test.go | 4 +++- system_tests/program_test.go | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/system_tests/common_test.go b/system_tests/common_test.go index 027a41d875..21eaf89cd7 100644 --- a/system_tests/common_test.go +++ b/system_tests/common_test.go @@ -1322,6 +1322,7 @@ func createNonL1BlockChainWithStackConfig( if execConfig == nil { execConfig = ExecConfigDefaultTest(t) } + Require(t, execConfig.Validate()) stack, err := node.New(stackConfig) Require(t, err) @@ -1409,6 +1410,8 @@ func Create2ndNodeWithConfig( if execConfig == nil { execConfig = ExecConfigDefaultNonSequencerTest(t) } + Require(t, execConfig.Validate()) + feedErrChan := make(chan error, 10) parentChainRpcClient := parentChainStack.Attach() parentChainClient := ethclient.NewClient(parentChainRpcClient) @@ -1442,7 +1445,6 @@ func Create2ndNodeWithConfig( AddValNodeIfNeeded(t, ctx, nodeConfig, true, "", valnodeConfig.Wasm.RootPath) - Require(t, execConfig.Validate()) Require(t, nodeConfig.Validate()) configFetcher := func() *gethexec.Config { return execConfig } currentExec, err := gethexec.CreateExecutionNode(ctx, chainStack, chainDb, blockchain, parentChainClient, configFetcher) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 4c896d1791..156d9d3638 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -1991,6 +1991,7 @@ func readModuleHashes(t *testing.T, wasmDb ethdb.KeyValueStore) []common.Hash { } func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []string, numModules int) { + t.Helper() modules := readModuleHashes(t, wasmDb) if len(modules) != numModules { t.Fatalf("Unexpected number of module hashes found in wasm store, want: %d, have: %d", numModules, len(modules)) @@ -2002,12 +2003,16 @@ func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []s t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) } func() { + t.Helper() defer func() { if r := recover(); r != nil { t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) } }() - _ = rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + asm := rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + if len(asm) == 0 { + t.Fatalf("Missing activated asm for target: %v, module: %v", target, module) + } }() } } From 8914c571031897357d203632cab0b0f558b65901 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 19:32:40 +0200 Subject: [PATCH 06/67] run some tests with single wasm target --- system_tests/program_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 156d9d3638..342807cbe2 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -58,6 +58,12 @@ func TestProgramKeccak(t *testing.T) { builder.WithExtraArchs(allWasmTargets) }) }) + + t.Run("WithOnlyLocalTarget", func(t *testing.T) { + keccakTest(t, true, func(builder *NodeBuilder) { + builder.WithExtraArchs([]string{string(rawdb.LocalTarget())}) + }) + }) } func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { @@ -163,6 +169,11 @@ func TestProgramActivateTwice(t *testing.T) { builder.WithExtraArchs(allWasmTargets) }) }) + t.Run("WithOnlyLocalTarget", func(t *testing.T) { + testActivateTwice(t, true, func(builder *NodeBuilder) { + builder.WithExtraArchs([]string{string(rawdb.LocalTarget())}) + }) + }) } func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { From 1abc820181760f4b0ceddc4b16deaf27d6744756 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 23 Oct 2024 21:54:35 +0200 Subject: [PATCH 07/67] system_tests: check for unexpected extra asm in checkWasmStoreContent --- system_tests/program_test.go | 63 ++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/system_tests/program_test.go b/system_tests/program_test.go index 342807cbe2..65710a86a8 100644 --- a/system_tests/program_test.go +++ b/system_tests/program_test.go @@ -74,7 +74,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { programAddress := deployWasm(t, ctx, auth, l2client, rustFile("keccak")) wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) wasm, _ := readWasmFile(t, rustFile("keccak")) otherAddressSameCode := deployContract(t, ctx, auth, l2client, wasm) @@ -87,7 +87,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) { Fatal(t, "activate should have failed with ProgramUpToDate", err) } }) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) if programAddress == otherAddressSameCode { Fatal(t, "expected to deploy at two separate program addresses") @@ -205,7 +205,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) multiAddr := deployWasm(t, ctx, auth, l2client, rustFile("multicall")) wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) preimage := []byte("it's time to du-du-du-du d-d-d-d-d-d-d de-duplicate") @@ -230,7 +230,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) // Calling the contract pre-activation should fail. checkReverts() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // mechanisms for creating calldata activateProgram, _ := util.NewCallParser(pgen.ArbWasmABI, "activateProgram") @@ -253,7 +253,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) // Ensure the revert also reverted keccak's activation checkReverts() - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // Activate keccak program A, then call into B, which should succeed due to being the same codehash args = argsForMulticall(vm.CALL, types.ArbWasmAddress, oneEth, pack(activateProgram(keccakA))) @@ -261,7 +261,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder) tx = l2info.PrepareTxTo("Owner", &multiAddr, 1e9, oneEth, args) ensure(tx, l2client.SendTransaction(ctx, tx)) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 2) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 2) validateBlocks(t, 7, jit, builder) } @@ -1917,7 +1917,7 @@ func TestWasmStoreRebuilding(t *testing.T) { storeMap, err := createMapFromDb(wasmDb) Require(t, err) - checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1) // close nodeB cleanupB() @@ -1974,7 +1974,7 @@ func TestWasmStoreRebuilding(t *testing.T) { } } - checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.ExtraArchs, 1) + checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.WasmTargets(), 1) cleanupB() } @@ -2001,30 +2001,43 @@ func readModuleHashes(t *testing.T, wasmDb ethdb.KeyValueStore) []common.Hash { return modules } -func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []string, numModules int) { +func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, expectedTargets []ethdb.WasmTarget, numModules int) { t.Helper() modules := readModuleHashes(t, wasmDb) if len(modules) != numModules { t.Fatalf("Unexpected number of module hashes found in wasm store, want: %d, have: %d", numModules, len(modules)) } - for _, module := range modules { - for _, target := range targets { - wasmTarget := ethdb.WasmTarget(target) - if !rawdb.IsSupportedWasmTarget(wasmTarget) { - t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) - } - func() { - t.Helper() - defer func() { - if r := recover(); r != nil { - t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) - } - }() - asm := rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) - if len(asm) == 0 { - t.Fatalf("Missing activated asm for target: %v, module: %v", target, module) + readAsm := func(module common.Hash, target string) []byte { + wasmTarget := ethdb.WasmTarget(target) + if !rawdb.IsSupportedWasmTarget(wasmTarget) { + t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target) + } + return func() []byte { + t.Helper() + defer func() { + if r := recover(); r != nil { + t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module) } }() + return rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module) + }() + } + for _, module := range modules { + for _, target := range allWasmTargets { + var expected bool + for _, expectedTarget := range expectedTargets { + if ethdb.WasmTarget(target) == expectedTarget { + expected = true + break + } + } + asm := readAsm(module, target) + if expected && len(asm) == 0 { + t.Fatalf("Missing asm for target: %v, module: %v", target, module) + } + if !expected && len(asm) > 0 { + t.Fatalf("Found asm for target: %v, module: %v, expected targets: %v", target, module, expectedTargets) + } } } } From 233c3248c94d6cc2707a021c8068a8267f13d594 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Wed, 13 Nov 2024 18:09:58 +0100 Subject: [PATCH 08/67] always recompile module when recompiling native targets to validate module hash --- arbos/programs/native.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 7fc3500e2e..8144cafb75 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -270,7 +270,7 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - moduleActivationMandatory := false + moduleActivationMandatory := true // TODO: refactor the parameter, always set to true info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) From 06c9affc5e53896b7ab1a7b77bc5cf47f490f1a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 11:32:39 +0000 Subject: [PATCH 09/67] Bump github.com/golang-jwt/jwt/v4 from 4.5.0 to 4.5.1 Bumps [github.com/golang-jwt/jwt/v4](https://github.com/golang-jwt/jwt) from 4.5.0 to 4.5.1. - [Release notes](https://github.com/golang-jwt/jwt/releases) - [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md) - [Commits](https://github.com/golang-jwt/jwt/compare/v4.5.0...v4.5.1) --- updated-dependencies: - dependency-name: github.com/golang-jwt/jwt/v4 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 34b04121f0..dc66862333 100644 --- a/go.mod +++ b/go.mod @@ -129,7 +129,7 @@ require ( github.com/gobwas/pool v0.2.1 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.1 // indirect github.com/golang/glog v1.2.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect diff --git a/go.sum b/go.sum index bbb38af6ac..fe0cef8edb 100644 --- a/go.sum +++ b/go.sum @@ -277,8 +277,8 @@ github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14j github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= From e6571ca397c43642dda0dc6da31140c16a3a5013 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Fri, 15 Nov 2024 17:55:28 +0800 Subject: [PATCH 10/67] feat: update google-cloud-storage parameters and object retention setting --- das/google_cloud_storage_service.go | 173 +++++++++------------------- 1 file changed, 57 insertions(+), 116 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index 829f4b5265..adf039347c 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -21,151 +21,88 @@ import ( "github.com/offchainlabs/nitro/util/pretty" ) -type GoogleCloudStorageOperator interface { - Bucket(name string) *googlestorage.BucketHandle - Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error - Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) - Close(ctx context.Context) error -} - -type GoogleCloudStorageClient struct { - client *googlestorage.Client -} - -func (g *GoogleCloudStorageClient) Bucket(name string) *googlestorage.BucketHandle { - return g.client.Bucket(name) -} - -func (g *GoogleCloudStorageClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error { - obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) - w := obj.NewWriter(ctx) - - if _, err := fmt.Fprintln(w, value); err != nil { - return err - } - return w.Close() - -} - -func (g *GoogleCloudStorageClient) Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) { - obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(key)) - reader, err := obj.NewReader(ctx) - if err != nil { - return nil, err - } - return io.ReadAll(reader) -} - -func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { - return g.client.Close() -} - type GoogleCloudStorageServiceConfig struct { - Enable bool `koanf:"enable"` - AccessToken string `koanf:"access-token"` - Bucket string `koanf:"bucket"` - ObjectPrefix string `koanf:"object-prefix"` - EnableExpiry bool `koanf:"enable-expiry"` - MaxRetention time.Duration `koanf:"max-retention"` + Enable bool `koanf:"enable"` + AccessTokenFile string `koanf:"access-token-file"` + Bucket string `koanf:"bucket"` + ObjectPrefix string `koanf:"object-prefix"` + DiscardAfterTimeout bool `koanf:"discard-after-timeout"` } var DefaultGoogleCloudStorageServiceConfig = GoogleCloudStorageServiceConfig{} func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultGoogleCloudStorageServiceConfig.Enable, "EXPERIMENTAL/unsupported - enable storage/retrieval of sequencer batch data from an Google Cloud Storage bucket") - f.String(prefix+".access-token", DefaultGoogleCloudStorageServiceConfig.AccessToken, "Google Cloud Storage access token") + f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token") f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") - f.Bool(prefix+".enable-expiry", DefaultLocalFileStorageConfig.EnableExpiry, "enable expiry of batches") - f.Duration(prefix+".max-retention", DefaultLocalFileStorageConfig.MaxRetention, "store requests with expiry times farther in the future than max-retention will be rejected") + f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") } type GoogleCloudStorageService struct { - operator GoogleCloudStorageOperator - bucket string - objectPrefix string - enableExpiry bool - maxRetention time.Duration + client *googlestorage.Client + bucket string + objectPrefix string + discardAfterTimeout bool } func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (StorageService, error) { - var client *googlestorage.Client - var err error - // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) - // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if config.AccessToken == "" { - client, err = googlestorage.NewClient(context.Background()) - } else { - client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken))) - } + client, err := buildGoogleCloudStorageClient(config.AccessTokenFile) if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) } - service := &GoogleCloudStorageService{ - operator: &GoogleCloudStorageClient{client: client}, - bucket: config.Bucket, - objectPrefix: config.ObjectPrefix, - enableExpiry: config.EnableExpiry, - maxRetention: config.MaxRetention, - } - if config.EnableExpiry { - lifecycleRule := googlestorage.LifecycleRule{ - Action: googlestorage.LifecycleAction{Type: "Delete"}, - Condition: googlestorage.LifecycleCondition{AgeInDays: int64(config.MaxRetention.Hours() / 24)}, // Objects older than 30 days - } - ctx := context.Background() - bucket := service.operator.Bucket(service.bucket) - // check if bucket exists (and others), and update expiration policy if enabled - attrs, err := bucket.Attrs(ctx) - if err != nil { - return nil, fmt.Errorf("error getting bucket attributes: %w", err) - } - attrs.Lifecycle.Rules = append(attrs.Lifecycle.Rules, lifecycleRule) - - bucketAttrsToUpdate := googlestorage.BucketAttrsToUpdate{ - Lifecycle: &attrs.Lifecycle, - } - if _, err := bucket.Update(ctx, bucketAttrsToUpdate); err != nil { - return nil, fmt.Errorf("failed to update bucket lifecycle: %w", err) - } - } - return service, nil + return &GoogleCloudStorageService{ + client: client, + bucket: config.Bucket, + objectPrefix: config.ObjectPrefix, + discardAfterTimeout: config.DiscardAfterTimeout, + }, nil } -func (gcs *GoogleCloudStorageService) Put(ctx context.Context, data []byte, expiry uint64) error { - logPut("das.GoogleCloudStorageService.Store", data, expiry, gcs) - if expiry > math.MaxInt64 { - return fmt.Errorf("request expiry time (%v) exceeds max int64", expiry) - } - // #nosec G115 - expiryTime := time.Unix(int64(expiry), 0) - currentTimePlusRetention := time.Now().Add(gcs.maxRetention) - if expiryTime.After(currentTimePlusRetention) { - return fmt.Errorf("requested expiry time (%v) exceeds current time plus maximum allowed retention period(%v)", expiryTime, currentTimePlusRetention) - } - if err := gcs.operator.Upload(ctx, gcs.bucket, gcs.objectPrefix, data); err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) - return err +func buildGoogleCloudStorageClient(accessTokenFile string) (*googlestorage.Client, error) { + // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) + // https://cloud.google.com/docs/authentication/provide-credentials-adc. + if accessTokenFile == "" { + return googlestorage.NewClient(context.Background()) } - return nil + return googlestorage.NewClient(context.Background(), option.WithCredentialsFile(accessTokenFile)) } func (gcs *GoogleCloudStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) { log.Trace("das.GoogleCloudStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", gcs) - buf, err := gcs.operator.Download(ctx, gcs.bucket, gcs.objectPrefix, key) + obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(key)) + reader, err := obj.NewReader(ctx) if err != nil { log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) return nil, err } + buf, err := io.ReadAll(reader) + if err != nil { + log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) + } return buf, nil } -func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { - if gcs.enableExpiry { - return daprovider.KeepForever, nil +func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { + logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) + obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) + w := obj.NewWriter(ctx) + if gcs.discardAfterTimeout && timeout <= math.MaxInt64 { + w.Retention = &googlestorage.ObjectRetention{ + Mode: "Unlocked", + RetainUntil: time.Unix(int64(timeout), 0), + } + } + if _, err := fmt.Fprintln(w, value); err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) + return err + } + err := w.Close() + if err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) } - return daprovider.DiscardAfterDataTimeout, nil + return err } func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { @@ -173,7 +110,14 @@ func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { } func (gcs *GoogleCloudStorageService) Close(ctx context.Context) error { - return gcs.operator.Close(ctx) + return gcs.client.Close() +} + +func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { + if gcs.discardAfterTimeout { + return daprovider.DiscardAfterDataTimeout, nil + } + return daprovider.KeepForever, nil } func (gcs *GoogleCloudStorageService) String() string { @@ -181,11 +125,9 @@ func (gcs *GoogleCloudStorageService) String() string { } func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { - bucket := gcs.operator.Bucket(gcs.bucket) + bucket := gcs.client.Bucket(gcs.bucket) // check if we have bucket permissions permissions := []string{ - "storage.buckets.get", - "storage.buckets.list", "storage.objects.create", "storage.objects.delete", "storage.objects.list", @@ -200,6 +142,5 @@ func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { if !cmp.Equal(perms, permissions) { return fmt.Errorf("permissions mismatch (-want +got):\n%s", cmp.Diff(permissions, perms)) } - return nil } From 12a4a053e2bf135872a29e173645b33ec2874874 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Tue, 19 Nov 2024 22:19:00 +0800 Subject: [PATCH 11/67] updated --- das/google_cloud_storage_service.go | 119 ++++++++++++++--------- das/google_cloud_storage_service_test.go | 5 +- 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index adf039347c..85fa796420 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -21,6 +21,51 @@ import ( "github.com/offchainlabs/nitro/util/pretty" ) +type GoogleCloudStorageOperator interface { + Bucket(name string) *googlestorage.BucketHandle + Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error + Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) + Close(ctx context.Context) error +} + +type GoogleCloudStorageClient struct { + client *googlestorage.Client +} + +func (g *GoogleCloudStorageClient) Bucket(name string) *googlestorage.BucketHandle { + return g.client.Bucket(name) +} + +func (g *GoogleCloudStorageClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error { + obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) + w := obj.NewWriter(ctx) + + if discardAfterTimeout && timeout <= math.MaxInt64 { + w.Retention = &googlestorage.ObjectRetention{ + Mode: "Unlocked", + RetainUntil: time.Unix(int64(timeout), 0), + } + } + + if _, err := fmt.Fprintln(w, value); err != nil { + return err + } + return w.Close() +} + +func (g *GoogleCloudStorageClient) Download(ctx context.Context, bucket, objectPrefix string, key common.Hash) ([]byte, error) { + obj := g.client.Bucket(bucket).Object(objectPrefix + EncodeStorageServiceKey(key)) + reader, err := obj.NewReader(ctx) + if err != nil { + return nil, err + } + return io.ReadAll(reader) +} + +func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { + return g.client.Close() +} + type GoogleCloudStorageServiceConfig struct { Enable bool `koanf:"enable"` AccessTokenFile string `koanf:"access-token-file"` @@ -37,72 +82,62 @@ func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") - } type GoogleCloudStorageService struct { - client *googlestorage.Client + operator GoogleCloudStorageOperator bucket string objectPrefix string discardAfterTimeout bool } func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (StorageService, error) { - client, err := buildGoogleCloudStorageClient(config.AccessTokenFile) + var client *googlestorage.Client + var err error + // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) + // https://cloud.google.com/docs/authentication/provide-credentials-adc. + if config.AccessTokenFile == "" { + client, err = googlestorage.NewClient(context.Background()) + } else { + client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsFile(config.AccessTokenFile)) + } if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) } - return &GoogleCloudStorageService{ - client: client, + service := &GoogleCloudStorageService{ + operator: &GoogleCloudStorageClient{client: client}, bucket: config.Bucket, objectPrefix: config.ObjectPrefix, discardAfterTimeout: config.DiscardAfterTimeout, - }, nil + } + return service, nil } -func buildGoogleCloudStorageClient(accessTokenFile string) (*googlestorage.Client, error) { - // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) - // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if accessTokenFile == "" { - return googlestorage.NewClient(context.Background()) +func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { + logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) + + if err := gcs.operator.Upload(ctx, gcs.bucket, gcs.objectPrefix, value, gcs.discardAfterTimeout, timeout); err != nil { + log.Error("das.GoogleCloudStorageService.Store", "err", err) + return err } - return googlestorage.NewClient(context.Background(), option.WithCredentialsFile(accessTokenFile)) + return nil } func (gcs *GoogleCloudStorageService) GetByHash(ctx context.Context, key common.Hash) ([]byte, error) { log.Trace("das.GoogleCloudStorageService.GetByHash", "key", pretty.PrettyHash(key), "this", gcs) - obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(key)) - reader, err := obj.NewReader(ctx) + buf, err := gcs.operator.Download(ctx, gcs.bucket, gcs.objectPrefix, key) if err != nil { log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) return nil, err } - buf, err := io.ReadAll(reader) - if err != nil { - log.Error("das.GoogleCloudStorageService.GetByHash", "err", err) - } return buf, nil } -func (gcs *GoogleCloudStorageService) Put(ctx context.Context, value []byte, timeout uint64) error { - logPut("das.GoogleCloudStorageService.Store", value, timeout, gcs) - obj := gcs.client.Bucket(gcs.bucket).Object(gcs.objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))) - w := obj.NewWriter(ctx) - if gcs.discardAfterTimeout && timeout <= math.MaxInt64 { - w.Retention = &googlestorage.ObjectRetention{ - Mode: "Unlocked", - RetainUntil: time.Unix(int64(timeout), 0), - } - } - if _, err := fmt.Fprintln(w, value); err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) - return err - } - err := w.Close() - if err != nil { - log.Error("das.GoogleCloudStorageService.Store", "err", err) +func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { + if gcs.discardAfterTimeout { + return daprovider.DiscardAfterDataTimeout, nil } - return err + return daprovider.KeepForever, nil } func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { @@ -110,14 +145,7 @@ func (gcs *GoogleCloudStorageService) Sync(ctx context.Context) error { } func (gcs *GoogleCloudStorageService) Close(ctx context.Context) error { - return gcs.client.Close() -} - -func (gcs *GoogleCloudStorageService) ExpirationPolicy(ctx context.Context) (daprovider.ExpirationPolicy, error) { - if gcs.discardAfterTimeout { - return daprovider.DiscardAfterDataTimeout, nil - } - return daprovider.KeepForever, nil + return gcs.operator.Close(ctx) } func (gcs *GoogleCloudStorageService) String() string { @@ -125,7 +153,7 @@ func (gcs *GoogleCloudStorageService) String() string { } func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { - bucket := gcs.client.Bucket(gcs.bucket) + bucket := gcs.operator.Bucket(gcs.bucket) // check if we have bucket permissions permissions := []string{ "storage.objects.create", @@ -142,5 +170,6 @@ func (gcs *GoogleCloudStorageService) HealthCheck(ctx context.Context) error { if !cmp.Equal(perms, permissions) { return fmt.Errorf("permissions mismatch (-want +got):\n%s", cmp.Diff(permissions, perms)) } + return nil } diff --git a/das/google_cloud_storage_service_test.go b/das/google_cloud_storage_service_test.go index 94d6f3ee44..545437708b 100644 --- a/das/google_cloud_storage_service_test.go +++ b/das/google_cloud_storage_service_test.go @@ -34,7 +34,7 @@ func (c *mockGCSClient) Close(ctx context.Context) error { return nil } -func (c *mockGCSClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte) error { +func (c *mockGCSClient) Upload(ctx context.Context, bucket, objectPrefix string, value []byte, discardAfterTimeout bool, timeout uint64) error { key := objectPrefix + EncodeStorageServiceKey(dastree.Hash(value)) c.storage[key] = value return nil @@ -47,7 +47,7 @@ func NewTestGoogleCloudStorageService(ctx context.Context, googleCloudStorageCon operator: &mockGCSClient{ storage: make(map[string][]byte), }, - maxRetention: googleCloudStorageConfig.MaxRetention, + discardAfterTimeout: true, }, nil } @@ -57,7 +57,6 @@ func TestNewGoogleCloudStorageService(t *testing.T) { expiry := uint64(time.Now().Add(time.Hour).Unix()) googleCloudStorageServiceConfig := DefaultGoogleCloudStorageServiceConfig googleCloudStorageServiceConfig.Enable = true - googleCloudStorageServiceConfig.MaxRetention = time.Hour * 24 googleCloudService, err := NewTestGoogleCloudStorageService(ctx, googleCloudStorageServiceConfig) Require(t, err) From 26cfce8ff986633bd8ebd5394d7a3f789ca85472 Mon Sep 17 00:00:00 2001 From: Antonio Nunez Date: Wed, 20 Nov 2024 13:58:41 +0800 Subject: [PATCH 12/67] support both access-token and access-token-file parameters --- das/google_cloud_storage_service.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/das/google_cloud_storage_service.go b/das/google_cloud_storage_service.go index 85fa796420..71924a690c 100644 --- a/das/google_cloud_storage_service.go +++ b/das/google_cloud_storage_service.go @@ -68,6 +68,7 @@ func (g *GoogleCloudStorageClient) Close(ctx context.Context) error { type GoogleCloudStorageServiceConfig struct { Enable bool `koanf:"enable"` + AccessToken string `koanf:"access-token"` AccessTokenFile string `koanf:"access-token-file"` Bucket string `koanf:"bucket"` ObjectPrefix string `koanf:"object-prefix"` @@ -78,7 +79,8 @@ var DefaultGoogleCloudStorageServiceConfig = GoogleCloudStorageServiceConfig{} func GoogleCloudConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultGoogleCloudStorageServiceConfig.Enable, "EXPERIMENTAL/unsupported - enable storage/retrieval of sequencer batch data from an Google Cloud Storage bucket") - f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token") + f.String(prefix+".access-token", DefaultGoogleCloudStorageServiceConfig.AccessToken, "Google Cloud Storage access token (JSON string)") + f.String(prefix+".access-token-file", DefaultGoogleCloudStorageServiceConfig.AccessTokenFile, "Google Cloud Storage access token (JSON file path)") f.String(prefix+".bucket", DefaultGoogleCloudStorageServiceConfig.Bucket, "Google Cloud Storage bucket") f.String(prefix+".object-prefix", DefaultGoogleCloudStorageServiceConfig.ObjectPrefix, "prefix to add to Google Cloud Storage objects") f.Bool(prefix+".discard-after-timeout", DefaultGoogleCloudStorageServiceConfig.DiscardAfterTimeout, "discard data after its expiry timeout") @@ -96,10 +98,12 @@ func NewGoogleCloudStorageService(config GoogleCloudStorageServiceConfig) (Stora var err error // Note that if the credentials are not specified, the client library will find credentials using ADC(Application Default Credentials) // https://cloud.google.com/docs/authentication/provide-credentials-adc. - if config.AccessTokenFile == "" { - client, err = googlestorage.NewClient(context.Background()) - } else { + if config.AccessToken != "" { + client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsJSON([]byte(config.AccessToken))) + } else if config.AccessTokenFile != "" { client, err = googlestorage.NewClient(context.Background(), option.WithCredentialsFile(config.AccessTokenFile)) + } else { + client, err = googlestorage.NewClient(context.Background()) } if err != nil { return nil, fmt.Errorf("error creating Google Cloud Storage client: %w", err) From a471aab128545224dfcad0431cf10614335f193c Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Fri, 29 Nov 2024 14:27:03 +0100 Subject: [PATCH 13/67] Create ADR-0001 Avoid primative constraint types This PR creates the ADR (Architectural Decision Record) structure in the docs in our repository and adds the first two ADRs. The first is sort of a meta-ADR in that it just captures our decision to actually use ADRs to record our architecturally-significant decisions for posterity and which format to use. --- ...markdown-architectural-decision-records.md | 29 ++++++ .../0001-avoid-primative-constraint-types.md | 96 +++++++++++++++++++ docs/decisions/README.md | 10 ++ docs/decisions/adr-template-bare-minimal.md | 16 ++++ docs/decisions/adr-template-bare.md | 44 +++++++++ docs/decisions/adr-template-minimal.md | 23 +++++ docs/decisions/adr-template.md | 74 ++++++++++++++ 7 files changed, 292 insertions(+) create mode 100644 docs/decisions/0000-use-markdown-architectural-decision-records.md create mode 100644 docs/decisions/0001-avoid-primative-constraint-types.md create mode 100644 docs/decisions/README.md create mode 100644 docs/decisions/adr-template-bare-minimal.md create mode 100644 docs/decisions/adr-template-bare.md create mode 100644 docs/decisions/adr-template-minimal.md create mode 100644 docs/decisions/adr-template.md diff --git a/docs/decisions/0000-use-markdown-architectural-decision-records.md b/docs/decisions/0000-use-markdown-architectural-decision-records.md new file mode 100644 index 0000000000..506f5fa28b --- /dev/null +++ b/docs/decisions/0000-use-markdown-architectural-decision-records.md @@ -0,0 +1,29 @@ +# Use Markdown Architectural Decision Records + +## Context and Problem Statement + +We want to record architectural decisions made in this project independent +whether decisions concern the architecture ("architectural decision record"), +the code, or other fields. + +Which format and structure should these records follow? + +## Considered Options + +* [MADR](https://adr.github.io/madr/) 4.0.0 – The Markdown Architectural Decision Records +* [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions) – The first incarnation of the term "ADR" +* [Sustainable Architectural Decisions](https://www.infoq.com/articles/sustainable-architectural-design-decisions) – The Y-Statements +* Other templates listed at +* Formless – No conventions for file format and structure + +## Decision Outcome + +Chosen option: "MADR 4.0.0", because + +* Implicit assumptions should be made explicit. + Design documentation is important to enable people understanding the decisions later on. + See also ["A rational design process: How and why to fake it"](https://doi.org/10.1109/TSE.1986.6312940). +* MADR allows for structured capturing of any decision. +* The MADR format is lean and fits our development style. +* The MADR structure is comprehensible and facilitates usage & maintenance. +* The MADR project is vivid. diff --git a/docs/decisions/0001-avoid-primative-constraint-types.md b/docs/decisions/0001-avoid-primative-constraint-types.md new file mode 100644 index 0000000000..b52cea8bdd --- /dev/null +++ b/docs/decisions/0001-avoid-primative-constraint-types.md @@ -0,0 +1,96 @@ +--- +status: accepted +date: 2024-11-29 +decision-makers: eljobe@ plasmapower@ +--- + +# Avoid primative constraint types + +## Context and Problem Statement + +When working on the go code for BoLD, we became slightly annoyed that several +places in the history package were checking the constraint that the `virtual` +argumet to a function was positive. One possible workaround would have been +to create a constrained wrapper type around `uint64` which would only allow +positive values. For example: + +```go +// Pos64 is a type which represents a positive uint64. +// +// The "zero" value of Pos64 is 1. +type Pos64 struct { + uint64 +} + +// NewPos64 returns a new Pos64 with the given value. +// +// errors if v is 0. +func NewPos64(v uint64) (Pos64, error) { + if v == 0 { + return Pos64{}, errors.New("v must be positive. got: 0") + } + return Pos64{v}, nil +} + +// MustPos64 returns a new Pos64 with the given value. +// +// panics if v is 0. +func MustPos64(v uint64) Pos64 { + if v == 0 { + panic("v must be positive. got: 0") + } + return Pos64{v} +} + +// Val returns the value of the Pos64. +func (p Pos64) Val() uint64 { + // The zero value of Pos64 is 1. + if p.uint64 == 0 { + return 1 + } + return p.uint64 +} +``` + +The idea being that within a package, all of the functions which needed to deal +with a `virtual` argument, could take in a `Pos64` instead of a `uint64` and it +would be up to clients of the package to ensure that they only passed in +positive values. + +## Considered Options + +* New Package: `util/chk` for checking type constraint +* Status Quo: check the constraint in multiple places +* Minimize Checks: no check in package private functions + +## Decision Outcome + +Chosen option: "Status Quo", because the "New Package" option introduces a +regression in being able to use type type with operators, and "Minimize Checks" +is too prone to bugs introduced by refactoring. + + +## Pros and Cons of the Options + +### New Pacakge: `util/chk` for checking type constraint + +* Good, because it is expressive +* Good, because the constraint only needs to be checked during construction +* Bad, because `Pos64` doesn't compile with operators like `+ * - /` + +### Status Quo: check the constraint in multiple places + +* Good, because it is what the code is already doing +* Good, because when a funciton becomes public, the constraint holds +* Good, because when a function moves to another file or package, the constraint holds +* Bad, because it means the check may need to be repeated. DRY + +### Minimize Checks: no check in package private functions + +* Good, because it reduces the amount of times a constraint is checked +* Bad, because the assumption might be violated if a private function becomes + public, or gains an additional caller. + +## More Information + +See the discussion on now-closed #2743 diff --git a/docs/decisions/README.md b/docs/decisions/README.md new file mode 100644 index 0000000000..63b1a18cd2 --- /dev/null +++ b/docs/decisions/README.md @@ -0,0 +1,10 @@ +# Decisions + +For new Architectural Decision Records (ADRs), please use one of the following templates as a starting point: + +* [adr-template.md](adr-template.md) has all sections, with explanations about them. +* [adr-template-minmal.md](adr-template-minimal.md) only contains mandatory sections, with explanations about them. +* [adr-template-bare.md](adr-template-bare.md) has all sections, wich are empty (no explanations). +* [adr-template-bare-minimal.md](adr-template-bare-minimal.md) has the mandatory sections, without explanations. + +The MADR documentation is available at while general information about ADRs is available at . diff --git a/docs/decisions/adr-template-bare-minimal.md b/docs/decisions/adr-template-bare-minimal.md new file mode 100644 index 0000000000..bd16d0ea21 --- /dev/null +++ b/docs/decisions/adr-template-bare-minimal.md @@ -0,0 +1,16 @@ +# + +## Context and Problem Statement + + + +## Considered Options + + + +## Decision Outcome + + + +### Consequences + diff --git a/docs/decisions/adr-template-bare.md b/docs/decisions/adr-template-bare.md new file mode 100644 index 0000000000..26f6598f70 --- /dev/null +++ b/docs/decisions/adr-template-bare.md @@ -0,0 +1,44 @@ +--- +status: +date: +decision-makers: +consulted: +informed: +--- + +# + +## Context and Problem Statement + + + +## Decision Drivers + +* + +## Considered Options + +* + +## Decision Outcome + +Chosen option: "", because + +### Consequences + +* Good, because +* Bad, because + +### Confirmation + + + +## Pros and Cons of the Options + +### + +* Good, because +* Neutral, because +* Bad, because + +## More Information diff --git a/docs/decisions/adr-template-minimal.md b/docs/decisions/adr-template-minimal.md new file mode 100644 index 0000000000..267640bfbc --- /dev/null +++ b/docs/decisions/adr-template-minimal.md @@ -0,0 +1,23 @@ +# {short title, representative of solved problem and found solution} + +## Context and Problem Statement + +{Describe the context and problem statement, e.g., in free form using two to three sentences or in the form of an illustrative story. You may want to articulate the problem in form of a question and add links to collaboration boards or issue management systems.} + +## Considered Options + +* {title of option 1} +* {title of option 2} +* {title of option 3} +* … + +## Decision Outcome + +Chosen option: "{title of option 1}", because {justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | … | comes out best (see below)}. + + +### Consequences + +* Good, because {positive consequence, e.g., improvement of one or more desired qualities, …} +* Bad, because {negative consequence, e.g., compromising one or more desired qualities, …} +* … diff --git a/docs/decisions/adr-template.md b/docs/decisions/adr-template.md new file mode 100644 index 0000000000..08dac30ed8 --- /dev/null +++ b/docs/decisions/adr-template.md @@ -0,0 +1,74 @@ +--- +# These are optional metadata elements. Feel free to remove any of them. +status: "{proposed | rejected | accepted | deprecated | … | superseded by ADR-0123" +date: {YYYY-MM-DD when the decision was last updated} +decision-makers: {list everyone involved in the decision} +consulted: {list everyone whose opinions are sought (typically subject-matter experts); and with whom there is a two-way communication} +informed: {list everyone who is kept up-to-date on progress; and with whom there is a one-way communication} +--- + +# {short title, representative of solved problem and found solution} + +## Context and Problem Statement + +{Describe the context and problem statement, e.g., in free form using two to three sentences or in the form of an illustrative story. You may want to articulate the problem in form of a question and add links to collaboration boards or issue management systems.} + + +## Decision Drivers + +* {decision driver 1, e.g., a force, facing concern, …} +* {decision driver 2, e.g., a force, facing concern, …} +* … + +## Considered Options + +* {title of option 1} +* {title of option 2} +* {title of option 3} +* … + +## Decision Outcome + +Chosen option: "{title of option 1}", because {justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force {force} | … | comes out best (see below)}. + + +### Consequences + +* Good, because {positive consequence, e.g., improvement of one or more desired qualities, …} +* Bad, because {negative consequence, e.g., compromising one or more desired qualities, …} +* … + + +### Confirmation + +{Describe how the implementation of/compliance with the ADR can/will be confirmed. Are the design that was decided for and its implementation in line with the decision made? E.g., a design/code review or a test with a library such as ArchUnit can help validate this. Not that although we classify this element as optional, it is included in many ADRs.} + + +## Pros and Cons of the Options + +### {title of option 1} + + +{example | description | pointer to more information | …} + +* Good, because {argument a} +* Good, because {argument b} + +* Neutral, because {argument c} +* Bad, because {argument d} +* … + +### {title of other option} + +{example | description | pointer to more information | …} + +* Good, because {argument a} +* Good, because {argument b} +* Neutral, because {argument c} +* Bad, because {argument d} +* … + + +## More Information + +{You might want to provide additional evidence/confidence for the decision outcome here and/or document the team agreement on the decision and/or define when/how this decision the decision should be realized and if/when it should be re-visited. Links to other decisions and resources might appear here as well.} From 5eb9704138f997a7b76f1ebf18745116f4ed2c68 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Mon, 9 Dec 2024 15:46:36 -0600 Subject: [PATCH 14/67] Allow waiting for a minimum amount of time since parent assertion was created to post a new assertion --- arbnode/node.go | 2 ++ bold | 2 +- staker/bold/bold_staker.go | 7 ++++++- system_tests/bold_challenge_protocol_test.go | 1 + system_tests/bold_new_challenge_test.go | 1 + system_tests/overflow_assertions_test.go | 1 + 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arbnode/node.go b/arbnode/node.go index f2e3433ecd..48920cdbdd 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -212,6 +212,7 @@ func ConfigDefaultL1NonSequencerTest() *Config { config.Staker = legacystaker.TestL1ValidatorConfig config.Staker.Enable = false config.BlockValidator.ValidationServerConfigs = []rpcclient.ClientConfig{{URL: ""}} + config.Bold.MinimumGapToParentAssertion = 0 return &config } @@ -230,6 +231,7 @@ func ConfigDefaultL2Test() *Config { config.Staker.Enable = false config.BlockValidator.ValidationServerConfigs = []rpcclient.ClientConfig{{URL: ""}} config.TransactionStreamer = DefaultTransactionStreamerConfig + config.Bold.MinimumGapToParentAssertion = 0 return &config } diff --git a/bold b/bold index d0a87de774..1b1c34c319 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit d0a87de774aecfa97161efd1b0a924d4d5fbcf74 +Subproject commit 1b1c34c31967242a492d29925640ede98d921fca diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index 1a8eed80fa..ad0e24e338 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -57,7 +57,9 @@ type BoldConfig struct { // How often to scan for newly created assertions onchain. AssertionScanningInterval time.Duration `koanf:"assertion-scanning-interval"` // How often to confirm assertions onchain. - AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` + AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` + // How long to wait since parent assertion was created to post a new assertion + MinimumGapToParentAssertion time.Duration `koanf:"minimum-gap-to-parent-assertion"` API bool `koanf:"api"` APIHost string `koanf:"api-host"` APIPort uint16 `koanf:"api-port"` @@ -98,6 +100,7 @@ var DefaultBoldConfig = BoldConfig{ AssertionPostingInterval: time.Minute * 15, AssertionScanningInterval: time.Minute, AssertionConfirmingInterval: time.Minute, + MinimumGapToParentAssertion: time.Minute, // Correct default? API: false, APIHost: "127.0.0.1", APIPort: 9393, @@ -121,6 +124,7 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.Duration(prefix+".assertion-posting-interval", DefaultBoldConfig.AssertionPostingInterval, "assertion posting interval") f.Duration(prefix+".assertion-scanning-interval", DefaultBoldConfig.AssertionScanningInterval, "scan assertion interval") f.Duration(prefix+".assertion-confirming-interval", DefaultBoldConfig.AssertionConfirmingInterval, "confirm assertion interval") + f.Duration(prefix+".minimum-gap-to-parent-assertion", DefaultBoldConfig.MinimumGapToParentAssertion, "minimum duration to wait since the parent assertion was created to post a new assertion") f.Duration(prefix+".check-staker-switch-interval", DefaultBoldConfig.CheckStakerSwitchInterval, "how often to check if staker can switch to bold") f.Bool(prefix+".api", DefaultBoldConfig.API, "enable api") f.String(prefix+".api-host", DefaultBoldConfig.APIHost, "bold api host") @@ -448,6 +452,7 @@ func newBOLDChallengeManager( challengemanager.StackWithPollingInterval(scanningInterval), challengemanager.StackWithPostingInterval(postingInterval), challengemanager.StackWithConfirmationInterval(confirmingInterval), + challengemanager.StackWithMinimumGapToParentAssertion(config.MinimumGapToParentAssertion), challengemanager.StackWithTrackChallengeParentAssertionHashes(config.TrackChallengeParentAssertionHashes), challengemanager.StackWithHeaderProvider(l1Reader), } diff --git a/system_tests/bold_challenge_protocol_test.go b/system_tests/bold_challenge_protocol_test.go index 777817bf3e..3677021c00 100644 --- a/system_tests/bold_challenge_protocol_test.go +++ b/system_tests/bold_challenge_protocol_test.go @@ -417,6 +417,7 @@ func testChallengeProtocolBOLD(t *testing.T, spawnerOpts ...server_arb.SpawnerOp challengemanager.StackWithMode(modes.MakeMode), challengemanager.StackWithPostingInterval(time.Second * 3), challengemanager.StackWithPollingInterval(time.Second), + challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), challengemanager.StackWithAverageBlockCreationTime(time.Second), } diff --git a/system_tests/bold_new_challenge_test.go b/system_tests/bold_new_challenge_test.go index ad6e44bc71..eb452ca5d4 100644 --- a/system_tests/bold_new_challenge_test.go +++ b/system_tests/bold_new_challenge_test.go @@ -344,6 +344,7 @@ func startBoldChallengeManager(t *testing.T, ctx context.Context, builder *NodeB challengemanager.StackWithPostingInterval(time.Second * 3), challengemanager.StackWithPollingInterval(time.Second), challengemanager.StackWithAverageBlockCreationTime(time.Second), + challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), } challengeManager, err := challengemanager.NewChallengeStack( diff --git a/system_tests/overflow_assertions_test.go b/system_tests/overflow_assertions_test.go index c024a43070..848c61e7d3 100644 --- a/system_tests/overflow_assertions_test.go +++ b/system_tests/overflow_assertions_test.go @@ -224,6 +224,7 @@ func TestOverflowAssertions(t *testing.T) { challengemanager.StackWithPostingInterval(time.Second), challengemanager.StackWithPollingInterval(time.Millisecond * 500), challengemanager.StackWithAverageBlockCreationTime(time.Second), + challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), } manager, err := challengemanager.NewChallengeStack( From 81dcb5a01589dcb58fd009fd622af1aef38f8e1a Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Mon, 9 Dec 2024 16:23:57 -0600 Subject: [PATCH 15/67] minor fix --- system_tests/bold_challenge_protocol_test.go | 2 +- system_tests/bold_new_challenge_test.go | 2 +- system_tests/overflow_assertions_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system_tests/bold_challenge_protocol_test.go b/system_tests/bold_challenge_protocol_test.go index 3677021c00..83700fc838 100644 --- a/system_tests/bold_challenge_protocol_test.go +++ b/system_tests/bold_challenge_protocol_test.go @@ -417,7 +417,7 @@ func testChallengeProtocolBOLD(t *testing.T, spawnerOpts ...server_arb.SpawnerOp challengemanager.StackWithMode(modes.MakeMode), challengemanager.StackWithPostingInterval(time.Second * 3), challengemanager.StackWithPollingInterval(time.Second), - challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), + challengemanager.StackWithMinimumGapToParentAssertion(0), challengemanager.StackWithAverageBlockCreationTime(time.Second), } diff --git a/system_tests/bold_new_challenge_test.go b/system_tests/bold_new_challenge_test.go index eb452ca5d4..fae4a57deb 100644 --- a/system_tests/bold_new_challenge_test.go +++ b/system_tests/bold_new_challenge_test.go @@ -344,7 +344,7 @@ func startBoldChallengeManager(t *testing.T, ctx context.Context, builder *NodeB challengemanager.StackWithPostingInterval(time.Second * 3), challengemanager.StackWithPollingInterval(time.Second), challengemanager.StackWithAverageBlockCreationTime(time.Second), - challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), + challengemanager.StackWithMinimumGapToParentAssertion(0), } challengeManager, err := challengemanager.NewChallengeStack( diff --git a/system_tests/overflow_assertions_test.go b/system_tests/overflow_assertions_test.go index 848c61e7d3..eb2bb01470 100644 --- a/system_tests/overflow_assertions_test.go +++ b/system_tests/overflow_assertions_test.go @@ -224,7 +224,7 @@ func TestOverflowAssertions(t *testing.T) { challengemanager.StackWithPostingInterval(time.Second), challengemanager.StackWithPollingInterval(time.Millisecond * 500), challengemanager.StackWithAverageBlockCreationTime(time.Second), - challengemanager.StackWithMinimumGapToParentAssertionCreationTime(0), + challengemanager.StackWithMinimumGapToParentAssertion(0), } manager, err := challengemanager.NewChallengeStack( From 231da30980575693c2c9f6d7be127ac77772cc9d Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Tue, 10 Dec 2024 10:52:02 -0600 Subject: [PATCH 16/67] update bold pin --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 1b1c34c319..81f1b421b2 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 1b1c34c31967242a492d29925640ede98d921fca +Subproject commit 81f1b421b2dbbf96c7a2b427a9458667b07b0b27 From 3e59f8fb3a6576c84d2387574dd4907d1f60bd62 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 08:31:57 -0600 Subject: [PATCH 17/67] update bold submodule --- bold | 2 +- nitro-testnode | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bold b/bold index d0a87de774..d3f4d600ab 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit d0a87de774aecfa97161efd1b0a924d4d5fbcf74 +Subproject commit d3f4d600abdacec800e9e27a429a730639233073 diff --git a/nitro-testnode b/nitro-testnode index c177f28234..fa19e22104 160000 --- a/nitro-testnode +++ b/nitro-testnode @@ -1 +1 @@ -Subproject commit c177f282340285bcdae2d6a784547e2bb8b97498 +Subproject commit fa19e2210403ad24519ea46c2d337f54a9f47593 From da609b6c5bedb1999362ffaa28257f0fa7291d97 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 08:50:05 -0600 Subject: [PATCH 18/67] include all the new config opts --- staker/bold/bold_staker.go | 88 +++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index 1a8eed80fa..2a6c32f5a9 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "math/big" + "strings" "time" flag "github.com/spf13/pflag" @@ -57,16 +58,21 @@ type BoldConfig struct { // How often to scan for newly created assertions onchain. AssertionScanningInterval time.Duration `koanf:"assertion-scanning-interval"` // How often to confirm assertions onchain. - AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` - API bool `koanf:"api"` - APIHost string `koanf:"api-host"` - APIPort uint16 `koanf:"api-port"` - APIDBPath string `koanf:"api-db-path"` - TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"` - CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"` - StateProviderConfig StateProviderConfig `koanf:"state-provider-config"` - StartValidationFromStaked bool `koanf:"start-validation-from-staked"` + AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"` + API bool `koanf:"api"` + APIHost string `koanf:"api-host"` + APIPort uint16 `koanf:"api-port"` + APIDBPath string `koanf:"api-db-path"` + TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"` + CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"` + StateProviderConfig StateProviderConfig `koanf:"state-provider-config"` + StartValidationFromStaked bool `koanf:"start-validation-from-staked"` + AutoDeposit bool `koanf:"auto-deposit"` + AutoIncreaseAllowance bool `koanf:"auto-increase-allowance"` + DelegatedStaking DelegatedStakingConfig `koanf:"delegated-staking"` + RPCBlockNumber string `koanf:"rpc-block-number"` strategy legacystaker.StakerStrategy + blockNum rpc.BlockNumber } func (c *BoldConfig) Validate() error { @@ -75,9 +81,31 @@ func (c *BoldConfig) Validate() error { return err } c.strategy = strategy + var blockNum rpc.BlockNumber + switch strings.ToLower(c.RPCBlockNumber) { + case "safe": + blockNum = rpc.SafeBlockNumber + case "finalized": + blockNum = rpc.FinalizedBlockNumber + case "latest": + blockNum = rpc.LatestBlockNumber + default: + return fmt.Errorf("unknown rpc block number \"%v\", expected either latest, safe, or finalized", c.RPCBlockNumber) + } + c.blockNum = blockNum return nil } +type DelegatedStakingConfig struct { + Enable bool `koanf:"enable"` + CustomWithdrawalAddress string `koanf:"custom-withdrawal-address"` +} + +var DefaultDelegatedStakingConfig = DelegatedStakingConfig{ + Enable: false, + CustomWithdrawalAddress: "", +} + type StateProviderConfig struct { // A name identifier for the validator for cosmetic purposes. ValidatorName string `koanf:"validator-name"` @@ -106,6 +134,10 @@ var DefaultBoldConfig = BoldConfig{ CheckStakerSwitchInterval: time.Minute, // Every minute, check if the Nitro node staker should switch to using BOLD. StateProviderConfig: DefaultStateProviderConfig, StartValidationFromStaked: true, + AutoDeposit: true, + AutoIncreaseAllowance: true, + DelegatedStaking: DefaultDelegatedStakingConfig, + RPCBlockNumber: "finalized", } var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{ @@ -118,6 +150,7 @@ var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.Bool(prefix+".enable", DefaultBoldConfig.Enable, "enable bold challenge protocol") f.String(prefix+".strategy", DefaultBoldConfig.Strategy, "define the bold validator staker strategy, either watchtower, defensive, stakeLatest, or makeNodes") + f.String(prefix+".rpc-block-number", DefaultBoldConfig.RPCBlockNumber, "define the block number to use for reading data onchain, either latest, safe, or finalized") f.Duration(prefix+".assertion-posting-interval", DefaultBoldConfig.AssertionPostingInterval, "assertion posting interval") f.Duration(prefix+".assertion-scanning-interval", DefaultBoldConfig.AssertionScanningInterval, "scan assertion interval") f.Duration(prefix+".assertion-confirming-interval", DefaultBoldConfig.AssertionConfirmingInterval, "confirm assertion interval") @@ -129,6 +162,9 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.StringSlice(prefix+".track-challenge-parent-assertion-hashes", DefaultBoldConfig.TrackChallengeParentAssertionHashes, "only track challenges/edges with these parent assertion hashes") StateProviderConfigAddOptions(prefix+".state-provider-config", f) f.Bool(prefix+".start-validation-from-staked", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-deposit", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + DelegatedStakingConfigAddOptions(prefix+".delegated-staking", f) } func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { @@ -137,6 +173,11 @@ func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { f.String(prefix+".machine-leaves-cache-path", DefaultStateProviderConfig.MachineLeavesCachePath, "path to machine cache") } +func DelegatedStakingConfigAddOptions(prefix string, f *flag.FlagSet) { + f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "check batch finality") + f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "path to machine cache") +} + type BOLDStaker struct { stopwaiter.StopWaiter config *BoldConfig @@ -365,7 +406,25 @@ func newBOLDChallengeManager( if err != nil { return nil, fmt.Errorf("could not create challenge manager bindings: %w", err) } - assertionChain, err := solimpl.NewAssertionChain(ctx, rollupAddress, chalManager, txOpts, client, NewDataPosterTransactor(dataPoster)) + assertionChainOpts := []solimpl.Opt{ + solimpl.WithRpcHeadBlockNumber(config.blockNum), + } + if config.DelegatedStaking.Enable && config.DelegatedStaking.CustomWithdrawalAddress != "" { + withdrawalAddr := common.HexToAddress(config.DelegatedStaking.CustomWithdrawalAddress) + assertionChainOpts = append(assertionChainOpts, solimpl.WithCustomWithdrawalAddress(withdrawalAddr)) + } + if !config.AutoDeposit { + assertionChainOpts = append(assertionChainOpts, solimpl.WithoutAutoDeposit()) + } + assertionChain, err := solimpl.NewAssertionChain( + ctx, + rollupAddress, + chalManager, + txOpts, + client, + NewDataPosterTransactor(dataPoster), + assertionChainOpts..., + ) if err != nil { return nil, fmt.Errorf("could not create assertion chain: %w", err) } @@ -455,6 +514,15 @@ func newBOLDChallengeManager( apiAddr := fmt.Sprintf("%s:%d", config.APIHost, config.APIPort) stackOpts = append(stackOpts, challengemanager.StackWithAPIEnabled(apiAddr, apiDBPath)) } + if !config.AutoDeposit { + stackOpts = append(stackOpts, challengemanager.StackWithoutAutoDeposit()) + } + if !config.AutoIncreaseAllowance { + stackOpts = append(stackOpts, challengemanager.StackWithoutAutoAllowanceApproval()) + } + if config.DelegatedStaking.Enable { + stackOpts = append(stackOpts, challengemanager.StackWithDelegatedStaking()) + } manager, err := challengemanager.NewChallengeStack( assertionChain, From 177b7a887821aceb838254acd7c040485ba8d999 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 16 Dec 2024 09:09:41 -0600 Subject: [PATCH 19/67] comment --- staker/bold/bold_staker.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index 2a6c32f5a9..b08b2ec18b 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -162,8 +162,8 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) { f.StringSlice(prefix+".track-challenge-parent-assertion-hashes", DefaultBoldConfig.TrackChallengeParentAssertionHashes, "only track challenges/edges with these parent assertion hashes") StateProviderConfigAddOptions(prefix+".state-provider-config", f) f.Bool(prefix+".start-validation-from-staked", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") - f.Bool(prefix+".auto-deposit", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") - f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid") + f.Bool(prefix+".auto-deposit", DefaultBoldConfig.AutoDeposit, "auto-deposit stake token whenever making a move in BoLD that does not have enough stake token balance") + f.Bool(prefix+".auto-increase-allowance", DefaultBoldConfig.AutoIncreaseAllowance, "auto-increase spending allowance of the stake token by the rollup and challenge manager contracts") DelegatedStakingConfigAddOptions(prefix+".delegated-staking", f) } @@ -174,8 +174,8 @@ func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) { } func DelegatedStakingConfigAddOptions(prefix string, f *flag.FlagSet) { - f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "check batch finality") - f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "path to machine cache") + f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "enable delegated staking by having the validator call newStake on startup") + f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "enable a custom withdrawal address for staking on the rollup contract, useful for delegated stakers") } type BOLDStaker struct { From 6e0b0e0dbd84dc07681cb2fdf3c7a5696b114c42 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Tue, 17 Dec 2024 19:24:47 +0530 Subject: [PATCH 20/67] Store last message pruned in database --- arbnode/message_pruner.go | 50 +++++++++++++++++++++++++++++++++++---- arbnode/schema.go | 12 ++++++---- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/arbnode/message_pruner.go b/arbnode/message_pruner.go index 840a15f328..c86b88f2d0 100644 --- a/arbnode/message_pruner.go +++ b/arbnode/message_pruner.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/rlp" "github.com/offchainlabs/nitro/arbutil" "github.com/offchainlabs/nitro/util/stopwaiter" @@ -121,7 +122,7 @@ func (m *MessagePruner) prune(ctx context.Context, count arbutil.MessageIndex, g } func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCount arbutil.MessageIndex, delayedMessageCount uint64) error { - prunedKeysRange, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, &m.cachedPrunedMessageResult, uint64(messageCount)) + prunedKeysRange, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, lastPrunedMessageResultKey, &m.cachedPrunedMessageResult, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting message results: %w", err) } @@ -129,7 +130,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned message results:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, &m.cachedPrunedBlockHashesInputFeed, uint64(messageCount)) + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, lastPrunedBlockHashInputFeedKey, &m.cachedPrunedBlockHashesInputFeed, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting expected block hashes: %w", err) } @@ -137,7 +138,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned expected block hashes:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, &m.cachedPrunedMessages, uint64(messageCount)) + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, lastPrunedMessageKey, &m.cachedPrunedMessages, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting last batch messages: %w", err) } @@ -145,7 +146,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned last batch messages:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, &m.cachedPrunedDelayedMessages, delayedMessageCount) + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, lastPrunedRlpDelayedMessageKey, &m.cachedPrunedDelayedMessages, delayedMessageCount) if err != nil { return fmt.Errorf("error deleting last batch delayed messages: %w", err) } @@ -157,8 +158,12 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun // deleteFromLastPrunedUptoEndKey is similar to deleteFromRange but automatically populates the start key // cachedStartMinKey must not be nil. It's set to the new start key at the end of this function if successful. -func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, cachedStartMinKey *uint64, endMinKey uint64) ([]uint64, error) { +// Checks if the last pruned key is set in the database and uses it as the start key if it is. +func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, lastPrunedKey []byte, cachedStartMinKey *uint64, endMinKey uint64) ([]uint64, error) { startMinKey := *cachedStartMinKey + if startMinKey == 0 { + startMinKey = fetchLastPrunedKey(db, lastPrunedKey) + } if startMinKey == 0 { startIter := db.NewIterator(prefix, uint64ToKey(1)) if !startIter.Next() { @@ -169,11 +174,46 @@ func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, pref } if endMinKey <= startMinKey { *cachedStartMinKey = startMinKey + insertLastPrunedKey(db, lastPrunedKey, startMinKey) return nil, nil } keys, err := deleteFromRange(ctx, db, prefix, startMinKey, endMinKey-1) if err == nil { *cachedStartMinKey = endMinKey - 1 + insertLastPrunedKey(db, lastPrunedKey, endMinKey-1) } return keys, err } + +func insertLastPrunedKey(db ethdb.Database, lastPrunedKey []byte, lastPrunedValue uint64) { + lastPrunedValueByte, err := rlp.EncodeToBytes(lastPrunedValue) + if err != nil { + log.Error("error encoding last pruned value: %w", err) + } else { + err = db.Put(lastPrunedKey, lastPrunedValueByte) + if err != nil { + log.Error("error saving last pruned value: %w", err) + } + } +} + +func fetchLastPrunedKey(db ethdb.Database, lastPrunedKey []byte) uint64 { + hasKey, err := db.Has(lastPrunedKey) + if err != nil { + log.Warn("error checking for last pruned key: %w", err) + } else if hasKey { + lastPrunedValueByte, err := db.Get(lastPrunedKey) + if err != nil { + log.Warn("error fetching last pruned key: %w", err) + } else { + var lastPrunedValue uint64 + err = rlp.DecodeBytes(lastPrunedValueByte, &lastPrunedValue) + if err != nil { + log.Warn("error decoding last pruned value: %w", err) + } else { + return lastPrunedValue + } + } + } + return 0 +} diff --git a/arbnode/schema.go b/arbnode/schema.go index 1aaded2b95..e06d6a75c7 100644 --- a/arbnode/schema.go +++ b/arbnode/schema.go @@ -13,10 +13,14 @@ var ( sequencerBatchMetaPrefix []byte = []byte("s") // maps a batch sequence number to BatchMetadata delayedSequencedPrefix []byte = []byte("a") // maps a delayed message count to the first sequencer batch sequence number with this delayed count - messageCountKey []byte = []byte("_messageCount") // contains the current message count - delayedMessageCountKey []byte = []byte("_delayedMessageCount") // contains the current delayed message count - sequencerBatchCountKey []byte = []byte("_sequencerBatchCount") // contains the current sequencer message count - dbSchemaVersion []byte = []byte("_schemaVersion") // contains a uint64 representing the database schema version + messageCountKey []byte = []byte("_messageCount") // contains the current message count + lastPrunedMessageResultKey []byte = []byte("_lastPrunedMessageResultKey") // contains the last pruned message result key + lastPrunedBlockHashInputFeedKey []byte = []byte("_lastPrunedBlockHashInputFeedPrefix") // contains the last pruned block hash input feed key + lastPrunedMessageKey []byte = []byte("_lastPrunedMessageKey") // contains the last pruned message key + lastPrunedRlpDelayedMessageKey []byte = []byte("_lastPrunedRlpDelayedMessageKey") // contains the last pruned RLP delayed message key + delayedMessageCountKey []byte = []byte("_delayedMessageCount") // contains the current delayed message count + sequencerBatchCountKey []byte = []byte("_sequencerBatchCount") // contains the current sequencer message count + dbSchemaVersion []byte = []byte("_schemaVersion") // contains a uint64 representing the database schema version ) const currentDbSchemaVersion uint64 = 1 From ffdce5c13833c00b0a8f58463b95209e66cdc0aa Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 17 Dec 2024 14:01:58 -0600 Subject: [PATCH 21/67] edits --- nitro-testnode | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nitro-testnode b/nitro-testnode index fa19e22104..c177f28234 160000 --- a/nitro-testnode +++ b/nitro-testnode @@ -1 +1 @@ -Subproject commit fa19e2210403ad24519ea46c2d337f54a9f47593 +Subproject commit c177f282340285bcdae2d6a784547e2bb8b97498 From f7bacf667afd7b6fcb40516a2378e424c177b9f1 Mon Sep 17 00:00:00 2001 From: thirdkeyword Date: Thu, 19 Dec 2024 14:15:19 +0800 Subject: [PATCH 22/67] chore: fix some problematic method name and typos in comment Signed-off-by: thirdkeyword --- cmd/datool/datool.go | 2 +- execution/nodeInterface/NodeInterface.go | 2 +- relay/relay_stress_test.go | 2 +- system_tests/outbox_test.go | 2 +- system_tests/seqinbox_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/datool/datool.go b/cmd/datool/datool.go index 06f94dc952..2eb1e95660 100644 --- a/cmd/datool/datool.go +++ b/cmd/datool/datool.go @@ -99,7 +99,7 @@ func parseClientStoreConfig(args []string) (*ClientStoreConfig, error) { f.String("url", "", "URL of DAS server to connect to") f.String("message", "", "message to send") f.Int("random-message-size", 0, "send a message of a specified number of random bytes") - f.String("signing-key", "", "ecdsa private key to sign the message with, treated as a hex string if prefixed with 0x otherise treated as a file; if not specified the message is not signed") + f.String("signing-key", "", "ecdsa private key to sign the message with, treated as a hex string if prefixed with 0x otherwise treated as a file; if not specified the message is not signed") f.String("signing-wallet", "", "wallet containing ecdsa key to sign the message with") f.String("signing-wallet-password", genericconf.PASSWORD_NOT_SET, "password to unlock the wallet, if not specified the user is prompted for the password") f.Duration("das-retention-period", 24*time.Hour, "The period which DASes are requested to retain the stored batches.") diff --git a/execution/nodeInterface/NodeInterface.go b/execution/nodeInterface/NodeInterface.go index 20282f8231..189640d5d1 100644 --- a/execution/nodeInterface/NodeInterface.go +++ b/execution/nodeInterface/NodeInterface.go @@ -405,7 +405,7 @@ func (n NodeInterface) ConstructOutboxProof(c ctx, evm mech, size, leaf uint64) if !balanced { // This tree isn't balanced, so we'll need to use the partials to recover the missing info. - // To do this, we'll walk the boundry of what's known, computing hashes along the way + // To do this, we'll walk the boundary of what's known, computing hashes along the way step := *minPartialPlace step.Leaf += 1 << step.Level // we start on the min partial's zero-hash sibling diff --git a/relay/relay_stress_test.go b/relay/relay_stress_test.go index 93ba510193..e2cff07341 100644 --- a/relay/relay_stress_test.go +++ b/relay/relay_stress_test.go @@ -93,7 +93,7 @@ func (ts *dummyTxStreamer) AddBroadcastMessages(feedMessages []*message.Broadcas time.Sleep(50 * time.Millisecond) if !ts.logConnection { ts.logConnection = true - log.Info("test client is succesfully receiving messages", "client_Id", ts.id, "msg_size", feedMessages[0].Size()) + log.Info("test client is successfully receiving messages", "client_Id", ts.id, "msg_size", feedMessages[0].Size()) } return nil } diff --git a/system_tests/outbox_test.go b/system_tests/outbox_test.go index 10d1ebec42..2b3ff38da1 100644 --- a/system_tests/outbox_test.go +++ b/system_tests/outbox_test.go @@ -283,7 +283,7 @@ func TestOutboxProofs(t *testing.T) { if !balanced { // This tree isn't balanced, so we'll need to use the partials to recover the missing info. - // To do this, we'll walk the boundry of what's known, computing hashes along the way + // To do this, we'll walk the boundary of what's known, computing hashes along the way zero := common.Hash{} diff --git a/system_tests/seqinbox_test.go b/system_tests/seqinbox_test.go index a9f66b0e2f..44d96f39e7 100644 --- a/system_tests/seqinbox_test.go +++ b/system_tests/seqinbox_test.go @@ -353,7 +353,7 @@ func testSequencerInboxReaderImpl(t *testing.T, validator bool) { AfterDelayedMessagesRead: 1, }) if diff := diffAccessList(accessed, *wantAL); diff != "" { - t.Errorf("Access list mistmatch:\n%s\n", diff) + t.Errorf("Access list mismatch:\n%s\n", diff) } if i%5 == 0 { tx, err = seqInbox.AddSequencerL2Batch(&seqOpts, big.NewInt(int64(len(blockStates))), batchData, big.NewInt(1), gasRefunderAddr, big.NewInt(0), big.NewInt(0)) From 5fb7c01631eac527b698570a8e9448212bc32b98 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 19 Dec 2024 19:21:55 +0530 Subject: [PATCH 23/67] Add mock external signer binary --- Dockerfile | 1 + Makefile | 5 +- arbnode/dataposter/data_poster.go | 16 +++ arbnode/dataposter/dataposter_test.go | 18 +--- .../externalsignertest/externalsignertest.go | 4 +- cmd/mockexternalsigner/mockexternalsigner.go | 97 +++++++++++++++++++ system_tests/batch_poster_test.go | 17 +--- system_tests/fast_confirm_test.go | 5 +- system_tests/staker_test.go | 3 +- 9 files changed, 127 insertions(+), 39 deletions(-) create mode 100644 cmd/mockexternalsigner/mockexternalsigner.go diff --git a/Dockerfile b/Dockerfile index ba1f2feb3e..17372f2d08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -333,6 +333,7 @@ RUN rm -f /home/user/target/machines/latest COPY --from=prover-export /bin/jit /usr/local/bin/ COPY --from=node-builder /workspace/target/bin/deploy /usr/local/bin/ COPY --from=node-builder /workspace/target/bin/seq-coordinator-invalidate /usr/local/bin/ +COPY --from=node-builder /workspace/target/bin/mockexternalsigner /usr/local/bin/ COPY --from=module-root-calc /workspace/target/machines/latest/machine.wavm.br /home/user/target/machines/latest/ COPY --from=module-root-calc /workspace/target/machines/latest/until-host-io-state.bin /home/user/target/machines/latest/ COPY --from=module-root-calc /workspace/target/machines/latest/module-root.txt /home/user/target/machines/latest/ diff --git a/Makefile b/Makefile index 12dfb07cf8..1a618df9f7 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ all: build build-replay-env test-gen-proofs @touch .make/all .PHONY: build -build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool seq-coordinator-invalidate nitro-val seq-coordinator-manager dbconv) +build: $(patsubst %,$(output_root)/bin/%, nitro deploy relay daserver datool mockexternalsigner seq-coordinator-invalidate nitro-val seq-coordinator-manager dbconv) @printf $(done) .PHONY: build-node-deps @@ -314,6 +314,9 @@ $(output_root)/bin/daserver: $(DEP_PREDICATE) build-node-deps $(output_root)/bin/datool: $(DEP_PREDICATE) build-node-deps go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/datool" +$(output_root)/bin/mockexternalsigner: $(DEP_PREDICATE) build-node-deps + go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/mockexternalsigner" + $(output_root)/bin/seq-coordinator-invalidate: $(DEP_PREDICATE) build-node-deps go build $(GOLANG_PARAMS) -o $@ "$(CURDIR)/cmd/seq-coordinator-invalidate" diff --git a/arbnode/dataposter/data_poster.go b/arbnode/dataposter/data_poster.go index a977b9fc08..5accd6312d 100644 --- a/arbnode/dataposter/data_poster.go +++ b/arbnode/dataposter/data_poster.go @@ -41,6 +41,7 @@ import ( "github.com/ethereum/go-ethereum/signer/core/apitypes" "github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage" + "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/noop" redisstorage "github.com/offchainlabs/nitro/arbnode/dataposter/redis" "github.com/offchainlabs/nitro/arbnode/dataposter/slice" @@ -1297,6 +1298,21 @@ type ExternalSignerCfg struct { InsecureSkipVerify bool `koanf:"insecure-skip-verify"` } +func ExternalSignerTestCfg(addr common.Address, url string) (*ExternalSignerCfg, error) { + cp, err := externalsignertest.CertPaths() + if err != nil { + return nil, fmt.Errorf("getting certificates path: %w", err) + } + return &ExternalSignerCfg{ + Address: common.Bytes2Hex(addr.Bytes()), + URL: url, + Method: externalsignertest.SignerMethod, + RootCA: cp.ServerCert, + ClientCert: cp.ClientCert, + ClientPrivateKey: cp.ClientKey, + }, nil +} + type DangerousConfig struct { // This should be used with caution, only when dataposter somehow gets in a // bad state and we require clearing it. diff --git a/arbnode/dataposter/dataposter_test.go b/arbnode/dataposter/dataposter_test.go index dc5df1a6c4..83401b2484 100644 --- a/arbnode/dataposter/dataposter_test.go +++ b/arbnode/dataposter/dataposter_test.go @@ -3,7 +3,6 @@ package dataposter import ( "context" "errors" - "fmt" "math/big" "testing" "time" @@ -25,21 +24,6 @@ import ( "github.com/offchainlabs/nitro/util/arbmath" ) -func signerTestCfg(addr common.Address, url string) (*ExternalSignerCfg, error) { - cp, err := externalsignertest.CertPaths() - if err != nil { - return nil, fmt.Errorf("getting certificates path: %w", err) - } - return &ExternalSignerCfg{ - Address: common.Bytes2Hex(addr.Bytes()), - URL: url, - Method: externalsignertest.SignerMethod, - RootCA: cp.ServerCert, - ClientCert: cp.ClientCert, - ClientPrivateKey: cp.ClientKey, - }, nil -} - var ( blobTx = types.NewTx( &types.BlobTx{ @@ -80,7 +64,7 @@ func TestExternalSigner(t *testing.T) { return } }() - signerCfg, err := signerTestCfg(srv.Address, srv.URL()) + signerCfg, err := ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting signer test config: %v", err) } diff --git a/arbnode/dataposter/externalsignertest/externalsignertest.go b/arbnode/dataposter/externalsignertest/externalsignertest.go index 51ccec1903..c71a36fc91 100644 --- a/arbnode/dataposter/externalsignertest/externalsignertest.go +++ b/arbnode/dataposter/externalsignertest/externalsignertest.go @@ -42,7 +42,7 @@ type CertAbsPaths struct { type SignerServer struct { *http.Server *SignerAPI - listener net.Listener + Listener net.Listener } func basePath() (string, error) { @@ -147,7 +147,7 @@ func (s *SignerServer) Start() error { if err != nil { return err } - if err := s.ServeTLS(s.listener, cp.ServerCert, cp.ServerKey); err != nil && !errors.Is(err, http.ErrServerClosed) { + if err := s.ServeTLS(s.Listener, cp.ServerCert, cp.ServerKey); err != nil && !errors.Is(err, http.ErrServerClosed) { return err } return nil diff --git a/cmd/mockexternalsigner/mockexternalsigner.go b/cmd/mockexternalsigner/mockexternalsigner.go new file mode 100644 index 0000000000..185923bcc8 --- /dev/null +++ b/cmd/mockexternalsigner/mockexternalsigner.go @@ -0,0 +1,97 @@ +package main + +import ( + "crypto/tls" + "crypto/x509" + "encoding/json" + "fmt" + "math/big" + "net/http" + "os" + "time" + + "github.com/ethereum/go-ethereum/rpc" + + "github.com/offchainlabs/nitro/arbnode/dataposter" + "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" + "github.com/offchainlabs/nitro/cmd/genericconf" + "github.com/offchainlabs/nitro/cmd/util" + "github.com/offchainlabs/nitro/util/testhelpers" +) + +func main() { + args := os.Args + if len(args) != 2 { + panic("Usage: mockexternalsigner [private_key]") + } + srv, err := NewServer(args[1]) + if err != nil { + panic(err) + } + go func() { + if err := srv.Start(); err != nil { + panic(err) + } + }() + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) + if err != nil { + panic(err) + } + signerCfgBytes, err := json.Marshal(signerCfg) + if err != nil { + panic(err) + } + fmt.Println(string(signerCfgBytes)) + +} + +func NewServer(privateKey string) (*externalsignertest.SignerServer, error) { + rpcServer := rpc.NewServer() + txOpts, _, err := util.OpenWallet( + "mockexternalsigner", + &genericconf.WalletConfig{PrivateKey: privateKey}, + big.NewInt(1337), + ) + if err != nil { + return nil, err + } + s := &externalsignertest.SignerAPI{SignerFn: txOpts.Signer, Address: txOpts.From} + if err := rpcServer.RegisterName("test", s); err != nil { + return nil, err + } + cp, err := externalsignertest.CertPaths() + if err != nil { + return nil, err + } + clientCert, err := os.ReadFile(cp.ClientCert) + if err != nil { + return nil, err + } + pool := x509.NewCertPool() + pool.AppendCertsFromPEM(clientCert) + + ln, err := testhelpers.FreeTCPPortListener() + if err != nil { + return nil, err + } + + httpServer := &http.Server{ + Addr: ln.Addr().String(), + Handler: rpcServer, + ReadTimeout: 30 * time.Second, + ReadHeaderTimeout: 30 * time.Second, + WriteTimeout: 30 * time.Second, + IdleTimeout: 120 * time.Second, + TLSConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + ClientAuth: tls.RequireAndVerifyClientCert, + ClientCAs: pool, + }, + } + + return &externalsignertest.SignerServer{ + Server: httpServer, + SignerAPI: s, + Listener: ln, + }, nil +} diff --git a/system_tests/batch_poster_test.go b/system_tests/batch_poster_test.go index ee0c3b4a3a..fe2fa2df1d 100644 --- a/system_tests/batch_poster_test.go +++ b/system_tests/batch_poster_test.go @@ -64,21 +64,6 @@ func addNewBatchPoster(ctx context.Context, t *testing.T, builder *NodeBuilder, } } -func externalSignerTestCfg(addr common.Address, url string) (*dataposter.ExternalSignerCfg, error) { - cp, err := externalsignertest.CertPaths() - if err != nil { - return nil, fmt.Errorf("getting certificates path: %w", err) - } - return &dataposter.ExternalSignerCfg{ - Address: common.Bytes2Hex(addr.Bytes()), - URL: url, - Method: externalsignertest.SignerMethod, - RootCA: cp.ServerCert, - ClientCert: cp.ClientCert, - ClientPrivateKey: cp.ClientKey, - }, nil -} - func testBatchPosterParallel(t *testing.T, useRedis bool) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -105,7 +90,7 @@ func testBatchPosterParallel(t *testing.T, useRedis bool) { builder := NewNodeBuilder(ctx).DefaultConfig(t, true) builder.nodeConfig.BatchPoster.Enable = false builder.nodeConfig.BatchPoster.RedisUrl = redisUrl - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } diff --git a/system_tests/fast_confirm_test.go b/system_tests/fast_confirm_test.go index 8eb71bffd4..384e9649c6 100644 --- a/system_tests/fast_confirm_test.go +++ b/system_tests/fast_confirm_test.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/arbnode/dataposter" "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/storage" "github.com/offchainlabs/nitro/arbos/l2pricing" @@ -174,7 +175,7 @@ func TestFastConfirmation(t *testing.T) { err = stakerA.Initialize(ctx) Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } @@ -375,7 +376,7 @@ func TestFastConfirmationWithSafe(t *testing.T) { err = stakerA.Initialize(ctx) Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } diff --git a/system_tests/staker_test.go b/system_tests/staker_test.go index 69645d8878..b223e79a8c 100644 --- a/system_tests/staker_test.go +++ b/system_tests/staker_test.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbnode" + "github.com/offchainlabs/nitro/arbnode/dataposter" "github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest" "github.com/offchainlabs/nitro/arbnode/dataposter/storage" "github.com/offchainlabs/nitro/arbos/l2pricing" @@ -229,7 +230,7 @@ func stakerTestImpl(t *testing.T, faultyStaker bool, honestStakerInactive bool) } Require(t, err) cfg := arbnode.ConfigDefaultL1NonSequencerTest() - signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL()) + signerCfg, err := dataposter.ExternalSignerTestCfg(srv.Address, srv.URL()) if err != nil { t.Fatalf("Error getting external signer config: %v", err) } From c5285afa712b3cb972f1ffbee5b04fdec1cb3e5c Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 19 Dec 2024 21:25:28 +0530 Subject: [PATCH 24/67] minor fix --- cmd/mockexternalsigner/mockexternalsigner.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/mockexternalsigner/mockexternalsigner.go b/cmd/mockexternalsigner/mockexternalsigner.go index 185923bcc8..4678d586ef 100644 --- a/cmd/mockexternalsigner/mockexternalsigner.go +++ b/cmd/mockexternalsigner/mockexternalsigner.go @@ -3,8 +3,6 @@ package main import ( "crypto/tls" "crypto/x509" - "encoding/json" - "fmt" "math/big" "net/http" "os" @@ -37,12 +35,15 @@ func main() { if err != nil { panic(err) } - signerCfgBytes, err := json.Marshal(signerCfg) - if err != nil { - panic(err) + print(" --externalSignerUrl " + signerCfg.URL) + print(" --externalSignerAddress " + signerCfg.Address) + print(" --externalSignerMethod " + signerCfg.Method) + print(" --externalSignerRootCA " + signerCfg.RootCA) + print(" --externalSignerClientCert " + signerCfg.ClientCert) + print(" --externalSignerClientPrivateKey " + signerCfg.ClientPrivateKey) + if signerCfg.InsecureSkipVerify { + print(" --externalSignerInsecureSkipVerify ") } - fmt.Println(string(signerCfgBytes)) - } func NewServer(privateKey string) (*externalsignertest.SignerServer, error) { From 784fa4662f2415d9b1f461d87a4e56ca03790282 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:10:00 +0000 Subject: [PATCH 25/67] Bump golang.org/x/crypto from 0.24.0 to 0.31.0 Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.24.0 to 0.31.0. - [Commits](https://github.com/golang/crypto/compare/v0.24.0...v0.31.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 12 ++++++------ go.sum | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 7a48b0520d..cfcca3628b 100644 --- a/go.mod +++ b/go.mod @@ -20,6 +20,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.27 github.com/aws/aws-sdk-go-v2/service/s3 v1.64.1 github.com/cavaliergopher/grab/v3 v3.0.1 + github.com/ccoveille/go-safecast v1.1.0 github.com/cockroachdb/pebble v1.1.0 github.com/codeclysm/extract/v3 v3.0.2 github.com/dgraph-io/badger/v4 v4.2.0 @@ -46,9 +47,9 @@ require ( github.com/spf13/pflag v1.0.5 github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/wealdtech/go-merkletree v1.0.0 - golang.org/x/crypto v0.24.0 - golang.org/x/sys v0.21.0 - golang.org/x/term v0.21.0 + golang.org/x/crypto v0.31.0 + golang.org/x/sys v0.28.0 + golang.org/x/term v0.27.0 golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d google.golang.org/api v0.187.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 @@ -60,7 +61,6 @@ require ( cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect cloud.google.com/go/compute/metadata v0.3.0 // indirect cloud.google.com/go/iam v1.1.8 // indirect - github.com/ccoveille/go-safecast v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -195,8 +195,8 @@ require ( golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.22.0 - golang.org/x/sync v0.8.0 - golang.org/x/text v0.16.0 // indirect + golang.org/x/sync v0.10.0 + golang.org/x/text v0.21.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/protobuf v1.34.2 // indirect rsc.io/tmplfunc v0.0.3 // indirect diff --git a/go.sum b/go.sum index 55ad86267a..01b58980dd 100644 --- a/go.sum +++ b/go.sum @@ -535,8 +535,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= @@ -580,8 +580,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -614,14 +614,14 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -631,8 +631,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= From e3aaf054df3bb7bfb8d2cfb4f4267bde6849a2f2 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 23 Dec 2024 13:07:27 -0600 Subject: [PATCH 26/67] update submod --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index d3f4d600ab..53a6195bd7 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit d3f4d600abdacec800e9e27a429a730639233073 +Subproject commit 53a6195bd7bbd749a81319920429a98b0b9213d4 From f2bfd88fc2508e7dddda97f3f23e57eee9c30906 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 30 Dec 2024 20:37:51 -0600 Subject: [PATCH 27/67] edit bold submod --- bold | 2 +- go-ethereum | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bold b/bold index 53a6195bd7..3df1191028 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 53a6195bd7bbd749a81319920429a98b0b9213d4 +Subproject commit 3df119102815a7c17b87251e18df6e09f6e58128 diff --git a/go-ethereum b/go-ethereum index 26b4dff616..0d33cae0dd 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 +Subproject commit 0d33cae0dd24ce387c589532e9557911780b389c From 7fd9dba8e7cb3b9540065057c88eb51ac3f58e2f Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 30 Dec 2024 21:38:07 -0600 Subject: [PATCH 28/67] build --- arbos/util/transfer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/util/transfer.go b/arbos/util/transfer.go index 0b61868abe..55281fa284 100644 --- a/arbos/util/transfer.go +++ b/arbos/util/transfer.go @@ -67,7 +67,7 @@ func TransferBalance( if arbmath.BigLessThan(balance.ToBig(), amount) { return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount) } - if evm.Context.ArbOSVersion < params.ArbosVersion_30 && amount.Sign() == 0 { + if evm.Context.ArbOSVersion < params.ArbosVersion_Stylus && amount.Sign() == 0 { evm.StateDB.CreateZombieIfDeleted(*from) } evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer) From a46dc68c366a76290e7f480f2d18e3c214577414 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 31 Dec 2024 10:31:30 -0600 Subject: [PATCH 29/67] geth --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 0d33cae0dd..26b4dff616 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 0d33cae0dd24ce387c589532e9557911780b389c +Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 From 693c4066100689aaefee081b3f9a1e0c4175bdb8 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 2 Jan 2025 20:32:20 +0530 Subject: [PATCH 30/67] Changes based on PR comments --- arbnode/message_pruner.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/arbnode/message_pruner.go b/arbnode/message_pruner.go index 5cdd1128d0..3805bd8637 100644 --- a/arbnode/message_pruner.go +++ b/arbnode/message_pruner.go @@ -201,19 +201,21 @@ func fetchLastPrunedKey(db ethdb.Database, lastPrunedKey []byte) uint64 { hasKey, err := db.Has(lastPrunedKey) if err != nil { log.Warn("error checking for last pruned key: %w", err) - } else if hasKey { - lastPrunedValueByte, err := db.Get(lastPrunedKey) - if err != nil { - log.Warn("error fetching last pruned key: %w", err) - } else { - var lastPrunedValue uint64 - err = rlp.DecodeBytes(lastPrunedValueByte, &lastPrunedValue) - if err != nil { - log.Warn("error decoding last pruned value: %w", err) - } else { - return lastPrunedValue - } - } + return 0 + } + if !hasKey { + return 0 + } + lastPrunedValueByte, err := db.Get(lastPrunedKey) + if err != nil { + log.Warn("error fetching last pruned key: %w", err) + return 0 + } + var lastPrunedValue uint64 + err = rlp.DecodeBytes(lastPrunedValueByte, &lastPrunedValue) + if err != nil { + log.Warn("error decoding last pruned value: %w", err) + return 0 } - return 0 + return lastPrunedValue } From 669c5ef052d76ac264c0ba3fed0eeb4717db1a9a Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 2 Jan 2025 21:01:43 +0530 Subject: [PATCH 31/67] Changes based on PR comments --- arbnode/message_pruner.go | 46 ++++++++++++++++++++++----------------- arbnode/schema.go | 14 +++++------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/arbnode/message_pruner.go b/arbnode/message_pruner.go index 3805bd8637..b18796a4c5 100644 --- a/arbnode/message_pruner.go +++ b/arbnode/message_pruner.go @@ -24,15 +24,13 @@ import ( type MessagePruner struct { stopwaiter.StopWaiter - transactionStreamer *TransactionStreamer - inboxTracker *InboxTracker - config MessagePrunerConfigFetcher - pruningLock sync.Mutex - lastPruneDone time.Time - cachedPrunedMessages uint64 - cachedPrunedBlockHashesInputFeed uint64 - cachedPrunedMessageResult uint64 - cachedPrunedDelayedMessages uint64 + transactionStreamer *TransactionStreamer + inboxTracker *InboxTracker + config MessagePrunerConfigFetcher + pruningLock sync.Mutex + lastPruneDone time.Time + cachedPrunedMessages uint64 + cachedPrunedDelayedMessages uint64 } type MessagePrunerConfig struct { @@ -122,7 +120,14 @@ func (m *MessagePruner) prune(ctx context.Context, count arbutil.MessageIndex, g } func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCount arbutil.MessageIndex, delayedMessageCount uint64) error { - prunedKeysRange, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, lastPrunedMessageResultKey, &m.cachedPrunedMessageResult, uint64(messageCount)) + if m.cachedPrunedMessages == 0 { + m.cachedPrunedMessages = fetchLastPrunedKey(m.transactionStreamer.db, lastPrunedMessageKey) + } + if m.cachedPrunedDelayedMessages == 0 { + m.cachedPrunedDelayedMessages = fetchLastPrunedKey(m.inboxTracker.db, lastPrunedDelayedMessageKey) + } + lastPrunedMessage := m.cachedPrunedMessages + prunedKeysRange, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, &lastPrunedMessage, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting message results: %w", err) } @@ -130,7 +135,8 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned message results:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, lastPrunedBlockHashInputFeedKey, &m.cachedPrunedBlockHashesInputFeed, uint64(messageCount)) + lastPrunedMessage = m.cachedPrunedMessages + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, &lastPrunedMessage, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting expected block hashes: %w", err) } @@ -138,32 +144,34 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned expected block hashes:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, lastPrunedMessageKey, &m.cachedPrunedMessages, uint64(messageCount)) + lastPrunedMessage = m.cachedPrunedMessages + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, &lastPrunedMessage, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting last batch messages: %w", err) } if len(prunedKeysRange) > 0 { log.Info("Pruned last batch messages:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } + insertLastPrunedKey(m.transactionStreamer.db, lastPrunedMessageKey, lastPrunedMessage) + m.cachedPrunedMessages = lastPrunedMessage - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, lastPrunedRlpDelayedMessageKey, &m.cachedPrunedDelayedMessages, delayedMessageCount) + lastPrunedDelayedMessage := m.cachedPrunedDelayedMessages + prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, &lastPrunedDelayedMessage, delayedMessageCount) if err != nil { return fmt.Errorf("error deleting last batch delayed messages: %w", err) } if len(prunedKeysRange) > 0 { log.Info("Pruned last batch delayed messages:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } + insertLastPrunedKey(m.inboxTracker.db, lastPrunedDelayedMessageKey, lastPrunedMessage) + m.cachedPrunedDelayedMessages = lastPrunedDelayedMessage return nil } // deleteFromLastPrunedUptoEndKey is similar to deleteFromRange but automatically populates the start key // cachedStartMinKey must not be nil. It's set to the new start key at the end of this function if successful. -// Checks if the last pruned key is set in the database and uses it as the start key if it is. -func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, lastPrunedKey []byte, cachedStartMinKey *uint64, endMinKey uint64) ([]uint64, error) { +func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, cachedStartMinKey *uint64, endMinKey uint64) ([]uint64, error) { startMinKey := *cachedStartMinKey - if startMinKey == 0 { - startMinKey = fetchLastPrunedKey(db, lastPrunedKey) - } if startMinKey == 0 { startIter := db.NewIterator(prefix, uint64ToKey(1)) if !startIter.Next() { @@ -174,13 +182,11 @@ func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, pref } if endMinKey <= startMinKey { *cachedStartMinKey = startMinKey - insertLastPrunedKey(db, lastPrunedKey, startMinKey) return nil, nil } keys, err := deleteFromRange(ctx, db, prefix, startMinKey, endMinKey-1) if err == nil { *cachedStartMinKey = endMinKey - 1 - insertLastPrunedKey(db, lastPrunedKey, endMinKey-1) } return keys, err } diff --git a/arbnode/schema.go b/arbnode/schema.go index e06d6a75c7..88a31ce90a 100644 --- a/arbnode/schema.go +++ b/arbnode/schema.go @@ -13,14 +13,12 @@ var ( sequencerBatchMetaPrefix []byte = []byte("s") // maps a batch sequence number to BatchMetadata delayedSequencedPrefix []byte = []byte("a") // maps a delayed message count to the first sequencer batch sequence number with this delayed count - messageCountKey []byte = []byte("_messageCount") // contains the current message count - lastPrunedMessageResultKey []byte = []byte("_lastPrunedMessageResultKey") // contains the last pruned message result key - lastPrunedBlockHashInputFeedKey []byte = []byte("_lastPrunedBlockHashInputFeedPrefix") // contains the last pruned block hash input feed key - lastPrunedMessageKey []byte = []byte("_lastPrunedMessageKey") // contains the last pruned message key - lastPrunedRlpDelayedMessageKey []byte = []byte("_lastPrunedRlpDelayedMessageKey") // contains the last pruned RLP delayed message key - delayedMessageCountKey []byte = []byte("_delayedMessageCount") // contains the current delayed message count - sequencerBatchCountKey []byte = []byte("_sequencerBatchCount") // contains the current sequencer message count - dbSchemaVersion []byte = []byte("_schemaVersion") // contains a uint64 representing the database schema version + messageCountKey []byte = []byte("_messageCount") // contains the current message count + lastPrunedMessageKey []byte = []byte("_lastPrunedMessageKey") // contains the last pruned message key + lastPrunedDelayedMessageKey []byte = []byte("_lastPrunedDelayedMessageKey") // contains the last pruned RLP delayed message key + delayedMessageCountKey []byte = []byte("_delayedMessageCount") // contains the current delayed message count + sequencerBatchCountKey []byte = []byte("_sequencerBatchCount") // contains the current sequencer message count + dbSchemaVersion []byte = []byte("_schemaVersion") // contains a uint64 representing the database schema version ) const currentDbSchemaVersion uint64 = 1 From 89cf1f87db443ccea57d9b5fbd32f7207d363750 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 2 Jan 2025 14:11:21 -0600 Subject: [PATCH 32/67] use proper bold commit --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 3df1191028..eae8d51fcf 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 3df119102815a7c17b87251e18df6e09f6e58128 +Subproject commit eae8d51fcf02002d3216a0b15f23b66f819f792d From d3de311d8ac5153ee4299b0053d7a93d84e735b3 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Thu, 2 Jan 2025 13:51:48 -0700 Subject: [PATCH 33/67] remove most occurences of log.Crit --- arbos/arbosState/arbosstate.go | 7 ++-- arbos/arbosState/initialize.go | 4 +-- arbos/programs/api.go | 10 +++--- arbos/programs/native_api.go | 5 ++- arbos/programs/programs.go | 2 +- arbstate/inbox.go | 6 ++-- precompiles/context.go | 7 ++-- precompiles/precompile.go | 59 ++++++++++++++++------------------ precompiles/precompile_test.go | 9 ------ system_tests/staker_test.go | 2 +- 10 files changed, 46 insertions(+), 65 deletions(-) diff --git a/arbos/arbosState/arbosstate.go b/arbos/arbosState/arbosstate.go index 5ee070f942..de1a970b87 100644 --- a/arbos/arbosState/arbosstate.go +++ b/arbos/arbosState/arbosstate.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/triedb" "github.com/ethereum/go-ethereum/triedb/hashdb" @@ -123,13 +122,13 @@ func NewArbosMemoryBackedArbOSState() (*ArbosState, *state.StateDB) { db := state.NewDatabaseWithConfig(raw, trieConfig) statedb, err := state.New(common.Hash{}, db, nil) if err != nil { - log.Crit("failed to init empty statedb", "error", err) + panic("failed to init empty statedb: " + err.Error()) } burner := burn.NewSystemBurner(nil, false) chainConfig := chaininfo.ArbitrumDevTestChainConfig() newState, err := InitializeArbosState(statedb, burner, chainConfig, arbostypes.TestInitMessage) if err != nil { - log.Crit("failed to open the ArbOS state", "error", err) + panic("failed to open the ArbOS state: " + err.Error()) } return newState, statedb } @@ -139,7 +138,7 @@ func ArbOSVersion(stateDB vm.StateDB) uint64 { backingStorage := storage.NewGeth(stateDB, burn.NewSystemBurner(nil, false)) arbosVersion, err := backingStorage.GetUint64ByUint64(uint64(versionOffset)) if err != nil { - log.Crit("failed to get the ArbOS version", "error", err) + panic("failed to get the ArbOS version: " + err.Error()) } return arbosVersion } diff --git a/arbos/arbosState/initialize.go b/arbos/arbosState/initialize.go index 8fd417c2b2..840204382c 100644 --- a/arbos/arbosState/initialize.go +++ b/arbos/arbosState/initialize.go @@ -66,7 +66,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig, }() statedb, err := state.New(common.Hash{}, stateDatabase, nil) if err != nil { - log.Crit("failed to init empty statedb", "error", err) + panic("failed to init empty statedb :" + err.Error()) } noStateTrieChangesToCommitError := regexp.MustCompile("^triedb layer .+ is disk layer$") @@ -96,7 +96,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig, burner := burn.NewSystemBurner(nil, false) arbosState, err := InitializeArbosState(statedb, burner, chainConfig, initMessage) if err != nil { - log.Crit("failed to open the ArbOS state", "error", err) + panic("failed to open the ArbOS state :" + err.Error()) } chainOwner, err := initData.GetChainOwner() diff --git a/arbos/programs/api.go b/arbos/programs/api.go index d8f12ffbd3..cd2143f5d0 100644 --- a/arbos/programs/api.go +++ b/arbos/programs/api.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos/util" @@ -151,7 +150,7 @@ func newApiClosures( case vm.STATICCALL: ret, returnGas, err = evm.StaticCall(scope.Contract, contract, input, gas) default: - log.Crit("unsupported call type", "opcode", opcode) + panic("unsupported call type: " + opcode.String()) } interpreter.SetReturnData(ret) @@ -266,7 +265,7 @@ func newApiClosures( original := input crash := func(reason string) { - log.Crit("bad API call", "reason", reason, "request", req, "len", len(original), "remaining", len(input)) + panic("bad API call reason: " + reason + " request: " + string(req) + " len: " + string(len(original)) + " remaining: " + string(len(input))) } takeInput := func(needed int, reason string) []byte { if len(input) < needed { @@ -338,7 +337,7 @@ func newApiClosures( case StaticCall: opcode = vm.STATICCALL default: - log.Crit("unsupported call type", "opcode", opcode) + panic("unsupported call type opcode: " + opcode.String()) } contract := takeAddress() value := takeU256() @@ -414,8 +413,7 @@ func newApiClosures( captureHostio(name, args, outs, startInk, endInk) return []byte{}, nil, 0 default: - log.Crit("unsupported call type", "req", req) - return []byte{}, nil, 0 + panic("unsupported call type: " + string(req)) } } } diff --git a/arbos/programs/native_api.go b/arbos/programs/native_api.go index ab15800ef9..bf9cda658d 100644 --- a/arbos/programs/native_api.go +++ b/arbos/programs/native_api.go @@ -29,7 +29,6 @@ import ( "sync/atomic" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/log" "github.com/offchainlabs/nitro/arbos/util" "github.com/offchainlabs/nitro/arbutil" @@ -69,11 +68,11 @@ func newApi( func getApi(id usize) NativeApi { any, ok := apiObjects.Load(uintptr(id)) if !ok { - log.Crit("failed to load stylus Go API", "id", id) + panic("failed to load stylus Go API id: " + string(id)) } api, ok := any.(NativeApi) if !ok { - log.Crit("wrong type for stylus Go API", "id", id) + panic("wrong type for stylus Go API id: " + string(id)) } return api } diff --git a/arbos/programs/programs.go b/arbos/programs/programs.go index 06ba6ead8c..6b2a0c318b 100644 --- a/arbos/programs/programs.go +++ b/arbos/programs/programs.go @@ -219,7 +219,7 @@ func (p Programs) CallProgram( localAsm, err := getLocalAsm(statedb, moduleHash, contract.Address(), contract.Code, contract.CodeHash, params.PageLimit, evm.Context.Time, debugMode, program) if err != nil { - log.Crit("failed to get local wasm for activated program", "program", contract.Address()) + panic("failed to get local wasm for activated program: " + contract.Address().Hex()) return nil, err } diff --git a/arbstate/inbox.go b/arbstate/inbox.go index b58a7420b7..5539a75ce1 100644 --- a/arbstate/inbox.go +++ b/arbstate/inbox.go @@ -85,11 +85,11 @@ func parseSequencerMessage(ctx context.Context, batchNum uint64, batchBlockHash // Matches the way keyset validation was done inside DAS readers i.e logging the error // But other daproviders might just want to return the error if errors.Is(err, daprovider.ErrSeqMsgValidation) && daprovider.IsDASMessageHeaderByte(payload[0]) { - logLevel := log.Error if keysetValidationMode == daprovider.KeysetPanicIfInvalid { - logLevel = log.Crit + panic(err.Error()) + } else { + log.Error(err.Error()) } - logLevel(err.Error()) } else { return nil, err } diff --git a/precompiles/context.go b/precompiles/context.go index 670ffa7443..86e56ffbff 100644 --- a/precompiles/context.go +++ b/precompiles/context.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/log" "github.com/offchainlabs/nitro/arbos" "github.com/offchainlabs/nitro/arbos/arbosState" @@ -58,7 +57,7 @@ func (c *Context) GasLeft() *uint64 { } func (c *Context) Restrict(err error) { - log.Crit("A metered burner was used for access-controlled work", "error", err) + panic("A metered burner was used for access-controlled work :" + err.Error()) } func (c *Context) HandleError(err error) error { @@ -88,13 +87,13 @@ func testContext(caller addr, evm mech) *Context { } state, err := arbosState.OpenArbosState(evm.StateDB, burn.NewSystemBurner(tracingInfo, false)) if err != nil { - log.Crit("unable to open arbos state", "error", err) + panic("unable to open arbos state :" + err.Error()) } ctx.State = state var ok bool ctx.txProcessor, ok = evm.ProcessingHook.(*arbos.TxProcessor) if !ok { - log.Crit("must have tx processor") + panic("must have tx processor") } return ctx } diff --git a/precompiles/precompile.go b/precompiles/precompile.go index 54d18a0cc9..f34c418313 100644 --- a/precompiles/precompile.go +++ b/precompiles/precompile.go @@ -120,7 +120,7 @@ func (e *SolError) Error() string { func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Precompile) { source, err := abi.JSON(strings.NewReader(metadata.ABI)) if err != nil { - log.Crit("Bad ABI") + panic("Bad ABI") } implementerType := reflect.TypeOf(implementer) @@ -128,12 +128,12 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr _, ok := implementerType.Elem().FieldByName("Address") if !ok { - log.Crit("Implementer for precompile ", contract, " is missing an Address field") + panic("Implementer for precompile " + contract + " is missing an Address field") } address, ok := reflect.ValueOf(implementer).Elem().FieldByName("Address").Interface().(addr) if !ok { - log.Crit("Implementer for precompile ", contract, "'s Address field has the wrong type") + panic("Implementer for precompile " + contract + "'s Address field has the wrong type") } gethAbiFuncTypeEquality := func(actual, geth reflect.Type) bool { @@ -167,7 +167,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr name = capitalize + name[1:] if len(method.ID) != 4 { - log.Crit("Method ID isn't 4 bytes") + panic("Method ID isn't 4 bytes") } id := *(*[4]byte)(method.ID) @@ -175,7 +175,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr handler, ok := implementerType.MethodByName(name) if !ok { - log.Crit("Precompile " + contract + " must implement " + name) + panic("Precompile " + contract + " must implement " + name) } var needs = []reflect.Type{ @@ -199,7 +199,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr needs = append(needs, reflect.TypeOf(&big.Int{})) purity = payable default: - log.Crit("Unknown state mutability ", method.StateMutability) + panic("Unknown state mutability " + method.StateMutability) } for _, arg := range method.Inputs { @@ -215,10 +215,9 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr expectedHandlerType := reflect.FuncOf(needs, outputs, false) if !gethAbiFuncTypeEquality(handler.Type, expectedHandlerType) { - log.Crit( - "Precompile "+contract+"'s "+name+"'s implementer has the wrong type\n", - "\texpected:\t", expectedHandlerType, "\n\tbut have:\t", handler.Type, - ) + panic( + "Precompile " + contract + "'s " + name + "'s implementer has the wrong type\n" + + "\texpected:\t" + expectedHandlerType.String() + "\n\tbut have:\t" + handler.Type.String()) } method := PrecompileMethod{ @@ -237,7 +236,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr method := implementerType.Method(i) name := method.Name if method.IsExported() && methodsByName[name] == nil { - log.Crit(contract + " is missing a solidity interface for " + name) + panic(contract + " is missing a solidity interface for " + name) } } @@ -269,11 +268,10 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr if arg.Indexed { _, ok := supportedIndices[arg.Type.String()] if !ok { - log.Crit( - "Please change the solidity for precompile ", contract, - "'s event ", name, ":\n\tEvent indices of type ", - arg.Type.String(), " are not supported", - ) + panic( + "Please change the solidity for precompile " + contract + + "'s event " + name + ":\n\tEvent indices of type " + + arg.Type.String() + " are not supported") } } } @@ -288,23 +286,21 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr field, ok := implementerType.Elem().FieldByName(name) if !ok { - log.Crit(missing, "event ", name, " of type\n\t", expectedFieldType) + panic(missing + "event " + name + " of type\n\t" + expectedFieldType.String()) } costField, ok := implementerType.Elem().FieldByName(name + "GasCost") if !ok { - log.Crit(missing, "event ", name, "'s GasCost of type\n\t", expectedCostType) + panic(missing + "event " + name + "'s GasCost of type\n\t" + expectedCostType.String()) } if !gethAbiFuncTypeEquality(field.Type, expectedFieldType) { - log.Crit( - context, "'s field for event ", name, " has the wrong type\n", - "\texpected:\t", expectedFieldType, "\n\tbut have:\t", field.Type, - ) + panic( + context + "'s field for event " + name + " has the wrong type\n" + + "\texpected:\t" + expectedFieldType.String() + "\n\tbut have:\t" + field.Type.String()) } if !gethAbiFuncTypeEquality(costField.Type, expectedCostType) { - log.Crit( - context, "'s field for event ", name, "GasCost has the wrong type\n", - "\texpected:\t", expectedCostType, "\n\tbut have:\t", costField.Type, - ) + panic( + context + "'s field for event " + name + "GasCost has the wrong type\n" + + "\texpected:\t" + expectedCostType.String() + "\n\tbut have:\t" + costField.Type.String()) } structFields := reflect.ValueOf(implementer).Elem() @@ -464,13 +460,12 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr field, ok := implementerType.Elem().FieldByName(name + "Error") if !ok { - log.Crit(missing, "custom error ", name, "Error of type\n\t", expectedFieldType) + panic(missing + "custom error " + name + "Error of type\n\t" + expectedFieldType.String()) } if field.Type != expectedFieldType { - log.Crit( - context, "'s field for error ", name, "Error has the wrong type\n", - "\texpected:\t", expectedFieldType, "\n\tbut have:\t", field.Type, - ) + panic( + context + "'s field for error " + name + "Error has the wrong type\n" + + "\texpected:\t" + expectedFieldType.String() + "\n\tbut have:\t" + field.Type.String()) } structFields := reflect.ValueOf(implementer).Elem() @@ -756,7 +751,7 @@ func (p *Precompile) Call( reflectArgs = append(reflectArgs, reflect.ValueOf(evm)) reflectArgs = append(reflectArgs, reflect.ValueOf(value)) default: - log.Crit("Unknown state mutability ", method.purity) + panic("Unknown state mutability " + string(method.purity)) } args, err := method.template.Inputs.Unpack(input[4:]) diff --git a/precompiles/precompile_test.go b/precompiles/precompile_test.go index 75fed711eb..183ec1f083 100644 --- a/precompiles/precompile_test.go +++ b/precompiles/precompile_test.go @@ -5,15 +5,12 @@ package precompiles import ( "fmt" - "io" "math/big" - "os" "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/offchainlabs/nitro/arbos/storage" @@ -183,12 +180,6 @@ func TestEventCosts(t *testing.T) { } func TestPrecompilesPerArbosVersion(t *testing.T) { - // Set up a logger in case log.Crit is called by Precompiles() - glogger := log.NewGlogHandler( - log.NewTerminalHandler(io.Writer(os.Stderr), false)) - glogger.Verbosity(log.LevelWarn) - log.SetDefault(log.NewLogger(glogger)) - expectedNewMethodsPerArbosVersion := map[uint64]int{ 0: 89, params.ArbosVersion_5: 3, diff --git a/system_tests/staker_test.go b/system_tests/staker_test.go index 69645d8878..55c13d664d 100644 --- a/system_tests/staker_test.go +++ b/system_tests/staker_test.go @@ -504,7 +504,7 @@ func TestGetValidatorWalletContractWithDataposterOnlyUsedToCreateValidatorWallet parentChainID, ) if err != nil { - log.Crit("error creating data poster to create validator wallet contract", "err", err) + Fatal(t, "error creating data poster to create validator wallet contract", "err", err) } getExtraGas := func() uint64 { return builder.nodeConfig.Staker.ExtraGas } From 468d6892432b23af5a77db119ab510f1541d52f4 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Thu, 2 Jan 2025 18:58:56 -0700 Subject: [PATCH 34/67] fix int to string conversions --- arbos/programs/api.go | 6 ++++-- arbos/programs/native_api.go | 5 +++-- precompiles/precompile.go | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arbos/programs/api.go b/arbos/programs/api.go index cd2143f5d0..a622f55397 100644 --- a/arbos/programs/api.go +++ b/arbos/programs/api.go @@ -4,6 +4,8 @@ package programs import ( + "strconv" + "github.com/holiman/uint256" "github.com/ethereum/go-ethereum/common" @@ -265,7 +267,7 @@ func newApiClosures( original := input crash := func(reason string) { - panic("bad API call reason: " + reason + " request: " + string(req) + " len: " + string(len(original)) + " remaining: " + string(len(input))) + panic("bad API call reason: " + reason + " request: " + strconv.Itoa(int(req)) + " len: " + strconv.Itoa(len(original)) + " remaining: " + strconv.Itoa(len(input))) } takeInput := func(needed int, reason string) []byte { if len(input) < needed { @@ -413,7 +415,7 @@ func newApiClosures( captureHostio(name, args, outs, startInk, endInk) return []byte{}, nil, 0 default: - panic("unsupported call type: " + string(req)) + panic("unsupported call type: " + strconv.Itoa(int(req))) } } } diff --git a/arbos/programs/native_api.go b/arbos/programs/native_api.go index bf9cda658d..ad8cc0477b 100644 --- a/arbos/programs/native_api.go +++ b/arbos/programs/native_api.go @@ -25,6 +25,7 @@ import "C" import ( "runtime" + "strconv" "sync" "sync/atomic" @@ -68,11 +69,11 @@ func newApi( func getApi(id usize) NativeApi { any, ok := apiObjects.Load(uintptr(id)) if !ok { - panic("failed to load stylus Go API id: " + string(id)) + panic("failed to load stylus Go API id: " + strconv.Itoa(int(id))) } api, ok := any.(NativeApi) if !ok { - panic("wrong type for stylus Go API id: " + string(id)) + panic("wrong type for stylus Go API id: " + strconv.Itoa(int(id))) } return api } diff --git a/precompiles/precompile.go b/precompiles/precompile.go index f34c418313..7ca9d409c6 100644 --- a/precompiles/precompile.go +++ b/precompiles/precompile.go @@ -751,7 +751,7 @@ func (p *Precompile) Call( reflectArgs = append(reflectArgs, reflect.ValueOf(evm)) reflectArgs = append(reflectArgs, reflect.ValueOf(value)) default: - panic("Unknown state mutability " + string(method.purity)) + panic("Unknown state mutability " + strconv.Itoa(int(method.purity))) } args, err := method.template.Inputs.Unpack(input[4:]) From 89516a0075cb11a17b48b5ab2d9829062ffcb32a Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Thu, 2 Jan 2025 19:32:49 -0700 Subject: [PATCH 35/67] remove dead code --- arbos/programs/programs.go | 1 - 1 file changed, 1 deletion(-) diff --git a/arbos/programs/programs.go b/arbos/programs/programs.go index 6b2a0c318b..4c81de1308 100644 --- a/arbos/programs/programs.go +++ b/arbos/programs/programs.go @@ -220,7 +220,6 @@ func (p Programs) CallProgram( localAsm, err := getLocalAsm(statedb, moduleHash, contract.Address(), contract.Code, contract.CodeHash, params.PageLimit, evm.Context.Time, debugMode, program) if err != nil { panic("failed to get local wasm for activated program: " + contract.Address().Hex()) - return nil, err } evmData := &EvmData{ From 7200ff5f706693e026e3c70dcee73f640cb718b5 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Fri, 3 Jan 2025 18:05:45 +0530 Subject: [PATCH 36/67] Changes based on PR comments --- arbnode/message_pruner.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/arbnode/message_pruner.go b/arbnode/message_pruner.go index b18796a4c5..dedc579a01 100644 --- a/arbnode/message_pruner.go +++ b/arbnode/message_pruner.go @@ -126,8 +126,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun if m.cachedPrunedDelayedMessages == 0 { m.cachedPrunedDelayedMessages = fetchLastPrunedKey(m.inboxTracker.db, lastPrunedDelayedMessageKey) } - lastPrunedMessage := m.cachedPrunedMessages - prunedKeysRange, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, &lastPrunedMessage, uint64(messageCount)) + prunedKeysRange, _, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messageResultPrefix, m.cachedPrunedMessages, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting message results: %w", err) } @@ -135,8 +134,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned message results:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - lastPrunedMessage = m.cachedPrunedMessages - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, &lastPrunedMessage, uint64(messageCount)) + prunedKeysRange, _, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, blockHashInputFeedPrefix, m.cachedPrunedMessages, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting expected block hashes: %w", err) } @@ -144,8 +142,7 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun log.Info("Pruned expected block hashes:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - lastPrunedMessage = m.cachedPrunedMessages - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, &lastPrunedMessage, uint64(messageCount)) + prunedKeysRange, lastPrunedMessage, err := deleteFromLastPrunedUptoEndKey(ctx, m.transactionStreamer.db, messagePrefix, m.cachedPrunedMessages, uint64(messageCount)) if err != nil { return fmt.Errorf("error deleting last batch messages: %w", err) } @@ -155,40 +152,34 @@ func (m *MessagePruner) deleteOldMessagesFromDB(ctx context.Context, messageCoun insertLastPrunedKey(m.transactionStreamer.db, lastPrunedMessageKey, lastPrunedMessage) m.cachedPrunedMessages = lastPrunedMessage - lastPrunedDelayedMessage := m.cachedPrunedDelayedMessages - prunedKeysRange, err = deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, &lastPrunedDelayedMessage, delayedMessageCount) + prunedKeysRange, lastPrunedDelayedMessage, err := deleteFromLastPrunedUptoEndKey(ctx, m.inboxTracker.db, rlpDelayedMessagePrefix, m.cachedPrunedDelayedMessages, delayedMessageCount) if err != nil { return fmt.Errorf("error deleting last batch delayed messages: %w", err) } if len(prunedKeysRange) > 0 { log.Info("Pruned last batch delayed messages:", "first pruned key", prunedKeysRange[0], "last pruned key", prunedKeysRange[len(prunedKeysRange)-1]) } - insertLastPrunedKey(m.inboxTracker.db, lastPrunedDelayedMessageKey, lastPrunedMessage) + insertLastPrunedKey(m.inboxTracker.db, lastPrunedDelayedMessageKey, lastPrunedDelayedMessage) m.cachedPrunedDelayedMessages = lastPrunedDelayedMessage return nil } -// deleteFromLastPrunedUptoEndKey is similar to deleteFromRange but automatically populates the start key -// cachedStartMinKey must not be nil. It's set to the new start key at the end of this function if successful. -func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, cachedStartMinKey *uint64, endMinKey uint64) ([]uint64, error) { - startMinKey := *cachedStartMinKey +// deleteFromLastPrunedUptoEndKey is similar to deleteFromRange but automatically populates the start key if it's not set. +// It's returns the new start key (i.e. last pruned key) at the end of this function if successful. +func deleteFromLastPrunedUptoEndKey(ctx context.Context, db ethdb.Database, prefix []byte, startMinKey uint64, endMinKey uint64) ([]uint64, uint64, error) { if startMinKey == 0 { startIter := db.NewIterator(prefix, uint64ToKey(1)) if !startIter.Next() { - return nil, nil + return nil, 0, nil } startMinKey = binary.BigEndian.Uint64(bytes.TrimPrefix(startIter.Key(), prefix)) startIter.Release() } if endMinKey <= startMinKey { - *cachedStartMinKey = startMinKey - return nil, nil + return nil, startMinKey, nil } keys, err := deleteFromRange(ctx, db, prefix, startMinKey, endMinKey-1) - if err == nil { - *cachedStartMinKey = endMinKey - 1 - } - return keys, err + return keys, endMinKey - 1, err } func insertLastPrunedKey(db ethdb.Database, lastPrunedKey []byte, lastPrunedValue uint64) { From 830a9245293f296cf9bcd16286abeb4c31dd5279 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 3 Jan 2025 10:00:08 -0600 Subject: [PATCH 37/67] update bold pin to latest commit on main --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 81f1b421b2..cb6922fb4f 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 81f1b421b2dbbf96c7a2b427a9458667b07b0b27 +Subproject commit cb6922fb4f50d1cdb12af467a18ecee6f1c688a4 From f9fa7827f2e8683f6aa43f93d63a96dc3b1f10fc Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 3 Jan 2025 20:22:58 -0600 Subject: [PATCH 38/67] update bold pin --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index eae8d51fcf..70c9755ae1 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit eae8d51fcf02002d3216a0b15f23b66f819f792d +Subproject commit 70c9755ae1b731f1b2fdedb986461754e4da2e8f From 1fb803dafe79e59be09e31f75371c2041cc80411 Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Tue, 7 Jan 2025 09:36:34 -0700 Subject: [PATCH 39/67] Update geth in for flatcalltracer fix Pulls in the following go-ethereum PRs https://github.com/OffchainLabs/go-ethereum/pull/372 https://github.com/OffchainLabs/go-ethereum/pull/385 https://github.com/OffchainLabs/go-ethereum/pull/393 --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index 26b4dff616..dd32b782ed 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit 26b4dff6165650b6963fb1b6f88958c29c059214 +Subproject commit dd32b782ed255c1ac20ed5beee11dd6a821f9be2 From 55c41f58fab13878c75f3a1ffad8245926360305 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 7 Jan 2025 14:09:57 -0600 Subject: [PATCH 40/67] bold submod to main --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index 70c9755ae1..a537dac0c5 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit 70c9755ae1b731f1b2fdedb986461754e4da2e8f +Subproject commit a537dac0c5fc95a07afe54dad4d7691121a4f484 From 7acdd8fa8dcb11d54b63746416ab5c0e1dce6d8c Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 18:07:44 -0700 Subject: [PATCH 41/67] update nightly version and fix wasm --- .github/workflows/arbitrator-ci.yml | 2 +- .github/workflows/ci.yml | 2 +- Makefile | 26 ++++++++++++++++++++++ arbitrator/stylus/tests/.cargo/config.toml | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index dd58a30571..d9c4618e8b 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -76,7 +76,7 @@ jobs: uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly with: - toolchain: 'nightly-2024-08-06' + toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt, clippy' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1eda1d9b7e..e9e184f786 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly with: - toolchain: 'nightly-2024-08-06' + toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt, clippy' diff --git a/Makefile b/Makefile index 12dfb07cf8..39b221dcee 100644 --- a/Makefile +++ b/Makefile @@ -440,54 +440,80 @@ $(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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 $@ @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 diff --git a/arbitrator/stylus/tests/.cargo/config.toml b/arbitrator/stylus/tests/.cargo/config.toml index 702a5c04b3..6ca5e18651 100644 --- a/arbitrator/stylus/tests/.cargo/config.toml +++ b/arbitrator/stylus/tests/.cargo/config.toml @@ -5,6 +5,7 @@ target = "wasm32-unknown-unknown" rustflags = [ "-C", "target-cpu=mvp", "-C", "link-arg=-zstack-size=8192", + "-C", "target-feature=-reference-types", # "-C", "link-arg=--export=__heap_base", # "-C", "link-arg=--export=__data_end", ] From 25ea73540716bf602e90bdb0587f35162dcf2531 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 18:35:22 -0700 Subject: [PATCH 42/67] fix rust stable to 1.80.1 --- .github/workflows/arbitrator-ci.yml | 2 +- .github/workflows/ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index d9c4618e8b..b765acee99 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -69,7 +69,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable with: - toolchain: 'stable' + toolchain: '1.80.1' components: 'llvm-tools-preview, rustfmt, clippy' - name: Install rust nightly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9e184f786..b943b34686 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable with: - toolchain: 'stable' + toolchain: '1.80.1' targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' From 6a66ea4db34886e13f1a317b97737b70f3bf3908 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 19:44:52 -0700 Subject: [PATCH 43/67] ci: only use stable clippy --- .github/workflows/arbitrator-ci.yml | 3 ++- .github/workflows/ci.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index b765acee99..3ef8d336ff 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -67,6 +67,7 @@ jobs: cache-dependency-path: '**/yarn.lock' - name: Install rust stable + id: install-rust uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' @@ -78,7 +79,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt, clippy' + components: 'rust-src, rustfmt' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b943b34686..006c01a378 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,7 @@ jobs: - name: Install rust stable uses: dtolnay/rust-toolchain@stable + id: install-rust with: toolchain: '1.80.1' targets: 'wasm32-wasi, wasm32-unknown-unknown' @@ -66,7 +67,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt, clippy' + components: 'rust-src, rustfmt' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From fb03fe67e1bec2fe9959915448e484add6d8d61f Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 19:31:06 -0700 Subject: [PATCH 44/67] clippy fixes: initial --- arbitrator/arbutil/src/operator.rs | 4 ++-- arbitrator/jit/src/caller_env.rs | 2 +- arbitrator/prover/src/binary.rs | 2 +- arbitrator/prover/src/programs/counter.rs | 2 +- arbitrator/prover/src/programs/depth.rs | 4 ++-- arbitrator/prover/src/programs/meter.rs | 2 +- arbitrator/prover/src/programs/mod.rs | 6 +++--- arbitrator/stylus/src/env.rs | 10 +++++----- arbitrator/stylus/src/host.rs | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arbitrator/arbutil/src/operator.rs b/arbitrator/arbutil/src/operator.rs index cc1f684366..9abf237a66 100644 --- a/arbitrator/arbutil/src/operator.rs +++ b/arbitrator/arbutil/src/operator.rs @@ -595,13 +595,13 @@ impl Display for OperatorCode { } } -impl<'a> From> for OperatorCode { +impl From> for OperatorCode { fn from(op: Operator) -> Self { OperatorCode::from(&op) } } -impl<'a> From<&Operator<'a>> for OperatorCode { +impl From<&Operator<'_>> for OperatorCode { fn from(op: &Operator) -> Self { use Operator as O; diff --git a/arbitrator/jit/src/caller_env.rs b/arbitrator/jit/src/caller_env.rs index 41240d3d98..9fe4288d21 100644 --- a/arbitrator/jit/src/caller_env.rs +++ b/arbitrator/jit/src/caller_env.rs @@ -34,7 +34,7 @@ impl<'a> JitEnv<'a> for WasmEnvMut<'a> { } } -impl<'s> JitMemAccess<'s> { +impl JitMemAccess<'_> { fn view(&self) -> MemoryView { self.memory.view(&self.store) } diff --git a/arbitrator/prover/src/binary.rs b/arbitrator/prover/src/binary.rs index 2260f6bf48..77bc44ec4c 100644 --- a/arbitrator/prover/src/binary.rs +++ b/arbitrator/prover/src/binary.rs @@ -499,7 +499,7 @@ pub fn parse<'a>(input: &'a [u8], path: &'_ Path) -> Result> { Ok(binary) } -impl<'a> Debug for WasmBinary<'a> { +impl Debug for WasmBinary<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("WasmBinary") .field("types", &self.types) diff --git a/arbitrator/prover/src/programs/counter.rs b/arbitrator/prover/src/programs/counter.rs index cd54178cf8..4006e70ee6 100644 --- a/arbitrator/prover/src/programs/counter.rs +++ b/arbitrator/prover/src/programs/counter.rs @@ -75,7 +75,7 @@ pub struct FuncCounter<'a> { block: Vec>, } -impl<'a> FuncCounter<'a> { +impl FuncCounter<'_> { fn new(counters: Arc>>) -> Self { let block = vec![]; Self { counters, block } diff --git a/arbitrator/prover/src/programs/depth.rs b/arbitrator/prover/src/programs/depth.rs index 2000190917..fb0e0cb6d2 100644 --- a/arbitrator/prover/src/programs/depth.rs +++ b/arbitrator/prover/src/programs/depth.rs @@ -107,7 +107,7 @@ pub struct FuncDepthChecker<'a> { done: bool, } -impl<'a> FuncDepthChecker<'a> { +impl FuncDepthChecker<'_> { fn new( global: GlobalIndex, funcs: Arc>, @@ -227,7 +227,7 @@ impl<'a> FuncMiddleware<'a> for FuncDepthChecker<'a> { } } -impl<'a> FuncDepthChecker<'a> { +impl FuncDepthChecker<'_> { fn worst_case_depth(&self) -> Result { use Operator::*; diff --git a/arbitrator/prover/src/programs/meter.rs b/arbitrator/prover/src/programs/meter.rs index 0d7b3151d7..258c932944 100644 --- a/arbitrator/prover/src/programs/meter.rs +++ b/arbitrator/prover/src/programs/meter.rs @@ -122,7 +122,7 @@ pub struct FuncMeter<'a, F: OpcodePricer> { sigs: Arc, } -impl<'a, F: OpcodePricer> FuncMeter<'a, F> { +impl FuncMeter<'_, F> { fn new( ink_global: GlobalIndex, status_global: GlobalIndex, diff --git a/arbitrator/prover/src/programs/mod.rs b/arbitrator/prover/src/programs/mod.rs index a35308e7ff..517ccc1971 100644 --- a/arbitrator/prover/src/programs/mod.rs +++ b/arbitrator/prover/src/programs/mod.rs @@ -244,7 +244,7 @@ impl ModuleMod for ModuleInfo { fn drop_exports_and_names(&mut self, keep: &HashMap<&str, ExportKind>) { self.exports.retain(|name, export| { keep.get(name.as_str()) - .map_or(false, |x| *x == (*export).into()) + .is_some_and(|x| *x == (*export).into()) }); self.function_names.clear(); } @@ -263,7 +263,7 @@ impl ModuleMod for ModuleInfo { } } -impl<'a> ModuleMod for WasmBinary<'a> { +impl ModuleMod for WasmBinary<'_> { fn add_global(&mut self, name: &str, _ty: Type, init: GlobalInit) -> Result { let global = match init { GlobalInit::I32Const(x) => Value::I32(x as u32), @@ -364,7 +364,7 @@ impl<'a> ModuleMod for WasmBinary<'a> { fn drop_exports_and_names(&mut self, keep: &HashMap<&str, ExportKind>) { self.exports - .retain(|name, ty| keep.get(name.as_str()).map_or(false, |x| *x == ty.1)); + .retain(|name, ty| keep.get(name.as_str()).is_some_and(|x| *x == ty.1)); self.names.functions.clear(); } diff --git a/arbitrator/stylus/src/env.rs b/arbitrator/stylus/src/env.rs index a2c8189029..ef12d2480a 100644 --- a/arbitrator/stylus/src/env.rs +++ b/arbitrator/stylus/src/env.rs @@ -147,7 +147,7 @@ pub struct HostioInfo<'a, D: DataReader, E: EvmApi> { pub start_ink: Ink, } -impl<'a, D: DataReader, E: EvmApi> HostioInfo<'a, D, E> { +impl> HostioInfo<'_, D, E> { pub fn config(&self) -> StylusConfig { self.config.expect("no config") } @@ -172,7 +172,7 @@ impl<'a, D: DataReader, E: EvmApi> HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> MeteredMachine for HostioInfo<'a, D, E> { +impl> MeteredMachine for HostioInfo<'_, D, E> { fn ink_left(&self) -> MachineMeter { let vm = self.env.meter(); match vm.status() { @@ -188,13 +188,13 @@ impl<'a, D: DataReader, E: EvmApi> MeteredMachine for HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> GasMeteredMachine for HostioInfo<'a, D, E> { +impl> GasMeteredMachine for HostioInfo<'_, D, E> { fn pricing(&self) -> PricingParams { self.config().pricing } } -impl<'a, D: DataReader, E: EvmApi> Deref for HostioInfo<'a, D, E> { +impl> Deref for HostioInfo<'_, D, E> { type Target = WasmEnv; fn deref(&self) -> &Self::Target { @@ -202,7 +202,7 @@ impl<'a, D: DataReader, E: EvmApi> Deref for HostioInfo<'a, D, E> { } } -impl<'a, D: DataReader, E: EvmApi> DerefMut for HostioInfo<'a, D, E> { +impl> DerefMut for HostioInfo<'_, D, E> { fn deref_mut(&mut self) -> &mut Self::Target { self.env } diff --git a/arbitrator/stylus/src/host.rs b/arbitrator/stylus/src/host.rs index 67497302a1..c4fc7cea1e 100644 --- a/arbitrator/stylus/src/host.rs +++ b/arbitrator/stylus/src/host.rs @@ -22,7 +22,7 @@ use std::{ use user_host_trait::UserHost; use wasmer::{MemoryAccessError, WasmPtr}; -impl<'a, DR, A> UserHost for HostioInfo<'a, DR, A> +impl UserHost for HostioInfo<'_, DR, A> where DR: DataReader, A: EvmApi, From 00cb2f9b5ab025e13dd156c6cda346149aa10985 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 20:30:29 -0700 Subject: [PATCH 45/67] circumvent lifetime errors from clippy --- arbitrator/prover/src/programs/meter.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/arbitrator/prover/src/programs/meter.rs b/arbitrator/prover/src/programs/meter.rs index 258c932944..cfb91e647d 100644 --- a/arbitrator/prover/src/programs/meter.rs +++ b/arbitrator/prover/src/programs/meter.rs @@ -1,5 +1,6 @@ // Copyright 2022-2023, Offchain Labs, Inc. // For license information, see https://github.com/nitro/blob/master/LICENSE +#![allow(clippy::needless_lifetimes)] use crate::{ programs::{ From 82274225c91ce0a294485cac8c5472dc468768f1 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 20:54:53 -0700 Subject: [PATCH 46/67] ci: add nightly clippy back --- .github/workflows/arbitrator-ci.yml | 16 ++++++++-------- .github/workflows/ci.yml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 3ef8d336ff..45cf3c1a3d 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -66,20 +66,20 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' - - name: Install rust stable - id: install-rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: '1.80.1' - 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' - components: 'rust-src, rustfmt' + components: 'rust-src, rustfmt, clippy' + + - name: Install rust stable + id: install-rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: '1.80.1' + components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 006c01a378..b4ce5bf27f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: with: toolchain: 'nightly-2024-10-06' targets: 'wasm32-wasi, wasm32-unknown-unknown' - components: 'rust-src, rustfmt' + components: 'rust-src, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From 12c76eac50b8b30d90874452f449128a91897067 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Tue, 7 Jan 2025 21:10:09 -0700 Subject: [PATCH 47/67] arbitrator ci: stable after nightly --- .github/workflows/arbitrator-ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 3ef8d336ff..0552fc4a3a 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -66,13 +66,6 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' - - name: Install rust stable - id: install-rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: '1.80.1' - components: 'llvm-tools-preview, rustfmt, clippy' - - name: Install rust nightly uses: dtolnay/rust-toolchain@nightly id: install-rust-nightly @@ -81,6 +74,13 @@ jobs: targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'rust-src, rustfmt' + - name: Install rust stable + id: install-rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: '1.80.1' + components: 'llvm-tools-preview, rustfmt, clippy' + - name: Set STYLUS_NIGHTLY_VER environment variable run: echo "STYLUS_NIGHTLY_VER=+$(rustup toolchain list | grep '^nightly' | head -n1 | cut -d' ' -f1)" >> "$GITHUB_ENV" From ffa2f67140f44223eab539524d9019983ed32c07 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Wed, 8 Jan 2025 13:38:54 +0100 Subject: [PATCH 48/67] Add the wasm targets to the stable rust installation Without these targets the build was complaining about the missing `core` crate and suggested installing them. --- .github/workflows/arbitrator-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 45cf3c1a3d..51c0617f3e 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -79,6 +79,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' + targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable From 79b3af04cbe77ea8f071658968e04278c9757d93 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 8 Jan 2025 10:07:23 -0600 Subject: [PATCH 49/67] update main --- bold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bold b/bold index a537dac0c5..290743f517 160000 --- a/bold +++ b/bold @@ -1 +1 @@ -Subproject commit a537dac0c5fc95a07afe54dad4d7691121a4f484 +Subproject commit 290743f517f7a94d62460231399fb095cb18c3a4 From 6102825e2aeb59769e496587f2dac5c6c2d35048 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 15:10:46 +0100 Subject: [PATCH 50/67] don't required waxm module recompilation when getting local asm --- arbos/programs/native.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 8eb2aacda1..3ca3003175 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -272,14 +272,14 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c targets := statedb.Database().WasmTargets() // we know program is activated, so it must be in correct version and not use too much memory - moduleActivationMandatory := true // TODO: refactor the parameter, always set to true + moduleActivationMandatory := false info, asmMap, err := activateProgramInternal(addressForLogging, codehash, wasm, pagelimit, program.version, zeroArbosVersion, debugMode, &zeroGas, targets, moduleActivationMandatory) if err != nil { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "err", err) return nil, fmt.Errorf("failed to reactivate program address: %v err: %w", addressForLogging, err) } - if info.moduleHash != moduleHash { + if info != nil && info.moduleHash != moduleHash { log.Error("failed to reactivate program", "address", addressForLogging, "expected moduleHash", moduleHash, "got", info.moduleHash) return nil, fmt.Errorf("failed to reactivate program. address: %v, expected ModuleHash: %v", addressForLogging, moduleHash) } @@ -296,7 +296,7 @@ func getLocalAsm(statedb vm.StateDB, moduleHash common.Hash, addressForLogging c } else { // program activated recently, possibly in this eth_call // store it to statedb. It will be stored to database if statedb is commited - statedb.ActivateWasm(info.moduleHash, asmMap) + statedb.ActivateWasm(moduleHash, asmMap) } asm, exists := asmMap[localTarget] if !exists { From 2275b42ff710e94d0150aef71dc19553a5c84b1b Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:23:17 +0100 Subject: [PATCH 51/67] refactor activateProgramInternal --- arbos/programs/native.go | 76 +++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 3ca3003175..9d34504888 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -164,10 +164,12 @@ func activateProgramInternal( moduleActivationMandatory bool, ) (*activationInfo, map[ethdb.WasmTarget][]byte, error) { var wavmFound bool + var nativeTargets []ethdb.WasmTarget for _, target := range targets { if target == rawdb.TargetWavm { wavmFound = true - break + } else { + nativeTargets = append(nativeTargets, target) } } type result struct { @@ -175,59 +177,53 @@ func activateProgramInternal( asm []byte err error } - asmMap := make(map[ethdb.WasmTarget][]byte, len(targets)) - - // info can be set in separate thread, make sure to wait before reading + results := make(chan result) + // info will be set in separate thread, make sure to wait before reading var info *activationInfo - var moduleActivationStarted bool + asmMap := make(map[ethdb.WasmTarget][]byte, len(nativeTargets)+1) + if moduleActivationMandatory || wavmFound { + go func() { + var err error + var module []byte + info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) + results <- result{rawdb.TargetWavm, module, err} + }() + } if moduleActivationMandatory { - moduleActivationStarted = true - var err error - var module []byte - info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) - if err != nil { - return nil, nil, err - } - if wavmFound { - asmMap[rawdb.TargetWavm] = module + // wait for the module activation before starting compilation for other targets + res := <-results + if res.err != nil { + return info, nil, res.err + } else if wavmFound { + asmMap[res.target] = res.asm } } - results := make(chan result, len(targets)) - for _, target := range targets { + for _, target := range nativeTargets { target := target - if target == rawdb.TargetWavm { - if moduleActivationStarted { - // skip if already started or activated because of moduleActivationMandatory - results <- result{target, nil, nil} - continue - } - go func() { - var err error - var module []byte - info, module, err = activateModule(addressForLogging, codehash, wasm, page_limit, stylusVersion, arbosVersionForGas, debug, gasLeft) - results <- result{target, module, err} - }() - moduleActivationStarted = true - } else { - go func() { - asm, err := compileNative(wasm, stylusVersion, debug, target) - results <- result{target, asm, err} - }() - } + go func() { + asm, err := compileNative(wasm, stylusVersion, debug, target) + results <- result{target, asm, err} + }() } + + expectedResults := len(nativeTargets) + if !moduleActivationMandatory && wavmFound { + // we didn't wait for module activation result, so wait for it too + expectedResults++ + } + var err error - for range targets { + for i := 0; i < expectedResults; i++ { res := <-results - if res.asm == nil { - continue - } else if res.err != nil { + if res.err != nil { err = errors.Join(res.err, fmt.Errorf("%s:%w", res.target, err)) } else { asmMap[res.target] = res.asm } } - if err != nil && moduleActivationMandatory { + + if err != nil && (moduleActivationMandatory || len(asmMap[rawdb.TargetWavm]) > 0) { if info != nil { log.Error( "Compilation failed for one or more targets despite activation succeeding", From 83f572e632cc732419311d9fe512887291f43c12 Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:37:48 +0100 Subject: [PATCH 52/67] simplify panic condition when moduleActivationMandatory and some native compilation fails --- arbos/programs/native.go | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 9d34504888..1abbd91158 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -198,7 +198,6 @@ func activateProgramInternal( asmMap[res.target] = res.asm } } - for _, target := range nativeTargets { target := target go func() { @@ -206,13 +205,11 @@ func activateProgramInternal( results <- result{target, asm, err} }() } - expectedResults := len(nativeTargets) if !moduleActivationMandatory && wavmFound { // we didn't wait for module activation result, so wait for it too expectedResults++ } - var err error for i := 0; i < expectedResults; i++ { res := <-results @@ -222,29 +219,17 @@ func activateProgramInternal( asmMap[res.target] = res.asm } } - - if err != nil && (moduleActivationMandatory || len(asmMap[rawdb.TargetWavm]) > 0) { - if info != nil { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codehash", codehash, - "moduleHash", info.moduleHash, - "targets", targets, - "err", err, - ) - } else { - log.Error( - "Compilation failed for one or more targets despite activation succeeding", - "address", addressForLogging, - "codehash", codehash, - "targets", targets, - "err", err, - ) - } + if err != nil && moduleActivationMandatory { + log.Error( + "Compilation failed for one or more targets despite activation succeeding", + "address", addressForLogging, + "codehash", codehash, + "moduleHash", info.moduleHash, + "targets", targets, + "err", err, + ) panic(fmt.Sprintf("Compilation of %v failed for one or more targets despite activation succeeding: %v", addressForLogging, err)) } - return info, asmMap, err } From 6be86bf4eb1ae4a0a391104daf4274877d93441e Mon Sep 17 00:00:00 2001 From: Maciej Kulawik Date: Thu, 9 Jan 2025 16:54:10 +0100 Subject: [PATCH 53/67] return nil activationInfo in case of error --- arbos/programs/native.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbos/programs/native.go b/arbos/programs/native.go index 1abbd91158..5995d9dafe 100644 --- a/arbos/programs/native.go +++ b/arbos/programs/native.go @@ -193,7 +193,7 @@ func activateProgramInternal( // wait for the module activation before starting compilation for other targets res := <-results if res.err != nil { - return info, nil, res.err + return nil, nil, res.err } else if wavmFound { asmMap[res.target] = res.asm } From 79422c9640570cb3408b9ee1ba24577e3cb4e942 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 11:23:56 -0600 Subject: [PATCH 54/67] Create a metric for local block execution time --- execution/gethexec/executionengine.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index ffc6ceee9f..b4f91a1605 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -56,6 +56,7 @@ var ( txCountHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/count", nil, metrics.NewBoundedHistogramSample()) txGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/gasused", nil, metrics.NewBoundedHistogramSample()) gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/gas_used", nil) + blockExecutionTimer = metrics.NewRegisteredTimer("arb/block/execution", nil) ) type L1PriceDataOfMsg struct { @@ -522,10 +523,11 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. false, core.MessageCommitMode, ) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - blockCalcTime := time.Since(startTime) if len(hooks.TxErrors) != len(txes) { return nil, fmt.Errorf("unexpected number of error results: %v vs number of txes %v", len(hooks.TxErrors), len(txes)) } @@ -611,10 +613,11 @@ func (s *ExecutionEngine) sequenceDelayedMessageWithBlockMutex(message *arbostyp startTime := time.Now() block, statedb, receipts, err := s.createBlockFromNextMessage(&messageWithMeta, false) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - blockCalcTime := time.Since(startTime) msgResult, err := s.resultFromHeader(block.Header()) if err != nil { @@ -875,11 +878,13 @@ func (s *ExecutionEngine) digestMessageWithBlockMutex(num arbutil.MessageIndex, } block, statedb, receipts, err := s.createBlockFromNextMessage(msg, false) + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } - err = s.appendBlock(block, statedb, receipts, time.Since(startTime)) + err = s.appendBlock(block, statedb, receipts, blockCalcTime) if err != nil { return nil, err } From e3385d0eaa5aa8883a1b55786ec898592e7f2db2 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 14:49:03 -0600 Subject: [PATCH 55/67] address PR comments --- execution/gethexec/executionengine.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index b4f91a1605..2475c816d4 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -57,6 +57,7 @@ var ( txGasUsedHistogram = metrics.NewRegisteredHistogram("arb/block/transactions/gasused", nil, metrics.NewBoundedHistogramSample()) gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/gas_used", nil) blockExecutionTimer = metrics.NewRegisteredTimer("arb/block/execution", nil) + blockWriteToDbTimer = metrics.NewRegisteredTimer("arb/block/writetodb", nil) ) type L1PriceDataOfMsg struct { @@ -523,11 +524,11 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. false, core.MessageCommitMode, ) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) if len(hooks.TxErrors) != len(txes) { return nil, fmt.Errorf("unexpected number of error results: %v vs number of txes %v", len(hooks.TxErrors), len(txes)) } @@ -613,11 +614,11 @@ func (s *ExecutionEngine) sequenceDelayedMessageWithBlockMutex(message *arbostyp startTime := time.Now() block, statedb, receipts, err := s.createBlockFromNextMessage(&messageWithMeta, false) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) msgResult, err := s.resultFromHeader(block.Header()) if err != nil { @@ -704,6 +705,7 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB for _, receipt := range receipts { logs = append(logs, receipt.Logs...) } + startTime := time.Now() status, err := s.bc.WriteBlockAndSetHeadWithTime(block, receipts, logs, statedb, true, duration) if err != nil { return err @@ -711,6 +713,8 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB if status == core.SideStatTy { return errors.New("geth rejected block as non-canonical") } + blockCalcTime := time.Since(startTime) + blockWriteToDbTimer.Update(blockCalcTime) baseFeeGauge.Update(block.BaseFee().Int64()) txCountHistogram.Update(int64(len(block.Transactions()) - 1)) var blockGasused uint64 @@ -878,11 +882,11 @@ func (s *ExecutionEngine) digestMessageWithBlockMutex(num arbutil.MessageIndex, } block, statedb, receipts, err := s.createBlockFromNextMessage(msg, false) - blockCalcTime := time.Since(startTime) - blockExecutionTimer.Update(blockCalcTime) if err != nil { return nil, err } + blockCalcTime := time.Since(startTime) + blockExecutionTimer.Update(blockCalcTime) err = s.appendBlock(block, statedb, receipts, blockCalcTime) if err != nil { From 7bab83a5af5b9e67b324580de287336addb7b7de Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Fri, 10 Jan 2025 15:51:22 -0700 Subject: [PATCH 56/67] fix arbitrator-ci --- .github/workflows/arbitrator-ci.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 0355ebb722..45cf3c1a3d 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -74,14 +74,6 @@ jobs: targets: 'wasm32-wasi, 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' - components: 'llvm-tools-preview, rustfmt, clippy' - - name: Install rust stable id: install-rust uses: dtolnay/rust-toolchain@stable From fe7ee6e9146054713b89ed5b4408cdc55478a5f6 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Fri, 10 Jan 2025 16:57:18 -0600 Subject: [PATCH 57/67] fix typo --- execution/gethexec/executionengine.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 2475c816d4..7cf83c7183 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -713,8 +713,7 @@ func (s *ExecutionEngine) appendBlock(block *types.Block, statedb *state.StateDB if status == core.SideStatTy { return errors.New("geth rejected block as non-canonical") } - blockCalcTime := time.Since(startTime) - blockWriteToDbTimer.Update(blockCalcTime) + blockWriteToDbTimer.Update(time.Since(startTime)) baseFeeGauge.Update(block.BaseFee().Int64()) txCountHistogram.Update(int64(len(block.Transactions()) - 1)) var blockGasused uint64 From 18478e0c43a15c582cc63249c10a384cab299937 Mon Sep 17 00:00:00 2001 From: Tsahi Zidenberg Date: Fri, 10 Jan 2025 16:08:31 -0700 Subject: [PATCH 58/67] add targets to arbitrator --- .github/workflows/arbitrator-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/arbitrator-ci.yml b/.github/workflows/arbitrator-ci.yml index 45cf3c1a3d..51c0617f3e 100644 --- a/.github/workflows/arbitrator-ci.yml +++ b/.github/workflows/arbitrator-ci.yml @@ -79,6 +79,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: '1.80.1' + targets: 'wasm32-wasi, wasm32-unknown-unknown' components: 'llvm-tools-preview, rustfmt, clippy' - name: Set STYLUS_NIGHTLY_VER environment variable From f3139eaa1ed6b605aea38a4aa844e38ddd8976ae Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Sat, 11 Jan 2025 20:37:16 -0700 Subject: [PATCH 59/67] Fix `--execution.rpc.gas-cap=0` to again mean infinite gas There was a regression introduced in v3.3.0 where specifying `--execution.rpc.gas-cap=0` would cause gas related errors. --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index dd32b782ed..aaded574dc 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit dd32b782ed255c1ac20ed5beee11dd6a821f9be2 +Subproject commit aaded574dcf7b2f6b5851ee858603cb61335217e From 26b4c1028fdc8475c349510dbe392d99e27dc082 Mon Sep 17 00:00:00 2001 From: dashangcun <907225865@qq.com> Date: Mon, 13 Jan 2025 17:42:03 +0800 Subject: [PATCH 60/67] refactor: using slices.Contains to simplify the code Signed-off-by: dashangcun <907225865@qq.com> --- cmd/conf/init.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cmd/conf/init.go b/cmd/conf/init.go index 74bd89fd16..97b31958d5 100644 --- a/cmd/conf/init.go +++ b/cmd/conf/init.go @@ -3,6 +3,7 @@ package conf import ( "fmt" "runtime" + "slices" "strings" "time" @@ -106,7 +107,7 @@ func (c *InitConfig) Validate() error { if c.Force && c.RecreateMissingStateFrom > 0 { log.Warn("force init enabled, recreate-missing-state-from will have no effect") } - if c.Latest != "" && !isAcceptedSnapshotKind(c.Latest) { + if c.Latest != "" && !slices.Contains(acceptedSnapshotKinds, c.Latest) { return fmt.Errorf("invalid value for latest option: \"%s\" %s", c.Latest, acceptedSnapshotKindsStr) } if c.Prune != "" && c.PruneThreads <= 0 { @@ -139,12 +140,3 @@ var ( acceptedSnapshotKinds = []string{"archive", "pruned", "genesis"} acceptedSnapshotKindsStr = "(accepted values: \"" + strings.Join(acceptedSnapshotKinds, "\" | \"") + "\")" ) - -func isAcceptedSnapshotKind(kind string) bool { - for _, valid := range acceptedSnapshotKinds { - if kind == valid { - return true - } - } - return false -} From c721fdbf0f6e824b25f2c78875b079bb0d2aa5ed Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 13 Jan 2025 18:43:37 +0100 Subject: [PATCH 61/67] Fix typo pimative -> primitive --- ...traint-types.md => 0001-avoid-primitive-constraint-types.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename docs/decisions/{0001-avoid-primative-constraint-types.md => 0001-avoid-primitive-constraint-types.md} (98%) diff --git a/docs/decisions/0001-avoid-primative-constraint-types.md b/docs/decisions/0001-avoid-primitive-constraint-types.md similarity index 98% rename from docs/decisions/0001-avoid-primative-constraint-types.md rename to docs/decisions/0001-avoid-primitive-constraint-types.md index b52cea8bdd..8a3ecb0632 100644 --- a/docs/decisions/0001-avoid-primative-constraint-types.md +++ b/docs/decisions/0001-avoid-primitive-constraint-types.md @@ -4,7 +4,7 @@ date: 2024-11-29 decision-makers: eljobe@ plasmapower@ --- -# Avoid primative constraint types +# Avoid primitive constraint types ## Context and Problem Statement From b7e28f2f12c8b808ade3f0103d45d780cdb19c83 Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Mon, 13 Jan 2025 11:53:45 -0700 Subject: [PATCH 62/67] Update geth pin to pull in extra comment --- go-ethereum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go-ethereum b/go-ethereum index aaded574dc..779b669ac0 160000 --- a/go-ethereum +++ b/go-ethereum @@ -1 +1 @@ -Subproject commit aaded574dcf7b2f6b5851ee858603cb61335217e +Subproject commit 779b669ac0d0020099a67a1c39fbaf66b901c1a5 From 84bfafa45edf97a50828a0d57790cdaed3999b42 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Tue, 14 Jan 2025 10:25:11 -0700 Subject: [PATCH 63/67] Enable the geth trie prefetcher for the sequencer --- execution/gethexec/executionengine.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/execution/gethexec/executionengine.go b/execution/gethexec/executionengine.go index 7cf83c7183..e606027419 100644 --- a/execution/gethexec/executionengine.go +++ b/execution/gethexec/executionengine.go @@ -508,6 +508,8 @@ func (s *ExecutionEngine) sequenceTransactionsWithBlockMutex(header *arbostypes. if err != nil { return nil, err } + statedb.StartPrefetcher("Sequencer") + defer statedb.StopPrefetcher() delayedMessagesRead := lastBlockHeader.Nonce.Uint64() From b18e8f0d8d48093c7a2986404ae78870b76c888b Mon Sep 17 00:00:00 2001 From: Joshua Colvin Date: Tue, 14 Jan 2025 14:39:00 -0700 Subject: [PATCH 64/67] Revert wasmer update New version of wasmer considers binaries created by current version of wasmer as incompatible. Will delay merging in new versions to reduce the number of times that stylus contracts will need to be recompiled. This reverts commit 93841cee1db6d2fc826c169992aa8bb73163703b, reversing changes made to 3ba8fc2dd39315e2d449f5f6666c23a472d11cf1. --- arbitrator/Cargo.lock | 61 +++++++++++----------------- arbitrator/tools/wasmer | 2 +- arbitrator/wasm-libraries/Cargo.lock | 14 +------ 3 files changed, 25 insertions(+), 52 deletions(-) diff --git a/arbitrator/Cargo.lock b/arbitrator/Cargo.lock index 9688d07229..2b437968fa 100644 --- a/arbitrator/Cargo.lock +++ b/arbitrator/Cargo.lock @@ -747,12 +747,11 @@ dependencies = [ [[package]] name = "dashmap" -version = "6.1.0" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils", "hashbrown 0.14.5", "lock_api", "once_cell", @@ -975,10 +974,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -1315,6 +1312,15 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "mach2" version = "0.4.2" @@ -2552,7 +2558,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytes", "cfg-if 1.0.0", @@ -2574,12 +2580,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wat", - "windows-sys 0.59.0", + "winapi", ] [[package]] name = "wasmer-compiler" -version = "4.3.7" +version = "4.2.8" dependencies = [ "backtrace", "bytes", @@ -2588,7 +2594,6 @@ dependencies = [ "enumset", "lazy_static", "leb128", - "libc", "memmap2 0.5.10", "more-asserts", "region", @@ -2600,13 +2605,12 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser", - "windows-sys 0.59.0", - "xxhash-rust", + "winapi", ] [[package]] name = "wasmer-compiler-cranelift" -version = "4.3.7" +version = "4.2.8" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -2623,7 +2627,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-llvm" -version = "4.3.7" +version = "4.2.8" dependencies = [ "byteorder", "cc", @@ -2645,7 +2649,7 @@ dependencies = [ [[package]] name = "wasmer-compiler-singlepass" -version = "4.3.7" +version = "4.2.8" dependencies = [ "byteorder", "dynasm", @@ -2662,7 +2666,7 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.3.7" +version = "4.2.8" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2672,25 +2676,21 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", - "getrandom", - "hex", "indexmap 1.9.3", "more-asserts", "rkyv", - "sha2 0.10.8", "target-lexicon", "thiserror", - "xxhash-rust", ] [[package]] name = "wasmer-vm" -version = "4.3.7" +version = "4.2.8" dependencies = [ "backtrace", "cc", @@ -2704,14 +2704,14 @@ dependencies = [ "indexmap 1.9.3", "lazy_static", "libc", - "mach2", + "mach", "memoffset", "more-asserts", "region", "scopeguard", "thiserror", "wasmer-types", - "windows-sys 0.59.0", + "winapi", ] [[package]] @@ -2830,15 +2830,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -2951,12 +2942,6 @@ dependencies = [ "tap", ] -[[package]] -name = "xxhash-rust" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - [[package]] name = "zerocopy" version = "0.6.6" diff --git a/arbitrator/tools/wasmer b/arbitrator/tools/wasmer index 84aec79c13..6b15433d83 160000 --- a/arbitrator/tools/wasmer +++ b/arbitrator/tools/wasmer @@ -1 +1 @@ -Subproject commit 84aec79c13888bf3fb324ddbd69b3fecc22d4a8c +Subproject commit 6b15433d83f951555c24f0c56dc05e4751b0cc76 diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index e62acf43a6..a5a066e5c9 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -518,10 +518,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", - "js-sys", "libc", "wasi", - "wasm-bindgen", ] [[package]] @@ -1635,20 +1633,16 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.3.7" +version = "4.2.8" dependencies = [ "bytecheck", "enum-iterator 0.7.0", "enumset", - "getrandom", - "hex", "indexmap 1.9.3", "more-asserts", "rkyv", - "sha2 0.10.8", "target-lexicon", "thiserror", - "xxhash-rust", ] [[package]] @@ -1809,12 +1803,6 @@ dependencies = [ "tap", ] -[[package]] -name = "xxhash-rust" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a5cbf750400958819fb6178eaa83bee5cd9c29a26a40cc241df8c70fdd46984" - [[package]] name = "zerocopy" version = "0.7.35" From f272f84ae0043c8e8992811468583e9d9c8d149a Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Thu, 16 Jan 2025 10:07:37 -0600 Subject: [PATCH 65/67] Upgrade actions/upload-artifact in CI --- .github/workflows/ci.yml | 2 +- .github/workflows/docker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ce5bf27f..2e9c7e1bf4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,7 +204,7 @@ jobs: run: ${{ github.workspace }}/.github/workflows/gotestsum.sh --tags stylustest --run TestProgramLong --timeout 60m --cover - name: Archive detailed run log - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.test-mode }}-full.log path: full.log diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 2aacf32f00..8526024fb3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -81,7 +81,7 @@ jobs: echo -e "\x1b[1;34mWAVM module root:\x1b[0m $module_root" - name: Upload WAVM machine as artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wavm-machine-${{ steps.module-root.outputs.module-root }} path: target/machines/latest/* From ab3c7f0a3deeb744397ee6503efff442684ea25e Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Fri, 17 Jan 2025 14:22:01 +0100 Subject: [PATCH 66/67] Add the installation of the cbindgen binary This binary is used in the make invocation, so it needs to be installed. --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 26447947d4..247f434ea0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -128,7 +128,7 @@ jobs: restore-keys: ${{ runner.os }}-go- - name: Build all lint dependencies - run: make -j build-node-deps + run: cargo install --force cbindgen && make -j build-node-deps # ℹ️ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun From 7244e7a39304b17319a519a3dc73fb8a8b3ea251 Mon Sep 17 00:00:00 2001 From: Pepper Lebeck-Jobe Date: Mon, 20 Jan 2025 09:47:52 +0100 Subject: [PATCH 67/67] Add cbindgen to both workflows It turns out that the ci.yml workflow was also failing because of the removal of cbindgen from the Ubuntu 24.04 image used by the GitHub action runners. This change also moves the installation of cbindgen earlier in the codequl-analysis.yml file and expands the scope of what is cached after a rust installation to include the cbindgen binary (which is installed in ~/.cargo/bin) --- .github/workflows/ci.yml | 3 +++ .github/workflows/codeql-analysis.yml | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e9c7e1bf4..32f50917d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,9 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 + + - name: Install cbindgen + run: cargo install --force cbindgen - name: Cache Build Products uses: actions/cache@v3 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 247f434ea0..f9a46a92c3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -81,12 +81,14 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 + - name: Install cbindgen + run: cargo install --force cbindgen + - name: Cache Rust Build Products uses: actions/cache@v3 with: path: | - ~/.cargo/registry/ - ~/.cargo/git/ + ~/.cargo/ arbitrator/target/ arbitrator/wasm-libraries/target/ arbitrator/wasm-libraries/soft-float/SoftFloat/build @@ -128,7 +130,7 @@ jobs: restore-keys: ${{ runner.os }}-go- - name: Build all lint dependencies - run: cargo install --force cbindgen && make -j build-node-deps + run: make -j build-node-deps # ℹ️ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun