From 1e60183f066e5957a5df46693ac08fdc2291c7a3 Mon Sep 17 00:00:00 2001 From: corver Date: Thu, 5 Sep 2024 18:21:41 +0200 Subject: [PATCH] chore(cli): init archives as persisted peer --- cli/cmd/initnodes.go | 7 +++ halo/cmd/init.go | 5 +- lib/netconf/netconf_test.go | 63 ++++++++++++++++++++++ lib/netconf/omega/consensus-archives.txt | 2 + lib/netconf/staging/consensus-archives.txt | 1 + lib/netconf/static.go | 20 +++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 lib/netconf/omega/consensus-archives.txt create mode 100644 lib/netconf/staging/consensus-archives.txt diff --git a/cli/cmd/initnodes.go b/cli/cmd/initnodes.go index ec02f24ec..ec3ec0767 100644 --- a/cli/cmd/initnodes.go +++ b/cli/cmd/initnodes.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "text/template" "github.com/omni-network/omni/e2e/app/geth" @@ -141,6 +142,12 @@ func initNodes(ctx context.Context, cfg initConfig) error { CometCfgFunc: func(cmtCfg *cmtconfig.Config) { cmtCfg.LogLevel = logLevel cmtCfg.Instrumentation.Prometheus = true + if cfg.Archive { + if cmtCfg.P2P.PersistentPeers != "" { + cmtCfg.P2P.PersistentPeers += "," + } + cmtCfg.P2P.PersistentPeers += strings.Join(cfg.Network.Static().ConsensusArchives(), ",") + } }, LogCfgFunc: func(logCfg *log.Config) { logCfg.Color = log.ColorForce diff --git a/halo/cmd/init.go b/halo/cmd/init.go index 2e0ef9e46..c28d51b61 100644 --- a/halo/cmd/init.go +++ b/halo/cmd/init.go @@ -190,7 +190,10 @@ func InitFiles(ctx context.Context, initCfg InitConfig) error { // Add P2P seeds to comet config (persisted peers works better than seeds) if seeds := network.Static().ConsensusSeeds(); len(seeds) > 0 { - comet.P2P.PersistentPeers = strings.Join(seeds, ",") + if comet.P2P.PersistentPeers != "" { + comet.P2P.PersistentPeers += "," + } + comet.P2P.PersistentPeers += strings.Join(seeds, ",") } // Setup node key diff --git a/lib/netconf/netconf_test.go b/lib/netconf/netconf_test.go index 5956b6d96..57f5c1dec 100644 --- a/lib/netconf/netconf_test.go +++ b/lib/netconf/netconf_test.go @@ -72,6 +72,54 @@ func TestGenConsSeeds(t *testing.T) { } } +//go:generate go test -golden -run=TestGenConsArchives + +// TestGenConsArchives generates /consensus-archives.txt by loading e2e manifests and parsing archive* p2p_consensus keys. +func TestGenConsArchives(t *testing.T) { + t.Parallel() + tests := []struct { + network netconf.ID + manifestFunc func() []byte + }{ + { + network: netconf.Omega, + manifestFunc: manifests.Omega, + }, + { + network: netconf.Staging, + manifestFunc: manifests.Staging, + }, + } + for _, test := range tests { + t.Run(test.network.String(), func(t *testing.T) { + t.Parallel() + var manifest types.Manifest + _, err := toml.Decode(string(test.manifestFunc()), &manifest) + require.NoError(t, err) + + var peers []string + for _, node := range sortedKeys(manifest.Keys) { + if !isArchiveNode(test.network, node) { + continue + } + + for typ, addr := range manifest.Keys[node] { + if typ != key.P2PConsensus { + continue + } + addr = strings.ToLower(addr) // CometBFT P2P IDs are lowercase. + + peers = append(peers, fmt.Sprintf("%s@%s.%s.omni.network:26656", addr, node, test.network)) // abcde123@archive01.staging.omni.network:26656 + } + } + + seeds := strings.Join(peers, "\n") + seedsFile := fmt.Sprintf("../%s/consensus-archives.txt", test.network) + tutil.RequireGoldenBytes(t, []byte(seeds), tutil.WithFilename(seedsFile)) + }) + } +} + var genExecutionSeeds = flag.Bool("gen-execution-seeds", false, "Enable to generate execution-seeds.txt. Note this requires GCP secret manager read-access") //go:generate go test -golden -gen-execution-seeds -run=TestGenExecutionSeeds @@ -206,6 +254,21 @@ func isSeedNode(network netconf.ID, node string) bool { return false } +// isArchiveNode returns true if the node should be added to archive node static config. +func isArchiveNode(network netconf.ID, node string) bool { + // All "seed*" nodes in the manifest are seed noes + if strings.HasPrefix(node, "archive") { + return true + } + + // In staging, we only have 1 archive, it the fullnode as well + if network == netconf.Staging && strings.HasPrefix(node, "full") { + return true + } + + return false +} + func sortedKeys[T any](m map[string]T) []string { keys := make([]string, 0, len(m)) for k := range m { diff --git a/lib/netconf/omega/consensus-archives.txt b/lib/netconf/omega/consensus-archives.txt new file mode 100644 index 000000000..cfa4c692c --- /dev/null +++ b/lib/netconf/omega/consensus-archives.txt @@ -0,0 +1,2 @@ +2320703bf5434bbc4b1050a90f0fbf842d4878f9@archive01.omega.omni.network:26656 +1afc3479b2a16bca9da5bec7bff750a7b5ffe53d@archive02.omega.omni.network:26656 \ No newline at end of file diff --git a/lib/netconf/staging/consensus-archives.txt b/lib/netconf/staging/consensus-archives.txt new file mode 100644 index 000000000..375bc12b0 --- /dev/null +++ b/lib/netconf/staging/consensus-archives.txt @@ -0,0 +1 @@ +b0b2f907c12d79d0d74973faf8bbc4f5435a8e86@fullnode01.staging.omni.network:26656 \ No newline at end of file diff --git a/lib/netconf/static.go b/lib/netconf/static.go index c380bb2ae..df2cbd577 100644 --- a/lib/netconf/static.go +++ b/lib/netconf/static.go @@ -33,6 +33,7 @@ type Static struct { MaxValidators uint32 ConsensusGenesisJSON []byte ConsensusSeedTXT []byte + ConsensusArchiveTXT []byte ExecutionGenesisJSON []byte ExecutionSeedTXT []byte } @@ -96,6 +97,17 @@ func (s Static) ConsensusSeeds() []string { return resp } +func (s Static) ConsensusArchives() []string { + var resp []string + for _, archive := range strings.Split(string(s.ConsensusArchiveTXT), "\n") { + if archive = strings.TrimSpace(archive); archive != "" { + resp = append(resp, archive) + } + } + + return resp +} + func (s Static) ExecutionSeeds() []string { var resp []string for _, seed := range strings.Split(string(s.ExecutionSeedTXT), "\n") { @@ -141,6 +153,9 @@ var ( //go:embed omega/consensus-seeds.txt omegaConsensusSeedsTXT []byte + //go:embed omega/consensus-archives.txt + omegaConsensusArchivesTXT []byte + //go:embed omega/execution-genesis.json omegaExecutionGenesisJSON []byte @@ -150,6 +165,9 @@ var ( //go:embed staging/consensus-seeds.txt stagingConsensusSeedsTXT []byte + //go:embed staging/consensus-archives.txt + stagingConsensusArchivesTXT []byte + //go:embed staging/execution-seeds.txt stagingExecutionSeedsTXT []byte ) @@ -174,6 +192,7 @@ var statics = map[ID]Static{ OmniExecutionChainID: evmchain.IDOmniEphemeral, MaxValidators: maxValidators, ConsensusSeedTXT: stagingConsensusSeedsTXT, + ConsensusArchiveTXT: stagingConsensusArchivesTXT, ExecutionSeedTXT: stagingExecutionSeedsTXT, }, Omega: { @@ -190,6 +209,7 @@ var statics = map[ID]Static{ }, ConsensusGenesisJSON: omegaConsensusGenesisJSON, ConsensusSeedTXT: omegaConsensusSeedsTXT, + ConsensusArchiveTXT: omegaConsensusArchivesTXT, ExecutionGenesisJSON: omegaExecutionGenesisJSON, ExecutionSeedTXT: omegaExecutionSeedsTXT, },