diff --git a/rocketpool/watchtower/generate-rewards-tree.go b/rocketpool/watchtower/generate-rewards-tree.go index 092e37a02..78d3ed9b6 100644 --- a/rocketpool/watchtower/generate-rewards-tree.go +++ b/rocketpool/watchtower/generate-rewards-tree.go @@ -142,8 +142,10 @@ func (t *generateRewardsTree) generateRewardsTree(index uint64) { // Get previous rewards pool addresses previousRewardsPoolAddresses := t.cfg.Smartnode.GetPreviousRewardsPoolAddresses() + rewardsClient := rprewards.NewRewardsExecutionClient(t.rp) + // Find the event for this interval - rewardsEvent, err := rprewards.GetRewardSnapshotEvent(t.rp, previousRewardsPoolAddresses, index, nil) + rewardsEvent, err := rewardsClient.GetRewardSnapshotEvent(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/execution-client.go b/shared/services/rewards/execution-client.go new file mode 100644 index 000000000..306d07e5f --- /dev/null +++ b/shared/services/rewards/execution-client.go @@ -0,0 +1,56 @@ +package rewards + +import ( + "context" + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/rocket-pool/rocketpool-go/rewards" + "github.com/rocket-pool/rocketpool-go/rocketpool" + "github.com/rocket-pool/rocketpool-go/settings/trustednode" +) + +// An implementation of RewardsExecutionClient that uses +// rocketpool-go to access chain data. +// +// Importantly, this struct instantiates rocketpool.RocketPool and passes it +// to the old fashioned rocketpool-go getters that take it as an argument +// but it also fulfills the requirements of an interface used for dependency injection +// in tests. +type defaultRewardsExecutionClient struct { + *rocketpool.RocketPool +} + +func NewRewardsExecutionClient(rp *rocketpool.RocketPool) (out *defaultRewardsExecutionClient) { + out.RocketPool = rp + return +} + +func (client *defaultRewardsExecutionClient) GetNetworkEnabled(networkId *big.Int, opts *bind.CallOpts) (bool, error) { + return trustednode.GetNetworkEnabled(client.RocketPool, networkId, opts) +} + +func (client *defaultRewardsExecutionClient) HeaderByNumber(ctx context.Context, block *big.Int) (*ethtypes.Header, error) { + return client.RocketPool.Client.HeaderByNumber(ctx, block) +} + +func (client *defaultRewardsExecutionClient) GetRewardsEvent(index uint64, rocketRewardsPoolAddresses []common.Address, opts *bind.CallOpts) (bool, rewards.RewardsEvent, error) { + return rewards.GetRewardsEvent(client.RocketPool, index, rocketRewardsPoolAddresses, opts) +} + +func (client *defaultRewardsExecutionClient) GetRewardSnapshotEvent(previousRewardsPoolAddresses []common.Address, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error) { + + found, event, err := client.GetRewardsEvent(interval, previousRewardsPoolAddresses, opts) + if err != nil { + return rewards.RewardsEvent{}, fmt.Errorf("error getting rewards event for interval %d: %w", interval, err) + } + if !found { + return rewards.RewardsEvent{}, fmt.Errorf("interval %d event not found", interval) + } + + return event, nil + +} diff --git a/shared/services/rewards/generator-impl-v8-rolling.go b/shared/services/rewards/generator-impl-v8-rolling.go index 6be877316..8e1cab814 100644 --- a/shared/services/rewards/generator-impl-v8-rolling.go +++ b/shared/services/rewards/generator-impl-v8-rolling.go @@ -12,8 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ipfs/go-cid" - "github.com/rocket-pool/rocketpool-go/rocketpool" - tnsettings "github.com/rocket-pool/rocketpool-go/settings/trustednode" "github.com/rocket-pool/rocketpool-go/utils/eth" "github.com/rocket-pool/smartnode/shared/services/beacon" "github.com/rocket-pool/smartnode/shared/services/config" @@ -30,7 +28,7 @@ type treeGeneratorImpl_v8_rolling struct { elSnapshotHeader *types.Header log *log.ColorLogger logPrefix string - rp *rocketpool.RocketPool + rp RewardsExecutionClient previousRewardsPoolAddresses []common.Address bc beacon.Client opts *bind.CallOpts @@ -97,7 +95,7 @@ func (r *treeGeneratorImpl_v8_rolling) getRulesetVersion() uint64 { return r.rewardsFile.RulesetVersion } -func (r *treeGeneratorImpl_v8_rolling) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) { +func (r *treeGeneratorImpl_v8_rolling) generateTree(rp RewardsExecutionClient, 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) @@ -173,7 +171,7 @@ func (r *treeGeneratorImpl_v8_rolling) generateTree(rp *rocketpool.RocketPool, n // 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, networkName string, bc beacon.Client) (*big.Int, error) { +func (r *treeGeneratorImpl_v8_rolling) approximateStakerShareOfSmoothingPool(rp RewardsExecutionClient, 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 @@ -758,7 +756,7 @@ func (r *treeGeneratorImpl_v8_rolling) validateNetwork(network uint64) (bool, er valid, exists := r.validNetworkCache[network] if !exists { var err error - valid, err = tnsettings.GetNetworkEnabled(r.rp, big.NewInt(int64(network)), r.opts) + valid, err = r.rp.GetNetworkEnabled(big.NewInt(int64(network)), r.opts) if err != nil { return false, err } @@ -785,7 +783,7 @@ func (r *treeGeneratorImpl_v8_rolling) getStartBlocksForInterval() (*types.Heade elBlockNumber := beaconBlock.ExecutionBlockNumber r.rewardsFile.ExecutionStartBlock = elBlockNumber r.rewardsFile.MinipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err := r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) + startElHeader, err := r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) if err != nil { return nil, fmt.Errorf("error getting EL header for block %d: %w", elBlockNumber, err) } diff --git a/shared/services/rewards/generator-impl-v8.go b/shared/services/rewards/generator-impl-v8.go index 154de5f24..d3f3eca1f 100644 --- a/shared/services/rewards/generator-impl-v8.go +++ b/shared/services/rewards/generator-impl-v8.go @@ -12,8 +12,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ipfs/go-cid" "github.com/rocket-pool/rocketpool-go/rewards" - "github.com/rocket-pool/rocketpool-go/rocketpool" - tnsettings "github.com/rocket-pool/rocketpool-go/settings/trustednode" rptypes "github.com/rocket-pool/rocketpool-go/types" "github.com/rocket-pool/rocketpool-go/utils/eth" rpstate "github.com/rocket-pool/rocketpool-go/utils/state" @@ -33,7 +31,7 @@ type treeGeneratorImpl_v8 struct { elSnapshotHeader *types.Header log *log.ColorLogger logPrefix string - rp *rocketpool.RocketPool + rp RewardsExecutionClient previousRewardsPoolAddresses []common.Address bc beacon.Client opts *bind.CallOpts @@ -104,7 +102,7 @@ func (r *treeGeneratorImpl_v8) getRulesetVersion() uint64 { return r.rewardsFile.RulesetVersion } -func (r *treeGeneratorImpl_v8) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) { +func (r *treeGeneratorImpl_v8) generateTree(rp RewardsExecutionClient, 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) @@ -181,7 +179,7 @@ func (r *treeGeneratorImpl_v8) generateTree(rp *rocketpool.RocketPool, networkNa // 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, networkName string, bc beacon.Client) (*big.Int, error) { +func (r *treeGeneratorImpl_v8) approximateStakerShareOfSmoothingPool(rp RewardsExecutionClient, 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 @@ -535,7 +533,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.previousRewardsPoolAddresses, r.rewardsFile.Index-1, nil) + previousIntervalEvent, err := r.rp.GetRewardSnapshotEvent(r.previousRewardsPoolAddresses, r.rewardsFile.Index-1, nil) if err != nil { return err } @@ -1116,7 +1114,7 @@ func (r *treeGeneratorImpl_v8) validateNetwork(network uint64) (bool, error) { valid, exists := r.validNetworkCache[network] if !exists { var err error - valid, err = tnsettings.GetNetworkEnabled(r.rp, big.NewInt(int64(network)), r.opts) + valid, err = r.rp.GetNetworkEnabled(big.NewInt(int64(network)), r.opts) if err != nil { return false, err } @@ -1163,7 +1161,7 @@ func (r *treeGeneratorImpl_v8) getStartBlocksForInterval(previousIntervalEvent r // We are pre-merge, so get the first block after the one from the previous interval r.rewardsFile.ExecutionStartBlock = previousIntervalEvent.ExecutionBlock.Uint64() + 1 r.rewardsFile.MinipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err = r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(r.rewardsFile.ExecutionStartBlock))) + startElHeader, err = r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(r.rewardsFile.ExecutionStartBlock))) if err != nil { return nil, fmt.Errorf("error getting EL start block %d: %w", r.rewardsFile.ExecutionStartBlock, err) } @@ -1171,7 +1169,7 @@ func (r *treeGeneratorImpl_v8) getStartBlocksForInterval(previousIntervalEvent r // We are post-merge, so get the EL block corresponding to the BC block r.rewardsFile.ExecutionStartBlock = elBlockNumber r.rewardsFile.MinipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err = r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) + startElHeader, err = r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) if err != nil { return nil, fmt.Errorf("error getting EL header for block %d: %w", elBlockNumber, err) } diff --git a/shared/services/rewards/generator-impl-v9-rolling.go b/shared/services/rewards/generator-impl-v9-rolling.go index 96a316351..c50366c52 100644 --- a/shared/services/rewards/generator-impl-v9-rolling.go +++ b/shared/services/rewards/generator-impl-v9-rolling.go @@ -11,8 +11,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ipfs/go-cid" - "github.com/rocket-pool/rocketpool-go/rocketpool" - tnsettings "github.com/rocket-pool/rocketpool-go/settings/trustednode" "github.com/rocket-pool/rocketpool-go/utils/eth" "github.com/rocket-pool/smartnode/shared/services/beacon" "github.com/rocket-pool/smartnode/shared/services/config" @@ -30,7 +28,7 @@ type treeGeneratorImpl_v9_rolling struct { snapshotEnd *SnapshotEnd log *log.ColorLogger logPrefix string - rp *rocketpool.RocketPool + rp RewardsExecutionClient previousRewardsPoolAddresses []common.Address bc beacon.Client opts *bind.CallOpts @@ -94,7 +92,7 @@ func (r *treeGeneratorImpl_v9_rolling) getRulesetVersion() uint64 { return r.rewardsFile.RulesetVersion } -func (r *treeGeneratorImpl_v9_rolling) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) { +func (r *treeGeneratorImpl_v9_rolling) generateTree(rp RewardsExecutionClient, 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) @@ -178,7 +176,7 @@ func (r *treeGeneratorImpl_v9_rolling) generateTree(rp *rocketpool.RocketPool, n // 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, networkName string, bc beacon.Client) (*big.Int, error) { +func (r *treeGeneratorImpl_v9_rolling) approximateStakerShareOfSmoothingPool(rp RewardsExecutionClient, 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 @@ -646,7 +644,7 @@ func (r *treeGeneratorImpl_v9_rolling) validateNetwork(network uint64) (bool, er valid, exists := r.validNetworkCache[network] if !exists { var err error - valid, err = tnsettings.GetNetworkEnabled(r.rp, big.NewInt(int64(network)), r.opts) + valid, err = r.rp.GetNetworkEnabled(big.NewInt(int64(network)), r.opts) if err != nil { return false, err } @@ -674,7 +672,7 @@ func (r *treeGeneratorImpl_v9_rolling) getBlocksAndTimesForInterval() (*types.He elBlockNumber := beaconBlock.ExecutionBlockNumber r.rewardsFile.ExecutionStartBlock = elBlockNumber r.minipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err := r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) + startElHeader, err := r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) if err != nil { return nil, fmt.Errorf("error getting EL header for block %d: %w", elBlockNumber, err) } diff --git a/shared/services/rewards/generator-impl-v9.go b/shared/services/rewards/generator-impl-v9.go index 05183ca0f..d569a5871 100644 --- a/shared/services/rewards/generator-impl-v9.go +++ b/shared/services/rewards/generator-impl-v9.go @@ -12,8 +12,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ipfs/go-cid" "github.com/rocket-pool/rocketpool-go/rewards" - "github.com/rocket-pool/rocketpool-go/rocketpool" - tnsettings "github.com/rocket-pool/rocketpool-go/settings/trustednode" rptypes "github.com/rocket-pool/rocketpool-go/types" "github.com/rocket-pool/rocketpool-go/utils/eth" rpstate "github.com/rocket-pool/rocketpool-go/utils/state" @@ -37,7 +35,7 @@ type treeGeneratorImpl_v9 struct { snapshotEnd *SnapshotEnd log *log.ColorLogger logPrefix string - rp *rocketpool.RocketPool + rp RewardsExecutionClient previousRewardsPoolAddresses []common.Address bc beacon.Client opts *bind.CallOpts @@ -105,7 +103,7 @@ func (r *treeGeneratorImpl_v9) getRulesetVersion() uint64 { return r.rewardsFile.RulesetVersion } -func (r *treeGeneratorImpl_v9) generateTree(rp *rocketpool.RocketPool, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) { +func (r *treeGeneratorImpl_v9) generateTree(rp RewardsExecutionClient, 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) @@ -190,7 +188,7 @@ func (r *treeGeneratorImpl_v9) generateTree(rp *rocketpool.RocketPool, networkNa // 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, networkName string, bc beacon.Client) (*big.Int, error) { +func (r *treeGeneratorImpl_v9) approximateStakerShareOfSmoothingPool(rp RewardsExecutionClient, 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 @@ -504,7 +502,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.previousRewardsPoolAddresses, r.rewardsFile.Index-1, r.opts) + previousIntervalEvent, err := r.rp.GetRewardSnapshotEvent(r.previousRewardsPoolAddresses, r.rewardsFile.Index-1, r.opts) if err != nil { return err } @@ -1075,7 +1073,7 @@ func (r *treeGeneratorImpl_v9) validateNetwork(network uint64) (bool, error) { valid, exists := r.validNetworkCache[network] if !exists { var err error - valid, err = tnsettings.GetNetworkEnabled(r.rp, big.NewInt(int64(network)), r.opts) + valid, err = r.rp.GetNetworkEnabled(big.NewInt(int64(network)), r.opts) if err != nil { return false, err } @@ -1139,7 +1137,7 @@ func (r *treeGeneratorImpl_v9) getBlocksAndTimesForInterval(previousIntervalEven // We are pre-merge, so get the first block after the one from the previous interval r.rewardsFile.ExecutionStartBlock = previousIntervalEvent.ExecutionBlock.Uint64() + 1 r.minipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err = r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(r.rewardsFile.ExecutionStartBlock))) + startElHeader, err = r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(r.rewardsFile.ExecutionStartBlock))) if err != nil { return nil, fmt.Errorf("error getting EL start block %d: %w", r.rewardsFile.ExecutionStartBlock, err) } @@ -1147,7 +1145,7 @@ func (r *treeGeneratorImpl_v9) getBlocksAndTimesForInterval(previousIntervalEven // We are post-merge, so get the EL block corresponding to the BC block r.rewardsFile.ExecutionStartBlock = elBlockNumber r.minipoolPerformanceFile.ExecutionStartBlock = r.rewardsFile.ExecutionStartBlock - startElHeader, err = r.rp.Client.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) + startElHeader, err = r.rp.HeaderByNumber(context.Background(), big.NewInt(int64(elBlockNumber))) if err != nil { return nil, fmt.Errorf("error getting EL header for block %d: %w", elBlockNumber, err) } diff --git a/shared/services/rewards/generator.go b/shared/services/rewards/generator.go index 5153b18e0..39fefabbd 100644 --- a/shared/services/rewards/generator.go +++ b/shared/services/rewards/generator.go @@ -61,7 +61,7 @@ type TreeGenerator struct { rewardsIntervalInfos map[uint64]rewardsIntervalInfo logger *log.ColorLogger logPrefix string - rp *rocketpool.RocketPool + rp *defaultRewardsExecutionClient cfg *config.RocketPoolConfig bc beacon.Client index uint64 @@ -84,8 +84,8 @@ type SnapshotEnd struct { } type treeGeneratorImpl interface { - 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) + generateTree(rp RewardsExecutionClient, networkName string, previousRewardsPoolAddresses []common.Address, bc beacon.Client) (*GenerateTreeResult, error) + approximateStakerShareOfSmoothingPool(rp RewardsExecutionClient, 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(smartnode *config.SmartnodeConfig, treeResult *GenerateTreeResult, nodeTrusted bool) (cid.Cid, map[string]cid.Cid, error) @@ -95,7 +95,7 @@ func NewTreeGenerator(logger *log.ColorLogger, logPrefix string, rp *rocketpool. t := &TreeGenerator{ logger: logger, logPrefix: logPrefix, - rp: rp, + rp: &defaultRewardsExecutionClient{rp}, cfg: cfg, bc: bc, index: index, diff --git a/shared/services/rewards/types.go b/shared/services/rewards/types.go index 4a33e0fe0..1c90d1f18 100644 --- a/shared/services/rewards/types.go +++ b/shared/services/rewards/types.go @@ -1,12 +1,16 @@ package rewards import ( + "context" "fmt" "math/big" "strings" "time" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/rocket-pool/rocketpool-go/rewards" "github.com/rocket-pool/rocketpool-go/types" "github.com/wealdtech/go-merkletree" ) @@ -23,6 +27,17 @@ const ( minRewardsFileVersionSSZ = rewardsFileVersionThree ) +// RewardsExecutionClient defines and interface +// that contains only the functions from rocketpool.RocketPool +// required for rewards generation. +// This facade makes it easier to perform dependency injection in tests. +type RewardsExecutionClient interface { + GetNetworkEnabled(networkId *big.Int, opts *bind.CallOpts) (bool, error) + HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error) + GetRewardsEvent(index uint64, rocketRewardsPoolAddresses []common.Address, opts *bind.CallOpts) (bool, rewards.RewardsEvent, error) + GetRewardSnapshotEvent(previousRewardsPoolAddresses []common.Address, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error) +} + // Interface for version-agnostic minipool performance type IMinipoolPerformanceFile interface { // Serialize a minipool performance file into bytes diff --git a/shared/services/rewards/utils.go b/shared/services/rewards/utils.go index d255434a3..6cf330b16 100644 --- a/shared/services/rewards/utils.go +++ b/shared/services/rewards/utils.go @@ -88,11 +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, previousRewardsPoolAddresses, interval, opts) + client := NewRewardsExecutionClient(rp) + event, err = client.GetRewardSnapshotEvent(previousRewardsPoolAddresses, interval, opts) if err != nil { return } @@ -154,21 +154,6 @@ func GetIntervalInfo(rp *rocketpool.RocketPool, cfg *config.RocketPoolConfig, no return } -// Get the event for a rewards snapshot -func GetRewardSnapshotEvent(rp *rocketpool.RocketPool, previousRewardsPoolAddresses []common.Address, interval uint64, opts *bind.CallOpts) (rewards.RewardsEvent, error) { - - 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) - } - if !found { - return rewards.RewardsEvent{}, fmt.Errorf("interval %d event not found", interval) - } - - return event, nil - -} - // Get the number of the latest EL block that was created before the given timestamp func GetELBlockHeaderForTime(targetTime time.Time, rp *rocketpool.RocketPool) (*types.Header, error) {