Skip to content

Commit

Permalink
Merge branch 'update_nightly_ci' into clippy_attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Jan 8, 2025
2 parents da97e03 + f93c17f commit 0968a9a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion arbos/util/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TransferBalance(
if arbmath.BigLessThan(balance.ToBig(), amount) {
return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount)
}
if evm.Context.ArbOSVersion < params.ArbosVersion_30 && amount.Sign() == 0 {
if evm.Context.ArbOSVersion < params.ArbosVersion_Stylus && amount.Sign() == 0 {
evm.StateDB.CreateZombieIfDeleted(*from)
}
evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount), tracing.BalanceChangeTransfer)
Expand Down
92 changes: 80 additions & 12 deletions staker/bold/bold_staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"time"

flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -57,18 +58,23 @@ type BoldConfig struct {
// How often to scan for newly created assertions onchain.
AssertionScanningInterval time.Duration `koanf:"assertion-scanning-interval"`
// How often to confirm assertions onchain.
AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"`
AssertionConfirmingInterval time.Duration `koanf:"assertion-confirming-interval"`
API bool `koanf:"api"`
APIHost string `koanf:"api-host"`
APIPort uint16 `koanf:"api-port"`
APIDBPath string `koanf:"api-db-path"`
TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"`
CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"`
StateProviderConfig StateProviderConfig `koanf:"state-provider-config"`
StartValidationFromStaked bool `koanf:"start-validation-from-staked"`
AutoDeposit bool `koanf:"auto-deposit"`
AutoIncreaseAllowance bool `koanf:"auto-increase-allowance"`
DelegatedStaking DelegatedStakingConfig `koanf:"delegated-staking"`
RPCBlockNumber string `koanf:"rpc-block-number"`
// How long to wait since parent assertion was created to post a new assertion
MinimumGapToParentAssertion time.Duration `koanf:"minimum-gap-to-parent-assertion"`
API bool `koanf:"api"`
APIHost string `koanf:"api-host"`
APIPort uint16 `koanf:"api-port"`
APIDBPath string `koanf:"api-db-path"`
TrackChallengeParentAssertionHashes []string `koanf:"track-challenge-parent-assertion-hashes"`
CheckStakerSwitchInterval time.Duration `koanf:"check-staker-switch-interval"`
StateProviderConfig StateProviderConfig `koanf:"state-provider-config"`
StartValidationFromStaked bool `koanf:"start-validation-from-staked"`
strategy legacystaker.StakerStrategy
MinimumGapToParentAssertion time.Duration `koanf:"minimum-gap-to-parent-assertion"`
strategy legacystaker.StakerStrategy
blockNum rpc.BlockNumber
}

func (c *BoldConfig) Validate() error {
Expand All @@ -77,9 +83,31 @@ func (c *BoldConfig) Validate() error {
return err
}
c.strategy = strategy
var blockNum rpc.BlockNumber
switch strings.ToLower(c.RPCBlockNumber) {
case "safe":
blockNum = rpc.SafeBlockNumber
case "finalized":
blockNum = rpc.FinalizedBlockNumber
case "latest":
blockNum = rpc.LatestBlockNumber
default:
return fmt.Errorf("unknown rpc block number \"%v\", expected either latest, safe, or finalized", c.RPCBlockNumber)
}
c.blockNum = blockNum
return nil
}

type DelegatedStakingConfig struct {
Enable bool `koanf:"enable"`
CustomWithdrawalAddress string `koanf:"custom-withdrawal-address"`
}

var DefaultDelegatedStakingConfig = DelegatedStakingConfig{
Enable: false,
CustomWithdrawalAddress: "",
}

