diff --git a/arbnode/node.go b/arbnode/node.go index c20722826b..f2e3433ecd 100644 --- a/arbnode/node.go +++ b/arbnode/node.go @@ -693,7 +693,7 @@ func createNodeImpl( confirmedNotifiers = append(confirmedNotifiers, messagePruner) } - stakerObj, err = multiprotocolstaker.NewMultiProtocolStaker(l1Reader, wallet, bind.CallOpts{}, func() *legacystaker.L1ValidatorConfig { return &configFetcher.Get().Staker }, &configFetcher.Get().Bold, blockValidator, statelessBlockValidator, nil, deployInfo.StakeToken, confirmedNotifiers, deployInfo.ValidatorUtils, deployInfo.Bridge, fatalErrChan) + stakerObj, err = multiprotocolstaker.NewMultiProtocolStaker(stack, l1Reader, wallet, bind.CallOpts{}, func() *legacystaker.L1ValidatorConfig { return &configFetcher.Get().Staker }, &configFetcher.Get().Bold, blockValidator, statelessBlockValidator, nil, deployInfo.StakeToken, confirmedNotifiers, deployInfo.ValidatorUtils, deployInfo.Bridge, fatalErrChan) if err != nil { return nil, err } diff --git a/staker/bold/bold_staker.go b/staker/bold/bold_staker.go index be3cb15572..1a8eed80fa 100644 --- a/staker/bold/bold_staker.go +++ b/staker/bold/bold_staker.go @@ -7,8 +7,6 @@ import ( "errors" "fmt" "math/big" - "os" - "path/filepath" "time" flag "github.com/spf13/pflag" @@ -17,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" protocol "github.com/offchainlabs/bold/chain-abstraction" @@ -29,7 +28,6 @@ import ( "github.com/offchainlabs/bold/util" "github.com/offchainlabs/nitro/arbnode/dataposter" "github.com/offchainlabs/nitro/arbutil" - "github.com/offchainlabs/nitro/cmd/conf" "github.com/offchainlabs/nitro/staker" legacystaker "github.com/offchainlabs/nitro/staker/legacy" "github.com/offchainlabs/nitro/util/headerreader" @@ -38,7 +36,6 @@ import ( ) var assertionCreatedId common.Hash -var homeDir string func init() { rollupAbi, err := boldrollup.RollupCoreMetaData.GetAbi() @@ -50,11 +47,6 @@ func init() { panic("RollupCore ABI missing AssertionCreated event") } assertionCreatedId = assertionCreatedEvent.ID - homeDirPath, err := os.UserHomeDir() - if err != nil { - panic(err) - } - homeDir = homeDirPath } type BoldConfig struct { @@ -97,7 +89,7 @@ type StateProviderConfig struct { var DefaultStateProviderConfig = StateProviderConfig{ ValidatorName: "default-validator", CheckBatchFinality: true, - MachineLeavesCachePath: filepath.Join(homeDir, conf.PersistentConfigDefault.GlobalConfig, "machine-hashes-cache"), + MachineLeavesCachePath: "machine-hashes-cache", } var DefaultBoldConfig = BoldConfig{ @@ -109,7 +101,7 @@ var DefaultBoldConfig = BoldConfig{ API: false, APIHost: "127.0.0.1", APIPort: 9393, - APIDBPath: filepath.Join(homeDir, conf.PersistentConfigDefault.GlobalConfig, "bold-api-db"), + APIDBPath: "bold-api-db", TrackChallengeParentAssertionHashes: []string{}, CheckStakerSwitchInterval: time.Minute, // Every minute, check if the Nitro node staker should switch to using BOLD. StateProviderConfig: DefaultStateProviderConfig, @@ -162,6 +154,7 @@ type BOLDStaker struct { func NewBOLDStaker( ctx context.Context, + stack *node.Node, rollupAddress common.Address, callOpts bind.CallOpts, txOpts *bind.TransactOpts, @@ -178,7 +171,7 @@ func NewBOLDStaker( return nil, err } wrappedClient := util.NewBackendWrapper(l1Reader.Client(), rpc.LatestBlockNumber) - manager, err := newBOLDChallengeManager(ctx, rollupAddress, txOpts, l1Reader, wrappedClient, blockValidator, statelessBlockValidator, config, dataPoster) + manager, err := newBOLDChallengeManager(ctx, stack, rollupAddress, txOpts, l1Reader, wrappedClient, blockValidator, statelessBlockValidator, config, dataPoster) if err != nil { return nil, err } @@ -349,6 +342,7 @@ func (b *BOLDStaker) getCallOpts(ctx context.Context) *bind.CallOpts { // implements the StopWaiter pattern as part of the Nitro validator. func newBOLDChallengeManager( ctx context.Context, + stack *node.Node, rollupAddress common.Address, txOpts *bind.TransactOpts, l1Reader *headerreader.HeaderReader, @@ -405,6 +399,15 @@ func newBOLDChallengeManager( bigStepHeight := l2stateprovider.Height(bigStepHeightBig.Uint64()) smallStepHeight := l2stateprovider.Height(smallStepHeightBig.Uint64()) + apiDBPath := config.APIDBPath + if apiDBPath != "" { + apiDBPath = stack.ResolvePath(apiDBPath) + } + machineHashesPath := config.StateProviderConfig.MachineLeavesCachePath + if machineHashesPath != "" { + machineHashesPath = stack.ResolvePath(machineHashesPath) + } + // Sets up the state provider interface that BOLD will use to request data such as // execution states for assertions, history commitments for machine execution, and one step proofs. stateProvider, err := NewBOLDStateProvider( @@ -414,6 +417,7 @@ func newBOLDChallengeManager( // TODO: Fetch these from the smart contract instead. blockChallengeLeafHeight, &config.StateProviderConfig, + machineHashesPath, ) if err != nil { return nil, fmt.Errorf("could not create state manager: %w", err) @@ -449,7 +453,7 @@ func newBOLDChallengeManager( } if config.API { apiAddr := fmt.Sprintf("%s:%d", config.APIHost, config.APIPort) - stackOpts = append(stackOpts, challengemanager.StackWithAPIEnabled(apiAddr, config.APIDBPath)) + stackOpts = append(stackOpts, challengemanager.StackWithAPIEnabled(apiAddr, apiDBPath)) } manager, err := challengemanager.NewChallengeStack( diff --git a/staker/bold/bold_state_provider.go b/staker/bold/bold_state_provider.go index 1ab2405bc4..13e08f7d3f 100644 --- a/staker/bold/bold_state_provider.go +++ b/staker/bold/bold_state_provider.go @@ -56,8 +56,9 @@ func NewBOLDStateProvider( statelessValidator *staker.StatelessBlockValidator, blockChallengeLeafHeight l2stateprovider.Height, stateProviderConfig *StateProviderConfig, + machineHashesCachePath string, ) (*BOLDStateProvider, error) { - historyCache, err := challengecache.New(stateProviderConfig.MachineLeavesCachePath) + historyCache, err := challengecache.New(machineHashesCachePath) if err != nil { return nil, err } diff --git a/staker/multi_protocol/multi_protocol_staker.go b/staker/multi_protocol/multi_protocol_staker.go index e08352f37d..0c104094ed 100644 --- a/staker/multi_protocol/multi_protocol_staker.go +++ b/staker/multi_protocol/multi_protocol_staker.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/node" "github.com/offchainlabs/bold/solgen/go/bridgegen" boldrollup "github.com/offchainlabs/bold/solgen/go/rollupgen" @@ -46,9 +47,11 @@ type MultiProtocolStaker struct { callOpts bind.CallOpts boldConfig *boldstaker.BoldConfig stakeTokenAddress common.Address + stack *node.Node } func NewMultiProtocolStaker( + stack *node.Node, l1Reader *headerreader.HeaderReader, wallet legacystaker.ValidatorWalletInterface, callOpts bind.CallOpts, @@ -102,6 +105,7 @@ func NewMultiProtocolStaker( callOpts: callOpts, boldConfig: boldConfig, stakeTokenAddress: stakeTokenAddress, + stack: stack, }, nil } @@ -224,6 +228,7 @@ func (m *MultiProtocolStaker) setupBoldStaker( } boldStaker, err := boldstaker.NewBOLDStaker( ctx, + m.stack, rollupAddress, m.callOpts, txBuilder.SingleTxAuth(), diff --git a/system_tests/validation_mock_test.go b/system_tests/validation_mock_test.go index 5e076b31b6..7493608f0c 100644 --- a/system_tests/validation_mock_test.go +++ b/system_tests/validation_mock_test.go @@ -84,7 +84,7 @@ func (s *mockSpawner) Stop() {} func (s *mockSpawner) Name() string { return "mock" } func (s *mockSpawner) Room() int { return 4 } -func (s *mockSpawner) CreateExecutionRun(wasmModuleRoot common.Hash, input *validator.ValidationInput, useBoldMachine *bool) containers.PromiseInterface[validator.ExecutionRun] { +func (s *mockSpawner) CreateExecutionRun(wasmModuleRoot common.Hash, input *validator.ValidationInput, useBoldMachine bool) containers.PromiseInterface[validator.ExecutionRun] { s.ExecSpawned = append(s.ExecSpawned, input.Id) return containers.NewReadyPromise[validator.ExecutionRun](&mockExecRun{ startState: input.StartState, @@ -261,7 +261,7 @@ func TestValidationServerAPI(t *testing.T) { t.Error("unexpected mock validation run") } useBoldMachine := false - execRun, err := client.CreateExecutionRun(wasmRoot, &valInput, &useBoldMachine).Await(ctx) + execRun, err := client.CreateExecutionRun(wasmRoot, &valInput, useBoldMachine).Await(ctx) Require(t, err) step0 := execRun.GetStepAt(0) step0Res, err := step0.Await(ctx) @@ -387,9 +387,9 @@ func TestExecutionKeepAlive(t *testing.T) { valInput := validator.ValidationInput{} useBoldMachine := false - runDefault, err := clientDefault.CreateExecutionRun(wasmRoot, &valInput, &useBoldMachine).Await(ctx) + runDefault, err := clientDefault.CreateExecutionRun(wasmRoot, &valInput, useBoldMachine).Await(ctx) Require(t, err) - runShortTO, err := clientShortTO.CreateExecutionRun(wasmRoot, &valInput, &useBoldMachine).Await(ctx) + runShortTO, err := clientShortTO.CreateExecutionRun(wasmRoot, &valInput, useBoldMachine).Await(ctx) Require(t, err) <-time.After(time.Second * 10) stepDefault := runDefault.GetStepAt(0) diff --git a/validator/client/validation_client.go b/validator/client/validation_client.go index caf3a789aa..9ac2271963 100644 --- a/validator/client/validation_client.go +++ b/validator/client/validation_client.go @@ -160,7 +160,7 @@ func (c *ExecutionClient) CreateExecutionRun( ) containers.PromiseInterface[validator.ExecutionRun] { return stopwaiter.LaunchPromiseThread(c, func(ctx context.Context) (validator.ExecutionRun, error) { var res uint64 - err := c.client.CallContext(ctx, &res, server_api.Namespace+"_createExecutionRun", wasmModuleRoot, server_api.ValidationInputToJson(input), useBoldMachine) + err := c.client.CallContext(ctx, &res, server_api.Namespace+"_createExecutionRun", wasmModuleRoot, server_api.ValidationInputToJson(input), *useBoldMachine) if err != nil { return nil, err } diff --git a/validator/server_arb/validator_spawner.go b/validator/server_arb/validator_spawner.go index 476b399921..5eb69ff60b 100644 --- a/validator/server_arb/validator_spawner.go +++ b/validator/server_arb/validator_spawner.go @@ -245,7 +245,7 @@ func (v *ArbitratorSpawner) CreateExecutionRun(wasmModuleRoot common.Hash, input return nil, err } var wrapped MachineInterface - if *useBoldMachine { + if useBoldMachine != nil && *useBoldMachine { wrapped = BoldMachineWrapper(machine) } else { wrapped = MachineInterface(machine)