Skip to content

Commit

Permalink
Merge branch 'master' into inputs-wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
eljobe committed Aug 22, 2024
2 parents e9bf293 + 28310ae commit e547683
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 59 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ linters-settings:
gosec:
excludes:
- G404 # checks that random numbers are securely generated
- G115 # Potential integer overflow when converting between integer types

govet:
enable-all: true
Expand Down
2 changes: 1 addition & 1 deletion arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ var DefaultDataPosterConfig = DataPosterConfig{
MaxMempoolWeight: 18,
MinTipCapGwei: 0.05,
MinBlobTxTipCapGwei: 1, // default geth minimum, and relays aren't likely to accept lower values given propagation time
MaxTipCapGwei: 5,
MaxTipCapGwei: 1.2,
MaxBlobTxTipCapGwei: 1, // lower than normal because 4844 rbf is a minimum of a 2x
MaxFeeBidMultipleBips: arbmath.OneInBips * 10,
NonceRbfSoftConfs: 1,
Expand Down
2 changes: 1 addition & 1 deletion arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func createNodeImpl(
confirmedNotifiers = append(confirmedNotifiers, messagePruner)
}

stakerObj, err = staker.NewStaker(l1Reader, wallet, bind.CallOpts{}, config.Staker, blockValidator, statelessBlockValidator, nil, confirmedNotifiers, deployInfo.ValidatorUtils, fatalErrChan)
stakerObj, err = staker.NewStaker(l1Reader, wallet, bind.CallOpts{}, func() *staker.L1ValidatorConfig { return &configFetcher.Get().Staker }, blockValidator, statelessBlockValidator, nil, confirmedNotifiers, deployInfo.ValidatorUtils, fatalErrChan)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dbconv/dbconv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var DefaultDBConvConfig = DBConvConfig{
func DBConvConfigAddOptions(f *flag.FlagSet) {
DBConfigAddOptions("src", f, &DefaultDBConvConfig.Src)
DBConfigAddOptions("dst", f, &DefaultDBConvConfig.Dst)
f.Int("ideal-batch-size", DefaultDBConvConfig.IdealBatchSize, "ideal write batch size")
f.Int("ideal-batch-size", DefaultDBConvConfig.IdealBatchSize, "ideal write batch size in bytes")
f.Bool("convert", DefaultDBConvConfig.Convert, "enables conversion step")
f.Bool("compact", DefaultDBConvConfig.Compact, "enables compaction step")
f.String("verify", DefaultDBConvConfig.Verify, "enables verification step (\"\" = disabled, \"keys\" = only keys, \"full\" = keys and values)")
Expand Down
2 changes: 0 additions & 2 deletions cmd/dbconv/dbconv/dbconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"context"
"testing"

"github.com/ethereum/go-ethereum/log"
"github.com/offchainlabs/nitro/util/testhelpers"
)

func TestConversion(t *testing.T) {
_ = testhelpers.InitTestLog(t, log.LvlTrace)
oldDBConfig := DBConfigDefaultSrc
oldDBConfig.Data = t.TempDir()

Expand Down
2 changes: 1 addition & 1 deletion cmd/dbconv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func main() {
os.Exit(1)
}
stats := conv.Stats()
log.Info("Conversion finished.", "entries", stats.Entries(), "MB", stats.Bytes()/1024/1024, "avg Ke/s", stats.AverageEntriesPerSecond()/1000, "avg MB/s", stats.AverageBytesPerSecond()/1024/1024, "elapsed", stats.Elapsed())
log.Info("Conversion finished.", "entries", stats.Entries(), "MB", stats.Bytes()/1024/1024, "avg entries/s", fmt.Sprintf("%.3e", stats.AverageEntriesPerSecond()/1000), "avg MB/s", stats.AverageBytesPerSecond()/1024/1024, "elapsed", stats.Elapsed())
}

if config.Compact {
Expand Down
11 changes: 6 additions & 5 deletions cmd/util/confighelpers/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/json"
koanfjson "github.com/knadh/koanf/parsers/json"
"github.com/knadh/koanf/providers/confmap"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/providers/file"
Expand Down Expand Up @@ -215,15 +214,17 @@ func devFlagArgs() []string {
}

func BeginCommonParse(f *flag.FlagSet, args []string) (*koanf.Koanf, error) {
var expandedArgs []string
for _, arg := range args {
if arg == "--version" || arg == "-v" {
return nil, ErrVersion
} else if arg == "--dev" {
args = devFlagArgs()
break
expandedArgs = append(expandedArgs, devFlagArgs()...)
} else {
expandedArgs = append(expandedArgs, arg)
}
}
if err := f.Parse(args); err != nil {
if err := f.Parse(expandedArgs); err != nil {
return nil, err
}

Expand Down Expand Up @@ -305,7 +306,7 @@ func DumpConfig(k *koanf.Koanf, extraOverrideFields map[string]interface{}) erro
return fmt.Errorf("error removing extra parameters before dump: %w", err)
}

c, err := k.Marshal(koanfjson.Parser())
c, err := k.Marshal(json.Parser())
if err != nil {
return fmt.Errorf("unable to marshal config file to JSON: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion das/s3_storage_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s3s *S3StorageService) Put(ctx context.Context, value []byte, timeout uint
Bucket: aws.String(s3s.bucket),
Key: aws.String(s3s.objectPrefix + EncodeStorageServiceKey(dastree.Hash(value))),
Body: bytes.NewReader(value)}
if !s3s.discardAfterTimeout {
if s3s.discardAfterTimeout {
expires := time.Unix(int64(timeout), 0)
putObjectInput.Expires = &expires
}
Expand Down
6 changes: 3 additions & 3 deletions das/syncing_fallback_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ type l1SyncService struct {
lastBatchAcc common.Hash
}

// The original syncing process had a bug, so the file was renamed to cause any mirrors
// in the wild to re-sync from their configured starting block number.
const nextBlockNoFilename = "nextBlockNumberV2"
// The filename has been updated when we have discovered bugs that may have impacted
// syncing, to cause mirrors to re-sync.
const nextBlockNoFilename = "nextBlockNumberV3"

func readSyncStateOrDefault(syncDir string, dflt uint64) uint64 {
if syncDir == "" {
Expand Down
2 changes: 1 addition & 1 deletion scripts/convert-databases.bash
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fi

convert_result=
convert () {
srcdir=$(echo $src/$1 | tr -s /)
srcdir="$src"/$1
dstdir=$(echo $dst/$1 | tr -s /)
if ! [ -e $dstdir ]; then
echo "== Converting $1 db"
Expand Down
59 changes: 33 additions & 26 deletions staker/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (c *L1ValidatorConfig) Validate() error {
return nil
}

type L1ValidatorConfigFetcher func() *L1ValidatorConfig

var DefaultL1ValidatorConfig = L1ValidatorConfig{
Enable: true,
Strategy: "Watchtower",
Expand Down Expand Up @@ -257,7 +259,7 @@ type Staker struct {
confirmedNotifiers []LatestConfirmedNotifier
activeChallenge *ChallengeManager
baseCallOpts bind.CallOpts
config L1ValidatorConfig
config L1ValidatorConfigFetcher
highGasBlocksBuffer *big.Int
lastActCalledBlock *big.Int
inactiveLastCheckedNode *nodeAndHash
Expand Down Expand Up @@ -295,7 +297,7 @@ func NewStaker(
l1Reader *headerreader.HeaderReader,
wallet ValidatorWalletInterface,
callOpts bind.CallOpts,
config L1ValidatorConfig,
config L1ValidatorConfigFetcher,
blockValidator *BlockValidator,
statelessBlockValidator *StatelessBlockValidator,
stakedNotifiers []LatestStakedNotifier,
Expand All @@ -304,7 +306,7 @@ func NewStaker(
fatalErr chan<- error,
) (*Staker, error) {

if err := config.Validate(); err != nil {
if err := config().Validate(); err != nil {
return nil, err
}
client := l1Reader.Client()
Expand All @@ -314,7 +316,7 @@ func NewStaker(
return nil, err
}
stakerLastSuccessfulActionGauge.Update(time.Now().Unix())
if config.StartValidationFromStaked && blockValidator != nil {
if config().StartValidationFromStaked && blockValidator != nil {
stakedNotifiers = append(stakedNotifiers, blockValidator)
}
inactiveValidatedNodes := btree.NewG(2, func(a, b validatedNode) bool {
Expand All @@ -327,7 +329,7 @@ func NewStaker(
confirmedNotifiers: confirmedNotifiers,
baseCallOpts: callOpts,
config: config,
highGasBlocksBuffer: big.NewInt(config.PostingStrategy.HighGasDelayBlocks),
highGasBlocksBuffer: big.NewInt(config().PostingStrategy.HighGasDelayBlocks),
lastActCalledBlock: nil,
inboxReader: statelessBlockValidator.inboxReader,
statelessBlockValidator: statelessBlockValidator,
Expand All @@ -345,7 +347,7 @@ func (s *Staker) Initialize(ctx context.Context) error {
if walletAddressOrZero != (common.Address{}) {
s.updateStakerBalanceMetric(ctx)
}
if s.blockValidator != nil && s.config.StartValidationFromStaked {
if s.blockValidator != nil && s.config().StartValidationFromStaked {
latestStaked, _, err := s.validatorUtils.LatestStaked(&s.baseCallOpts, s.rollupAddress, walletAddressOrZero)
if err != nil {
return err
Expand All @@ -369,7 +371,8 @@ func (s *Staker) Initialize(ctx context.Context) error {
// based on the config, the wallet address, and the on-chain rollup designated fast confirmer.
// Before this function, both variables should be their default (i.e. fast confirmation is disabled).
func (s *Staker) setupFastConfirmation(ctx context.Context) error {
if !s.config.EnableFastConfirmation {
cfg := s.config()
if !cfg.EnableFastConfirmation {
return nil
}
if s.wallet.Address() == nil {
Expand Down Expand Up @@ -400,7 +403,7 @@ func (s *Staker) setupFastConfirmation(ctx context.Context) error {
fastConfirmer,
s.builder,
s.wallet,
s.config.gasRefunder,
cfg.gasRefunder,
s.l1Reader,
)
if err != nil {
Expand Down Expand Up @@ -516,8 +519,9 @@ func (s *Staker) Start(ctxIn context.Context) {
}
}()
var err error
if common.HexToAddress(s.config.GasRefunderAddress) != (common.Address{}) {
gasRefunderBalance, err := s.client.BalanceAt(ctx, common.HexToAddress(s.config.GasRefunderAddress), nil)
cfg := s.config()
if common.HexToAddress(cfg.GasRefunderAddress) != (common.Address{}) {
gasRefunderBalance, err := s.client.BalanceAt(ctx, common.HexToAddress(cfg.GasRefunderAddress), nil)
if err != nil {
log.Warn("error fetching validator gas refunder balance", "err", err)
} else {
Expand Down Expand Up @@ -546,7 +550,7 @@ func (s *Staker) Start(ctxIn context.Context) {
// Try to create another tx
return 0
}
return s.config.StakerInterval
return cfg.StakerInterval
}
stakerActionFailureCounter.Inc(1)
backoff *= 2
Expand Down Expand Up @@ -587,7 +591,7 @@ func (s *Staker) Start(ctxIn context.Context) {
notifier.UpdateLatestConfirmed(confirmedMsgCount, *confirmedGlobalState)
}
}
return s.config.StakerInterval
return s.config().StakerInterval
})
}

Expand All @@ -608,14 +612,15 @@ func (s *Staker) IsWhitelisted(ctx context.Context) (bool, error) {
}

func (s *Staker) shouldAct(ctx context.Context) bool {
cfg := s.config()
var gasPriceHigh = false
var gasPriceFloat float64
gasPrice, err := s.client.SuggestGasPrice(ctx)
if err != nil {
log.Warn("error getting gas price", "err", err)
} else {
gasPriceFloat = float64(gasPrice.Int64()) / 1e9
if gasPriceFloat >= s.config.PostingStrategy.HighGasThreshold {
if gasPriceFloat >= cfg.PostingStrategy.HighGasThreshold {
gasPriceHigh = true
}
}
Expand All @@ -640,14 +645,14 @@ func (s *Staker) shouldAct(ctx context.Context) bool {
// Clamp `s.highGasBlocksBuffer` to between 0 and HighGasDelayBlocks
if s.highGasBlocksBuffer.Sign() < 0 {
s.highGasBlocksBuffer.SetInt64(0)
} else if s.highGasBlocksBuffer.Cmp(big.NewInt(s.config.PostingStrategy.HighGasDelayBlocks)) > 0 {
s.highGasBlocksBuffer.SetInt64(s.config.PostingStrategy.HighGasDelayBlocks)
} else if s.highGasBlocksBuffer.Cmp(big.NewInt(cfg.PostingStrategy.HighGasDelayBlocks)) > 0 {
s.highGasBlocksBuffer.SetInt64(cfg.PostingStrategy.HighGasDelayBlocks)
}
if gasPriceHigh && s.highGasBlocksBuffer.Sign() > 0 {
log.Warn(
"not acting yet as gas price is high",
"gasPrice", gasPriceFloat,
"highGasPriceConfig", s.config.PostingStrategy.HighGasThreshold,
"highGasPriceConfig", cfg.PostingStrategy.HighGasThreshold,
"highGasBuffer", s.highGasBlocksBuffer,
)
return false
Expand Down Expand Up @@ -678,7 +683,8 @@ func (s *Staker) confirmDataPosterIsReady(ctx context.Context) error {
}

func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
if s.config.strategy != WatchtowerStrategy {
cfg := s.config()
if cfg.strategy != WatchtowerStrategy {
err := s.confirmDataPosterIsReady(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -732,7 +738,7 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
StakeExists: rawInfo != nil,
}

effectiveStrategy := s.config.strategy
effectiveStrategy := cfg.strategy
nodesLinear, err := s.validatorUtils.AreUnresolvedNodesLinear(callOpts, s.rollupAddress)
if err != nil {
return nil, fmt.Errorf("error checking for rollup assertion fork: %w", err)
Expand Down Expand Up @@ -760,7 +766,7 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
info.LatestStakedNodeHash = s.inactiveLastCheckedNode.hash
}

if s.config.EnableFastConfirmation {
if cfg.EnableFastConfirmation {
firstUnresolvedNode, err := s.rollup.FirstUnresolvedNode(callOpts)
if err != nil {
return nil, err
Expand Down Expand Up @@ -799,7 +805,7 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
if s.builder.BuildingTransactionCount() > 0 {
// Try to fast confirm previous nodes before working on new ones
log.Info("fast confirming previous node", "node", firstUnresolvedNode)
return s.wallet.ExecuteTransactions(ctx, s.builder, s.config.gasRefunder)
return s.wallet.ExecuteTransactions(ctx, s.builder, cfg.gasRefunder)
}
}
}
Expand Down Expand Up @@ -886,7 +892,7 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
return nil, fmt.Errorf("error withdrawing staker funds from our staker %v: %w", walletAddressOrZero, err)
}
log.Info("removing old stake and withdrawing funds")
return s.wallet.ExecuteTransactions(ctx, s.builder, s.config.gasRefunder)
return s.wallet.ExecuteTransactions(ctx, s.builder, cfg.gasRefunder)
}
}

Expand Down Expand Up @@ -940,7 +946,7 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
if info.StakerInfo == nil && info.StakeExists {
log.Info("staking to execute transactions")
}
return s.wallet.ExecuteTransactions(ctx, s.builder, s.config.gasRefunder)
return s.wallet.ExecuteTransactions(ctx, s.builder, cfg.gasRefunder)
}

func (s *Staker) handleConflict(ctx context.Context, info *StakerInfo) error {
Expand All @@ -966,7 +972,7 @@ func (s *Staker) handleConflict(ctx context.Context, info *StakerInfo) error {
*info.CurrentChallenge,
s.statelessBlockValidator,
latestConfirmedCreated,
s.config.ConfirmationBlocks,
s.config().ConfirmationBlocks,
)
if err != nil {
return fmt.Errorf("error creating challenge manager: %w", err)
Expand All @@ -980,8 +986,9 @@ func (s *Staker) handleConflict(ctx context.Context, info *StakerInfo) error {
}

func (s *Staker) advanceStake(ctx context.Context, info *OurStakerInfo, effectiveStrategy StakerStrategy) error {
cfg := s.config()
active := effectiveStrategy >= StakeLatestStrategy
action, wrongNodesExist, err := s.generateNodeAction(ctx, info, effectiveStrategy, &s.config)
action, wrongNodesExist, err := s.generateNodeAction(ctx, info, effectiveStrategy, cfg)
if err != nil {
return fmt.Errorf("error generating node action: %w", err)
}
Expand All @@ -995,7 +1002,7 @@ func (s *Staker) advanceStake(ctx context.Context, info *OurStakerInfo, effectiv

switch action := action.(type) {
case createNodeAction:
if wrongNodesExist && s.config.DisableChallenge {
if wrongNodesExist && cfg.DisableChallenge {
log.Error("refusing to challenge assertion as config disables challenges")
info.CanProgress = false
return nil
Expand Down Expand Up @@ -1192,7 +1199,7 @@ func (s *Staker) createConflict(ctx context.Context, info *StakerInfo) error {
}

func (s *Staker) Strategy() StakerStrategy {
return s.config.strategy
return s.config().strategy
}

func (s *Staker) Rollup() *RollupWatcher {
Expand Down
Loading

0 comments on commit e547683

Please sign in to comment.