-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathstatus.go
More file actions
437 lines (396 loc) · 19.8 KB
/
status.go
File metadata and controls
437 lines (396 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
package node
import (
"bytes"
"errors"
"fmt"
"math/big"
"sort"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/rocket-pool/smartnode/bindings/utils/eth"
"github.com/urfave/cli"
"github.com/rocket-pool/smartnode/addons/rescue_node"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
cliutils "github.com/rocket-pool/smartnode/shared/utils/cli"
"github.com/rocket-pool/smartnode/shared/utils/math"
)
const (
colorReset string = "\033[0m"
colorRed string = "\033[31m"
colorGreen string = "\033[32m"
colorYellow string = "\033[33m"
smoothingPoolLink string = "https://docs.rocketpool.net/guides/redstone/whats-new.html#smoothing-pool"
signallingAddressLink string = "https://docs.rocketpool.net/guides/houston/participate#setting-your-snapshot-signalling-address"
maxAlertItems int = 3
)
func getStatus(c *cli.Context) error {
// Get RP client
rp := rocketpool.NewClientFromCtx(c)
defer rp.Close()
// Get the config
cfg, isNew, err := rp.LoadConfig()
if err != nil {
return fmt.Errorf("Error loading configuration: %w", err)
}
// Get wallet status
walletStatus, err := rp.WalletStatus()
if err != nil {
return err
}
// Rescue Node Plugin - ensure that we print the rescue node stuff even
// when the eth1 node is syncing by deferring it here.
//
// Since we collected all the data we need for this message, we can safely
// defer it and let it execute even if we fail further down, eg because
// the EC is still syncing.
if walletStatus.WalletInitialized {
defer func() {
if cfg.RescueNode.GetEnabledParameter().Value.(bool) {
fmt.Println()
cfg.RescueNode.(*rescue_node.RescueNode).PrintStatusText(walletStatus.AccountAddress)
}
}()
}
// Print what network we're on
err = cliutils.PrintNetwork(cfg.GetNetwork(), isNew)
if err != nil {
return err
}
// rp.NodeStatus() will fail with an error, but we can short-circuit it here.
if !walletStatus.WalletInitialized {
return errors.New("The node wallet is not initialized.")
}
// Get node status
status, err := rp.NodeStatus()
if err != nil {
return err
}
// Account address & balances
fmt.Printf("%s=== Account and Balances ===%s\n", colorGreen, colorReset)
fmt.Printf(
"The node %s%s%s has a balance of %.6f ETH and %.6f RPL.\n",
colorBlue,
status.AccountAddressFormatted,
colorReset,
math.RoundDown(eth.WeiToEth(status.AccountBalances.ETH), 6),
math.RoundDown(eth.WeiToEth(status.AccountBalances.RPL), 6))
if status.AccountBalances.FixedSupplyRPL.Cmp(big.NewInt(0)) > 0 {
fmt.Printf("The node has a balance of %.6f old RPL which can be swapped for new RPL.\n", math.RoundDown(eth.WeiToEth(status.AccountBalances.FixedSupplyRPL), 6))
}
fmt.Printf(
"The node has %.6f ETH in its credit balance and %.6f ETH staked on its behalf. %.6f can be used to make new validators.\n",
math.RoundDown(eth.WeiToEth(status.CreditBalance), 6),
math.RoundDown(eth.WeiToEth(status.EthOnBehalfBalance), 6),
math.RoundDown(eth.WeiToEth(status.UsableCreditAndEthOnBehalfBalance), 6),
)
// Registered node details
if status.Registered {
// Node status
fmt.Printf("The node is registered with Rocket Pool with a timezone location of %s.\n", status.TimezoneLocation)
if status.Trusted {
fmt.Println("The node is a member of the oracle DAO - it can vote on DAO proposals and perform watchtower duties.")
}
fmt.Println()
if status.IsSaturnDeployed {
fmt.Printf("%s=== Megapool ===%s\n", colorGreen, colorReset)
if status.MegapoolDeployed {
fmt.Printf("The node has a megapool deployed at %s%s%s.", colorBlue, status.MegapoolAddress.Hex(), colorReset)
fmt.Println()
fmt.Printf("The megapool has %d validators.", status.MegapoolActiveValidatorCount)
fmt.Println()
if status.MegapoolNodeDebt.Cmp(big.NewInt(0)) > 0 {
fmt.Printf("The megapool debt is %.6f ETH.", math.RoundDown(eth.WeiToEth(status.MegapoolNodeDebt), 6))
fmt.Println()
}
if status.MegapoolRefundValue.Cmp(big.NewInt(0)) > 0 {
fmt.Printf("The megapool refund value is %.6f ETH.", math.RoundDown(eth.WeiToEth(status.MegapoolRefundValue), 6))
fmt.Println()
}
} else {
fmt.Println("The node does not have a megapool deployed yet.")
fmt.Println()
}
fmt.Printf("The node has %d express ticket(s).", status.ExpressTicketCount)
fmt.Println()
fmt.Println()
}
// Penalties
fmt.Printf("%s=== Penalty Status ===%s\n", colorGreen, colorReset)
if len(status.PenalizedMinipools) > 0 {
strikeMinipools := []common.Address{}
infractionMinipools := []common.Address{}
for mp, count := range status.PenalizedMinipools {
if count < 3 {
strikeMinipools = append(strikeMinipools, mp)
} else {
infractionMinipools = append(infractionMinipools, mp)
}
}
if len(strikeMinipools) > 0 {
sort.Slice(strikeMinipools, func(i, j int) bool { // Sort them lexicographically
return strikeMinipools[i].Hex() < strikeMinipools[j].Hex()
})
fmt.Printf("%sWARNING: The following minipools have been given strikes for cheating with an invalid fee recipient:\n", colorYellow)
for _, mp := range strikeMinipools {
fmt.Printf("\t%s: %d strikes\n", mp.Hex(), status.PenalizedMinipools[mp])
}
fmt.Println(colorReset)
fmt.Println()
}
if len(infractionMinipools) > 0 {
sort.Slice(infractionMinipools, func(i, j int) bool { // Sort them lexicographically
return infractionMinipools[i].Hex() < infractionMinipools[j].Hex()
})
fmt.Printf("%sWARNING: The following minipools have been given infractions for cheating with an invalid fee recipient:\n", colorRed)
for _, mp := range infractionMinipools {
fmt.Printf("\t%s: %d infractions\n", mp.Hex(), status.PenalizedMinipools[mp]-2)
}
fmt.Println(colorReset)
fmt.Println()
}
} else {
fmt.Println("The node does not have any penalties for cheating with an invalid fee recipient.")
fmt.Println()
}
// Signalling Status
fmt.Printf("%s=== Signalling on Snapshot ===%s\n", colorGreen, colorReset)
blankAddress := common.Address{}
if status.SignallingAddress == blankAddress {
fmt.Printf("The node does not currently have a snapshot signalling address set.\nTo learn more about snapshot signalling, please visit %s.\n", signallingAddressLink)
} else {
fmt.Printf("The node has a signalling address of %s%s%s which can represent it when voting on Rocket Pool Snapshot governance proposals.\n", colorBlue, status.SignallingAddressFormatted, colorReset)
}
if status.SnapshotResponse.Error != "" {
fmt.Printf("Unable to fetch latest voting information from snapshot.org: %s\n", status.SnapshotResponse.Error)
} else {
voteCount := 0
for _, activeProposal := range status.SnapshotResponse.ActiveSnapshotProposals {
for _, votedProposal := range status.SnapshotResponse.ProposalVotes {
if votedProposal.Proposal.Id == activeProposal.Id {
voteCount++
break
}
}
}
if len(status.SnapshotResponse.ActiveSnapshotProposals) == 0 {
fmt.Print("Rocket Pool has no Snapshot governance proposals being voted on.\n")
} else {
fmt.Printf("Rocket Pool has %d Snapshot governance proposal(s) being voted on. You have voted on %d of those. See details using 'rocketpool network dao-proposals'.\n", len(status.SnapshotResponse.ActiveSnapshotProposals), voteCount)
}
fmt.Println("")
}
// Onchain voting status
fmt.Printf("%s=== Onchain Voting ===%s\n", colorGreen, colorReset)
if status.OnchainVotingDelegate == blankAddress {
fmt.Println("The node doesn't have a delegate, which means it can vote directly on onchain proposals after it initializes voting.")
} else if status.OnchainVotingDelegate == status.AccountAddress {
fmt.Println("The node doesn't have a delegate, which means it can vote directly on onchain proposals. You can have another node represent you by running `rocketpool p svd <address>`.")
} else {
fmt.Printf("The node has a voting delegate of %s%s%s which can represent it when voting on Rocket Pool onchain governance proposals.\n", colorBlue, status.OnchainVotingDelegateFormatted, colorReset)
}
if status.IsRPLLockingAllowed {
fmt.Print("The node is allowed to lock RPL to create governance proposals/challenges.\n")
if status.NodeRPLLocked.Cmp(big.NewInt(0)) != 0 {
fmt.Printf("The node currently has %.6f RPL locked.\n",
math.RoundDown(eth.WeiToEth(status.NodeRPLLocked), 6))
}
} else {
fmt.Print("The node is NOT allowed to lock RPL to create governance proposals/challenges.\n")
}
fmt.Println("")
// Primary withdrawal address & balances
fmt.Printf("%s=== Primary Withdrawal Address ===%s\n", colorGreen, colorReset)
if !bytes.Equal(status.AccountAddress.Bytes(), status.PrimaryWithdrawalAddress.Bytes()) {
fmt.Printf(
"The node's primary withdrawal address %s%s%s has a balance of %.6f ETH and %.6f RPL.\n",
colorBlue,
status.PrimaryWithdrawalAddressFormatted,
colorReset,
math.RoundDown(eth.WeiToEth(status.PrimaryWithdrawalBalances.ETH), 6),
math.RoundDown(eth.WeiToEth(status.PrimaryWithdrawalBalances.RPL), 6))
} else {
fmt.Printf("%sThe node's primary withdrawal address has not been changed, so ETH rewards and minipool withdrawals will be sent to the node itself.\n", colorYellow)
fmt.Printf("Consider changing this to a cold wallet address that you control using the `set-withdrawal-address` command.\n%s", colorReset)
}
fmt.Println("")
if status.PendingPrimaryWithdrawalAddress.Hex() != blankAddress.Hex() {
fmt.Printf("%sThe node's primary withdrawal address has a pending change to %s which has not been confirmed yet.\n", colorYellow, status.PendingPrimaryWithdrawalAddressFormatted)
fmt.Printf("Please visit the Rocket Pool website with a web3-compatible wallet to complete this change.%s\n", colorReset)
fmt.Println("")
}
// RPL withdrawal address & balances
fmt.Printf("%s=== RPL Withdrawal Address ===%s\n", colorGreen, colorReset)
if !status.IsRPLWithdrawalAddressSet {
fmt.Printf("The node's RPL withdrawal address has not been set. All RPL rewards will be sent to the primary withdrawal address.\n")
} else if bytes.Equal(status.AccountAddress.Bytes(), status.RPLWithdrawalAddress.Bytes()) {
fmt.Printf("The node's RPL withdrawal address has been explicitly set to the node address itself (%s%s%s).\n", colorBlue, status.RPLWithdrawalAddressFormatted, colorReset)
} else if bytes.Equal(status.PrimaryWithdrawalAddress.Bytes(), status.RPLWithdrawalAddress.Bytes()) {
fmt.Printf("The node's RPL withdrawal address has been explicitly set to the primary withdrawal address (%s%s%s).\n", colorBlue, status.RPLWithdrawalAddressFormatted, colorReset)
} else {
fmt.Printf(
"The node's RPL withdrawal address %s%s%s has a balance of %.6f ETH and %.6f RPL.\n",
colorBlue,
status.RPLWithdrawalAddressFormatted,
colorReset,
math.RoundDown(eth.WeiToEth(status.RPLWithdrawalBalances.ETH), 6),
math.RoundDown(eth.WeiToEth(status.RPLWithdrawalBalances.RPL), 6))
}
fmt.Println("")
if status.PendingRPLWithdrawalAddress.Hex() != blankAddress.Hex() {
fmt.Printf("%sThe node's RPL withdrawal address has a pending change to %s which has not been confirmed yet.\n", colorYellow, status.PendingRPLWithdrawalAddressFormatted)
fmt.Printf("Please visit the Rocket Pool website with a web3-compatible wallet to complete this change.%s\n", colorReset)
fmt.Println("")
}
// Fee distributor details
fmt.Printf("%s=== Fee Distributor and Smoothing Pool ===%s\n", colorGreen, colorReset)
fmt.Printf("The node's fee distributor %s%s%s has a balance of %.6f ETH.\n", colorBlue, status.FeeRecipientInfo.FeeDistributorAddress.Hex(), colorReset, math.RoundDown(eth.WeiToEth(status.FeeDistributorBalance), 6))
if cfg.IsNativeMode && !status.FeeRecipientInfo.IsInSmoothingPool && !status.FeeRecipientInfo.IsInOptOutCooldown {
fmt.Printf("%sNOTE: You are in Native Mode; you MUST ensure that your Validator Client is using this address as its fee recipient!%s\n", colorYellow, colorReset)
}
if !status.IsFeeDistributorInitialized {
fmt.Printf("\n%sThe fee distributor hasn't been initialized yet. When you are able, please initialize it with `rocketpool node initialize-fee-distributor`.%s\n", colorYellow, colorReset)
}
if status.FeeRecipientInfo.IsInSmoothingPool {
fmt.Printf(
"The node is currently opted into the Smoothing Pool (%s%s%s).\n",
colorBlue,
status.FeeRecipientInfo.SmoothingPoolAddress.Hex(),
colorReset)
if cfg.IsNativeMode {
fmt.Printf("%sNOTE: You are in Native Mode; you MUST ensure that your Validator Client is using this address as its fee recipient!%s\n", colorYellow, colorReset)
}
} else if status.FeeRecipientInfo.IsInOptOutCooldown {
fmt.Printf(
"The node is currently opting out of the Smoothing Pool, but cannot safely change its fee recipient yet.\nIt must remain the Smoothing Pool's address (%s%s%s) until the opt-out process is complete.\nIt can safely be changed once Epoch %d is finalized on the Beacon Chain.\n",
colorBlue,
status.FeeRecipientInfo.SmoothingPoolAddress.Hex(),
colorReset,
status.FeeRecipientInfo.OptOutEpoch)
if cfg.IsNativeMode {
fmt.Printf("%sNOTE: You are in Native Mode; you MUST ensure that your Validator Client is using this address as its fee recipient!%s\n", colorYellow, colorReset)
}
} else {
fmt.Printf("The node is not opted into the Smoothing Pool.\nTo learn more about the Smoothing Pool, please visit %s.\n", smoothingPoolLink)
// Count the number of 8 ETH, <10% commission minipools
poolsWithMissingCommission := 0
leb16wei := new(big.Int)
leb16wei.SetString("16000000000000000000", 10)
for _, minipool := range status.Minipools {
if minipool.Node.DepositBalance.Cmp(leb16wei) < 0 && minipool.Node.Fee*100 < 10 && minipool.Validator.Active {
poolsWithMissingCommission++
}
}
if poolsWithMissingCommission == 1 {
fmt.Printf("%sYou have %d minipool that would earn extra commission if you opted into the smoothing pool!%s\n", colorYellow, poolsWithMissingCommission, colorReset)
fmt.Println("See https://rpips.rocketpool.net/RPIPs/RPIP-62 for more information about bonus commission, or run `rocketpool node join-smoothing-pool` to opt in.")
}
if poolsWithMissingCommission > 1 {
fmt.Printf("%sYou have %d minipools that would earn extra commission if you opted into the smoothing pool!%s\n", colorYellow, poolsWithMissingCommission, colorReset)
fmt.Println("See https://rpips.rocketpool.net/RPIPs/RPIP-62 for more information about bonus commission, or run `rocketpool node join-smoothing-pool` to opt in.")
}
}
fmt.Println()
// RPL stake details
fmt.Printf("%s=== RPL Stake ===%s\n", colorGreen, colorReset)
fmt.Println("NOTE: The following figures take *any pending bond reductions* into account.")
fmt.Println()
fmt.Printf("The node has a total stake of %.6f RPL.\n", math.RoundDown(eth.WeiToEth(status.RplStake), 6))
if status.BorrowedCollateralRatio > 0 {
fmt.Printf("This is currently %.2f%% of its borrowed ETH and %.2f%% of its bonded ETH.\n", status.BorrowedCollateralRatio*100, status.BondedCollateralRatio*100)
}
if status.IsSaturnDeployed {
fmt.Printf("The node has %.6f megapool staked RPL.\n", math.RoundDown(eth.WeiToEth(status.RplStakeMegapool), 6))
if status.RplStakeLegacy != nil && status.RplStakeLegacy.Cmp(big.NewInt(0)) != 0 {
fmt.Printf("The node has %6f legacy staked RPL.\n", math.RoundDown(eth.WeiToEth(status.RplStakeLegacy), 6))
fmt.Printf("The node has a total stake (legacy minipool RPL plus megapool RPL) of %.6f RPL.\n", math.RoundDown(eth.WeiToEth(status.RplStake), 6))
}
var unstakingPeriodEnd time.Time
if status.UnstakingRPL.Cmp(big.NewInt(0)) > 0 {
fmt.Printf("The unstaking period is currently %s\n", status.UnstakingPeriodDuration)
// Check if unstaking period passed considering the last unstake time
unstakingPeriodEnd = status.LastRPLUnstakeTime.Add(status.UnstakingPeriodDuration)
fmt.Printf("Your node has %.6f RPL unstaking. That amount will be withdrawable on %s.\n", math.RoundDown(eth.WeiToEth(status.UnstakingRPL), 6), unstakingPeriodEnd.Format(TimeFormat))
}
// Max withdrawable amount for megapools
var maxAmount big.Int
maxAmount.Sub(status.RplStake, status.NodeRPLLocked)
if maxAmount.Cmp(status.RplStakeMegapool) < 0 {
maxAmount.Set(status.RplStakeMegapool)
}
fmt.Printf("You have %.6f RPL staked on your megapool and can request to unstake up to %.6f RPL\n", math.RoundDown(eth.WeiToEth(status.RplStakeMegapool), 6), math.RoundDown(eth.WeiToEth(&maxAmount), 6))
} else {
// Withdrawal limit pre-saturn 1
rplTotalStake := math.RoundDown(eth.WeiToEth(status.RplStake), 6)
rplWithdrawalLimit := math.RoundDown(eth.WeiToEth(status.MaximumRplStake), 6)
if rplTotalStake > rplWithdrawalLimit {
fmt.Printf(
"You can withdraw down to %.6f RPL (%.0f%% of bonded eth)\n", math.RoundDown(eth.WeiToEth(status.MaximumRplStake), 6), (status.MaximumStakeFraction)*100)
}
}
fmt.Printf(
"RPIP-30 is in effect and the node will gradually earn rewards in amounts above the previous limit of 150%% of bonded ETH. Read more at https://github.com/rocket-pool/RPIPs/blob/main/RPIPs/RPIP-30.md\n")
fmt.Println()
remainingAmount := big.NewInt(0).Sub(status.EthBorrowedLimit, status.EthBorrowed)
remainingAmount.Sub(remainingAmount, status.PendingBorrowAmount)
remainingAmountEth := int(eth.WeiToEth(remainingAmount))
remainingFor8EB := max(remainingAmountEth/24, 0)
remainingFor16EB := max(remainingAmountEth/16, 0)
fmt.Printf("The node has enough RPL staked to make %d more 8-ETH minipools (or %d more 16-ETH minipools).\n\n", remainingFor8EB, remainingFor16EB)
// Minipool details
fmt.Printf("%s=== Minipools ===%s\n", colorGreen, colorReset)
if status.MinipoolCounts.Total > 0 {
// Minipools
fmt.Printf("The node has a total of %d active minipool(s):\n", status.MinipoolCounts.Total-status.MinipoolCounts.Finalised)
if status.MinipoolCounts.Initialized > 0 {
fmt.Printf("- %d initialized\n", status.MinipoolCounts.Initialized)
}
if status.MinipoolCounts.Prelaunch > 0 {
fmt.Printf("- %d at prelaunch\n", status.MinipoolCounts.Prelaunch)
}
if status.MinipoolCounts.Staking > 0 {
fmt.Printf("- %d staking\n", status.MinipoolCounts.Staking)
}
if status.MinipoolCounts.Withdrawable > 0 {
fmt.Printf("- %d withdrawable (after withdrawal delay)\n", status.MinipoolCounts.Withdrawable)
}
if status.MinipoolCounts.Dissolved > 0 {
fmt.Printf("- %d dissolved\n", status.MinipoolCounts.Dissolved)
}
if status.MinipoolCounts.RefundAvailable > 0 {
fmt.Printf("* %d minipool(s) have refunds available!\n", status.MinipoolCounts.RefundAvailable)
}
if status.MinipoolCounts.WithdrawalAvailable > 0 {
fmt.Printf("* %d minipool(s) are ready for withdrawal!\n", status.MinipoolCounts.WithdrawalAvailable)
}
if status.MinipoolCounts.CloseAvailable > 0 {
fmt.Printf("* %d dissolved minipool(s) can be closed and your deposit (minus the prelaunch amount) refunded!\n", status.MinipoolCounts.CloseAvailable)
}
if status.MinipoolCounts.Finalised > 0 {
fmt.Printf("* %d minipool(s) are finalized and no longer active.\n", status.MinipoolCounts.Finalised)
}
} else {
fmt.Println("The node does not have any minipools yet.")
}
} else {
fmt.Println("The node is not registered with Rocket Pool.")
}
// Alerts
if cfg.EnableMetrics.Value == true && len(status.Alerts) > 0 {
// only print alerts if enabled; to avoid misleading the user to thinking everything is fine (since we really don't know).
fmt.Printf("\n%s=== Alerts ===%s\n", colorGreen, colorReset)
for i, alert := range status.Alerts {
fmt.Println(alert.ColorString())
if i == maxAlertItems-1 {
break
}
}
if len(status.Alerts) > maxAlertItems {
fmt.Printf("... and %d more.\n", len(status.Alerts)-maxAlertItems)
}
}
if status.Warning != "" {
fmt.Printf("\n%sWARNING: %s%s\n", colorRed, status.Warning, colorReset)
}
// Return
return nil
}