node: add avalanche support in testnet mode

Change-Id: Icdf6c26187547d1b1929e43530beeec17c142e3f
This commit is contained in:
Leo 2021-12-09 22:40:55 +01:00 committed by Josh Siegel
parent 5c30438f35
commit 864e983e04
5 changed files with 35 additions and 4 deletions

View File

@ -67,9 +67,9 @@ func runListNodes(cmd *cobra.Command, args []string) {
if *testnetMode {
// Include Ropsten in testnet mode
if showDetails {
_, _ = w.Write([]byte("Node key\tGuardian key\tNode name\tVersion\tLast seen\tUptime\tSolana\tEthereum\tTerra\tBSC\tPolygon\tRopsten\n"))
_, _ = w.Write([]byte("Node key\tGuardian key\tNode name\tVersion\tLast seen\tUptime\tSolana\tEthereum\tTerra\tBSC\tPolygon\tAvalanche\tRopsten\n"))
} else {
_, _ = w.Write([]byte("Node key\tGuardian key\tNode name\tVersion\tLast seen\tSolana\tEthereum\tTerra\tBSC\tPolygon\tRopsten\n"))
_, _ = w.Write([]byte("Node key\tGuardian key\tNode name\tVersion\tLast seen\tSolana\tEthereum\tTerra\tBSC\tPolygon\tAvalanche\tRopsten\n"))
}
} else {
if showDetails {
@ -103,7 +103,7 @@ func runListNodes(cmd *cobra.Command, args []string) {
if *testnetMode {
if showDetails {
fmt.Fprintf(w,
"%s\t%s\t%s\t%s\t%s\t%s\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\n",
"%s\t%s\t%s\t%s\t%s\t%s\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\t%s %d (%d)\n",
h.P2PNodeAddr,
h.RawHeartbeat.GuardianAddr,
h.RawHeartbeat.NodeName,
@ -125,13 +125,16 @@ func runListNodes(cmd *cobra.Command, args []string) {
truncAddrs[vaa.ChainIDPolygon],
heights[vaa.ChainIDPolygon],
errors[vaa.ChainIDPolygon],
truncAddrs[vaa.ChainIDAvalanche],
heights[vaa.ChainIDAvalanche],
errors[vaa.ChainIDAvalanche],
truncAddrs[vaa.ChainIDEthereumRopsten],
heights[vaa.ChainIDEthereumRopsten],
errors[vaa.ChainIDEthereumRopsten],
)
} else {
fmt.Fprintf(w,
"%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\n",
"%s\t%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
h.P2PNodeAddr,
h.RawHeartbeat.GuardianAddr,
h.RawHeartbeat.NodeName,
@ -142,6 +145,7 @@ func runListNodes(cmd *cobra.Command, args []string) {
heights[vaa.ChainIDTerra],
heights[vaa.ChainIDBSC],
heights[vaa.ChainIDPolygon],
heights[vaa.ChainIDAvalanche],
heights[vaa.ChainIDEthereumRopsten],
)
}

View File

@ -68,6 +68,9 @@ var (
ethRopstenRPC *string
ethRopstenContract *string
avalancheRPC *string
avalancheContract *string
terraWS *string
terraLCD *string
terraContract *string
@ -128,6 +131,9 @@ func init() {
ethRopstenRPC = NodeCmd.Flags().String("ethRopstenRPC", "", "Ethereum Ropsten RPC URL")
ethRopstenContract = NodeCmd.Flags().String("ethRopstenContract", "", "Ethereum Ropsten contract address")
avalancheRPC = NodeCmd.Flags().String("avalancheRPC", "", "Avalanche RPC URL")
avalancheContract = NodeCmd.Flags().String("avalancheContract", "", "Avalanche contract address")
terraWS = NodeCmd.Flags().String("terraWS", "", "Path to terrad root for websocket connection")
terraLCD = NodeCmd.Flags().String("terraLCD", "", "Path to LCD service root for http calls")
terraContract = NodeCmd.Flags().String("terraContract", "", "Wormhole contract address on Terra blockchain")
@ -238,6 +244,7 @@ func runNode(cmd *cobra.Command, args []string) {
readiness.RegisterComponent(common.ReadinessPolygonSyncing)
if *testnetMode {
readiness.RegisterComponent(common.ReadinessEthRopstenSyncing)
readiness.RegisterComponent(common.ReadinessAvalancheSyncing)
}
if *statusAddr != "" {
@ -328,6 +335,9 @@ func runNode(cmd *cobra.Command, args []string) {
if *ethRopstenContract == "" {
logger.Fatal("Please specify --ethRopstenContract")
}
if *avalancheRPC == "" {
logger.Fatal("Please specify --avalancheRPC")
}
} else {
if *ethRopstenRPC != "" {
logger.Fatal("Please do not specify --ethRopstenRPC in non-testnet mode")
@ -335,6 +345,9 @@ func runNode(cmd *cobra.Command, args []string) {
if *ethRopstenContract != "" {
logger.Fatal("Please do not specify --ethRopstenContract in non-testnet mode")
}
if *avalancheRPC != "" {
logger.Fatal("Please do not specify --avalancheRPC in non-testnet mode")
}
}
if *nodeName == "" {
logger.Fatal("Please specify --nodeName")
@ -402,6 +415,7 @@ func runNode(cmd *cobra.Command, args []string) {
bscContractAddr := eth_common.HexToAddress(*bscContract)
polygonContractAddr := eth_common.HexToAddress(*polygonContract)
ethRopstenContractAddr := eth_common.HexToAddress(*ethRopstenContract)
avalancheContractAddr := eth_common.HexToAddress(*avalancheContract)
solAddress, err := solana_types.PublicKeyFromBase58(*solanaContract)
if err != nil {
logger.Fatal("invalid Solana contract address", zap.Error(err))
@ -539,6 +553,10 @@ func runNode(cmd *cobra.Command, args []string) {
ethereum.NewEthWatcher(*ethRopstenRPC, ethRopstenContractAddr, "ethropsten", common.ReadinessEthRopstenSyncing, vaa.ChainIDEthereumRopsten, lockC, setC).Run); err != nil {
return err
}
if err := supervisor.Run(ctx, "avalanchewatch",
ethereum.NewEthWatcher(*avalancheRPC, avalancheContractAddr, "avalanche", common.ReadinessAvalancheSyncing, vaa.ChainIDAvalanche, lockC, nil).Run); err != nil {
return err
}
}
// Start Terra watcher only if configured

View File

@ -9,4 +9,5 @@ const (
ReadinessBSCSyncing readiness.Component = "bscSyncing"
ReadinessPolygonSyncing readiness.Component = "polygonSyncing"
ReadinessEthRopstenSyncing readiness.Component = "ethRopstenSyncing"
ReadinessAvalancheSyncing readiness.Component = "avalancheSyncing"
)

View File

@ -94,6 +94,8 @@ func (c ChainID) String() string {
return "bsc"
case ChainIDPolygon:
return "polygon"
case ChainIDAvalanche:
return "avalanche"
case ChainIDEthereumRopsten:
return "ethereum-ropsten"
default:
@ -115,6 +117,8 @@ func ChainIDFromString(s string) (ChainID, error) {
return ChainIDBSC, nil
case "polygon":
return ChainIDPolygon, nil
case "avalanche":
return ChainIDAvalanche, nil
case "ethereum-ropsten":
return ChainIDEthereumRopsten, nil
default:
@ -134,6 +138,9 @@ const (
ChainIDBSC ChainID = 4
// ChainIDPolygon is the ChainID of Polygon
ChainIDPolygon ChainID = 5
// ChainIDAvalanche is the ChainID of Avalanche
ChainIDAvalanche ChainID = 6
// ChainIDEthereumRopsten is the ChainID of Ethereum Ropsten
ChainIDEthereumRopsten ChainID = 10001

View File

@ -14,6 +14,7 @@ enum ChainID {
CHAIN_ID_TERRA = 3;
CHAIN_ID_BSC = 4;
CHAIN_ID_POLYGON = 5;
CHAIN_ID_AVALANCHE = 6;
// Special case - Eth has two testnets. CHAIN_ID_ETHEREUM is Goerli,
// but we also want to connect to Ropsten, so we add a separate chain.
CHAIN_ID_ETHEREUM_ROPSTEN = 10001;