Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions bindings/utils/state/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ type NativeNodeDetails struct {
BalanceRPL *big.Int `json:"balance_rpl"`
BalanceOldRPL *big.Int `json:"balance_old_rpl"`
DepositCreditBalance *big.Int `json:"deposit_credit_balance"`
DistributorBalanceUserETH *big.Int `json:"distributor_balance_user_eth"` // Must call CalculateAverageFeeAndDistributorShares to get this
DistributorBalanceNodeETH *big.Int `json:"distributor_balance_node_eth"` // Must call CalculateAverageFeeAndDistributorShares to get this
WithdrawalAddress common.Address `json:"withdrawal_address"`
PendingWithdrawalAddress common.Address `json:"pending_withdrawal_address"`
SmoothingPoolRegistrationState bool `json:"smoothing_pool_registration_state"`
SmoothingPoolRegistrationChanged *big.Int `json:"smoothing_pool_registration_changed"`
NodeAddress common.Address `json:"node_address"`
AverageNodeFee *big.Int `json:"average_node_fee"` // Must call CalculateAverageFeeAndDistributorShares to get this
CollateralisationRatio *big.Int `json:"collateralisation_ratio"`
DistributorBalance *big.Int `json:"distributor_balance"`
MegapoolAddress common.Address `json:"megapool_address"`
MegapoolDeployed bool `json:"megapool_deployed"`
}

type NodeFeeDetails struct {
DistributorBalanceUserETH *big.Int `json:"distributor_balance_user_eth"`
DistributorBalanceNodeETH *big.Int `json:"distributor_balance_node_eth"`
AverageNodeFee *big.Int `json:"average_node_fee"`
}

