[FLY] Remove duplicated code (#172)

Remove duplicated constants, use the definitions in the `common` package instead.
This commit is contained in:
agodnic 2023-03-06 14:36:40 -03:00 committed by GitHub
parent f169af3d37
commit d51695999a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 18 deletions

View File

@ -4,17 +4,12 @@ import (
"fmt"
"os"
"strconv"
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
)
const defaultMaxHealthTimeSeconds = 60
// p2p network constants.
const (
P2pMainNet = "mainnet"
P2pTestNet = "testnet"
P2pDevNet = "devnet"
)
// p2p network configuration constants.
const (
// mainnet p2p config.
@ -43,14 +38,16 @@ type P2pNetworkConfig struct {
// GetP2pNetwork get p2p network config.
func GetP2pNetwork() (*P2pNetworkConfig, error) {
p2pEnviroment := os.Getenv("P2P_NETWORK")
switch p2pEnviroment {
case P2pMainNet:
return &P2pNetworkConfig{P2pMainNet, MainNetP2ppNetworkID, MainNetP2pBootstrap, MainNetP2pPort}, nil
case P2pTestNet:
return &P2pNetworkConfig{P2pTestNet, TestNetP2ppNetworkID, TestNetP2pBootstrap, TestNetP2pPort}, nil
case P2pDevNet:
return &P2pNetworkConfig{P2pDevNet, DevNetP2ppNetworkID, DevNetP2pBootstrap, DevNetP2pPort}, nil
case domain.P2pMainNet:
return &P2pNetworkConfig{domain.P2pMainNet, MainNetP2ppNetworkID, MainNetP2pBootstrap, MainNetP2pPort}, nil
case domain.P2pTestNet:
return &P2pNetworkConfig{domain.P2pTestNet, TestNetP2ppNetworkID, TestNetP2pBootstrap, TestNetP2pPort}, nil
case domain.P2pDevNet:
return &P2pNetworkConfig{domain.P2pDevNet, DevNetP2ppNetworkID, DevNetP2pBootstrap, DevNetP2pPort}, nil
default:
return nil, fmt.Errorf(`invalid P2P_NETWORK enviroment variable: "%s"`, p2pEnviroment)
}

View File

@ -16,7 +16,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/testify v1.8.1
github.com/wormhole-foundation/wormhole/sdk v0.0.0-20230123141139-45b3d18d80b2
go.mongodb.org/mongo-driver v1.10.2
go.mongodb.org/mongo-driver v1.11.2
go.uber.org/zap v1.23.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
)
@ -273,6 +273,7 @@ require (
require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/schollz/progressbar v1.0.0
github.com/wormhole-foundation/wormhole-explorer/common v0.0.0-20230301134427-b3ec0bcc9eda
)
// Needed for cosmos-sdk based chains. See

View File

@ -2888,6 +2888,8 @@ github.com/wormhole-foundation/cosmos-sdk v0.45.9-wormhole h1:oWRuBpqReZoLX3pXeq
github.com/wormhole-foundation/cosmos-sdk v0.45.9-wormhole/go.mod h1:Z5M4TX7PsHNHlF/1XanI2DIpORQ+Q/st7oaeufEjnvU=
github.com/wormhole-foundation/wasmd v0.28.0-wormhole-2 h1:NkPCElDxTyzwyUxGPl5khoSNaoROMm1hY0Im3lPVEu8=
github.com/wormhole-foundation/wasmd v0.28.0-wormhole-2/go.mod h1:5QgkFAQDC1F+6L/DXjxvoj5Jm/74HTupu5EEDm1s54U=
github.com/wormhole-foundation/wormhole-explorer/common v0.0.0-20230301134427-b3ec0bcc9eda h1:lcM/4CMIPhbl1T71+IVczDzHmUbQyVZmAjIO2VCrXSc=
github.com/wormhole-foundation/wormhole-explorer/common v0.0.0-20230301134427-b3ec0bcc9eda/go.mod h1:FLzG4ZpbraKhr60Qgn09hck/Owfz6QL0gsOZaSXYRpM=
github.com/wormhole-foundation/wormhole/sdk v0.0.0-20220926172624-4b38dc650bb0/go.mod h1:Vg7Cbb370S+JihB+of1rWm9Aaxzf0GPPvKszPeSb7AE=
github.com/wormhole-foundation/wormhole/sdk v0.0.0-20230123141139-45b3d18d80b2 h1:we8iat9DdKt8V6aopxFe+2PkKol9cDPYwH8xZue0R60=
github.com/wormhole-foundation/wormhole/sdk v0.0.0-20230123141139-45b3d18d80b2/go.mod h1:9KomdyKDfd0O0A64dfapTbTp6I9LGkudkK8Q7s72RyI=
@ -2966,6 +2968,8 @@ go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD0
go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4=
go.mongodb.org/mongo-driver v1.10.2 h1:4Wk3cnqOrQCn0P92L3/mmurMxzdvWWs5J9jinAVKD+k=
go.mongodb.org/mongo-driver v1.10.2/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8=
go.mongodb.org/mongo-driver v1.11.2 h1:+1v2rDQUWNcGW7/7E0Jvdz51V38XXxJfhzbV17aNHCw=
go.mongodb.org/mongo-driver v1.11.2/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk=
go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0=

View File

@ -6,10 +6,10 @@ import (
"time"
"github.com/certusone/wormhole/node/pkg/common"
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
eth_common "github.com/ethereum/go-ethereum/common"
"github.com/wormhole-foundation/wormhole-explorer/fly/config"
)
// GuardianSetHistory contains information about all guardian sets for the current network (past and present).
@ -47,7 +47,7 @@ func (h GuardianSetHistory) GetLatest() common.GuardianSet {
// Get get guardianset config by enviroment.
func GetByEnv(enviroment string) GuardianSetHistory {
switch enviroment {
case config.P2pTestNet:
case domain.P2pTestNet:
return getTestnetGuardianSet()
default:
return getMainnetGuardianSet()

View File

@ -12,6 +12,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/go-redis/redis/v8"
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
"github.com/wormhole-foundation/wormhole-explorer/fly/config"
"github.com/wormhole-foundation/wormhole-explorer/fly/deduplicator"
"github.com/wormhole-foundation/wormhole-explorer/fly/guardiansets"
@ -462,7 +463,7 @@ func discardMessages[T any](ctx context.Context, obsvReqC chan T) {
// filterObservation filter observation by enviroment.
func filterObservationByEnv(o *gossipv1.SignedObservation, enviroment string) bool {
if enviroment == config.P2pTestNet {
if enviroment == domain.P2pTestNet {
// filter pyth message in test enviroment.
if strings.Contains((o.GetMessageId()), "1/f346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0") {
return true
@ -473,7 +474,7 @@ func filterObservationByEnv(o *gossipv1.SignedObservation, enviroment string) bo
// filterVaasByEnv filter vaa by enviroment.
func filterVaasByEnv(v *vaa.VAA, enviroment string) bool {
if enviroment == config.P2pTestNet {
if enviroment == domain.P2pTestNet {
vaaFromSolana := v.EmitterChain == vaa.ChainIDSolana
addressToFilter := strings.ToLower(v.EmitterAddress.String()) == "f346195ac02f37d60d4db8ffa6ef74cb1be3550047543a4a9ee9acf4d78697b0"
if vaaFromSolana && addressToFilter {