Skip to content

Commit c586733

Browse files
committed
remove RR, add fgprof, support v10
1 parent 5a99db6 commit c586733

2 files changed

Lines changed: 36 additions & 99 deletions

File tree

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"runtime"
77
"runtime/pprof"
88

9+
"github.com/felixge/fgprof"
910
"github.com/urfave/cli/v2"
1011
)
1112

@@ -105,6 +106,11 @@ func main() {
105106
Aliases: []string{"m"},
106107
Usage: "Path to which to save a pprof heap profile, e.g. ./treegen.pprof. If unset, profiling is disabled.",
107108
},
109+
&cli.StringFlag{
110+
Name: "fgprof",
111+
Aliases: []string{"f"},
112+
Usage: "Path to which to save a fgprof profile, e.g. ./treegen.pprof. If unset, profiling is disabled.",
113+
},
108114
}
109115

110116
app.Action = func(c *cli.Context) error {
@@ -139,6 +145,22 @@ func main() {
139145
}()
140146
}
141147

148+
fgprofile := c.String("fgprof")
149+
if fgprofile != "" {
150+
f, err := os.Create(fgprofile)
151+
if err != nil {
152+
fmt.Printf("%sError saving heap profile: %w%w\n", colorRed, err, colorReset)
153+
os.Exit(1)
154+
}
155+
closure := fgprof.Start(f, fgprof.FormatPprof)
156+
defer func() {
157+
err := closure()
158+
if err != nil {
159+
fmt.Fprintf(os.Stderr, "Error stopping fgprof: %s\n", err.Error())
160+
}
161+
}()
162+
}
163+
142164
return GenerateTree(c)
143165
}
144166

tree-gen.go

