Skip to content
Merged
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
2 changes: 1 addition & 1 deletion bindings/megapool/megapool-contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ValidatorInfo struct {
LockedTime uint64 `abi:"lockedTime"`
}

type ValidatorInfoFromGlobalIndex struct {
type MegapoolValidatorInfo struct {
Pubkey []byte `abi:"pubkey"`
ValidatorInfo ValidatorInfo `abi:"validatorInfo"`
MegapoolAddress common.Address `abi:"megapoolAddress"`
Expand Down
12 changes: 6 additions & 6 deletions bindings/megapool/megapool-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ func GetValidatorCount(rp *rocketpool.RocketPool, opts *bind.CallOpts) (uint32,
return uint32((*validatorCount).Uint64()), nil
}

func GetValidatorInfo(rp *rocketpool.RocketPool, index uint32, opts *bind.CallOpts) (ValidatorInfoFromGlobalIndex, error) {
func GetValidatorInfo(rp *rocketpool.RocketPool, index uint32, opts *bind.CallOpts) (MegapoolValidatorInfo, error) {
megapoolManager, err := getRocketMegapoolManager(rp, opts)
if err != nil {
return ValidatorInfoFromGlobalIndex{}, err
return MegapoolValidatorInfo{}, err
}

validator := new(ValidatorInfoFromGlobalIndex)
validator := new(MegapoolValidatorInfo)

indexBig := new(big.Int).SetUint64(uint64(index))

callData, err := megapoolManager.ABI.Pack("getValidatorInfo", indexBig)
if err != nil {
return ValidatorInfoFromGlobalIndex{}, fmt.Errorf("error creating calldata for getValidatorInfo: %w", err)
return MegapoolValidatorInfo{}, fmt.Errorf("error creating calldata for getValidatorInfo: %w", err)
}

response, err := megapoolManager.Client.CallContract(context.Background(), ethereum.CallMsg{To: megapoolManager.Address, Data: callData}, opts.BlockNumber)
if err != nil {
return ValidatorInfoFromGlobalIndex{}, fmt.Errorf("error calling getValidatorInfo: %w", err)
return MegapoolValidatorInfo{}, fmt.Errorf("error calling getValidatorInfo: %w", err)
}

// Both Call and UnpackIntoStruct were not working with this response (which contains a struct inside a struct)
// For the moment this was the only way for it to work. We should investigate further.
iface, err := megapoolManager.ABI.Unpack("getValidatorInfo", response)
if err != nil {
return ValidatorInfoFromGlobalIndex{}, fmt.Errorf("error unpacking getValidatorInfo response: %w", err)
return MegapoolValidatorInfo{}, fmt.Errorf("error unpacking getValidatorInfo response: %w", err)
}

src := iface[1].(struct {
Expand Down
4 changes: 2 additions & 2 deletions bindings/minipool/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

// Minipool queue capacity
type QueueCapacity struct {
Total *big.Int
Effective *big.Int
Total *big.Int `json:"total"`
Effective *big.Int `json:"effective"`
}

// Minipools queue status details
Expand Down
20 changes: 10 additions & 10 deletions bindings/utils/state/megapool.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m *NativeMegapoolDetails) GetMegapoolBondNormalized() *big.Int {
}

// Get all megapool validators using batched multicalls
func GetAllMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContracts) ([]megapool.ValidatorInfoFromGlobalIndex, error) {
func GetAllMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContracts) ([]megapool.MegapoolValidatorInfo, error) {
opts := &bind.CallOpts{
BlockNumber: contracts.ElBlockNumber,
}
Expand All @@ -74,7 +74,7 @@ func GetAllMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContr
}

count := int(megapoolValidatorsCount)
validators := make([]megapool.ValidatorInfoFromGlobalIndex, count)
validators := make([]megapool.MegapoolValidatorInfo, count)

var wg errgroup.Group
wg.SetLimit(threadLimit)
Expand Down Expand Up @@ -118,10 +118,10 @@ func GetAllMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContr
}

// Manually unpack a getValidatorInfo response (nested structs don't work with UnpackIntoInterface)
func unpackValidatorInfoFromGlobalIndex(contract *rocketpool.Contract, data []byte) (megapool.ValidatorInfoFromGlobalIndex, error) {
func unpackValidatorInfoFromGlobalIndex(contract *rocketpool.Contract, data []byte) (megapool.MegapoolValidatorInfo, error) {
iface, err := contract.ABI.Unpack("getValidatorInfo", data)
if err != nil {
return megapool.ValidatorInfoFromGlobalIndex{}, err
return megapool.MegapoolValidatorInfo{}, err
}

src := iface[1].(struct {
Expand All @@ -143,7 +143,7 @@ func unpackValidatorInfoFromGlobalIndex(contract *rocketpool.Contract, data []by
LockedTime uint64 `json:"lockedTime"`
})

var validator megapool.ValidatorInfoFromGlobalIndex
var validator megapool.MegapoolValidatorInfo
validator.Pubkey = iface[0].([]byte)
validator.ValidatorInfo.LastAssignmentTime = src.LastAssignmentTime
validator.ValidatorInfo.LastRequestedValue = src.LastRequestedValue
Expand All @@ -167,7 +167,7 @@ func unpackValidatorInfoFromGlobalIndex(contract *rocketpool.Contract, data []by

// Get all validators for a single megapool, via its own local index -- unlike
// GetAllMegapoolValidators, which walks the network-wide global index on RocketMegapoolManager.
func GetNodeMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContracts, megapoolAddress common.Address) ([]megapool.ValidatorInfoFromGlobalIndex, error) {
func GetNodeMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkContracts, megapoolAddress common.Address) ([]megapool.MegapoolValidatorInfo, error) {
opts := &bind.CallOpts{
BlockNumber: contracts.ElBlockNumber,
}
Expand All @@ -187,7 +187,7 @@ func GetNodeMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkCont
}

count := int(validatorCount)
validators := make([]megapool.ValidatorInfoFromGlobalIndex, count)
validators := make([]megapool.MegapoolValidatorInfo, count)
if count == 0 {
return validators, nil
}
Expand Down Expand Up @@ -241,10 +241,10 @@ func GetNodeMegapoolValidators(rp *rocketpool.RocketPool, contracts *NetworkCont
}

// Manually unpack a getValidatorInfoAndPubkey response (nested structs don't work with UnpackIntoInterface)
func unpackValidatorInfoAndPubkey(contract *rocketpool.Contract, data []byte) (megapool.ValidatorInfoFromGlobalIndex, error) {
func unpackValidatorInfoAndPubkey(contract *rocketpool.Contract, data []byte) (megapool.MegapoolValidatorInfo, error) {
iface, err := contract.ABI.Unpack("getValidatorInfoAndPubkey", data)
if err != nil {
return megapool.ValidatorInfoFromGlobalIndex{}, err
return megapool.MegapoolValidatorInfo{}, err
}

src := iface[0].(struct {
Expand All @@ -266,7 +266,7 @@ func unpackValidatorInfoAndPubkey(contract *rocketpool.Contract, data []byte) (m
LockedTime uint64 `json:"lockedTime"`
})

var validator megapool.ValidatorInfoFromGlobalIndex
var validator megapool.MegapoolValidatorInfo
validator.Pubkey = iface[1].([]byte)
validator.ValidatorInfo.LastAssignmentTime = src.LastAssignmentTime
validator.ValidatorInfo.LastRequestedValue = src.LastRequestedValue
Expand Down
53 changes: 0 additions & 53 deletions bindings/utils/state/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/rocket-pool/smartnode/bindings/megapool"
"github.com/rocket-pool/smartnode/bindings/node"
"github.com/rocket-pool/smartnode/bindings/rocketpool"
"github.com/rocket-pool/smartnode/bindings/types"
"github.com/rocket-pool/smartnode/bindings/utils/multicall"
)

Expand Down Expand Up @@ -62,12 +61,6 @@ type NativeNodeDetails struct {
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 @@ -255,52 +248,6 @@ func (node *NativeNodeDetails) WasOptedInAt(t time.Time) bool {
return t.Before(time.Unix(node.SmoothingPoolRegistrationChanged.Int64(), 0))
}

// Calculate the average node fee and user/node shares of the distributor's balance
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)
eligibleMinipools := int64(0)
for _, mpd := range minipoolDetails {
if mpd.Status == types.Staking && !mpd.Finalised {
totalFee.Add(totalFee, mpd.NodeFee)
eligibleMinipools++
}
}

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

// Get the user and node portions of the distributor balance
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, 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)
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, nfd.AverageNodeFee)
commissionEth.Div(commissionEth, big.NewInt(1e18))

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

}

}

// Get all node addresses using the multicaller
func getNodeAddressesFast(rp *rocketpool.RocketPool, contracts *NetworkContracts, opts *bind.CallOpts) ([]common.Address, error) {
// Get minipool count
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/node/collectors/node-collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func (collector *NodeCollector) Collect(channel chan<- prometheus.Metric) {
// state.MegapoolValidatorGlobalIndex is scoped to this node's own megapool, since the
// daemon builds its state via GetHeadStateForNode
wg.Go(func() error {
for _, validator := range state.MegapoolValidatorGlobalIndex {
for _, validator := range state.MegapoolValidators {
if validator.ValidatorInfo.Staked {
megapoolStakedCount++
}
Expand Down
2 changes: 1 addition & 1 deletion rocketpool/watchtower/challenge-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (t *challengeValidatorsExiting) challengeValidatorsExiting(state *state.Net

challengeMegapoolAddressToIds := make(map[common.Address][]uint32)
batched := 0
for _, validator := range state.MegapoolValidatorGlobalIndex {
for _, validator := range state.MegapoolValidators {
if batched >= batchSize {
t.log.Printlnf("Batched %d validators, exiting...", batched)
break
Expand Down
4 changes: 2 additions & 2 deletions rocketpool/watchtower/dissolve-invalid-credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *dissolveInvalidCredentials) run(state *state.NetworkStateIndex) error {
// Get megapool validators that can be dissolved due to using invalid credentials
func (t *dissolveInvalidCredentials) dissolveInvalidCredentialValidators(state *state.NetworkStateIndex) error {

for _, validator := range state.MegapoolValidatorGlobalIndex {
for _, validator := range state.MegapoolValidators {
if validator.ValidatorInfo.InPrestake {
expectedWithdrawalAddress := services.CalculateMegapoolWithdrawalCredentials(validator.MegapoolAddress)
// Fetch the validator from the beacon state to compare credentials
Expand Down Expand Up @@ -144,7 +144,7 @@ func (t *dissolveInvalidCredentials) dissolveInvalidCredentialValidators(state *
return nil
}

func (t *dissolveInvalidCredentials) dissolveMegapoolValidator(validator megapool.ValidatorInfoFromGlobalIndex) {
func (t *dissolveInvalidCredentials) dissolveMegapoolValidator(validator megapool.MegapoolValidatorInfo) {
// Log
t.log.Printlnf("Dissolving megapool validator ID: %d from megapool %s...", validator.ValidatorId, validator.MegapoolAddress)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (t *dissolveTimedOutMegapoolValidators) dissolveMegapoolValidators(state *s
return err
}

for _, validator := range state.MegapoolValidatorGlobalIndex {
for _, validator := range state.MegapoolValidators {
if validator.ValidatorInfo.InPrestake {
assignTime := time.Unix(int64(validator.ValidatorInfo.LastAssignmentTime), 0)
if time.Since(assignTime) >= time.Duration(timeBeforeDissolve)*time.Second {
Expand All @@ -104,7 +104,7 @@ func (t *dissolveTimedOutMegapoolValidators) dissolveMegapoolValidators(state *s
return nil
}

func (t *dissolveTimedOutMegapoolValidators) dissolveMegapoolValidator(validator megapool.ValidatorInfoFromGlobalIndex) error {
func (t *dissolveTimedOutMegapoolValidators) dissolveMegapoolValidator(validator megapool.MegapoolValidatorInfo) error {
// Log
t.log.Printlnf("Dissolving megapool validator ID: %d from megapool %s...", validator.ValidatorId, validator.MegapoolAddress)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestMegapoolBalanceWithDuplicatePubkey(t *testing.T) {
MegapoolValidatorDetails: state.ValidatorDetailsMap{
pubkey: {Pubkey: pubkey, Index: "4", Exists: true, Balance: 32000000000, ActivationEpoch: 0, ExitEpoch: ^uint64(0)},
},
MegapoolValidatorGlobalIndex: []megapool.ValidatorInfoFromGlobalIndex{
MegapoolValidators: []megapool.MegapoolValidatorInfo{
{
Pubkey: pubkey[:],
MegapoolAddress: megapoolAddrA,
Expand Down
2 changes: 1 addition & 1 deletion shared/services/rewards/mock_v11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMockIntervalDefaultsTreegenv11(tt *testing.T) {
for _, validator := range state.MinipoolValidatorDetails {
t.bc.SetMinipoolPerformance(validator.Index, make([]uint64, 0))
}
for _, validator := range state.MegapoolValidatorGlobalIndex {
for _, validator := range state.MegapoolValidators {
pubkey := rptypes.BytesToValidatorPubkey(validator.Pubkey)
details := state.MegapoolValidatorDetails[pubkey]
t.bc.SetMinipoolPerformance(details.Index, make([]uint64, 0))
Expand Down
2 changes: 1 addition & 1 deletion shared/services/rewards/test/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (bc *MockBeaconClient) SetState(state *state.NetworkStateIndex) {
}
bc.validatorPubkeys[validatorIndex(v.Index)] = v.Pubkey
}
for _, v := range state.MegapoolValidatorGlobalIndex {
for _, v := range state.MegapoolValidators {
pubkey := types.BytesToValidatorPubkey(v.Pubkey)
details, ok := state.MegapoolValidatorDetails[pubkey]
if !ok {
Expand Down
10 changes: 5 additions & 5 deletions shared/services/rewards/test/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,9 @@ func (h *MockHistory) GetEndNetworkState() *state.NetworkState {
OracleDaoMemberDetails: []rpstate.OracleDaoMemberDetails{},
ProtocolDaoProposalDetails: nil,

MegapoolValidatorGlobalIndex: []megapool.ValidatorInfoFromGlobalIndex{},
MegapoolDetails: make(map[common.Address]rpstate.NativeMegapoolDetails),
MegapoolValidatorDetails: make(state.ValidatorDetailsMap),
MegapoolValidators: []megapool.MegapoolValidatorInfo{},
MegapoolDetails: make(map[common.Address]rpstate.NativeMegapoolDetails),
MegapoolValidatorDetails: make(state.ValidatorDetailsMap),
}

// Add nodes
Expand Down Expand Up @@ -851,15 +851,15 @@ func (h *MockHistory) GetEndNetworkState() *state.NetworkState {
if err != nil {
panic(err)
}
vifgi := megapool.ValidatorInfoFromGlobalIndex{
vifgi := megapool.MegapoolValidatorInfo{
Pubkey: pubkey.Bytes(),
ValidatorInfo: megapool.ValidatorInfo{
Staked: true,
},
MegapoolAddress: node.MegapoolAddress(),
ValidatorId: uint32(intIdx),
}
out.MegapoolValidatorGlobalIndex = append(out.MegapoolValidatorGlobalIndex, vifgi)
out.MegapoolValidators = append(out.MegapoolValidators, vifgi)
out.MegapoolValidatorDetails[pubkey] = beacon.ValidatorStatus{
Pubkey: pubkey,
Index: idx,
Expand Down
2 changes: 1 addition & 1 deletion shared/services/rewards/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ type MegapoolValidatorInfo struct {
CompletedAttestations map[uint64]bool `json:"-"`
AttestationCount int `json:"attestationCount"`

NativeValidatorInfo *megapool.ValidatorInfoFromGlobalIndex `json:"nativeValidatorInfo"`
NativeValidatorInfo *megapool.MegapoolValidatorInfo `json:"nativeValidatorInfo"`

// Amount of eth earned by this validator in the smoothing pool
MegapoolValidatorShare *big.Int `json:"megapoolValidatorShare"`
Expand Down
4 changes: 2 additions & 2 deletions shared/services/state/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func truncateNetworkState(ns *state.NetworkStateIndex) {
if len(ns.MinipoolDetails) > 1 {
ns.MinipoolDetails = ns.MinipoolDetails[:1]
}
if len(ns.MegapoolValidatorGlobalIndex) > 1 {
ns.MegapoolValidatorGlobalIndex = ns.MegapoolValidatorGlobalIndex[:1]
if len(ns.MegapoolValidators) > 1 {
ns.MegapoolValidators = ns.MegapoolValidators[:1]
}
if len(ns.OracleDaoMemberDetails) > 1 {
ns.OracleDaoMemberDetails = ns.OracleDaoMemberDetails[:1]
Expand Down
Loading
Loading