Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): init archives as persisted peer #1827

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/cmd/initnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"text/template"

"github.com/omni-network/omni/e2e/app/geth"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion halo/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions lib/netconf/netconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,54 @@ func TestGenConsSeeds(t *testing.T) {
}
}

//go:generate go test -golden -run=TestGenConsArchives

// TestGenConsArchives generates <network>/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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions lib/netconf/omega/consensus-archives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2320703bf5434bbc4b1050a90f0fbf842d4878f9@archive01.omega.omni.network:26656
1afc3479b2a16bca9da5bec7bff750a7b5ffe53d@archive02.omega.omni.network:26656
1 change: 1 addition & 0 deletions lib/netconf/staging/consensus-archives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b0b2f907c12d79d0d74973faf8bbc4f5435a8e86@fullnode01.staging.omni.network:26656
20 changes: 20 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 {
MaxValidators uint32
ConsensusGenesisJSON []byte
ConsensusSeedTXT []byte
ConsensusArchiveTXT []byte
ExecutionGenesisJSON []byte
ExecutionSeedTXT []byte
}
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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

Expand All @@ -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
)
Expand All @@ -174,6 +192,7 @@ var statics = map[ID]Static{
OmniExecutionChainID: evmchain.IDOmniEphemeral,
MaxValidators: maxValidators,
ConsensusSeedTXT: stagingConsensusSeedsTXT,
ConsensusArchiveTXT: stagingConsensusArchivesTXT,
ExecutionSeedTXT: stagingExecutionSeedsTXT,
},
Omega: {
Expand All @@ -190,6 +209,7 @@ var statics = map[ID]Static{
},
ConsensusGenesisJSON: omegaConsensusGenesisJSON,
ConsensusSeedTXT: omegaConsensusSeedsTXT,
ConsensusArchiveTXT: omegaConsensusArchivesTXT,
ExecutionGenesisJSON: omegaExecutionGenesisJSON,
ExecutionSeedTXT: omegaExecutionSeedsTXT,
},
Expand Down
Loading