Lines changed: 14 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ type treeGenerator struct {
9191
log *log.ColorLogger
9292
errLog *log.ColorLogger
9393
rp rprewards.RewardsExecutionClient
94+
rpNative *rocketpool.RocketPool
9495
cfg *config.RocketPoolConfig
9596
mgr *state.NetworkStateManager
96-
recordMgr *rprewards.RollingRecordManager
9797
bn beacon.Client
9898
beaconConfig beacon.Eth2Config
9999
targets targets
@@ -171,6 +171,7 @@ func GenerateTree(c *cli.Context) error {
171171
log: &logger,
172172
errLog: &errLogger,
173173
rp: rprewards.NewRewardsExecutionClient(rp),
174+
rpNative: rp,
174175
cfg: cfg,
175176
bn: bn,
176177
mgr: mgr,
@@ -493,88 +494,8 @@ func (g *treeGenerator) writeFiles(result *rprewards.GenerateTreeResult) error {
493494
return nil
494495
}
495496

496-
// Create the manager for rolling records to use (if applicable) and update the record to the target slot
497-
func (g *treeGenerator) prepareRecordManager(args *treegenArguments) error {
498-
// Ignore this on old rulesets without rolling records
499-
if g.ruleset < 6 && g.ruleset > 0 {
500-
g.log.Printlnf("Ruleset %d does not use rolling records, ignoring them.", g.ruleset)
501-
return nil
502-
}
503-
504-
// Get the target index
505-
ignoreRollingRecords := false
506-
var index uint64
507-
if g.targets.rewardsEvent != nil {
508-
index = g.targets.rewardsEvent.Index.Uint64()
509-
} else {
510-
index = g.targets.snapshotDetails.index
511-
}
512-
513-
// Ignore rolling records for the first interval
514-
if index == 0 {
515-
g.log.Println("Interval 0 cannot use rolling records because there was no previous event to indicate when to start collecting records, ignoring them.")
516-
return nil
517-
}
518-
519-
// If a ruleset isn't specified, check if the interval is before v6
520-
if g.ruleset == 0 {
521-
network := g.cfg.Smartnode.Network.Value.(cfgtypes.Network)
522-
switch network {
523-
case cfgtypes.Network_Mainnet:
524-
ignoreRollingRecords = (index < rprewards.MainnetV8Interval)
525-
default:
526-
return fmt.Errorf("unknown network [%v]", network)
527-
}
528-
}
529-
530-
// Ignore this on old intervals without rolling records
531-
if ignoreRollingRecords {
532-
g.log.Printlnf("Rewards interval %d cannot use rolling records because it used an older ruleset, ignoring them.", index)
533-
return nil
534-
}
535-
536-
// Rolling records are supported, build up the manager
537-
var err error
538-
g.recordMgr, err = rprewards.NewRollingRecordManager(g.log, g.errLog, g.cfg, g.rp, g.bn, g.mgr, args.startSlot, g.beaconConfig, index)
539-
if err != nil {
540-
return fmt.Errorf("error creating rolling record manager: %w", err)
541-
}
542-
543-
// Determine the target slot for tree generation
544-
var targetSlot uint64
545-
if g.targets.rewardsEvent != nil {
546-
targetSlot = g.targets.rewardsEvent.ConsensusBlock.Uint64()
547-
} else {
548-
targetSlot = g.targets.snapshotDetails.snapshotBeaconBlock
549-
}
550-
551-
// Create and update the record to that slot
552-
g.log.Printlnf("Generation supports rolling records - creating a new record manager.")
553-
record, err := g.recordMgr.GenerateRecordForState(args.state)
554-
if err != nil {
555-
return fmt.Errorf("error creating record for slot %d: %w", targetSlot, err)
556-
}
557-
g.recordMgr.Record = record
558-
559-
return nil
560-
}
561-
562497
// Creates a tree generator using the provided arguments
563498
func (g *treeGenerator) getGenerator(args *treegenArguments) (*rprewards.TreeGenerator, error) {
564-
// Prepare the rolling record manager and record if applicable
565-
if g.useRollingRecords {
566-
g.log.Println("Rolling records are enabled, preparing rolling manager.")
567-
err := g.prepareRecordManager(args)
568-
if err != nil {
569-
return nil, fmt.Errorf("error preparing rolling record: %w", err)
570-
}
571-
} else {
572-
g.log.Println("Rolling records are not enabled, ignoring them.")
573-
}
574-
var record *rprewards.RollingRecord = nil
575-
if g.recordMgr != nil {
576-
record = g.recordMgr.Record
577-
}
578499

579500
// Create the tree generator
580501
out, err := rprewards.NewTreeGenerator(
@@ -585,7 +506,7 @@ func (g *treeGenerator) getGenerator(args *treegenArguments) (*rprewards.TreeGen
585506
ConsensusBlock: args.block.Slot,
586507
ExecutionBlock: args.elBlockHeader.Number.Uint64(),
587508
}, args.elBlockHeader,
588-
args.intervalsPassed, args.state, record)
509+
args.intervalsPassed, args.state)
589510
if err != nil {
590511
return nil, fmt.Errorf("error creating tree generator: %w", err)
591512
}
@@ -610,11 +531,11 @@ func (g *treeGenerator) approximateRethSpRewards() error {
610531
args.block.Slot, opts.BlockNumber.Uint64(), args.startTime, args.endTime)
611532

612533
// Get the Smoothing Pool contract's balance
613-
smoothingPoolContract, err := g.rp.Client().GetContract("rocketSmoothingPool", opts)
534+
smoothingPoolContract, err := g.rpNative.GetContract("rocketSmoothingPool", opts)
614535
if err != nil {
615536
return fmt.Errorf("error getting smoothing pool contract: %w", err)
616537
}
617-
smoothingPoolBalance, err := g.rp.Client().Client.BalanceAt(context.Background(), *smoothingPoolContract.Address, opts.BlockNumber)
538+
smoothingPoolBalance, err := g.rpNative.Client.BalanceAt(context.Background(), *smoothingPoolContract.Address, opts.BlockNumber)
618539
if err != nil {
619540
return fmt.Errorf("error getting smoothing pool balance: %w", err)
620541
}
@@ -696,22 +617,16 @@ func (g *treeGenerator) getSnapshotDetails() (*snapshotDetails, error) {
696617
// Get the number of the EL block matching the CL snapshot block
697618
var snapshotElBlockHeader *types.Header
698619
if g.targets.block.ExecutionBlockNumber == 0 {
699-
// No EL data so the Merge hasn't happened yet, figure out the EL block based on the Epoch ending time
700-
snapshotElBlockHeader, err = rprewards.GetELBlockHeaderForTime(endTime, g.rp)
701-
if err != nil {
702-
return nil, fmt.Errorf("error getting EL block for time %s: %w", endTime, err)
703-
}
704-
opts.BlockNumber = snapshotElBlockHeader.Number
705-
} else {
706-
opts.BlockNumber = big.NewInt(0).SetUint64(g.targets.block.ExecutionBlockNumber)
707-
snapshotElBlockHeader, err = g.rp.HeaderByNumber(context.Background(), opts.BlockNumber)
708-
if err != nil {
709-
return nil, fmt.Errorf("error getting EL block %d: %w", opts.BlockNumber.Uint64(), err)
710-
}
620+
return nil, fmt.Errorf("slot %d was pre-merge", g.targets.block.Slot)
621+
}
622+
opts.BlockNumber = big.NewInt(0).SetUint64(g.targets.block.ExecutionBlockNumber)
623+
snapshotElBlockHeader, err = g.rp.HeaderByNumber(context.Background(), opts.BlockNumber)
624+
if err != nil {
625+
return nil, fmt.Errorf("error getting EL block %d: %w", opts.BlockNumber.Uint64(), err)
711626
}
712627

713628
// Get the interval index
714-
indexBig, err := rewards.GetRewardIndex(g.rp.Client(), &opts)
629+
indexBig, err := g.rpNative.GetRewardIndex(&opts)
715630
if err != nil {
716631
return nil, fmt.Errorf("error getting current reward index: %w", err)
717632
}
@@ -736,11 +651,11 @@ func (g *treeGenerator) getSnapshotDetails() (*snapshotDetails, error) {
736651
}
737652

738653
// Get the start time for the interval, and how long an interval is supposed to take
739-
startTime, err := rewards.GetClaimIntervalTimeStart(g.rp.Client(), &opts)
654+
startTime, err := rewards.GetClaimIntervalTimeStart(g.rpNative, &opts)
740655
if err != nil {
741656
return nil, fmt.Errorf("error getting claim interval start time: %w", err)
742657
}
743-
intervalTime, err := rewards.GetClaimIntervalTime(g.rp.Client(), &opts)
658+
intervalTime, err := rewards.GetClaimIntervalTime(g.rpNative, &opts)
744659
if err != nil {
745660
return nil, fmt.Errorf("error getting claim interval time: %w", err)
746661
}

0 commit comments

Comments
 (0)