Skip to content

Commit

Permalink
add back
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Dec 5, 2024
1 parent 027e2bd commit 6365875
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func mainImpl() int {
flag.Usage()
log.Crit("validator must have the parent chain reader enabled")
}
strategy, err := nodeConfig.Node.Staker.ParseStrategy()
strategy, err := legacystaker.ParseStrategy(nodeConfig.Node.Staker.Strategy)
if err != nil {
log.Crit("couldn't parse staker strategy", "err", err)
}
Expand Down
145 changes: 145 additions & 0 deletions validator/server_arb/boldmach/machine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package boldmach

import (
"context"

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

Check failure on line 6 in validator/server_arb/boldmach/machine.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ethereum/go-ethereum) -s prefix(github.com/offchainlabs) (gci)

Check failure on line 6 in validator/server_arb/boldmach/machine.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ethereum/go-ethereum) -s prefix(github.com/offchainlabs) (gci)

Check failure on line 6 in validator/server_arb/boldmach/machine.go

View workflow job for this annotation

GitHub Actions / Go Tests (stylus)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ethereum/go-ethereum) -s prefix(github.com/offchainlabs) (gci)

Check failure on line 6 in validator/server_arb/boldmach/machine.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ethereum/go-ethereum) -s prefix(github.com/offchainlabs) (gci)

Check failure on line 6 in validator/server_arb/boldmach/machine.go

View workflow job for this annotation

GitHub Actions / Go Tests (long)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/ethereum/go-ethereum) -s prefix(github.com/offchainlabs) (gci)
"github.com/offchainlabs/nitro/validator"
"github.com/offchainlabs/nitro/validator/server_arb"
)

// boldMachine wraps a server_arb.MachineInterface.
type BoldMachine struct {
inner server_arb.MachineInterface
zeroMachine *server_arb.ArbitratorMachine
hasStepped bool
}

// Ensure boldMachine implements server_arb.MachineInterface.
var _ server_arb.MachineInterface = (*BoldMachine)(nil)

func newBoldMachine(inner server_arb.MachineInterface) *BoldMachine {
z := server_arb.NewFinishedMachine(inner.GetGlobalState())
return &BoldMachine{
inner: inner,
zeroMachine: z,
hasStepped: false,
}
}

// Wraps a server_arb.MachineInterface and adds one step to the
// front of the machine's execution.
//
// This zeroth step should be at the same global state as the inner arbitrator
// machine has at step 0, but the machine is in the Finished state rather than
// the Running state.
func MachineWrapper(inner server_arb.MachineInterface) server_arb.MachineInterface {
return newBoldMachine(inner)
}

// CloneMachineInterface returns a new boldMachine with the same inner machine.
func (m *BoldMachine) CloneMachineInterface() server_arb.MachineInterface {
bMach := newBoldMachine(m.inner.CloneMachineInterface())
bMach.hasStepped = m.hasStepped
return bMach
}

// GetStepCount returns zero if the machine has not stepped, otherwise it
// returns the inner machine's step count plus one.
func (m *BoldMachine) GetStepCount() uint64 {
if !m.hasStepped {
return 0
}
return m.inner.GetStepCount() + 1
}

// Hash returns the hash of the inner machine if the machine has not stepped,
// otherwise it returns the hash of the zeroth step machine.
func (m *BoldMachine) Hash() common.Hash {
if !m.hasStepped {
return m.zeroMachine.Hash()
}
return m.inner.Hash()
}

// Destroy destroys the inner machine and the zeroth step machine.
func (m *BoldMachine) Destroy() {
m.inner.Destroy()
m.zeroMachine.Destroy()
}

// Freeze freezes the inner machine and the zeroth step machine.
func (m *BoldMachine) Freeze() {
m.inner.Freeze()
m.zeroMachine.Freeze()
}

// Status returns the status of the inner machine if the machine has not
// stepped, otherwise it returns the status of the zeroth step machine.
func (m *BoldMachine) Status() uint8 {
if !m.hasStepped {
return m.zeroMachine.Status()
}
return m.inner.Status()
}

// IsRunning returns true if the machine has not stepped, otherwise it
// returns the running state of the inner machine.
func (m *BoldMachine) IsRunning() bool {
if !m.hasStepped {
return true
}
return m.inner.IsRunning()
}

// IsErrored returns the errored state of the inner machine, or false if the
// machine has not stepped.
func (m *BoldMachine) IsErrored() bool {
if !m.hasStepped {
return false
}
return m.inner.IsErrored()
}

// Step steps the inner machine if the machine has not stepped, otherwise it
// steps the zeroth step machine.
func (m *BoldMachine) Step(ctx context.Context, steps uint64) error {
if !m.hasStepped {
if steps == 0 {
// Zero is okay, but doesn't advance the machine.
return nil
}
m.hasStepped = true
// Only the first step or set of steps needs to be adjusted.
steps = steps - 1
}
return m.inner.Step(ctx, steps)
}

// ValidForStep returns true for step 0 if and only if the machine has not stepped yet,
// and the inner machine's ValidForStep for the step minus one otherwise.
func (m *BoldMachine) ValidForStep(step uint64) bool {
if step == 0 {
return !m.hasStepped
}
return m.inner.ValidForStep(step - 1)
}

// GetGlobalState returns the global state of the inner machine if the machine
// has stepped, otherwise it returns the global state of the zeroth step.
func (m *BoldMachine) GetGlobalState() validator.GoGlobalState {
if !m.hasStepped {
return m.zeroMachine.GetGlobalState()
}
return m.inner.GetGlobalState()
}

// ProveNextStep returns the proof of the next step of the inner machine if the
// machine has stepped, otherwise it returns the proof that the zeroth step
// results in the inner machine's initial global state.
func (m *BoldMachine) ProveNextStep() []byte {
if !m.hasStepped {
return m.zeroMachine.ProveNextStep()
}
return m.inner.ProveNextStep()
}

0 comments on commit 6365875

Please sign in to comment.