type StateProviderConfig struct {
// A name identifier for the validator for cosmetic purposes.
ValidatorName string `koanf:"validator-name"`
Expand Down Expand Up @@ -109,6 +137,10 @@ var DefaultBoldConfig = BoldConfig{
CheckStakerSwitchInterval: time.Minute, // Every minute, check if the Nitro node staker should switch to using BOLD.
StateProviderConfig: DefaultStateProviderConfig,
StartValidationFromStaked: true,
AutoDeposit: true,
AutoIncreaseAllowance: true,
DelegatedStaking: DefaultDelegatedStakingConfig,
RPCBlockNumber: "finalized",
}

var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{
Expand All @@ -121,6 +153,7 @@ var BoldModes = map[legacystaker.StakerStrategy]boldtypes.Mode{
func BoldConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".enable", DefaultBoldConfig.Enable, "enable bold challenge protocol")
f.String(prefix+".strategy", DefaultBoldConfig.Strategy, "define the bold validator staker strategy, either watchtower, defensive, stakeLatest, or makeNodes")
f.String(prefix+".rpc-block-number", DefaultBoldConfig.RPCBlockNumber, "define the block number to use for reading data onchain, either latest, safe, or finalized")
f.Duration(prefix+".assertion-posting-interval", DefaultBoldConfig.AssertionPostingInterval, "assertion posting interval")
f.Duration(prefix+".assertion-scanning-interval", DefaultBoldConfig.AssertionScanningInterval, "scan assertion interval")
f.Duration(prefix+".assertion-confirming-interval", DefaultBoldConfig.AssertionConfirmingInterval, "confirm assertion interval")
Expand All @@ -133,6 +166,9 @@ func BoldConfigAddOptions(prefix string, f *flag.FlagSet) {
f.StringSlice(prefix+".track-challenge-parent-assertion-hashes", DefaultBoldConfig.TrackChallengeParentAssertionHashes, "only track challenges/edges with these parent assertion hashes")
StateProviderConfigAddOptions(prefix+".state-provider-config", f)
f.Bool(prefix+".start-validation-from-staked", DefaultBoldConfig.StartValidationFromStaked, "assume staked nodes are valid")
f.Bool(prefix+".auto-deposit", DefaultBoldConfig.AutoDeposit, "auto-deposit stake token whenever making a move in BoLD that does not have enough stake token balance")
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)
}

func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) {
Expand All @@ -141,6 +177,11 @@ func StateProviderConfigAddOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".machine-leaves-cache-path", DefaultStateProviderConfig.MachineLeavesCachePath, "path to machine cache")
}

func DelegatedStakingConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".enable", DefaultDelegatedStakingConfig.Enable, "enable delegated staking by having the validator call newStake on startup")
f.String(prefix+".custom-withdrawal-address", DefaultDelegatedStakingConfig.CustomWithdrawalAddress, "enable a custom withdrawal address for staking on the rollup contract, useful for delegated stakers")
}

type BOLDStaker struct {
stopwaiter.StopWaiter
config *BoldConfig
Expand Down Expand Up @@ -376,7 +417,25 @@ func newBOLDChallengeManager(
if err != nil {
return nil, fmt.Errorf("could not create challenge manager bindings: %w", err)
}
assertionChain, err := solimpl.NewAssertionChain(ctx, rollupAddress, chalManager, txOpts, client, NewDataPosterTransactor(dataPoster))
assertionChainOpts := []solimpl.Opt{
solimpl.WithRpcHeadBlockNumber(config.blockNum),
}
if config.DelegatedStaking.Enable && config.DelegatedStaking.CustomWithdrawalAddress != "" {
withdrawalAddr := common.HexToAddress(config.DelegatedStaking.CustomWithdrawalAddress)
assertionChainOpts = append(assertionChainOpts, solimpl.WithCustomWithdrawalAddress(withdrawalAddr))
}
if !config.AutoDeposit {
assertionChainOpts = append(assertionChainOpts, solimpl.WithoutAutoDeposit())
}
assertionChain, err := solimpl.NewAssertionChain(
ctx,
rollupAddress,
chalManager,
txOpts,
client,
NewDataPosterTransactor(dataPoster),
assertionChainOpts...,
)
if err != nil {
return nil, fmt.Errorf("could not create assertion chain: %w", err)
}
Expand Down Expand Up @@ -467,6 +526,15 @@ func newBOLDChallengeManager(
apiAddr := fmt.Sprintf("%s:%d", config.APIHost, config.APIPort)
stackOpts = append(stackOpts, challengemanager.StackWithAPIEnabled(apiAddr, apiDBPath))
}
if !config.AutoDeposit {
stackOpts = append(stackOpts, challengemanager.StackWithoutAutoDeposit())
}
if !config.AutoIncreaseAllowance {
stackOpts = append(stackOpts, challengemanager.StackWithoutAutoAllowanceApproval())
}
if config.DelegatedStaking.Enable {
stackOpts = append(stackOpts, challengemanager.StackWithDelegatedStaking())
}

manager, err := challengemanager.NewChallengeStack(
assertionChain,
Expand Down

0 comments on commit 0968a9a

Please sign in to comment.