Skip to content

Commit

Permalink
Merge branch 'master' into add-ci-submodule-pin-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-Wilson authored Jul 12, 2024
2 parents eda3c94 + b6562ef commit a09a8a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion staker/l1_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (v *L1Validator) generateNodeAction(
return nil, false, nil
}

successorNodes, err := v.rollup.LookupNodeChildren(ctx, stakerInfo.LatestStakedNode, stakerInfo.LatestStakedNodeHash)
successorNodes, err := v.rollup.LookupNodeChildren(ctx, stakerInfo.LatestStakedNode, stakerConfig.LogQueryBatchSize, stakerInfo.LatestStakedNodeHash)
if err != nil {
return nil, false, fmt.Errorf("error looking up node %v (hash %v) children: %w", stakerInfo.LatestStakedNode, stakerInfo.LatestStakedNodeHash, err)
}
Expand Down
28 changes: 22 additions & 6 deletions staker/rollup_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
)

var rollupInitializedID common.Hash
Expand Down Expand Up @@ -165,7 +166,7 @@ func (r *RollupWatcher) LookupNode(ctx context.Context, number uint64) (*NodeInf
}, nil
}

func (r *RollupWatcher) LookupNodeChildren(ctx context.Context, nodeNum uint64, nodeHash common.Hash) ([]*NodeInfo, error) {
func (r *RollupWatcher) LookupNodeChildren(ctx context.Context, nodeNum uint64, logQueryRangeSize uint64, nodeHash common.Hash) ([]*NodeInfo, error) {
node, err := r.RollupUserLogic.GetNode(r.getCallOpts(ctx), nodeNum)
if err != nil {
return nil, err
Expand All @@ -180,17 +181,32 @@ func (r *RollupWatcher) LookupNodeChildren(ctx context.Context, nodeNum uint64,
Addresses: []common.Address{r.address},
Topics: [][]common.Hash{{nodeCreatedID}, nil, {nodeHash}},
}
query.FromBlock, err = r.getNodeCreationBlock(ctx, nodeNum)
fromBlock, err := r.getNodeCreationBlock(ctx, nodeNum)
if err != nil {
return nil, err
}
query.ToBlock, err = r.getNodeCreationBlock(ctx, node.LatestChildNumber)
toBlock, err := r.getNodeCreationBlock(ctx, node.LatestChildNumber)
if err != nil {
return nil, err
}
logs, err := r.client.FilterLogs(ctx, query)
if err != nil {
return nil, err
var logs []types.Log
// break down the query to avoid eth_getLogs query limit
for toBlock.Cmp(fromBlock) > 0 {
query.FromBlock = fromBlock
if logQueryRangeSize == 0 {
query.ToBlock = toBlock
} else {
query.ToBlock = new(big.Int).Add(fromBlock, big.NewInt(int64(logQueryRangeSize)))
}
if query.ToBlock.Cmp(toBlock) > 0 {
query.ToBlock = toBlock
}
segment, err := r.client.FilterLogs(ctx, query)
if err != nil {
return nil, err
}
logs = append(logs, segment...)
fromBlock = new(big.Int).Add(query.ToBlock, big.NewInt(1))
}
infos := make([]*NodeInfo, 0, len(logs))
lastHash := nodeHash
Expand Down
4 changes: 4 additions & 0 deletions staker/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type L1ValidatorConfig struct {
ExtraGas uint64 `koanf:"extra-gas" reload:"hot"`
Dangerous DangerousConfig `koanf:"dangerous"`
ParentChainWallet genericconf.WalletConfig `koanf:"parent-chain-wallet"`
LogQueryBatchSize uint64 `koanf:"log-query-batch-size" reload:"hot"`

strategy StakerStrategy
gasRefunder common.Address
Expand Down Expand Up @@ -156,6 +157,7 @@ var DefaultL1ValidatorConfig = L1ValidatorConfig{
ExtraGas: 50000,
Dangerous: DefaultDangerousConfig,
ParentChainWallet: DefaultValidatorL1WalletConfig,
LogQueryBatchSize: 0,
}

var TestL1ValidatorConfig = L1ValidatorConfig{
Expand All @@ -176,6 +178,7 @@ var TestL1ValidatorConfig = L1ValidatorConfig{
ExtraGas: 50000,
Dangerous: DefaultDangerousConfig,
ParentChainWallet: DefaultValidatorL1WalletConfig,
LogQueryBatchSize: 0,
}

var DefaultValidatorL1WalletConfig = genericconf.WalletConfig{
Expand All @@ -201,6 +204,7 @@ func L1ValidatorConfigAddOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".gas-refunder-address", DefaultL1ValidatorConfig.GasRefunderAddress, "The gas refunder contract address (optional)")
f.String(prefix+".redis-url", DefaultL1ValidatorConfig.RedisUrl, "redis url for L1 validator")
f.Uint64(prefix+".extra-gas", DefaultL1ValidatorConfig.ExtraGas, "use this much more gas than estimation says is necessary to post transactions")
f.Uint64(prefix+".log-query-batch-size", DefaultL1ValidatorConfig.LogQueryBatchSize, "range ro query from eth_getLogs")
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfigForValidator)
DangerousConfigAddOptions(prefix+".dangerous", f)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultL1ValidatorConfig.ParentChainWallet.Pathname)
Expand Down

0 comments on commit a09a8a1

Please sign in to comment.