Skip to content

Commit

Permalink
Remove RocketPoolConfig dependency from treegen
Browse files Browse the repository at this point in the history
  • Loading branch information
jshufro committed Sep 25, 2024
1 parent 400edce commit 19ca26b
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 161 deletions.
5 changes: 4 additions & 1 deletion rocketpool/watchtower/generate-rewards-tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ func (t *generateRewardsTree) generateRewardsTree(index uint64) {
generationPrefix := fmt.Sprintf("[Interval %d Tree]", index)
t.log.Printlnf("%s Starting generation of Merkle rewards tree for interval %d.", generationPrefix, index)

// Get previous rewards pool addresses
previousRewardsPoolAddresses := t.cfg.Smartnode.GetPreviousRewardsPoolAddresses()

// Find the event for this interval
rewardsEvent, err := rprewards.GetRewardSnapshotEvent(t.rp, t.cfg, index, nil)
rewardsEvent, err := rprewards.GetRewardSnapshotEvent(t.rp, previousRewardsPoolAddresses, index, nil)
if err != nil {
t.handleError(fmt.Errorf("%s Error getting event for interval %d: %w", generationPrefix, index, err))
return
Expand Down
59 changes: 29 additions & 30 deletions shared/services/rewards/generator-impl-v8-rolling.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ import (

// Implementation for tree generator ruleset v8 with rolling record support
type treeGeneratorImpl_v8_rolling struct {
networkState *state.NetworkState
rewardsFile *RewardsFile_v3
elSnapshotHeader *types.Header
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
cfg *config.RocketPoolConfig
bc beacon.Client
opts *bind.CallOpts
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
rollingRecord *RollingRecord
nodeDetails map[common.Address]*NodeSmoothingDetails
invalidNetworkNodes map[common.Address]uint64
networkState *state.NetworkState
rewardsFile *RewardsFile_v3
elSnapshotHeader *types.Header
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
previousRewardsPoolAddresses []common.Address
bc beacon.Client
opts *bind.CallOpts
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
rollingRecord *RollingRecord
nodeDetails map[common.Address]*NodeSmoothingDetails
invalidNetworkNodes map[common.Address]uint64
}

// Create a new tree generator
Expand Down Expand Up @@ -97,20 +97,20 @@ func (r *treeGeneratorImpl_v8_rolling) getRulesetVersion() uint64 {
return r.rewardsFile.RulesetVersion
}

func (r *treeGeneratorImpl_v8_rolling) generateTree(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*GenerateTreeResult, error) {
func (r *treeGeneratorImpl_v8_rolling) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) {

r.log.Printlnf("%s Generating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

// Provision some struct params
r.rp = rp
r.cfg = cfg
r.previousRewardsPoolAddresses = previousRewardsPoolAddresses
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network = networkName
r.rewardsFile.MinipoolPerformanceFile.Network = r.rewardsFile.Network
r.rewardsFile.MinipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.rewardsFile.MinipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion
Expand Down Expand Up @@ -173,18 +173,17 @@ func (r *treeGeneratorImpl_v8_rolling) generateTree(rp *rocketpool.RocketPool, c

// Quickly calculates an approximate of the staker's share of the smoothing pool balance without processing Beacon performance
// Used for approximate returns in the rETH ratio update
func (r *treeGeneratorImpl_v8_rolling) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*big.Int, error) {
func (r *treeGeneratorImpl_v8_rolling) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, networkName string, bc beacon.Client) (*big.Int, error) {
r.log.Printlnf("%s Approximating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

r.rp = rp
r.cfg = cfg
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network = networkName
r.rewardsFile.MinipoolPerformanceFile.Network = r.rewardsFile.Network
r.rewardsFile.MinipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.rewardsFile.MinipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion
Expand Down Expand Up @@ -812,6 +811,6 @@ func (r *treeGeneratorImpl_v8_rolling) getCheaters() map[common.Address]bool {
return cheatingNodes
}

func (r *treeGeneratorImpl_v8_rolling) saveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveJSONArtifacts(r.cfg.Smartnode, treeResult, nodeTrusted)
func (r *treeGeneratorImpl_v8_rolling) saveFiles(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveJSONArtifacts(smartnode, treeResult, nodeTrusted)
}
67 changes: 33 additions & 34 deletions shared/services/rewards/generator-impl-v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ var six = big.NewInt(6)

// Implementation for tree generator ruleset v8
type treeGeneratorImpl_v8 struct {
networkState *state.NetworkState
rewardsFile *RewardsFile_v3
elSnapshotHeader *types.Header
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
cfg *config.RocketPoolConfig
bc beacon.Client
opts *bind.CallOpts
nodeDetails []*NodeSmoothingDetails
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
validatorStatusMap map[rptypes.ValidatorPubkey]beacon.ValidatorStatus
totalAttestationScore *big.Int
successfulAttestations uint64
genesisTime time.Time
invalidNetworkNodes map[common.Address]uint64
networkState *state.NetworkState
rewardsFile *RewardsFile_v3
elSnapshotHeader *types.Header
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
previousRewardsPoolAddresses []common.Address
bc beacon.Client
opts *bind.CallOpts
nodeDetails []*NodeSmoothingDetails
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
validatorStatusMap map[rptypes.ValidatorPubkey]beacon.ValidatorStatus
totalAttestationScore *big.Int
successfulAttestations uint64
genesisTime time.Time
invalidNetworkNodes map[common.Address]uint64
}

// Create a new tree generator
Expand Down Expand Up @@ -104,20 +104,20 @@ func (r *treeGeneratorImpl_v8) getRulesetVersion() uint64 {
return r.rewardsFile.RulesetVersion
}

func (r *treeGeneratorImpl_v8) generateTree(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*GenerateTreeResult, error) {
func (r *treeGeneratorImpl_v8) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) {

r.log.Printlnf("%s Generating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

// Provision some struct params
r.rp = rp
r.cfg = cfg
r.previousRewardsPoolAddresses = previousRewardsPoolAddresses
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network = networkName
r.rewardsFile.MinipoolPerformanceFile.Network = r.rewardsFile.Network
r.rewardsFile.MinipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.rewardsFile.MinipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion
Expand Down Expand Up @@ -181,18 +181,17 @@ func (r *treeGeneratorImpl_v8) generateTree(rp *rocketpool.RocketPool, cfg *conf

// Quickly calculates an approximate of the staker's share of the smoothing pool balance without processing Beacon performance
// Used for approximate returns in the rETH ratio update
func (r *treeGeneratorImpl_v8) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*big.Int, error) {
func (r *treeGeneratorImpl_v8) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, networkName string, bc beacon.Client) (*big.Int, error) {
r.log.Printlnf("%s Approximating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

r.rp = rp
r.cfg = cfg
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network = networkName
r.rewardsFile.MinipoolPerformanceFile.Network = r.rewardsFile.Network
r.rewardsFile.MinipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.rewardsFile.MinipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion
Expand Down Expand Up @@ -536,7 +535,7 @@ func (r *treeGeneratorImpl_v8) calculateEthRewards(checkBeaconPerformance bool)

// Get the start time of this interval based on the event from the previous one
//previousIntervalEvent, err := GetRewardSnapshotEvent(r.rp, r.cfg, r.rewardsFile.Index-1, r.opts) // This is immutable so querying at the head is fine and mitigates issues around calls for pruned EL state
previousIntervalEvent, err := GetRewardSnapshotEvent(r.rp, r.cfg, r.rewardsFile.Index-1, nil)
previousIntervalEvent, err := GetRewardSnapshotEvent(r.rp, r.previousRewardsPoolAddresses, r.rewardsFile.Index-1, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -1207,6 +1206,6 @@ func (r *treeGeneratorImpl_v8) getMinipoolBondAndNodeFee(details *rpstate.Native
return currentBond, currentFee
}

func (r *treeGeneratorImpl_v8) saveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveJSONArtifacts(r.cfg.Smartnode, treeResult, nodeTrusted)
func (r *treeGeneratorImpl_v8) saveFiles(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveJSONArtifacts(smartnode, treeResult, nodeTrusted)
}
71 changes: 35 additions & 36 deletions shared/services/rewards/generator-impl-v9-rolling.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ import (

// Implementation for tree generator ruleset v9 with rolling record support
type treeGeneratorImpl_v9_rolling struct {
networkState *state.NetworkState
rewardsFile *ssz_types.SSZFile_v1
elSnapshotHeader *types.Header
snapshotEnd *SnapshotEnd
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
cfg *config.RocketPoolConfig
bc beacon.Client
opts *bind.CallOpts
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
rollingRecord *RollingRecord
nodeDetails map[common.Address]*NodeSmoothingDetails
invalidNetworkNodes map[common.Address]uint64
minipoolPerformanceFile *MinipoolPerformanceFile_v2
nodeRewards map[common.Address]*ssz_types.NodeReward
networkRewards map[ssz_types.Layer]*ssz_types.NetworkReward
networkState *state.NetworkState
rewardsFile *ssz_types.SSZFile_v1
elSnapshotHeader *types.Header
snapshotEnd *SnapshotEnd
log *log.ColorLogger
logPrefix string
rp *rocketpool.RocketPool
previousRewardsPoolAddresses []common.Address
bc beacon.Client
opts *bind.CallOpts
smoothingPoolBalance *big.Int
intervalDutiesInfo *IntervalDutiesInfo
slotsPerEpoch uint64
validatorIndexMap map[string]*MinipoolInfo
elStartTime time.Time
elEndTime time.Time
validNetworkCache map[uint64]bool
epsilon *big.Int
intervalSeconds *big.Int
beaconConfig beacon.Eth2Config
rollingRecord *RollingRecord
nodeDetails map[common.Address]*NodeSmoothingDetails
invalidNetworkNodes map[common.Address]uint64
minipoolPerformanceFile *MinipoolPerformanceFile_v2
nodeRewards map[common.Address]*ssz_types.NodeReward
networkRewards map[ssz_types.Layer]*ssz_types.NetworkReward
}

// Create a new tree generator
Expand Down Expand Up @@ -94,21 +94,21 @@ func (r *treeGeneratorImpl_v9_rolling) getRulesetVersion() uint64 {
return r.rewardsFile.RulesetVersion
}

func (r *treeGeneratorImpl_v9_rolling) generateTree(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*GenerateTreeResult, error) {
func (r *treeGeneratorImpl_v9_rolling) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) {

r.log.Printlnf("%s Generating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

// Provision some struct params
r.rp = rp
r.cfg = cfg
r.previousRewardsPoolAddresses = previousRewardsPoolAddresses
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network, _ = ssz_types.NetworkFromString(fmt.Sprint(cfg.Smartnode.Network.Value))
r.minipoolPerformanceFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network, _ = ssz_types.NetworkFromString(networkName)
r.minipoolPerformanceFile.Network = networkName
r.minipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.minipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion

Expand Down Expand Up @@ -178,19 +178,18 @@ func (r *treeGeneratorImpl_v9_rolling) generateTree(rp *rocketpool.RocketPool, c

// Quickly calculates an approximate of the staker's share of the smoothing pool balance without processing Beacon performance
// Used for approximate returns in the rETH ratio update
func (r *treeGeneratorImpl_v9_rolling) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*big.Int, error) {
func (r *treeGeneratorImpl_v9_rolling) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, networkName string, bc beacon.Client) (*big.Int, error) {
r.log.Printlnf("%s Approximating tree using Ruleset v%d.", r.logPrefix, r.rewardsFile.RulesetVersion)

r.rp = rp
r.cfg = cfg
r.bc = bc
r.validNetworkCache = map[uint64]bool{
0: true,
}

// Set the network name
r.rewardsFile.Network, _ = ssz_types.NetworkFromString(fmt.Sprint(cfg.Smartnode.Network.Value))
r.minipoolPerformanceFile.Network = fmt.Sprint(cfg.Smartnode.Network.Value)
r.rewardsFile.Network, _ = ssz_types.NetworkFromString(networkName)
r.minipoolPerformanceFile.Network = networkName
r.minipoolPerformanceFile.RewardsFileVersion = r.rewardsFile.RewardsFileVersion
r.minipoolPerformanceFile.RulesetVersion = r.rewardsFile.RulesetVersion

Expand Down Expand Up @@ -719,6 +718,6 @@ func (r *treeGeneratorImpl_v9_rolling) getCheaters() map[common.Address]bool {
return cheatingNodes
}

func (r *treeGeneratorImpl_v9_rolling) saveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveRewardsArtifacts(r.cfg.Smartnode, treeResult, nodeTrusted)
func (r *treeGeneratorImpl_v9_rolling) saveFiles(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) {
return saveRewardsArtifacts(smartnode, treeResult, nodeTrusted)
}
Loading

0 comments on commit 19ca26b

Please sign in to comment.