Skip to content

Commit

Permalink
Get the branch building again
Browse files Browse the repository at this point in the history
This is probably not where we ultimately want to be. Too much boilerplate is
escaping from the bold system. Maybe, before introducing a dependency injection
framework, I should just introduce something manual that would instatiate all
the instances that the challenge manager, watcher, assertion manager, etc. need
and then wires them together in the "default" way using the constructors from
each package.
  • Loading branch information
eljobe committed Nov 12, 2024
1 parent 7056809 commit 2f0bc89
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 14 deletions.
30 changes: 25 additions & 5 deletions staker/bold/bold_staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"
"time"

"github.com/offchainlabs/bold/assertions"
protocol "github.com/offchainlabs/bold/chain-abstraction"
solimpl "github.com/offchainlabs/bold/chain-abstraction/sol-implementation"
challengemanager "github.com/offchainlabs/bold/challenge-manager"
Expand Down Expand Up @@ -394,26 +395,45 @@ func newBOLDChallengeManager(
scanningInterval := config.AssertionScanningInterval
// The interval at which the manager will attempt to confirm assertions.
confirmingInterval := config.AssertionConfirmingInterval
opts := []challengemanager.Opt{

amOpts := []assertions.Opt{
assertions.WithPostingInterval(postingInterval),
assertions.WithPollingInterval(scanningInterval),
assertions.WithConfirmationInterval(confirmingInterval),
}
assertionManager, err := assertions.NewManager(
assertionChain,
provider,
assertionChain.Backend(),
assertionChain.RollupAddress(),
config.StateProviderConfig.ValidatorName,
nil, // TODO: This is not going to cut it.
BoldModes[config.Mode],
amOpts...,
)
if err != nil {
return nil, fmt.Errorf("could not create assertion manager: %w", err)
}

cmOpts := []challengemanager.Opt{
challengemanager.WithName(config.StateProviderConfig.ValidatorName),
challengemanager.WithMode(BoldModes[config.Mode]),
challengemanager.WithAssertionPostingInterval(postingInterval),
challengemanager.WithAssertionScanningInterval(scanningInterval),
challengemanager.WithAssertionConfirmingInterval(confirmingInterval),
challengemanager.WithAddress(txOpts.From),
// Configure the validator to track only certain challenges if configured to do so.
challengemanager.WithTrackChallengeParentAssertionHashes(config.TrackChallengeParentAssertionHashes),
}
if config.API {
// Conditionally enables the BOLD API if configured.
opts = append(opts, challengemanager.WithAPIEnabled(fmt.Sprintf("%s:%d", config.APIHost, config.APIPort), config.APIDBPath))
cmOpts = append(cmOpts, challengemanager.WithAPIEnabled(fmt.Sprintf("%s:%d", config.APIHost, config.APIPort), config.APIDBPath))
}
manager, err := challengemanager.New(
ctx,
assertionChain,
provider,
assertionManager,
assertionChain.RollupAddress(),
opts...,
cmOpts...,
)
if err != nil {
return nil, fmt.Errorf("could not create challenge manager: %w", err)
Expand Down
11 changes: 9 additions & 2 deletions staker/bold/bold_state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ func (s *BOLDStateProvider) CollectMachineHashes(
}
if vs.IsSome() {
m := server_arb.NewFinishedMachine()
m.SetGlobalState(vs.Unwrap())
if err := m.SetGlobalState(vs.Unwrap()); err != nil {
return nil, err
}
defer m.Destroy()
return []common.Hash{m.Hash()}, nil
}
Expand Down Expand Up @@ -517,14 +519,19 @@ func (s *BOLDStateProvider) CollectProof(
machineIndex l2stateprovider.OpcodeIndex,
) ([]byte, error) {
messageNum, err := s.messageNum(assertionMetadata, blockChallengeHeight)
if err != nil {
return nil, err
}
// Check if we have a virtual global state.
vs, err := s.virtualState(messageNum, assertionMetadata.BatchLimit)
if err != nil {
return nil, err
}
if vs.IsSome() {
m := server_arb.NewFinishedMachine()
m.SetGlobalState(vs.Unwrap())
if err := m.SetGlobalState(vs.Unwrap()); err != nil {
return nil, err
}
defer m.Destroy()
return m.ProveNextStep(), nil
}
Expand Down
35 changes: 31 additions & 4 deletions system_tests/bold_challenge_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/offchainlabs/bold/assertions"
protocol "github.com/offchainlabs/bold/chain-abstraction"
solimpl "github.com/offchainlabs/bold/chain-abstraction/sol-implementation"
challengemanager "github.com/offchainlabs/bold/challenge-manager"
Expand Down Expand Up @@ -387,30 +388,56 @@ func testChallengeProtocolBOLD(t *testing.T, spawnerOpts ...server_arb.SpawnerOp
nil, // Api db
)

assertionManager, err := assertions.NewManager(
assertionChain,
provider,
assertionChain.Backend(),
assertionChain.RollupAddress(),
"honest",
nil,
modes.MakeMode,
assertions.WithPostingInterval(time.Second*3),
assertions.WithPollingInterval(time.Second),
assertions.WithAverageBlockCreationTime(time.Second),
)
Require(t, err)

manager, err := challengemanager.New(
ctx,
assertionChain,
provider,
assertionManager,
assertionChain.RollupAddress(),
challengemanager.WithName("honest"),
challengemanager.WithMode(modes.MakeMode),
challengemanager.WithAddress(l1info.GetDefaultTransactOpts("Asserter", ctx).From),
challengemanager.WithAssertionPostingInterval(time.Second*3),
challengemanager.WithAssertionScanningInterval(time.Second),
challengemanager.WithAvgBlockCreationTime(time.Second),
)
Require(t, err)

assertionManagerB, err := assertions.NewManager(
chainB,
evilProvider,
chainB.Backend(),
chainB.RollupAddress(),
"evil",
nil,
modes.MakeMode,
assertions.WithPostingInterval(time.Second*3),
assertions.WithPollingInterval(time.Second),
assertions.WithAverageBlockCreationTime(time.Second),
)
Require(t, err)

managerB, err := challengemanager.New(
ctx,
chainB,
evilProvider,
assertionManagerB,
assertionChain.RollupAddress(),
challengemanager.WithName("evil"),
challengemanager.WithMode(modes.MakeMode),
challengemanager.WithAddress(l1info.GetDefaultTransactOpts("EvilAsserter", ctx).From),
challengemanager.WithAssertionPostingInterval(time.Second*3),
challengemanager.WithAssertionScanningInterval(time.Second),
challengemanager.WithAvgBlockCreationTime(time.Second),
)
Require(t, err)
Expand Down
18 changes: 16 additions & 2 deletions system_tests/bold_new_challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/offchainlabs/bold/assertions"
protocol "github.com/offchainlabs/bold/chain-abstraction"
solimpl "github.com/offchainlabs/bold/chain-abstraction/sol-implementation"
challengemanager "github.com/offchainlabs/bold/challenge-manager"
Expand Down Expand Up @@ -332,18 +333,31 @@ func startBoldChallengeManager(t *testing.T, ctx context.Context, builder *NodeB
builder.L1.Client,
solimpl.NewDataPosterTransactor(dp),
)
Require(t, err)

assertionManager, err := assertions.NewManager(
assertionChain,
provider,
assertionChain.Backend(),
assertionChain.RollupAddress(),
addressName,
nil,
modes.MakeMode,
assertions.WithPostingInterval(time.Second*3),
assertions.WithPollingInterval(time.Second),
assertions.WithAverageBlockCreationTime(time.Second),
)
Require(t, err)

challengeManager, err := challengemanager.New(
ctx,
assertionChain,
provider,
assertionManager,
assertionChain.RollupAddress(),
challengemanager.WithName(addressName),
challengemanager.WithMode(modes.MakeMode),
challengemanager.WithAddress(txOpts.From),
challengemanager.WithAssertionPostingInterval(time.Second*3),
challengemanager.WithAssertionScanningInterval(time.Second),
challengemanager.WithAvgBlockCreationTime(time.Second),
)
Require(t, err)
Expand Down

0 comments on commit 2f0bc89

Please sign in to comment.