Skip to content

Commit b219e63

Browse files
committed
Dedup deposit contract and network checks
1 parent 41917a0 commit b219e63

File tree

5 files changed

+34
-50
lines changed

5 files changed

+34
-50
lines changed

rocketpool-cli/commands/node/create-vacant-minipool.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,10 @@ func createVacantMinipool(c *cli.Context, pubkey beacon.ValidatorPubkey) error {
3434
if err != nil {
3535
return err
3636
}
37-
if depositContractInfo.Data.RPNetwork != depositContractInfo.Data.BeaconNetwork ||
38-
depositContractInfo.Data.RPDepositContract != depositContractInfo.Data.BeaconDepositContract {
39-
utils.PrintDepositMismatchError(
40-
depositContractInfo.Data.RPNetwork,
41-
depositContractInfo.Data.BeaconNetwork,
42-
depositContractInfo.Data.RPDepositContract,
43-
depositContractInfo.Data.BeaconDepositContract)
37+
if depositContractInfo.Data.PrintMismatch() {
4438
return nil
4539
}
4640

47-
fmt.Println("Your Beacon Node is on the correct network.")
48-
fmt.Println()
49-
5041
// Check if the fee distributor has been initialized
5142
feeDistributorResponse, err := rp.Api.Node.InitializeFeeDistributor()
5243
if err != nil {

rocketpool-cli/commands/node/deposit.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,10 @@ func nodeDeposit(c *cli.Context) error {
3333
if err != nil {
3434
return err
3535
}
36-
if depositContractInfo.Data.RPNetwork != depositContractInfo.Data.BeaconNetwork ||
37-
depositContractInfo.Data.RPDepositContract != depositContractInfo.Data.BeaconDepositContract {
38-
utils.PrintDepositMismatchError(
39-
depositContractInfo.Data.RPNetwork,
40-
depositContractInfo.Data.BeaconNetwork,
41-
depositContractInfo.Data.RPDepositContract,
42-
depositContractInfo.Data.BeaconDepositContract)
36+
if depositContractInfo.Data.PrintMismatch() {
4337
return nil
4438
}
4539

46-
fmt.Println("Your Beacon Node is on the correct network.")
47-
fmt.Println()
48-
4940
// Check if the fee distributor has been initialized
5041
feeDistributorResponse, err := rp.Api.Node.InitializeFeeDistributor()
5142
if err != nil {

rocketpool-cli/commands/service/sync.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,9 @@ func getSyncProgress(c *cli.Context) error {
9999
if err != nil {
100100
return err
101101
}
102-
if depositContractInfo.Data.RPNetwork != depositContractInfo.Data.BeaconNetwork ||
103-
depositContractInfo.Data.RPDepositContract != depositContractInfo.Data.BeaconDepositContract {
104-
utils.PrintDepositMismatchError(
105-
depositContractInfo.Data.RPNetwork,
106-
depositContractInfo.Data.BeaconNetwork,
107-
depositContractInfo.Data.RPDepositContract,
108-
depositContractInfo.Data.BeaconDepositContract)
109-
return nil
110-
} else {
111-
fmt.Println("Your Beacon Node is on the correct network.")
112-
fmt.Println()
113-
}
114102

115-
// Return
103+
// Print any mismatch between client networks
104+
depositContractInfo.Data.PrintMismatch()
105+
116106
return nil
117107
}

rocketpool-cli/utils/utils.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,6 @@ func PrettyPrintError(err error) {
153153
fmt.Println(prettyErr)
154154
}
155155

156-
// Prints an error message when the Beacon client is not using the deposit contract address that Rocket Pool expects
157-
func PrintDepositMismatchError(rpNetwork, beaconNetwork uint64, rpDepositAddress, beaconDepositAddress common.Address) {
158-
fmt.Printf("%s***ALERT***\n", terminal.ColorRed)
159-
fmt.Println("YOUR ETH2 CLIENT IS NOT CONNECTED TO THE SAME NETWORK THAT ROCKET POOL IS USING!")
160-
fmt.Println("This is likely because your ETH2 client is using the wrong configuration.")
161-
fmt.Println("For the safety of your funds, Rocket Pool will not let you deposit your ETH until this is resolved.")
162-
fmt.Println()
163-
fmt.Println("To fix it if you are in Docker mode:")
164-
fmt.Println("\t1. Run 'rocketpool service install -d' to get the latest configuration")
165-
fmt.Println("\t2. Run 'rocketpool service stop' and 'rocketpool service start' to apply the configuration.")
166-
fmt.Println("If you are using Hybrid or Native mode, please correct the network flags in your ETH2 launch script.")
167-
fmt.Println()
168-
fmt.Println("Details:")
169-
fmt.Printf("\tRocket Pool expects deposit contract %s on chain %d.\n", rpDepositAddress.Hex(), rpNetwork)
170-
fmt.Printf("\tYour Beacon client is using deposit contract %s on chain %d.%s\n", beaconDepositAddress.Hex(), beaconNetwork, terminal.ColorReset)
171-
}
172-
173156
// Prints what network you're currently on
174157
func PrintNetwork(currentNetwork config.Network, isNew bool) error {
175158
if isNew {

shared/types/api/network.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package api
22

33
import (
4+
"fmt"
45
"math/big"
56

67
"github.com/ethereum/go-ethereum/common"
8+
"github.com/rocket-pool/smartnode/v2/rocketpool-cli/utils/terminal"
79
sharedtypes "github.com/rocket-pool/smartnode/v2/shared/types"
810
)
911

@@ -73,3 +75,30 @@ type NetworkDepositContractInfoData struct {
7375
BeaconNetwork uint64 `json:"beaconNetwork"`
7476
SufficientSync bool `json:"sufficientSync"`
7577
}
78+
79+
func (ndcid *NetworkDepositContractInfoData) Mismatched() bool {
80+
return ndcid.RPNetwork != ndcid.BeaconNetwork ||
81+
ndcid.RPDepositContract != ndcid.BeaconDepositContract
82+
}
83+
84+
func (ndcid *NetworkDepositContractInfoData) PrintMismatch() bool {
85+
if !ndcid.Mismatched() {
86+
fmt.Println("Your Beacon Node is on the correct network.")
87+
fmt.Println()
88+
return false
89+
}
90+
fmt.Printf("%s***ALERT***\n", terminal.ColorRed)
91+
fmt.Println("YOUR ETH2 CLIENT IS NOT CONNECTED TO THE SAME NETWORK THAT ROCKET POOL IS USING!")
92+
fmt.Println("This is likely because your ETH2 client is using the wrong configuration.")
93+
fmt.Println("For the safety of your funds, Rocket Pool will not let you deposit your ETH until this is resolved.")
94+
fmt.Println()
95+
fmt.Println("To fix it if you are in Docker mode:")
96+
fmt.Println("\t1. Run 'rocketpool service install -d' to get the latest configuration")
97+
fmt.Println("\t2. Run 'rocketpool service stop' and 'rocketpool service start' to apply the configuration.")
98+
fmt.Println("If you are using Hybrid or Native mode, please correct the network flags in your ETH2 launch script.")
99+
fmt.Println()
100+
fmt.Println("Details:")
101+
fmt.Printf("\tRocket Pool expects deposit contract %s on chain %d.\n", ndcid.RPDepositContract.Hex(), ndcid.RPNetwork)
102+
fmt.Printf("\tYour Beacon client is using deposit contract %s on chain %d.%s\n", ndcid.BeaconDepositContract.Hex(), ndcid.BeaconNetwork, terminal.ColorReset)
103+
return true
104+
}

0 commit comments

Comments
 (0)