Skip to content

Commit

Permalink
Write both sets of properties (#393)
Browse files Browse the repository at this point in the history
* Write both sets of properties

* fix tests
  • Loading branch information
agouin authored Nov 28, 2023
1 parent fc173c9 commit 52a6a0d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
25 changes: 21 additions & 4 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,67 @@ func addConfigToml(buf *bytes.Buffer, cmData map[string]string, crd *cosmosv1.Co
)

if crd.Spec.Type == cosmosv1.Sentry {
base["priv_validator_laddr"] = fmt.Sprintf("tcp://0.0.0.0:%d", privvalPort)
privVal := fmt.Sprintf("tcp://0.0.0.0:%d", privvalPort)
base["priv_validator_laddr"] = privVal
base["priv-validator-laddr"] = privVal
// Disable indexing for sentries; they should not serve queries.
base["tx_index"] = map[string]string{"indexer": "null"}

txIndex := map[string]string{"indexer": "null"}
base["tx_index"] = txIndex
base["tx-index"] = txIndex
}
if v := spec.LogLevel; v != nil {
base["log_level"] = v
base["log-level"] = v
}
if v := spec.LogFormat; v != nil {
base["log_format"] = v
base["log-format"] = v
}

privatePeers := peers.Except(instance, crd.Namespace)
privatePeerStr := commaDelimited(privatePeers.AllPrivate()...)
comet := spec.Comet
persistentPeers := commaDelimited(privatePeerStr, comet.PersistentPeers)
p2p := decodedToml{
"persistent_peers": commaDelimited(privatePeerStr, comet.PersistentPeers),
"persistent_peers": persistentPeers,
"persistent-peers": persistentPeers,
"seeds": comet.Seeds,
}

privateIDStr := commaDelimited(privatePeers.NodeIDs()...)
privateIDs := commaDelimited(privateIDStr, comet.PrivatePeerIDs)
if v := privateIDs; v != "" {
p2p["private_peer_ids"] = v
p2p["private-peer-ids"] = v
}

unconditionalIDs := commaDelimited(privateIDStr, comet.UnconditionalPeerIDs)
if v := unconditionalIDs; v != "" {
p2p["unconditional_peer_ids"] = v
p2p["unconditional-peer-ids"] = v
}

if v := comet.MaxInboundPeers; v != nil {
p2p["max_num_inbound_peers"] = comet.MaxInboundPeers
p2p["max-num-inbound-peers"] = comet.MaxInboundPeers
}
if v := comet.MaxOutboundPeers; v != nil {
p2p["max_num_outbound_peers"] = comet.MaxOutboundPeers
p2p["max-num-outbound-peers"] = comet.MaxOutboundPeers
}
if v := peers.Get(instance, crd.Namespace).ExternalAddress; v != "" {
p2p["external_address"] = v
p2p["external-address"] = v
}

base["p2p"] = p2p

if v := comet.CorsAllowedOrigins; v != nil {
base["rpc"] = decodedToml{"cors_allowed_origins": v}
base["rpc"] = decodedToml{
"cors_allowed_origins": v,
"cors-allowed-origins": v,
}
}

dst := defaultComet()
Expand Down
13 changes: 13 additions & 0 deletions internal/fullnode/configmap_builder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fullnode

import (
"bytes"
_ "embed"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -219,11 +221,13 @@ func TestBuildConfigMaps(t *testing.T) {
[p2p]
external_address = "override.example.com"
external-address = "override.example.com"
seeds = "override@seed"
new_field = "p2p"
[rpc]
cors_allowed_origins = ["override"]
cors-allowed-origins = ["override"]
[new_section]
test = "value"
Expand All @@ -250,6 +254,15 @@ func TestBuildConfigMaps(t *testing.T) {
_, err = toml.Decode(cm.Data["config-overlay.toml"], &got)
require.NoError(t, err)

var gotBuffer bytes.Buffer
var wantBuffer bytes.Buffer

require.NoError(t, toml.NewEncoder(&gotBuffer).Encode(got))
require.NoError(t, toml.NewEncoder(&wantBuffer).Encode(want))

fmt.Printf("got:\n%s\n", gotBuffer.String())
fmt.Printf("want:\n%s\n", wantBuffer.String())

require.Equal(t, want, got)
})

Expand Down
6 changes: 6 additions & 0 deletions internal/fullnode/testdata/comet.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
log_format = "json"
log-format = "json"
log_level = "debug"
log-level = "debug"
priv_validator_laddr = ""

[p2p]
laddr = "tcp://0.0.0.0:26656"
persistent_peers = "[email protected]:789,[email protected]:789,[email protected]:789"
persistent-peers = "[email protected]:789,[email protected]:789,[email protected]:789"
seeds = "[email protected]:456,[email protected]:456"
max_num_inbound_peers = 5
max-num-inbound-peers = 5
max_num_outbound_peers = 15
max-num-outbound-peers = 15

[rpc]
laddr = "tcp://0.0.0.0:26657"
cors_allowed_origins = ["*"]
cors-allowed-origins = ["*"]

[tx_index]
indexer = "kv"
Expand Down
1 change: 1 addition & 0 deletions internal/fullnode/testdata/comet_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ priv_validator_laddr = ""
[p2p]
laddr = "tcp://0.0.0.0:26656"
persistent_peers = "[email protected]:789,[email protected]:789,[email protected]:789"
persistent-peers = "[email protected]:789,[email protected]:789,[email protected]:789"
seeds = "[email protected]:456,[email protected]:456"
max_num_inbound_peers = 20
max_num_outbound_peers = 20
Expand Down
4 changes: 3 additions & 1 deletion internal/fullnode/testdata/comet_overrides.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ priv_validator_laddr = ""
new_base = "new base value"

[p2p]
external-address = "override.example.com"
external_address = "override.example.com"
laddr = "tcp://0.0.0.0:26656"
persistent_peers = "[email protected]:789,[email protected]:789,[email protected]:789"
persistent-peers = "[email protected]:789,[email protected]:789,[email protected]:789"
seeds = "override@seed"
max_num_inbound_peers = 20
max_num_outbound_peers = 20
Expand All @@ -15,9 +17,9 @@ new_field = "p2p"
[rpc]
laddr = "tcp://0.0.0.0:26657"
cors_allowed_origins = ["override"]
cors-allowed-origins = ["override"]

[tx_index]

indexer = "null"

[new_section]
Expand Down

0 comments on commit 52a6a0d

Please sign in to comment.