Skip to content

Commit

Permalink
lib/netconf: add omniscan tx link (#2607)
Browse files Browse the repository at this point in the history
Adds convenience function to consistetly generate omniscan link per
network.

issue: none
  • Loading branch information
corverroos authored Dec 3, 2024
1 parent e7e4fe7 commit ba8ca78
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
18 changes: 12 additions & 6 deletions cli/cmd/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
60 changes: 21 additions & 39 deletions e2e/app/admin/allowoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package admin

import (
"context"
"fmt"

"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/e2e/app"
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}

Expand All @@ -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,
)

Expand Down
4 changes: 1 addition & 3 deletions e2e/app/admin/planupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package admin

import (
"context"
"fmt"

"github.com/omni-network/omni/contracts/bindings"
"github.com/omni-network/omni/e2e/app"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/netconf/netconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <network>/consensus-seeds.txt by loading e2e manifests and parsing seed* p2p_consensus keys.
Expand Down
7 changes: 7 additions & 0 deletions lib/netconf/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Static struct {
ConsensusArchiveTXT []byte
ExecutionGenesisJSON []byte
ExecutionSeedTXT []byte
OmniScanBaseURL string
}

type Deployment struct {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -225,6 +230,7 @@ var statics = map[ID]Static{
ConsensusArchiveTXT: omegaConsensusArchivesTXT,
ExecutionGenesisJSON: omegaExecutionGenesisJSON,
ExecutionSeedTXT: omegaExecutionSeedsTXT,
OmniScanBaseURL: "https://omega.omniscan.network",
},
Mainnet: {
Network: Mainnet,
Expand All @@ -245,6 +251,7 @@ var statics = map[ID]Static{
ConsensusSeedTXT: mainnetConsensusSeedsTXT,
ConsensusArchiveTXT: mainnetConsusensusArchivesTXT,
ExecutionSeedTXT: mainnetExecutionSeedsTXT,
OmniScanBaseURL: "https://omniscan.network",
},
}

Expand Down

0 comments on commit ba8ca78

Please sign in to comment.