func timeMax(a, b time.Time) time.Time {
if a.After(b) {
return a
Expand Down Expand Up @@ -102,11 +105,8 @@ func GetNativeNodeDetails(rp *rocketpool.RocketPool, contracts *NetworkContracts
BlockNumber: contracts.ElBlockNumber,
}
details := NativeNodeDetails{
NodeAddress: nodeAddress,
AverageNodeFee: big.NewInt(0),
CollateralisationRatio: big.NewInt(0),
DistributorBalanceUserETH: big.NewInt(0),
DistributorBalanceNodeETH: big.NewInt(0),
NodeAddress: nodeAddress,
CollateralisationRatio: big.NewInt(0),
}

err := addNodeDetailsCalls(contracts, contracts.Multicaller, &details, nodeAddress)
Expand Down Expand Up @@ -189,9 +189,6 @@ func GetAllNativeNodeDetails(rp *rocketpool.RocketPool, contracts *NetworkContra
address := addresses[j]
details := &nodeDetails[j]
details.NodeAddress = address
details.AverageNodeFee = big.NewInt(0)
details.DistributorBalanceUserETH = big.NewInt(0)
details.DistributorBalanceNodeETH = big.NewInt(0)
details.CollateralisationRatio = big.NewInt(0)

err = addNodeDetailsCalls(contracts, mc, details, address)
Expand Down Expand Up @@ -259,7 +256,7 @@ func (node *NativeNodeDetails) WasOptedInAt(t time.Time) bool {
}

// Calculate the average node fee and user/node shares of the distributor's balance
func (node *NativeNodeDetails) CalculateAverageFeeAndDistributorShares(minipoolDetails []*NativeMinipoolDetails) {
func (nfd *NodeFeeDetails) CalculateAverageFeeAndDistributorShares(nnd *NativeNodeDetails, minipoolDetails []*NativeMinipoolDetails) {

// Calculate the total of all fees for staking minipools that aren't finalized
totalFee := big.NewInt(0)
Expand All @@ -273,37 +270,33 @@ func (node *NativeNodeDetails) CalculateAverageFeeAndDistributorShares(minipoolD

// Get the average fee (0 if there aren't any minipools)
if eligibleMinipools > 0 {
node.AverageNodeFee.Div(totalFee, big.NewInt(eligibleMinipools))
nfd.AverageNodeFee.Div(totalFee, big.NewInt(eligibleMinipools))
}

// Get the user and node portions of the distributor balance
distributorBalance := big.NewInt(0).Set(node.DistributorBalance)
distributorBalance := big.NewInt(0).Set(nnd.DistributorBalance)
if distributorBalance.Cmp(big.NewInt(0)) > 0 {
nodeBalance := big.NewInt(0)
nodeBalance.Mul(distributorBalance, big.NewInt(1e18))
nodeBalance.Div(nodeBalance, node.CollateralisationRatio)
nodeBalance.Div(nodeBalance, nnd.CollateralisationRatio)

userBalance := big.NewInt(0)
userBalance.Sub(distributorBalance, nodeBalance)

if eligibleMinipools == 0 {
// Split it based solely on the collateralisation ratio if there are no minipools (and hence no average fee)
node.DistributorBalanceNodeETH = big.NewInt(0).Set(nodeBalance)
node.DistributorBalanceUserETH = big.NewInt(0).Sub(distributorBalance, nodeBalance)
nfd.DistributorBalanceNodeETH = big.NewInt(0).Set(nodeBalance)
nfd.DistributorBalanceUserETH = big.NewInt(0).Sub(distributorBalance, nodeBalance)
} else {
// Amount of ETH given to the NO as a commission
commissionEth := big.NewInt(0)
commissionEth.Mul(userBalance, node.AverageNodeFee)
commissionEth.Mul(userBalance, nfd.AverageNodeFee)
commissionEth.Div(commissionEth, big.NewInt(1e18))

node.DistributorBalanceNodeETH.Add(nodeBalance, commissionEth) // Node gets their portion + commission on user portion
node.DistributorBalanceUserETH.Sub(distributorBalance, node.DistributorBalanceNodeETH) // User gets balance - node share
nfd.DistributorBalanceNodeETH.Add(nodeBalance, commissionEth) // Node gets their portion + commission on user portion
nfd.DistributorBalanceUserETH.Sub(distributorBalance, nfd.DistributorBalanceNodeETH) // User gets balance - node share
}

} else {
// No distributor balance
node.DistributorBalanceNodeETH = big.NewInt(0)
node.DistributorBalanceUserETH = big.NewInt(0)
}

}
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/api/node/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getRewards(c *cli.Command) (*api.NodeRewardsResponse, error) {
var trustedNodeOperatorRewardsPercent float64
var totalDepositBalance float64
var totalNodeShare float64
var networkState *state.NetworkState
var networkState *state.NetworkStateIndex

// Sync
var wg errgroup.Group
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/feerecipient/fee-recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Details struct {
OptOutEpoch uint64 `json:"optOutEpoch"`
}

func GetDetails(rp *rocketpool.RocketPool, bc beacon.Client, nodeAddress common.Address, state *state.NetworkState) (*Details, error) {
func GetDetails(rp *rocketpool.RocketPool, bc beacon.Client, nodeAddress common.Address, state *state.NetworkStateIndex) (*Details, error) {

info := &Details{
IsInOptOutCooldown: false,
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/collectors/beacon-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (collector *BeaconCollector) Collect(channel chan<- prometheus.Metric) {
}

// Get the Beacon indices of all of the node's validators, both minipool and megapool
func getNodeValidatorIndices(networkState *state.NetworkState, nodeAddress common.Address) []string {
func getNodeValidatorIndices(networkState *state.NetworkStateIndex, nodeAddress common.Address) []string {
var validatorIndices []string

for _, mpd := range networkState.MinipoolDetailsByNode[nodeAddress] {
Expand Down
6 changes: 3 additions & 3 deletions rocketpool/node/collectors/state-locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type StateLocker struct {
state *state.NetworkState
state *state.NetworkStateIndex

// Internal fields
lock *sync.RWMutex
Expand All @@ -19,13 +19,13 @@ func NewStateLocker() *StateLocker {
}
}

func (l *StateLocker) UpdateState(state *state.NetworkState) {
func (l *StateLocker) UpdateState(state *state.NetworkStateIndex) {
l.lock.Lock()
defer l.lock.Unlock()
l.state = state
}

func (l *StateLocker) GetState() *state.NetworkState {
func (l *StateLocker) GetState() *state.NetworkStateIndex {
l.lock.RLock()
defer l.lock.RUnlock()
return l.state
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/defend-challenge-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func newDefendChallengeExit(c *cli.Command, logger log.ColorLogger) (*defendChal
}

// Prestake megapool validator
func (t *defendChallengeExit) run(state *state.NetworkState) error {
func (t *defendChallengeExit) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for validators with an incorrect exit challenge ...")

Expand Down Expand Up @@ -152,7 +152,7 @@ func (t *defendChallengeExit) run(state *state.NetworkState) error {

}

func (t *defendChallengeExit) defendChallenge(rp *rocketpool.RocketPool, mp megapool.Megapool, validatorId uint32, state *state.NetworkState, validatorPubkey types.ValidatorPubkey, exiting bool, callopts *bind.CallOpts) error {
func (t *defendChallengeExit) defendChallenge(rp *rocketpool.RocketPool, mp megapool.Megapool, validatorId uint32, state *state.NetworkStateIndex, validatorPubkey types.ValidatorPubkey, exiting bool, callopts *bind.CallOpts) error {

// Get transactor
opts, err := t.w.GetNodeAccountTransactor()
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/defend-pdao-props.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func newDefendPdaoProps(c *cli.Command, logger log.ColorLogger) (*defendPdaoProp
}

// Defend pDAO proposals
func (t *defendPdaoProps) run(state *state.NetworkState) error {
func (t *defendPdaoProps) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for Protocol DAO proposal challenges to defend...")

Expand Down Expand Up @@ -136,7 +136,7 @@ func (t *defendPdaoProps) run(state *state.NetworkState) error {
}

// Get a list of this node's proposals with open challenges against them
func (t *defendPdaoProps) getDefendableProposals(state *state.NetworkState, opts *bind.CallOpts) ([]defendableProposal, error) {
func (t *defendPdaoProps) getDefendableProposals(state *state.NetworkStateIndex, opts *bind.CallOpts) ([]defendableProposal, error) {
// Get proposals made by this node that are still in the challenge phase (Pending)
eligibleProps := []protocol.ProtocolDaoProposalDetails{}
for _, prop := range state.ProtocolDaoProposalDetails {
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/distribute-minipools.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func newDistributeMinipools(c *cli.Command, logger log.ColorLogger) (*distribute
}

// Distribute minipools
func (t *distributeMinipools) run(state *state.NetworkState) error {
func (t *distributeMinipools) run(state *state.NetworkStateIndex) error {

// Check if auto-distribute is disabled
if t.disabled {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (t *distributeMinipools) run(state *state.NetworkState) error {
}

// Get distributable minipools
func (t *distributeMinipools) getDistributableMinipools(nodeAddress common.Address, state *state.NetworkState, opts *bind.CallOpts) ([]*rpstate.NativeMinipoolDetails, error) {
func (t *distributeMinipools) getDistributableMinipools(nodeAddress common.Address, state *state.NetworkStateIndex, opts *bind.CallOpts) ([]*rpstate.NativeMinipoolDetails, error) {

// Filter minipools by status
distributableMinipools := []*rpstate.NativeMinipoolDetails{}
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/download-reward-trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func newDownloadRewardsTrees(c *cli.Command, logger log.ColorLogger) (*downloadR
}

// Manage fee recipient
func (d *downloadRewardsTrees) run(state *state.NetworkState) error {
func (d *downloadRewardsTrees) run(state *state.NetworkStateIndex) error {

// Wait for eth client to sync
if err := services.WaitEthClientSynced(d.c, true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/manage-fee-recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func newManageFeeRecipient(c *cli.Command, logger log.ColorLogger) (*manageFeeRe
}

// Manage fee recipient
func (m *manageFeeRecipient) run(state *state.NetworkState) error {
func (m *manageFeeRecipient) run(state *state.NetworkStateIndex) error {

// Wait for eth client to sync
if err := services.WaitEthClientSynced(m.c, true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func removeLegacyFeeRecipientFiles(c *cli.Command) error {
}

// Update the latest network state at each cycle
func updateNetworkState(m state.NetworkStateProvider, log *log.ColorLogger, nodeAddress common.Address) (*state.NetworkState, error) {
func updateNetworkState(m state.NetworkStateProvider, log *log.ColorLogger, nodeAddress common.Address) (*state.NetworkStateIndex, error) {
// Get the state of the network
state, err := m.GetHeadStateForNode(nodeAddress)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/notify-final-balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func newNotifyFinalBalance(c *cli.Command, logger log.ColorLogger) (*notifyFinal
}

// Notify Final Balance
func (t *notifyFinalBalance) run(state *state.NetworkState) error {
func (t *notifyFinalBalance) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking if there are megapool validators with a final balance withdrawn...")

Expand Down Expand Up @@ -161,7 +161,7 @@ func (t *notifyFinalBalance) run(state *state.NetworkState) error {

}

func (t *notifyFinalBalance) createFinalBalanceProof(rp *rocketpool.RocketPool, mp megapool.Megapool, state *state.NetworkState, validatorId uint32, validatorDetails beacon.ValidatorStatus, callopts *bind.CallOpts) error {
func (t *notifyFinalBalance) createFinalBalanceProof(rp *rocketpool.RocketPool, mp megapool.Megapool, state *state.NetworkStateIndex, validatorId uint32, validatorDetails beacon.ValidatorStatus, callopts *bind.CallOpts) error {

// Get transactor
opts, err := t.w.GetNodeAccountTransactor()
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/notify-validator-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func newNotifyValidatorExit(c *cli.Command, logger log.ColorLogger) (*notifyVali
}

// Prestake megapool validator
func (t *notifyValidatorExit) run(state *state.NetworkState) error {
func (t *notifyValidatorExit) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking if there are megapool validators exiting...")

Expand Down Expand Up @@ -192,7 +192,7 @@ func (t *notifyValidatorExit) run(state *state.NetworkState) error {

}

func (t *notifyValidatorExit) createExitProof(rp *rocketpool.RocketPool, beaconState eth2.BeaconState, mp megapool.Megapool, validatorId uint32, state *state.NetworkState, validatorPubkey types.ValidatorPubkey, callopts *bind.CallOpts) error {
func (t *notifyValidatorExit) createExitProof(rp *rocketpool.RocketPool, beaconState eth2.BeaconState, mp megapool.Megapool, validatorId uint32, state *state.NetworkStateIndex, validatorPubkey types.ValidatorPubkey, callopts *bind.CallOpts) error {

// Get transactor
opts, err := t.w.GetNodeAccountTransactor()
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/prestake-megapool-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newPrestakeMegapoolValidator(c *cli.Command, logger log.ColorLogger) (*pres
}

// Prestake megapool validator
func (t *prestakeMegapoolValidator) run(state *state.NetworkState) error {
func (t *prestakeMegapoolValidator) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for megapool validators to pre-stake...")

Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/provision-express-tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newProvisionExpressTickets(c *cli.Command, logger log.ColorLogger) (*provis
}

// Provision Express tickets
func (t *provisionExpress) run(state *state.NetworkState) error {
func (t *provisionExpress) run(state *state.NetworkStateIndex) error {
// Check if automatic transactions are disabled
if t.disabled {
return nil
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/set-latest-delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func newSetUseLatestDelegate(c *cli.Command, logger log.ColorLogger) (*setUseLat
}

// Distribute minipools
func (t *setUseLatestDelegate) run(state *state.NetworkState) error {
func (t *setUseLatestDelegate) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for minipools to set use latest delegate...")

Expand Down Expand Up @@ -145,7 +145,7 @@ func (t *setUseLatestDelegate) run(state *state.NetworkState) error {
}

// Get minipools that can have use latest delegate set
func (t *setUseLatestDelegate) getSettableMinipools(nodeAddress common.Address, state *state.NetworkState, opts *bind.CallOpts) ([]*rpstate.NativeMinipoolDetails, error) {
func (t *setUseLatestDelegate) getSettableMinipools(nodeAddress common.Address, state *state.NetworkStateIndex, opts *bind.CallOpts) ([]*rpstate.NativeMinipoolDetails, error) {

// Filter minipools by status
settableMinipools := []*rpstate.NativeMinipoolDetails{}
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/node/stake-megapool-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func newStakeMegapoolValidator(c *cli.Command, logger log.ColorLogger) (*stakeMe
}

// Prestake megapool validator
func (t *stakeMegapoolValidator) run(state *state.NetworkState) error {
func (t *stakeMegapoolValidator) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for megapool validators to stake...")

Expand Down Expand Up @@ -194,7 +194,7 @@ func (t *stakeMegapoolValidator) run(state *state.NetworkState) error {
return nil
}

func (t *stakeMegapoolValidator) stakeValidator(rp *rocketpool.RocketPool, beaconState eth2.BeaconState, mp megapool.Megapool, validatorId uint32, state *state.NetworkState, validatorPubkey types.ValidatorPubkey, callopts *bind.CallOpts) error {
func (t *stakeMegapoolValidator) stakeValidator(rp *rocketpool.RocketPool, beaconState eth2.BeaconState, mp megapool.Megapool, validatorId uint32, state *state.NetworkStateIndex, validatorPubkey types.ValidatorPubkey, callopts *bind.CallOpts) error {

// Get transactor
opts, err := t.w.GetNodeAccountTransactor()
Expand Down
6 changes: 3 additions & 3 deletions rocketpool/node/verify-pdao-props.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (c *liveChallengeArtifactChecker) CheckForChallengeableArtifacts(event prot
}

// Verify pDAO proposals
func (t *verifyPdaoProps) run(state *state.NetworkState) error {
func (t *verifyPdaoProps) run(state *state.NetworkStateIndex) error {
// Log
t.log.Println("Checking for Protocol DAO proposals to challenge...")

Expand Down Expand Up @@ -226,7 +226,7 @@ func (t *verifyPdaoProps) run(state *state.NetworkState) error {
return nil
}

func (t *verifyPdaoProps) getChallengesandDefeats(ns *state.NetworkState, opts *bind.CallOpts) ([]challenge, []defeat, error) {
func (t *verifyPdaoProps) getChallengesandDefeats(ns *state.NetworkStateIndex, opts *bind.CallOpts) ([]challenge, []defeat, error) {
nodeGetter := &liveProposalNodeGetter{rp: t.rp, opts: opts}
treeProvider := &liveNetworkTreeProvider{propMgr: t.propMgr}
stateGetter := &liveChallengeStateGetter{rp: t.rp, opts: opts}
Expand All @@ -245,7 +245,7 @@ func (t *verifyPdaoProps) getChallengesandDefeats(ns *state.NetworkState, opts *
// All chain dependencies are injected via interfaces so this can be tested with
// static network state and stub implementations.
func getChallengesFromState(
ns *state.NetworkState,
ns *state.NetworkStateIndex,
nodeAddress common.Address,
log *log.ColorLogger,
bc beacon.Client,
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/watchtower/challenge-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func newChallengeValidatorsExiting(c *cli.Command, logger log.ColorLogger) (*cha
}

// Flag validators exiting that didn't notify the exit
func (t *challengeValidatorsExiting) run(state *state.NetworkState) error {
func (t *challengeValidatorsExiting) run(state *state.NetworkStateIndex) error {
// Wait for eth client to sync
if err := services.WaitEthClientSynced(t.c, true); err != nil {
return err
Expand All @@ -85,7 +85,7 @@ func (t *challengeValidatorsExiting) run(state *state.NetworkState) error {
}

// Get megapool validators that can be challenged for exiting without a notification
func (t *challengeValidatorsExiting) challengeValidatorsExiting(state *state.NetworkState) error {
func (t *challengeValidatorsExiting) challengeValidatorsExiting(state *state.NetworkStateIndex) error {

// Calculate the current epoch based on state.BeaconSlotNumber
currentSlot := state.BeaconSlotNumber
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/watchtower/check-solo-migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func newCheckSoloMigrations(c *cli.Command, logger log.ColorLogger, errorLogger
}

// Start the solo migration checking thread
func (t *checkSoloMigrations) run(state *state.NetworkState) error {
func (t *checkSoloMigrations) run(state *state.NetworkStateIndex) error {

// Wait for eth clients to sync
if err := services.WaitEthClientSynced(t.c, true); err != nil {
Expand Down Expand Up @@ -138,7 +138,7 @@ func (t *checkSoloMigrations) run(state *state.NetworkState) error {
}

// Check for solo staker migration validity
func (t *checkSoloMigrations) checkSoloMigrations(state *state.NetworkState) error {
func (t *checkSoloMigrations) checkSoloMigrations(state *state.NetworkStateIndex) error {

t.printMessage(fmt.Sprintf("Checking for Beacon slot %d (EL block %d)", state.BeaconSlotNumber, state.ElBlockNumber))
oneGwei := math.GweiToWei(1)
Expand Down
Loading
Loading