Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions staker/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ func (v *BlockValidator) InitAssumeValid(globalState validator.GoGlobalState) er

// don't do anything if we already validated past that
if !v.validGSIsNew(globalState) {
log.Info("block_validator: assume-valid not newer")
return nil
}

Expand All @@ -1119,6 +1120,7 @@ func (v *BlockValidator) InitAssumeValid(globalState validator.GoGlobalState) er
log.Error("failed writing new validated to database", "pos", v.lastValidGS, "err", err)
}

log.Info("block_validator: assume-valid", "blockhash", globalState.BlockHash, "batch", globalState.Batch, "posInBatch", globalState.PosInBatch)
return nil
}

Expand Down
80 changes: 72 additions & 8 deletions staker/bold/bold_staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import (

"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/bold/chain-abstraction"
"github.com/offchainlabs/nitro/bold/chain-abstraction/sol-implementation"
"github.com/offchainlabs/nitro/bold/challenge-manager"
protocol "github.com/offchainlabs/nitro/bold/chain-abstraction"
solimpl "github.com/offchainlabs/nitro/bold/chain-abstraction/sol-implementation"
challengemanager "github.com/offchainlabs/nitro/bold/challenge-manager"
"github.com/offchainlabs/nitro/bold/challenge-manager/types"
"github.com/offchainlabs/nitro/bold/layer2-state-provider"
l2stateprovider "github.com/offchainlabs/nitro/bold/layer2-state-provider"
"github.com/offchainlabs/nitro/bold/util"
"github.com/offchainlabs/nitro/solgen/go/challengeV2gen"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/staker/legacy"
legacystaker "github.com/offchainlabs/nitro/staker/legacy"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/headerreader"
"github.com/offchainlabs/nitro/util/stopwaiter"
Expand Down Expand Up @@ -83,6 +83,12 @@ type BoldConfig struct {
// How long to wait since parent assertion was created to post a new assertion
MinimumGapToParentAssertion time.Duration `koanf:"minimum-gap-to-parent-assertion"`
blockNum rpc.BlockNumber
Dangerous DangerousBoldConfig `koanf:"dangerous"`
}

type DangerousBoldConfig struct {
AssumeValidBlockhash string `koanf:"assume-valid-blockhash"`
AssumeValid uint64 `koanf:"assume-valid"`
}

func (c *BoldConfig) Validate() error {
Expand Down Expand Up @@ -174,6 +180,7 @@ func BoldConfigAddOptions(prefix string, f *pflag.FlagSet) {
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)
f.Bool(prefix+".enable-fast-confirmation", DefaultBoldConfig.EnableFastConfirmation, "enable fast confirmation")
DangerousBoldConfigAddOptions(prefix+".dangerous", f)
}

func StateProviderConfigAddOptions(prefix string, f *pflag.FlagSet) {
Expand All @@ -187,6 +194,11 @@ func DelegatedStakingConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "enable a custom withdrawal address for staking on the rollup contract, useful for delegated stakers")
}

func DangerousBoldConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Uint64(prefix+".assume-valid", 0, "assume this message index is valid (if blockhash matches)")
f.String(prefix+".assume-valid-blockhash", "", "blockhash of the assumed-valid message")
}

type BOLDStaker struct {
stopwaiter.StopWaiter
config *BoldConfig
Expand Down Expand Up @@ -251,6 +263,43 @@ func NewBOLDStaker(
}, nil
}

func (b *BOLDStaker) initAssumeValid() (*protocol.GoGlobalState, error) {
if b.config.Dangerous.AssumeValid == 0 {
return nil, nil
}
blockMessage := arbutil.MessageIndex(b.config.Dangerous.AssumeValid)
result, err := b.inboxStreamer.ResultAtMessageIndex(blockMessage)
if err != nil {
return nil, err
}
expectedHash := common.HexToHash(b.config.Dangerous.AssumeValidBlockhash)
if result.BlockHash != expectedHash {
return nil, fmt.Errorf("unexpected assume-valid hash, expected: %v, found: %v", expectedHash, result.BlockHash)
}
afterStateMessage := blockMessage + 1
batch, found, err := b.inboxTracker.FindInboxBatchContainingMessage(afterStateMessage)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("batch not found")
}
if batch == 0 {
return nil, fmt.Errorf("batch is zero")
}
prevCount, err := b.inboxTracker.GetBatchMessageCount(batch - 1)
if err != nil {
return nil, err
}
posInBatch := afterStateMessage - prevCount
return &protocol.GoGlobalState{
BlockHash: result.BlockHash,
SendRoot: result.SendRoot,
Batch: batch,
PosInBatch: uint64(posInBatch),
}, nil
}

// Initialize Updates the block validator module root.
// And updates the init state of the block validator if block validator has not started yet.
func (b *BOLDStaker) Initialize(ctx context.Context) error {
Expand All @@ -265,6 +314,11 @@ func (b *BOLDStaker) Initialize(ctx context.Context) error {
}
log.Info("running as validator", "txSender", stakerAddr, "actingAsWallet", walletAddressOrZero, "strategy", b.strategy.ToString())

validState, err := b.initAssumeValid()
if err != nil {
log.Warn("Assume valid hit problem", "err", err)
}

if b.blockValidator != nil && b.config.StartValidationFromStaked && !b.blockValidator.Started() {
rollupUserLogic, err := rollupgen.NewRollupUserLogic(b.rollupAddress, b.client)
if err != nil {
Expand All @@ -291,10 +345,20 @@ func (b *BOLDStaker) Initialize(ctx context.Context) error {
if err != nil {
return err
}
afterState := protocol.GoGlobalStateFromSolidity(assertion.AfterState.GlobalState)
return b.blockValidator.InitAssumeValid(validator.GoGlobalState(afterState))
onchainValidState := protocol.GoGlobalStateFromSolidity(assertion.AfterState.GlobalState)
if validState == nil {
validState = &onchainValidState
} else if validState.Batch < onchainValidState.Batch {
validState = &onchainValidState
} else if validState.Batch == onchainValidState.Batch && validState.PosInBatch < onchainValidState.PosInBatch {
validState = &onchainValidState
}
}
return nil

if validState == nil {
return nil
}
return b.blockValidator.InitAssumeValid(validator.GoGlobalState(*validState))
}

func (b *BOLDStaker) Start(ctxIn context.Context) {
Expand Down
Loading