1-
21package megapool
32
43import (
@@ -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 {
0 commit comments