From 35f061e900f52fc66509ec698b118feaf94bd0a9 Mon Sep 17 00:00:00 2001 From: amsanghi Date: Wed, 31 Jan 2024 21:01:47 +0530 Subject: [PATCH] fixes --- staker/challenge-cache/cache_test.go | 2 +- staker/state_provider.go | 2 +- system_tests/staker_test.go | 7 ++++++- system_tests/validation_mock_test.go | 4 ---- validator/interface.go | 1 - validator/server_api/validation_api.go | 17 ----------------- validator/server_api/validation_client.go | 16 ---------------- validator/server_arb/execution_run.go | 17 +++-------------- 8 files changed, 11 insertions(+), 55 deletions(-) diff --git a/staker/challenge-cache/cache_test.go b/staker/challenge-cache/cache_test.go index 8267e9a3a5..68491ebaa2 100644 --- a/staker/challenge-cache/cache_test.go +++ b/staker/challenge-cache/cache_test.go @@ -52,7 +52,7 @@ func TestCache(t *testing.T) { common.BytesToHash([]byte("bar")), common.BytesToHash([]byte("baz")), } - err := cache.Put(key, want) + err = cache.Put(key, want) if err != nil { t.Fatal(err) } diff --git a/staker/state_provider.go b/staker/state_provider.go index c478e57332..e0fc93392e 100644 --- a/staker/state_provider.go +++ b/staker/state_provider.go @@ -365,7 +365,7 @@ func (s *StateManager) CollectMachineHashes( if err != nil { return nil, err } - execRun, err := s.validator.execSpawner.CreateBoldExecutionRun(cfg.WasmModuleRoot, uint64(cfg.StepSize), input).Await(ctx) + execRun, err := s.validator.execSpawner.CreateExecutionRun(cfg.WasmModuleRoot, input).Await(ctx) if err != nil { return nil, err } diff --git a/system_tests/staker_test.go b/system_tests/staker_test.go index 12752c6943..1caee96fe5 100644 --- a/system_tests/staker_test.go +++ b/system_tests/staker_test.go @@ -567,7 +567,11 @@ func setupNonBoldStaker(t *testing.T, ctx context.Context) (*staker.Staker, *Nod valConfig.Bold.Enable = true valConfig.StakerInterval = 100 * time.Millisecond - dp, err := arbnode.StakerDataposter(ctx, rawdb.NewTable(l2node.ArbDB, storage.StakerPrefix), l2node.L1Reader, &l1auth, NewFetcherFromConfig(arbnode.ConfigDefaultL1NonSequencerTest()), nil) + parentChainID, err := builder.L1.Client.ChainID(ctx) + if err != nil { + t.Fatalf("Failed to get parent chain id: %v", err) + } + dp, err := arbnode.StakerDataposter(ctx, rawdb.NewTable(l2node.ArbDB, storage.StakerPrefix), l2node.L1Reader, &l1auth, NewFetcherFromConfig(arbnode.ConfigDefaultL1NonSequencerTest()), nil, parentChainID) if err != nil { t.Fatalf("Error creating validator dataposter: %v", err) } @@ -583,6 +587,7 @@ func setupNonBoldStaker(t *testing.T, ctx context.Context) (*staker.Staker, *Nod l2node.Execution, l2node.ArbDB, nil, + nil, StaticFetcherFrom(t, &blockValidatorConfig), valStack, ) diff --git a/system_tests/validation_mock_test.go b/system_tests/validation_mock_test.go index e10133aac7..f3bb6d505a 100644 --- a/system_tests/validation_mock_test.go +++ b/system_tests/validation_mock_test.go @@ -86,10 +86,6 @@ func (s *mockSpawner) WriteToFile(input *validator.ValidationInput, expOut valid return containers.NewReadyPromise[struct{}](struct{}{}, nil) } -func (s *mockSpawner) CreateBoldExecutionRun(wasmModuleRoot common.Hash, stepSize uint64, input *validator.ValidationInput) containers.PromiseInterface[validator.ExecutionRun] { - return containers.NewReadyPromise[validator.ExecutionRun](nil, nil) -} - type mockValRun struct { containers.Promise[validator.GoGlobalState] root common.Hash diff --git a/validator/interface.go b/validator/interface.go index 4ff0f332f1..da56be7ffb 100644 --- a/validator/interface.go +++ b/validator/interface.go @@ -24,7 +24,6 @@ type ValidationRun interface { type ExecutionSpawner interface { ValidationSpawner CreateExecutionRun(wasmModuleRoot common.Hash, input *ValidationInput) containers.PromiseInterface[ExecutionRun] - CreateBoldExecutionRun(wasmModuleRoot common.Hash, stepSize uint64, input *ValidationInput) containers.PromiseInterface[ExecutionRun] LatestWasmModuleRoot() containers.PromiseInterface[common.Hash] WriteToFile(input *ValidationInput, expOut GoGlobalState, moduleRoot common.Hash) containers.PromiseInterface[struct{}] } diff --git a/validator/server_api/validation_api.go b/validator/server_api/validation_api.go index ea6912234b..1848897521 100644 --- a/validator/server_api/validation_api.go +++ b/validator/server_api/validation_api.go @@ -69,23 +69,6 @@ func NewExecutionServerAPI(valSpawner validator.ValidationSpawner, execution val } } -func (a *ExecServerAPI) CreateBoldExecutionRun(ctx context.Context, wasmModuleRoot common.Hash, stepSize uint64, jsonInput *ValidationInputJson) (uint64, error) { - input, err := ValidationInputFromJson(jsonInput) - if err != nil { - return 0, err - } - execRun, err := a.execSpawner.CreateBoldExecutionRun(wasmModuleRoot, stepSize, input).Await(ctx) - if err != nil { - return 0, err - } - a.runIdLock.Lock() - defer a.runIdLock.Unlock() - newId := a.nextId - a.nextId++ - a.runs[newId] = &execRunEntry{execRun, time.Now()} - return newId, nil -} - func (a *ExecServerAPI) CreateExecutionRun(ctx context.Context, wasmModuleRoot common.Hash, jsonInput *ValidationInputJson) (uint64, error) { input, err := ValidationInputFromJson(jsonInput) if err != nil { diff --git a/validator/server_api/validation_client.go b/validator/server_api/validation_client.go index 108f25e6f7..eaeb53df1a 100644 --- a/validator/server_api/validation_client.go +++ b/validator/server_api/validation_client.go @@ -106,22 +106,6 @@ func NewExecutionClient(config rpcclient.ClientConfigFetcher, stack *node.Node) } } -func (c *ExecutionClient) CreateBoldExecutionRun(wasmModuleRoot common.Hash, stepSize uint64, input *validator.ValidationInput) containers.PromiseInterface[validator.ExecutionRun] { - return stopwaiter.LaunchPromiseThread[validator.ExecutionRun](c, func(ctx context.Context) (validator.ExecutionRun, error) { - var res uint64 - err := c.client.CallContext(ctx, &res, Namespace+"_createBoldExecutionRun", wasmModuleRoot, stepSize, ValidationInputToJson(input)) - if err != nil { - return nil, err - } - run := &ExecutionClientRun{ - client: c, - id: res, - } - run.Start(c.GetContext()) // note: not this temporary thread's context! - return run, nil - }) -} - func (c *ExecutionClient) CreateExecutionRun(wasmModuleRoot common.Hash, input *validator.ValidationInput) containers.PromiseInterface[validator.ExecutionRun] { return stopwaiter.LaunchPromiseThread[validator.ExecutionRun](c, func(ctx context.Context) (validator.ExecutionRun, error) { var res uint64 diff --git a/validator/server_arb/execution_run.go b/validator/server_arb/execution_run.go index f0defae474..7be54a4adb 100644 --- a/validator/server_arb/execution_run.go +++ b/validator/server_arb/execution_run.go @@ -15,28 +15,23 @@ import ( "github.com/offchainlabs/nitro/util/containers" "github.com/offchainlabs/nitro/util/stopwaiter" "github.com/offchainlabs/nitro/validator" - "github.com/offchainlabs/nitro/validator/server_common" ) type executionRun struct { stopwaiter.StopWaiter - cache *MachineCache - initialMachineGetter func(context.Context, ...server_common.MachineLoaderOpt) (MachineInterface, error) - config *MachineCacheConfig - close sync.Once + cache *MachineCache + close sync.Once } // NewExecutionChallengeBackend creates a backend with the given arguments. // Note: machineCache may be nil, but if present, it must not have a restricted range. func NewExecutionRun( ctxIn context.Context, - initialMachineGetter func(context.Context, ...server_common.MachineLoaderOpt) (MachineInterface, error), + initialMachineGetter func(context.Context) (MachineInterface, error), config *MachineCacheConfig, ) (*executionRun, error) { exec := &executionRun{} exec.Start(ctxIn, exec) - exec.initialMachineGetter = initialMachineGetter - exec.config = config exec.cache = NewMachineCache(exec.GetContext(), initialMachineGetter, config) return exec, nil } @@ -65,16 +60,10 @@ func (e *executionRun) GetStepAt(position uint64) containers.PromiseInterface[*v func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64) containers.PromiseInterface[[]common.Hash] { return stopwaiter.LaunchPromiseThread[[]common.Hash](e, func(ctx context.Context) ([]common.Hash, error) { - if stepSize == 1 { - e.cache = NewMachineCache(e.GetContext(), e.initialMachineGetter, e.config, server_common.WithAlwaysMerkleize()) - log.Info("Enabling Merkleization of machines for faster hashing. However, advancing to start index might take a while...") - } - log.Info(fmt.Sprintf("Starting BOLD machine computation at index %d", machineStartIndex)) machine, err := e.cache.GetMachineAt(ctx, machineStartIndex) if err != nil { return nil, err } - log.Info(fmt.Sprintf("Advanced machine to index %d, beginning hash computation", machineStartIndex)) // If the machine is starting at index 0, we always want to start at the "Machine finished" global state status // to align with the state roots that the inbox machine will produce. var stateRoots []common.Hash