@@ -3,6 +3,7 @@ package megapool
33import (
44 "fmt"
55 "sort"
6+ "strings"
67
78 "github.com/rocket-pool/smartnode/shared/services/beacon"
89 "github.com/rocket-pool/smartnode/shared/services/rocketpool"
@@ -26,7 +27,26 @@ func getExitableValidator() (uint64, bool, error) {
2627 defer rp .Close ()
2728
2829 // Get the latest block and identify the withdrawals present in it
29-
30+ withdrawalsResp , err := rp .GetLatestBlockWithdrawals ()
31+ if err != nil {
32+ fmt .Printf ("Warning: could not fetch latest beacon block withdrawals: %s\n \n " , err .Error ())
33+ } else if len (withdrawalsResp .Withdrawals ) == 0 {
34+ fmt .Printf ("Latest beacon block (slot %d, exec block %d) has no validator withdrawals.\n \n " ,
35+ withdrawalsResp .Slot , withdrawalsResp .BlockNumber )
36+ } else {
37+ indexes := make ([]string , 0 , len (withdrawalsResp .Withdrawals ))
38+ seen := make (map [string ]struct {}, len (withdrawalsResp .Withdrawals ))
39+ for _ , wd := range withdrawalsResp .Withdrawals {
40+ if _ , ok := seen [wd .ValidatorIndex ]; ok {
41+ continue
42+ }
43+ seen [wd .ValidatorIndex ] = struct {}{}
44+ indexes = append (indexes , wd .ValidatorIndex )
45+ }
46+ fmt .Printf ("Latest beacon block (slot %d, exec block %d) processed withdrawals for %d validator(s):\n " ,
47+ withdrawalsResp .Slot , withdrawalsResp .BlockNumber , len (indexes ))
48+ fmt .Printf (" %s\n \n " , strings .Join (indexes , ", " ))
49+ }
3050
3151 // Get Megapool status
3252 status , err := rp .MegapoolStatus (false )
@@ -50,7 +70,9 @@ func getExitableValidator() (uint64, bool, error) {
5070 }
5171 }
5272 if len (exitingValidators ) > 0 {
53- sort .Sort (ByIndex (exitingValidators ))
73+ // Make sure that exitingValidators is sorted by validator index ascending from the last withdrawal index
74+
75+ //sort.Sort(ByIndex(exitingValidators))
5476 fmt .Println ("The following validators are still active and have already received their exit request on the Beacon Chain:" )
5577 for _ , v := range exitingValidators {
5678 fmt .Printf ("ID %d: - Index %d Pubkey: 0x%s\n " , v .ValidatorId , v .ValidatorIndex , v .PubKey .String ())
0 commit comments