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(confix): audit (backport #16764) #16774

Merged
merged 1 commit into from
Jun 29, 2023
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
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ More information about [confix](https://docs.cosmos.network/main/tooling/confix)

#### gRPC-Web

gRPC-Web is now listening to the same address as the gRPC Gateway API server (default: `localhost:1317`).
gRPC-Web is now listening to the same address and port as the gRPC Gateway API server (default: `localhost:1317`).
The possibility to listen to a different address has been removed, as well as its settings.
Use `confix` to clean-up your `app.toml`. A nginx (or alike) reverse-proxy can be set to keep the previous behavior.

Expand Down
41 changes: 38 additions & 3 deletions tools/confix/data/v0.47-app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ inter-block-cache = true
# ["message.sender", "message.recipient"]
index-events = []

# IavlCacheSize set the size of the iavl tree cache.
# Default cache size is 50mb.
# IavlCacheSize set the size of the iavl tree cache (in number of nodes).
iavl-cache-size = 781250

# IAVLDisableFastNode enables or disables the fast node feature of IAVL.
Expand Down Expand Up @@ -141,6 +140,42 @@ rpc-max-body-bytes = 1000000
# EnableUnsafeCORS defines if CORS should be enabled (unsafe - use it at your own risk).
enabled-unsafe-cors = false

###############################################################################
### Rosetta Configuration ###
###############################################################################

[rosetta]

# Enable defines if the Rosetta API server should be enabled.
enable = false

# Address defines the Rosetta API server to listen on.
address = ":8080"

# Network defines the name of the blockchain that will be returned by Rosetta.
blockchain = "app"

# Network defines the name of the network that will be returned by Rosetta.
network = "network"

# Retries defines the number of retries when connecting to the node before failing.
retries = 3

# Offline defines if Rosetta server should run in offline mode.
offline = false

# EnableDefaultSuggestedFee defines if the server should suggest fee by default.
# If 'construction/medata' is called without gas limit and gas price,
# suggested fee based on gas-to-suggest and denom-to-suggest will be given.
enable-fee-suggestion = false

# GasToSuggest defines gas limit when calculating the fee
gas-to-suggest = 200000

# DenomToSuggest defines the defult denom for fee suggestion.
# Price must be in minimum-gas-prices.
denom-to-suggest = "uatom"

###############################################################################
### gRPC Configuration ###
###############################################################################
Expand Down Expand Up @@ -233,4 +268,4 @@ max-txs = "5000"
query_gas_limit = 300000
# This is the number of wasm vm instances we keep cached in memory for speed-up
# Warning: this is currently unstable and may lead to crashes, best to keep for 0 unless testing locally
lru_size = 0
lru_size = 0
9 changes: 5 additions & 4 deletions tools/confix/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"github.com/creachadair/tomledit/transform"
)

type DiffType string

const (
Section = "S"
Mapping = "M"
Section DiffType = "S"
Mapping DiffType = "M"
)

type KV struct {
Expand All @@ -22,7 +24,7 @@ type KV struct {
}

type Diff struct {
Type string // "section" or "mapping"
Type DiffType
Deleted bool

KV KV
Expand All @@ -41,7 +43,6 @@ func DiffKeys(lhs, rhs *tomledit.Document) []Diff {
i, j := 0, 0
for i < len(lsec) && j < len(rsec) {
switch {

case lsec[i].Name.Before(rsec[j].Name):
diff = append(diff, Diff{Type: Section, Deleted: true, KV: KV{Key: lsec[i].Name.String()}})
for _, kv := range allKVs(lsec[i]) {
Expand Down
33 changes: 19 additions & 14 deletions tools/confix/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
step = transform.Step{
Desc: fmt.Sprintf("add %s section", kv.Key),
T: transform.Func(func(_ context.Context, doc *tomledit.Document) error {
title := fmt.Sprintf("### %s Configuration ###", strings.Title(kv.Key))
doc.Sections = append(doc.Sections, &tomledit.Section{
Heading: &parser.Heading{
Block: parser.Comments{
"###############################################################################",
fmt.Sprintf("### %s Configuration ###", strings.Title(kv.Key)),
"###############################################################################",
strings.Repeat("#", len(title)),
title,
strings.Repeat("#", len(title)),
},
Name: keys,
},
Expand All @@ -77,9 +78,9 @@ func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
} else if len(keys) > 1 {
step = transform.Step{
Desc: fmt.Sprintf("add %s key", kv.Key),
T: transform.EnsureKey(parser.Key{keys[0]}, &parser.KeyValue{
T: transform.EnsureKey(keys[0:len(keys)-1], &parser.KeyValue{
Block: kv.Block,
Name: parser.Key{keys[1]},
Name: parser.Key{keys[len(keys)-1]},
Value: parser.MustValue(kv.Value),
}),
}
Expand All @@ -90,16 +91,20 @@ func PlanBuilder(from *tomledit.Document, to string) transform.Plan {
} else {
if diff.Type == Section {
deletedSections[kv.Key] = true
}

// when the whole section is deleted we don't need to remove the keys
if len(keys) > 1 && deletedSections[keys[0]] {
continue
}
step = transform.Step{
Desc: fmt.Sprintf("remove %s section", kv.Key),
T: transform.Remove(keys),
}
} else {
// when the whole section is deleted we don't need to remove the keys
if len(keys) > 1 && deletedSections[keys[0]] {
continue
}

step = transform.Step{
Desc: fmt.Sprintf("remove %s key", kv.Key),
T: transform.Remove(keys),
step = transform.Step{
Desc: fmt.Sprintf("remove %s key", kv.Key),
T: transform.Remove(keys),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/confix/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func CheckValid(fileName string, data []byte) error {
}

if err := cfg.ValidateBasic(); err != nil {
return fmt.Errorf("server config invalid : %w", err)
return fmt.Errorf("server config invalid: %w", err)
}
case strings.HasSuffix(fileName, ClientConfig):
var cfg clientcfg.ClientConfig
Expand Down
4 changes: 0 additions & 4 deletions tools/confix/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ func mustReadConfig(t *testing.T, path string) []byte {
return f
}

func TestUpgrade(t *testing.T) {
// TODO: add more test cases
}

func TestCheckValid(t *testing.T) {
err := confix.CheckValid("foo", []byte{})
assert.ErrorContains(t, err, "unknown config")
Expand Down