Skip to content

Commit 8ceb914

Browse files
committed
Add the finalized slot to the api call
1 parent e8db553 commit 8ceb914

5 files changed

Lines changed: 44 additions & 18 deletions

File tree

bindings/utils/eth/units.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ func WeiToEthWithDecimals(amount *big.Int, decimals uint8) float64 {
9191
eth.Quo(&weiFloat, big.NewFloat(math.Pow(10, float64(decimals))))
9292
eth64, _ := eth.Float64()
9393
return eth64
94-
}
94+
}

rocketpool-cli/megapool/dissolve-validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func dissolveValidator(c *cli.Context) error {
3838
// Get Megapool status
3939
status, err := rp.MegapoolStatus(false)
4040
if err != nil {
41-
return err
41+
return err
4242
}
4343

4444
validatorsInPrestake := []api.MegapoolValidatorDetails{}

rocketpool-cli/megapool/notify-final-balance.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func notifyFinalBalance(c *cli.Context) error {
8181

8282
if c.IsSet("slot") {
8383
fmt.Println("Using withdrawal slot: ", c.Uint64("slot"))
84+
slot = c.Uint64("slot")
8485
} else {
8586
fmt.Println("The Smart Node needs to find the slot containing the validator withdrawal. This may take a while. You can speed up the final balance proof generation by submitting the withdrawal slot for your validator.")
8687
fmt.Println()

rocketpool/api/megapool/notify-final-balance.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package megapool
32

43
import (
@@ -9,12 +8,12 @@ import (
98
"github.com/rocket-pool/smartnode/bindings/types"
109
"github.com/rocket-pool/smartnode/shared/services"
1110
"github.com/rocket-pool/smartnode/shared/types/api"
12-
"github.com/rocket-pool/smartnode/shared/utils/eth1"
1311
cfgtypes "github.com/rocket-pool/smartnode/shared/types/config"
12+
"github.com/rocket-pool/smartnode/shared/utils/eth1"
1413
"github.com/urfave/cli"
1514
)
1615

17-
func canNotifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*api.CanNotifyFinalBalanceResponse, error) {
16+
func canNotifyFinalBalance(c *cli.Context, validatorId uint32, withdrawalSlot uint64) (*api.CanNotifyFinalBalanceResponse, error) {
1817

1918
// Get services
2019
if err := services.RequireNodeRegistered(c); err != nil {
@@ -75,15 +74,21 @@ func canNotifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*ap
7574
return nil, fmt.Errorf("Error parsing the validator index")
7675
}
7776
// If the slot was not provided, use the validator's withdrawable epoch supplied by the beacon client
78-
if slot == 0 {
79-
slot = validatorStatus.WithdrawableEpoch * 32
77+
if withdrawalSlot == 0 {
78+
withdrawalSlot = validatorStatus.WithdrawableEpoch * 32
79+
}
80+
81+
beaconHead, err := bc.GetBeaconHead()
82+
if err != nil {
83+
return nil, err
8084
}
85+
finalizedSlot := beaconHead.FinalizedEpoch * 32
8186

82-
withdrawalProof, slotUsed, stateUsed, err := services.GetWithdrawalProofForSlot(c, slot, validatorIndex)
87+
withdrawalProof, slotUsed, stateUsed, err := services.GetWithdrawalProofForSlot(c, withdrawalSlot, validatorIndex)
8388
if err != nil {
8489
fmt.Printf("An error occurred while getting the withdrawal proof: %s\n", err)
8590
// try to fetch the withdrawal proof from the Rocket Pool API
86-
withdrawalProof, slotUsed, err = services.GetWithdrawalProofForSlotFromAPI(c, slot, validatorIndex, network)
91+
withdrawalProof, slotUsed, err = services.GetWithdrawalProofForSlotFromAPI(c, finalizedSlot, withdrawalSlot, validatorIndex, network)
8792
if err != nil {
8893
fmt.Printf("An error occurred while getting the withdrawal proof from the Rocket Pool API: %s\n", err)
8994
return nil, err
@@ -133,7 +138,7 @@ func canNotifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*ap
133138

134139
}
135140

136-
func notifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*api.NotifyValidatorExitResponse, error) {
141+
func notifyFinalBalance(c *cli.Context, validatorId uint32, withdrawalSlot uint64) (*api.NotifyValidatorExitResponse, error) {
137142

138143
// Get services
139144
if err := services.RequireNodeRegistered(c); err != nil {
@@ -155,6 +160,14 @@ func notifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*api.N
155160
return nil, err
156161
}
157162

163+
cfg, err := services.GetConfig(c)
164+
if err != nil {
165+
return nil, err
166+
}
167+
168+
// Get the network
169+
network := cfg.Smartnode.Network.Value.(cfgtypes.Network)
170+
158171
// Validate minipool owner
159172
nodeAccount, err := w.GetNodeAccount()
160173
if err != nil {
@@ -197,13 +210,25 @@ func notifyFinalBalance(c *cli.Context, validatorId uint32, slot uint64) (*api.N
197210
return nil, fmt.Errorf("Error parsing the validator index")
198211
}
199212
// If the slot was not provided, use the validator's withdrawable epoch supplied by the beacon client
200-
if slot == 0 {
201-
slot = validatorStatus.WithdrawableEpoch * 32
213+
if withdrawalSlot == 0 {
214+
withdrawalSlot = validatorStatus.WithdrawableEpoch * 32
215+
}
216+
217+
beaconHead, err := bc.GetBeaconHead()
218+
if err != nil {
219+
return nil, err
202220
}
221+
finalizedSlot := beaconHead.FinalizedEpoch * 32
203222

204-
withdrawalProof, proofSlot, stateUsed, err := services.GetWithdrawalProofForSlot(c, slot, validatorIndex)
223+
withdrawalProof, proofSlot, stateUsed, err := services.GetWithdrawalProofForSlot(c, withdrawalSlot, validatorIndex)
205224
if err != nil {
206-
fmt.Printf("An error occurred: %s\n", err)
225+
fmt.Printf("An error occurred while getting the withdrawal proof: %s\n", err)
226+
// try to fetch the withdrawal proof from the Rocket Pool API
227+
withdrawalProof, proofSlot, err = services.GetWithdrawalProofForSlotFromAPI(c, finalizedSlot, withdrawalSlot, validatorIndex, network)
228+
if err != nil {
229+
fmt.Printf("An error occurred while getting the withdrawal proof from the Rocket Pool API: %s\n", err)
230+
return nil, err
231+
}
207232
}
208233

209234
withdrawal := megapool.Withdrawal{

shared/services/megapools.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
const MAX_WITHDRAWAL_SLOT_DISTANCE = 144000 // 20 days.
4343

4444
// API URL for the withdrawal proofs (base URL + network + withdrawal slot + validator index)
45-
const apiURL = "https://api.rocketpool.net/%s/withdrawals/proofs/%d/%d"
45+
const apiURL = "https://api.rocketpool.net/%s/withdrawals/proofs/%d/%d/%d"
4646

4747
type Withdrawal struct {
4848
Index uint64 `json:"index"`
@@ -654,17 +654,17 @@ func calculatePositionInQueue(rp *rocketpool.RocketPool, queueDetails api.QueueD
654654

655655
}
656656

657-
func GetWithdrawalProofForSlotFromAPI(c *cli.Context, slot uint64, validatorIndex uint64, network cfgtypes.Network) (megapool.FinalBalanceProof, uint64, error) {
657+
func GetWithdrawalProofForSlotFromAPI(c *cli.Context, finalizedSlot uint64, withdrawalSlot uint64, validatorIndex uint64, network cfgtypes.Network) (megapool.FinalBalanceProof, uint64, error) {
658658

659659
/* API calls follow this format:
660-
https://api.rocketpool.net/devnet/withdrawals/proofs/<withdrawal_slot>/<validator_index>
660+
https://api.rocketpool.net/<network>/withdrawals/proofs/<finalized_slot>/<withdrawal_slot>/<validator_index>
661661
662662
An example API response:
663663
664664
{"slot":2277023,"withdrawalSlot":2244697,"withdrawalNum":5,"withdrawal":{"index":33227778,"validatorIndex":1265923,"withdrawalCredentials":"0xf24c70772544b8ae60af28ddd34f13cc9c428ee7","amountInGwei":31995839800},"witnesses":["0x3410c5feb39b3f702d9b56634136cfb904a1f86c8f367e16fe2d4f969c898b0f","0xe2ba28dfa59acd70227d134be96c2e77e9ea1ccf7d27f94b7e3aff50eb344a53","0xf217264812ed46e949aaa1d8006b05409bbdb1438daa70cef95938140e412062","0x7fb96870d35763e6ab832250c9f8b1091f2383cde611d161b8564437f7910fc4","0x1000000000000000000000000000000000000000000000000000000000000000","0x0000100000000000000000000000000000000000000000000000000000000000","0x3f700c8ef3d83fe50eeb18e4f3df37ad98fe6f380f72c238c90d14c2cb18eefd","0x1085626fa4323b8bbe2acad06da450d8a9edc3cfcc0efe5b2830718a06d66a10","0x9c9bd327030be8c943838fd7083cb0d93d5f9c8408f78f3cd339e0f28e41c370","0xca7e70f57e9b781e937fa905ad6f090076d01db09959e31aa5b181a0d1c8569a","0x8ea7caad7a8238c943f26be0b020fb17ff83b12de0eb5977d763d2a11a21fc2c","0xaa3e128e91825440f40be45202d472ac6b70275a7999d5aa09e7b03a7f10e1d7","0x6dd3b9955d892d92338b19976fd07084bfe88a76c3063482b7f30ee60feb2a58","0xd7a3d1a54f5271259f8a74bad234ebbd73c9ce97727177da2d2a244a114c7852","0x0000000000000000000000000000000000000000000000000000000000000000","0xf5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b","0xdd165f288f4232e65aa7873f0bd8c12cefbea56dc663a30c06d3190922b1fd24","0x4dd9e68fabfffa19a6765e8aa9a1130a4c89aa587b8fe3a94026ca1b8523f679","0x1854ce5a71bcceb3c268c12bbeefbe5668bcb3f4a7e81a4856a9f43c10049859","0xbca9d545006824d4eb061f4e0b4908edffc6a50c25fbed6133e64141b86bc8b3","0xf13045a0e245b3959fa463a60028529f1a558ddf8d971c867d6a15218dd8279a","0xcc50292a5848698d71cae30bf5e6f897c8bef60dfc3e02ad6f1942e2044d8c69","0xec92853cdf50b7de0437d100cdf905e1114edd570f787eacf99fbd597c4300c1","0x982a2bee4c6798f97538986ed8bdf4327aa3ed5559421e693ca1c5513cc6d20b","0x06feb5a3ce20048e0b918726ed5cf15c4a098d4271035b1b58e975fde1cc8381","0xcd846f1c9978a061d010eb7eec8b3bd11a85b791a27e045eaf92f0ec3d7453f7","0xc33805f67b05f7f76a3db10096d2399f19cbf68be4d83e03c44fe8bc4c7f8620","0x8f9d27bbc7ec8fc85f61ac7f3bdbdcf9e7489bc3d55014dc7cdabc79d489cfe4","0xa97d47c50569d287b611735eeeb108004c0a4b64fc35b5c9d28adaa78c42b434","0x25a68400f09df83d1f6db6e9eea1db5b834bb26eb411dddf30f970994a278c8a","0xc80d5f6f2940ee052aac33fe0078ff5b52a64112c08617c8f71313a5e5f6b3de","0x114ef5c4f4bbc789f42d3367156029782916ab844a9ba92b5eac4bc7c0a1e6ae","0x5816ed9efb563c976395c126fd210ab89b7ba9f3b6336f830d4d052833fecbde","0xf9c4052c9567a598edae2a270cf8933b4b24323e49c01e1a3071ec3c56396de8","0xc78009fdf07fc56a11f122370658a353aaa542ed63e44c4bc15ff4cd105ab33c","0xa6c0f739071376d5fae6e5713a77f43bfb900e7e926a272a1fce2c046eb1af15","0x9efde052aa15429fae05bad4d0b1d7c64da64d03d7a1854a588c2cb8430c0d30","0xd88ddfeed400a8755596b21942c1497e114c302e6118290f91e6772976041fa1","0x87eb0ddba57e35f6d286673802a4af5975e22506c7cf4c64bb6be5ee11527f2c","0x92700a3530f06301b0ea071690a88c7723d5ebde9a5505c994351821be155309","0x506d86582d252405b840018792cad2bf1259f1ef5aa5f887e13cb2f0094f51e1","0xffff0ad7e659772f9534c195c815efc4014ef1e1daed4404c06385d11192e92b","0x6cf04127db05441cd833107a52be852868890e4317e6a02ab47683aa75964220","0xb7d05f875f140027ef5118a2247bbb84ce8f2f0f1123623085daf7960c329f5f","0xdf6af5f5bbdb6be9ef8aa618e4bf8073960867171e29676f8b284dea6a08a85e","0xb58d900f5e182e3c50ef74969ea16c7726c549757cc23523c369587da7293784","0xd49a7502ffcfb0340b1d7885688500ca308161a7f96b62df9d083b71fcc8f2bb","0x8fe6b1689256c0d385f42f5bbe2027a22c1996e110ba97c171d3e5948de92beb","0x8d0d63c39ebade8509e0ae3c9c3876fb5fa112be18f905ecacfecb92057603ab","0x95eec8b2e541cad4e91de38385f2e046619f54496c2382cb6cacd5b98c26f5a4","0xf893e908917775b62bff23294dbbe3a1cd8e6cc1c35b4801887b646a6f81f17f","0xcddba7b592e3133393c16194fac7431abf2f5485ed711db282183c819e08ebaa","0x8a8d7fe3af8caa085a7639a832001457dfb9128a8061142ad0335629ff23ff9c","0xfeb3c337d7a51a6fbf00b9e34c52e1c9195c969bd4e7a0bfd51d5c5bed9c1167","0xe71f0aa83cc32edfbefa9f4d3e0174ca85182eec9f3a09f6a6c0df6377a510d7","0x1501000000000000000000000000000000000000000000000000000000000000","0xbb4a0d0000000000000000000000000000000000000000000000000000000000","0x675afa2a5607e4b52f90aa67641f4d2a87d1d37e894912832fcb7879dd43b2bd","0xe0a37ef350f23459204e32961caab1b635c7349b8c21d0b170e64c760af8ccb7","0x95bee184cc5eab4b78d31c50ee452486edfedf473864c7fac86cef1de9b56d21","0x639a4850fe20dbbb573079ef58139feb5f6e7fd4d6e5319c4bd54448402a4c4a","0x91a46d0e5f2f963abc96b45ebb1867df4044298fa87235091e392b6c02aa9584","0x6c9497c4b3fb8b1a7e499db515726638d9468baad37c8b712f57636afb20b40d","0x44ce5bfa4c2c3c9e3f04c74c3cdb56404fb6b7a83bbf386f11e7305dc9aade0d","0x664471f37724d6eff852d4a3bc3b39aa1d3b37334e6184805a5364530433f860"]}/
665665
*/
666666

667-
url := fmt.Sprintf(apiURL, network, slot, validatorIndex)
667+
url := fmt.Sprintf(apiURL, network, finalizedSlot, withdrawalSlot, validatorIndex)
668668
response, err := http.Get(url)
669669
if err != nil {
670670
return megapool.FinalBalanceProof{}, 0, err

0 commit comments

Comments
 (0)