From f605e5d94ccf3f8335bb5e721209a6a87984562e Mon Sep 17 00:00:00 2001 From: corver Date: Tue, 3 Dec 2024 10:28:11 +0200 Subject: [PATCH] lib/netconf: add omniscan tx link --- cli/cmd/staking.go | 18 ++++++---- e2e/app/admin/allowoperator.go | 60 ++++++++++++---------------------- e2e/app/admin/planupgrade.go | 4 +-- lib/netconf/netconf_test.go | 8 +++++ lib/netconf/static.go | 7 ++++ 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/cli/cmd/staking.go b/cli/cmd/staking.go index 2167713d7..1e47da9eb 100644 --- a/cli/cmd/staking.go +++ b/cli/cmd/staking.go @@ -224,8 +224,10 @@ func createValidator(ctx context.Context, cfg createValConfig) error { return errors.Wrap(err, "wait mined") } - link := fmt.Sprintf("https://%s.omniscan.network/tx/%s", cfg.Network, tx.Hash().Hex()) - log.Info(ctx, "🎉 Create-validator transaction sent and included on-chain", "link", link, "block", rec.BlockNumber.Uint64()) + log.Info(ctx, "🎉 Create-validator transaction sent and included on-chain", + "link", cfg.Network.Static().OmniScanTXURL(tx.Hash()), + "block", rec.BlockNumber.Uint64(), + ) return nil } @@ -328,8 +330,10 @@ func delegate(ctx context.Context, cfg delegateConfig) error { return errors.Wrap(err, "wait mined") } - link := fmt.Sprintf("https://%s.omniscan.network/tx/%s", cfg.Network, tx.Hash().Hex()) - log.Info(ctx, "🎉 Delegate transaction sent and included on-chain", "link", link, "block", rec.BlockNumber.Uint64()) + log.Info(ctx, "🎉 Delegate transaction sent and included on-chain", + "link", cfg.Network.Static().OmniScanTXURL(tx.Hash()), + "block", rec.BlockNumber.Uint64(), + ) return nil } @@ -419,8 +423,10 @@ func unjailValidator(ctx context.Context, cfg eoaConfig) error { return errors.Wrap(err, "wait mined") } - link := fmt.Sprintf("https://%s.omniscan.network/tx/%s", cfg.Network, rec.TxHash.Hex()) - log.Info(ctx, "🎉 Unjail transaction sent and included on-chain", "link", link, "block", rec.BlockNumber.Uint64()) + log.Info(ctx, "🎉 Unjail transaction sent and included on-chain", + "link", cfg.Network.Static().OmniScanTXURL(tx.Hash()), + "block", rec.BlockNumber.Uint64(), + ) return nil } diff --git a/e2e/app/admin/allowoperator.go b/e2e/app/admin/allowoperator.go index eedbf43d1..43c57a0b2 100644 --- a/e2e/app/admin/allowoperator.go +++ b/e2e/app/admin/allowoperator.go @@ -2,7 +2,6 @@ package admin import ( "context" - "fmt" "github.com/omni-network/omni/contracts/bindings" "github.com/omni-network/omni/e2e/app" @@ -16,31 +15,30 @@ import ( "github.com/ethereum/go-ethereum/common" ) -// omegaOperators are the operators that are allowed to be validators on the Omega network. -var omegaOperators = []common.Address{ - common.HexToAddress("0xdc5754Fb79163A65753D2CAF23dDA2398cC1f277"), // A41 - common.HexToAddress("0x446924c33A33F413B773d952E7054504788E4c08"), // BlockDaemon - common.HexToAddress("0xb3E5246B42BC6a12033d5758Dc1752d43807B1dC"), // RHINO - common.HexToAddress("0x1B6881C66fFd311eE7b0C9b925EB7fd612E1C7B9"), // Kingnodes - common.HexToAddress("0x641F5938E0d093988d7Cf99509C3152FC7922B88"), // Galaxy - common.HexToAddress("0xb86DDe58C05dF3C09a8eB7476152793138D113C9"), // Chorusone - common.HexToAddress("0xcf8EB4Ee3cb3C9c14a4b290bD902dC06d2926ec1"), // P-OPS - common.HexToAddress("0x27eA917d14d637797FDeb3f9A9824395e7744941"), // DAIC - common.HexToAddress("0x44Fb4c265E551139e4D3956Aba6fe2DEa27AE4De"), // Finoa -} - -// mainnetOperators are the operators that are allowed to be validators on the Mainnet network. -var mainnetOperators = []common.Address{ - common.HexToAddress("0x85bD563C4636a6006BCFB3fd367757676e2Dd269"), // RHINO - common.HexToAddress("0xc6A510df0F6d2D8CEbD6112FB3132aba4bAc23d1"), // A41 +var allowedOperators = map[netconf.ID][]common.Address{ + netconf.Omega: { + common.HexToAddress("0xdc5754Fb79163A65753D2CAF23dDA2398cC1f277"), // A41 + common.HexToAddress("0x446924c33A33F413B773d952E7054504788E4c08"), // BlockDaemon + common.HexToAddress("0xb3E5246B42BC6a12033d5758Dc1752d43807B1dC"), // RHINO + common.HexToAddress("0x1B6881C66fFd311eE7b0C9b925EB7fd612E1C7B9"), // Kingnodes + common.HexToAddress("0x641F5938E0d093988d7Cf99509C3152FC7922B88"), // Galaxy + common.HexToAddress("0xb86DDe58C05dF3C09a8eB7476152793138D113C9"), // Chorusone + common.HexToAddress("0xcf8EB4Ee3cb3C9c14a4b290bD902dC06d2926ec1"), // P-OPS + common.HexToAddress("0x27eA917d14d637797FDeb3f9A9824395e7744941"), // DAIC + common.HexToAddress("0x44Fb4c265E551139e4D3956Aba6fe2DEa27AE4De"), // Finoa + }, + netconf.Mainnet: { + common.HexToAddress("0x85bD563C4636a6006BCFB3fd367757676e2Dd269"), // RHINO + common.HexToAddress("0xc6A510df0F6d2D8CEbD6112FB3132aba4bAc23d1"), // A41 + }, } // AllowOperators ensures that all operators hard-coded in this package is allowed as validators. // Note it only adds any of the operators that are missing, it doesn't remove any ever. func AllowOperators(ctx context.Context, def app.Definition, cfg Config) error { network := def.Testnet.Network - if network.Static().Network != netconf.Omega && network.Static().Network != netconf.Mainnet { - return errors.New("allow operator only supported on omega or mainnet", "network", network.Static().Network.String()) + if !network.IsProtected() { + return errors.New("allow operator only supported on protected networks", "network", def.Testnet.Network) } backend, err := def.Backends().Backend(network.Static().OmniExecutionChainID) @@ -53,16 +51,8 @@ func AllowOperators(ctx context.Context, def app.Definition, cfg Config) error { return errors.Wrap(err, "new staking contract") } - var operatorsRange []common.Address - if network.Static().Network == netconf.Omega { - operatorsRange = omegaOperators - } else { - // Mainnet - operatorsRange = mainnetOperators - } - var toAllow []common.Address - for _, operator := range operatorsRange { + for _, operator := range allowedOperators[network] { if ok, err := contract.IsAllowedValidator(&bind.CallOpts{}, operator); err != nil { return errors.Wrap(err, "call is allowed validator") } else if ok { @@ -75,7 +65,7 @@ func AllowOperators(ctx context.Context, def app.Definition, cfg Config) error { } if len(toAllow) == 0 { - log.Info(ctx, "All operators already allowed to be validators", "count", len(operatorsRange)) + log.Info(ctx, "All operators already allowed to be validators", "count", len(allowedOperators[network])) return nil } @@ -98,17 +88,9 @@ func AllowOperators(ctx context.Context, def app.Definition, cfg Config) error { return errors.Wrap(err, "wait minded") } - var link string - if network.Static().Network == netconf.Omega { - link = fmt.Sprintf("https://%s.omniscan.network/tx/%s", network, tx.Hash().Hex()) - } else { - // Mainnet - link = fmt.Sprintf("https://omniscan.network/tx/%s", tx.Hash().Hex()) - } - log.Info(ctx, "🎉 Successfully allowed operators as validators", "count", len(toAllow), - "link", link, + "link", network.Static().OmniScanTXURL(tx.Hash()), "network", network, ) diff --git a/e2e/app/admin/planupgrade.go b/e2e/app/admin/planupgrade.go index 4c68ff72e..7fe0cbe9d 100644 --- a/e2e/app/admin/planupgrade.go +++ b/e2e/app/admin/planupgrade.go @@ -2,7 +2,6 @@ package admin import ( "context" - "fmt" "github.com/omni-network/omni/contracts/bindings" "github.com/omni-network/omni/e2e/app" @@ -75,12 +74,11 @@ func PlanUpgrade(ctx context.Context, def app.Definition, cfg Config) error { return errors.Wrap(err, "wait minded") } - link := fmt.Sprintf("https://%s.omniscan.network/tx/%s", network, tx.Hash().Hex()) log.Info(ctx, "🎉 Successfully planned network upgrade", "upgrade", plan.Name, "height", plan.Height, "network", network, - "link", link, + "link", network.Static().OmniScanTXURL(tx.Hash()), ) return nil diff --git a/lib/netconf/netconf_test.go b/lib/netconf/netconf_test.go index 726c7b916..a1c87cabb 100644 --- a/lib/netconf/netconf_test.go +++ b/lib/netconf/netconf_test.go @@ -24,6 +24,14 @@ import ( "github.com/stretchr/testify/require" ) +func TestStaticNetwork(t *testing.T) { + t.Parallel() + for _, chain := range netconf.All() { + static := chain.Static() + require.Equal(t, chain, static.Network) + } +} + //go:generate go test -golden -run=TestGenConsSeeds // TestGenConsSeeds generates /consensus-seeds.txt by loading e2e manifests and parsing seed* p2p_consensus keys. diff --git a/lib/netconf/static.go b/lib/netconf/static.go index 810db4cf5..6b34fa271 100644 --- a/lib/netconf/static.go +++ b/lib/netconf/static.go @@ -33,6 +33,7 @@ type Static struct { ConsensusArchiveTXT []byte ExecutionGenesisJSON []byte ExecutionSeedTXT []byte + OmniScanBaseURL string } type Deployment struct { @@ -136,6 +137,10 @@ func (s Static) ConsensusRPC() string { return fmt.Sprintf("https://consensus.%s.omni.network", s.Network) } +func (s Static) OmniScanTXURL(tx common.Hash) string { + return fmt.Sprintf("%s/tx/%s", s.OmniScanBaseURL, tx.Hex()) +} + //nolint:gochecknoglobals // Static addresses var ( omegaAVS = common.HexToAddress("0xa7b2e7830C51728832D33421670DbBE30299fD92") @@ -225,6 +230,7 @@ var statics = map[ID]Static{ ConsensusArchiveTXT: omegaConsensusArchivesTXT, ExecutionGenesisJSON: omegaExecutionGenesisJSON, ExecutionSeedTXT: omegaExecutionSeedsTXT, + OmniScanBaseURL: "https://omega.omniscan.network", }, Mainnet: { Network: Mainnet, @@ -245,6 +251,7 @@ var statics = map[ID]Static{ ConsensusSeedTXT: mainnetConsensusSeedsTXT, ConsensusArchiveTXT: mainnetConsusensusArchivesTXT, ExecutionSeedTXT: mainnetExecutionSeedsTXT, + OmniScanBaseURL: "https://omniscan.network", }, }