diff --git a/rocketpool/watchtower/generate-rewards-tree.go b/rocketpool/watchtower/generate-rewards-tree.go index 640f66bfc..092e37a02 100644 --- a/rocketpool/watchtower/generate-rewards-tree.go +++ b/rocketpool/watchtower/generate-rewards-tree.go @@ -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 diff --git a/shared/services/rewards/generator-impl-v8-rolling.go b/shared/services/rewards/generator-impl-v8-rolling.go index 8190c19bf..6be877316 100644 --- a/shared/services/rewards/generator-impl-v8-rolling.go +++ b/shared/services/rewards/generator-impl-v8-rolling.go @@ -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 @@ -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 @@ -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 @@ -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) } diff --git a/shared/services/rewards/generator-impl-v8.go b/shared/services/rewards/generator-impl-v8.go index 0dab12bad..154de5f24 100644 --- a/shared/services/rewards/generator-impl-v8.go +++ b/shared/services/rewards/generator-impl-v8.go @@ -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 @@ -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 @@ -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 @@ -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 } @@ -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) } diff --git a/shared/services/rewards/generator-impl-v9-rolling.go b/shared/services/rewards/generator-impl-v9-rolling.go index a1d2b00a8..96a316351 100644 --- a/shared/services/rewards/generator-impl-v9-rolling.go +++ b/shared/services/rewards/generator-impl-v9-rolling.go @@ -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 @@ -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 @@ -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 @@ -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) } diff --git a/shared/services/rewards/generator-impl-v9.go b/shared/services/rewards/generator-impl-v9.go index 6d7d1e9b1..05183ca0f 100644 --- a/shared/services/rewards/generator-impl-v9.go +++ b/shared/services/rewards/generator-impl-v9.go @@ -31,35 +31,35 @@ var _ IRewardsFile = (*ssz_types.SSZFile_v1)(nil) // Implementation for tree generator ruleset v9 type treeGeneratorImpl_v9 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 - 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 - 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 + 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 + minipoolPerformanceFile *MinipoolPerformanceFile_v2 + nodeRewards map[common.Address]*ssz_types.NodeReward + networkRewards map[ssz_types.Layer]*ssz_types.NetworkReward } // Create a new tree generator @@ -105,21 +105,21 @@ func (r *treeGeneratorImpl_v9) getRulesetVersion() uint64 { return r.rewardsFile.RulesetVersion } -func (r *treeGeneratorImpl_v9) generateTree(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*GenerateTreeResult, error) { +func (r *treeGeneratorImpl_v9) 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 @@ -190,19 +190,18 @@ func (r *treeGeneratorImpl_v9) 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_v9) approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*big.Int, error) { +func (r *treeGeneratorImpl_v9) 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 @@ -505,7 +504,7 @@ func (r *treeGeneratorImpl_v9) 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, r.opts) if err != nil { return err } @@ -1183,6 +1182,6 @@ func (r *treeGeneratorImpl_v9) getMinipoolBondAndNodeFee(details *rpstate.Native return currentBond, currentFee } -func (r *treeGeneratorImpl_v9) saveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) { - return saveRewardsArtifacts(r.cfg.Smartnode, treeResult, nodeTrusted) +func (r *treeGeneratorImpl_v9) saveFiles(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) { + return saveRewardsArtifacts(smartnode, treeResult, nodeTrusted) } diff --git a/shared/services/rewards/generator.go b/shared/services/rewards/generator.go index a1f43f060..5153b18e0 100644 --- a/shared/services/rewards/generator.go +++ b/shared/services/rewards/generator.go @@ -84,11 +84,11 @@ type SnapshotEnd struct { } type treeGeneratorImpl interface { - generateTree(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*GenerateTreeResult, error) - approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client) (*big.Int, error) + generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) + approximateStakerShareOfSmoothingPool(rp *rocketpool.RocketPool, networkName string, bc beacon.Client) (*big.Int, error) getRulesetVersion() uint64 // Returns the primary artifact cid for consensus, all cids of all files in a map, and any potential errors - saveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) + saveFiles(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) } func NewTreeGenerator(logger *log.ColorLogger, logPrefix string, rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, bc beacon.Client, index uint64, startTime time.Time, endTime time.Time, snapshotEnd *SnapshotEnd, elSnapshotHeader *types.Header, intervalsPassed uint64, state *state.NetworkState, rollingRecord *RollingRecord) (*TreeGenerator, error) { @@ -195,11 +195,11 @@ type GenerateTreeResult struct { } func (t *TreeGenerator) GenerateTree() (*GenerateTreeResult, error) { - return t.generatorImpl.generateTree(t.rp, t.cfg, t.bc) + return t.generatorImpl.generateTree(t.rp, fmt.Sprint(t.cfg.Smartnode.Network.Value), t.cfg.Smartnode.GetPreviousRewardsPoolAddresses(), t.bc) } func (t *TreeGenerator) ApproximateStakerShareOfSmoothingPool() (*big.Int, error) { - return t.approximatorImpl.approximateStakerShareOfSmoothingPool(t.rp, t.cfg, t.bc) + return t.approximatorImpl.approximateStakerShareOfSmoothingPool(t.rp, fmt.Sprint(t.cfg.Smartnode.Network.Value), t.bc) } func (t *TreeGenerator) GetGeneratorRulesetVersion() uint64 { @@ -216,7 +216,12 @@ func (t *TreeGenerator) GenerateTreeWithRuleset(ruleset uint64) (*GenerateTreeRe return nil, fmt.Errorf("ruleset v%d does not exist", ruleset) } - return info.generator.generateTree(t.rp, t.cfg, t.bc) + return info.generator.generateTree( + t.rp, + fmt.Sprint(t.cfg.Smartnode.Network.Value), + t.cfg.Smartnode.GetPreviousRewardsPoolAddresses(), + t.bc, + ) } func (t *TreeGenerator) ApproximateStakerShareOfSmoothingPoolWithRuleset(ruleset uint64) (*big.Int, error) { @@ -225,9 +230,9 @@ func (t *TreeGenerator) ApproximateStakerShareOfSmoothingPoolWithRuleset(ruleset return nil, fmt.Errorf("ruleset v%d does not exist", ruleset) } - return info.generator.approximateStakerShareOfSmoothingPool(t.rp, t.cfg, t.bc) + return info.generator.approximateStakerShareOfSmoothingPool(t.rp, fmt.Sprint(t.cfg.Smartnode.Network.Value), t.bc) } func (t *TreeGenerator) SaveFiles(treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) { - return t.generatorImpl.saveFiles(treeResult, nodeTrusted) + return t.generatorImpl.saveFiles(t.cfg.Smartnode, treeResult, nodeTrusted) } diff --git a/shared/services/rewards/rewards-file-v1.go b/shared/services/rewards/rewards-file-v1.go index 452f012fc..1e475fd25 100644 --- a/shared/services/rewards/rewards-file-v1.go +++ b/shared/services/rewards/rewards-file-v1.go @@ -201,6 +201,16 @@ func (f *RewardsFile_v1) GetConsensusEndBlock() uint64 { return f.RewardsFileHeader.ConsensusEndBlock } +// Get the start time +func (f *RewardsFile_v1) GetStartTime() time.Time { + return f.RewardsFileHeader.StartTime +} + +// Get the end time +func (f *RewardsFile_v1) GetEndTime() time.Time { + return f.RewardsFileHeader.EndTime +} + // Get all of the node addresses with rewards in this file // NOTE: the order of node addresses is not guaranteed to be stable, so don't rely on it func (f *RewardsFile_v1) GetNodeAddresses() []common.Address { diff --git a/shared/services/rewards/rewards-file-v2.go b/shared/services/rewards/rewards-file-v2.go index 27b02e97c..bdcbef9fe 100644 --- a/shared/services/rewards/rewards-file-v2.go +++ b/shared/services/rewards/rewards-file-v2.go @@ -198,6 +198,16 @@ func (f *RewardsFile_v2) GetConsensusEndBlock() uint64 { return f.RewardsFileHeader.ConsensusEndBlock } +// Get the start time +func (f *RewardsFile_v2) GetStartTime() time.Time { + return f.RewardsFileHeader.StartTime +} + +// Get the end time +func (f *RewardsFile_v2) GetEndTime() time.Time { + return f.RewardsFileHeader.EndTime +} + // Get all of the node addresses with rewards in this file // NOTE: the order of node addresses is not guaranteed to be stable, so don't rely on it func (f *RewardsFile_v2) GetNodeAddresses() []common.Address { diff --git a/shared/services/rewards/rewards-file-v3.go b/shared/services/rewards/rewards-file-v3.go index 374ab6b99..c8771b92b 100644 --- a/shared/services/rewards/rewards-file-v3.go +++ b/shared/services/rewards/rewards-file-v3.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/goccy/go-json" @@ -102,16 +103,26 @@ func (f *RewardsFile_v3) GetTotalNodeOperatorSmoothingPoolEth() *big.Int { return &f.RewardsFileHeader.TotalRewards.NodeOperatorSmoothingPoolEth.Int } -// Get the the execution end block +// Get the execution end block func (f *RewardsFile_v3) GetExecutionEndBlock() uint64 { return f.RewardsFileHeader.ExecutionEndBlock } -// Get the the consensus end block +// Get the consensus end block func (f *RewardsFile_v3) GetConsensusEndBlock() uint64 { return f.RewardsFileHeader.ConsensusEndBlock } +// Get the start time +func (f *RewardsFile_v3) GetStartTime() time.Time { + return f.RewardsFileHeader.StartTime +} + +// Get the end time +func (f *RewardsFile_v3) GetEndTime() time.Time { + return f.RewardsFileHeader.EndTime +} + // Get all of the node addresses with rewards in this file // NOTE: the order of node addresses is not guaranteed to be stable, so don't rely on it func (f *RewardsFile_v3) GetNodeAddresses() []common.Address { diff --git a/shared/services/rewards/ssz_types/rewards-file-v4.go b/shared/services/rewards/ssz_types/rewards-file-v4.go index 78f7d361e..9af686578 100644 --- a/shared/services/rewards/ssz_types/rewards-file-v4.go +++ b/shared/services/rewards/ssz_types/rewards-file-v4.go @@ -446,6 +446,14 @@ func (f *SSZFile_v1) GetExecutionEndBlock() uint64 { return f.ExecutionEndBlock } +func (f *SSZFile_v1) GetStartTime() time.Time { + return f.StartTime +} + +func (f *SSZFile_v1) GetEndTime() time.Time { + return f.EndTime +} + func (f *SSZFile_v1) GetIntervalsPassed() uint64 { return f.IntervalsPassed } diff --git a/shared/services/rewards/types.go b/shared/services/rewards/types.go index 6ac11f6a9..4a33e0fe0 100644 --- a/shared/services/rewards/types.go +++ b/shared/services/rewards/types.go @@ -65,6 +65,8 @@ type IRewardsFile interface { GetTotalPoolStakerSmoothingPoolEth() *big.Int GetExecutionEndBlock() uint64 GetConsensusEndBlock() uint64 + GetStartTime() time.Time + GetEndTime() time.Time // Get all of the node addresses with rewards in this file // NOTE: the order of node addresses is not guaranteed to be stable, so don't rely on it diff --git a/shared/services/rewards/utils.go b/shared/services/rewards/utils.go index ebb1cc201..d255434a3 100644 --- a/shared/services/rewards/utils.go +++ b/shared/services/rewards/utils.go @@ -88,8 +88,11 @@ func GetIntervalInfo(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, no info.Index = interval var event rewards.RewardsEvent + // Get previous rewards pool addresses + previousRewardsPoolAddresses := cfg.Smartnode.GetPreviousRewardsPoolAddresses() + // Get the event details for this interval - event, err = GetRewardSnapshotEvent(rp, cfg, interval, opts) + event, err = GetRewardSnapshotEvent(rp, previousRewardsPoolAddresses, interval, opts) if err != nil { return } @@ -152,10 +155,9 @@ func GetIntervalInfo(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, no } // Get the event for a rewards snapshot -func GetRewardSnapshotEvent(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error) { +func GetRewardSnapshotEvent(rp *rocketpool.RocketPool, previousRewardsPoolAddresses []common.Address, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error) { - addresses := cfg.Smartnode.GetPreviousRewardsPoolAddresses() - found, event, err := rewards.GetRewardsEvent(rp, interval, addresses, opts) + found, event, err := rewards.GetRewardsEvent(rp, interval, previousRewardsPoolAddresses, opts) if err != nil { return rewards.RewardsEvent{}, fmt.Errorf("error getting rewards event for interval %d: %w", interval, err) } diff --git a/shared/services/state/utils.go b/shared/services/state/utils.go index b09b06c28..d7bb23dd0 100644 --- a/shared/services/state/utils.go +++ b/shared/services/state/utils.go @@ -7,31 +7,30 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/rocket-pool/rocketpool-go/rewards" "github.com/rocket-pool/rocketpool-go/rocketpool" - "github.com/rocket-pool/smartnode/shared/services/config" ) // TODO: temp until rocketpool-go supports RocketStorage contract address lookups per block -func GetClaimIntervalTime(cfg *config.RocketPoolConfig, index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (time.Duration, error) { +func GetClaimIntervalTime(index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (time.Duration, error) { return rewards.GetClaimIntervalTime(rp, opts) } // TODO: temp until rocketpool-go supports RocketStorage contract address lookups per block -func GetNodeOperatorRewardsPercent(cfg *config.RocketPoolConfig, index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { +func GetNodeOperatorRewardsPercent(index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { return rewards.GetNodeOperatorRewardsPercent(rp, opts) } // TODO: temp until rocketpool-go supports RocketStorage contract address lookups per block -func GetTrustedNodeOperatorRewardsPercent(cfg *config.RocketPoolConfig, index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { +func GetTrustedNodeOperatorRewardsPercent(index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { return rewards.GetTrustedNodeOperatorRewardsPercent(rp, opts) } // TODO: temp until rocketpool-go supports RocketStorage contract address lookups per block -func GetProtocolDaoRewardsPercent(cfg *config.RocketPoolConfig, index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { +func GetProtocolDaoRewardsPercent(index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { return rewards.GetProtocolDaoRewardsPercent(rp, opts) } // TODO: temp until rocketpool-go supports RocketStorage contract address lookups per block -func GetPendingRPLRewards(cfg *config.RocketPoolConfig, index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { +func GetPendingRPLRewards(index uint64, rp *rocketpool.RocketPool, opts *bind.CallOpts) (*big.Int, error) { return rewards.GetPendingRPLRewards(rp, opts) }