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

feat: allow replicas to have different pruning values #434

Closed
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
8 changes: 4 additions & 4 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,18 +670,18 @@ type Pruning struct {
// Bock height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom').
// If not set, defaults to 0.
// +optional
Interval *uint32 `json:"interval"`
Interval *string `json:"interval"`

// Offset heights to keep on disk after 'keep-every' (ignored if pruning is not 'custom')
// Often, setting this to 0 is appropriate.
// If not set, defaults to 0.
// +optional
KeepEvery *uint32 `json:"keepEvery"`
KeepEvery *string `json:"keepEvery"`

// Number of recent block heights to keep on disk (ignored if pruning is not 'custom')
// If not set, defaults to 0.
// +optional
KeepRecent *uint32 `json:"keepRecent"`
KeepRecent *string `json:"keepRecent"`

// Defines the minimum block height offset from the current
// block being committed, such that all blocks past this offset are pruned
Expand All @@ -700,7 +700,7 @@ type Pruning struct {
//
// If not set, defaults to 0.
// +optional
MinRetainBlocks *uint32 `json:"minRetainBlocks"`
MinRetainBlocks *string `json:"minRetainBlocks"`
}

// PruningStrategy control pruning.
Expand Down
15 changes: 7 additions & 8 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5,207 changes: 2,615 additions & 2,592 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml

Large diffs are not rendered by default.

213 changes: 103 additions & 110 deletions config/crd/bases/cosmos.strange.love_scheduledvolumesnapshots.yaml

Large diffs are not rendered by default.

6,466 changes: 3,355 additions & 3,111 deletions config/crd/bases/cosmos.strange.love_statefuljobs.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/samples/cosmos_v1_cosmosfullnode_full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
# No need to set pruning in toml, set it here instead:
pruning:
strategy: "custom"
interval: 17
interval: 17,201
keepEvery: 1000
keepRecent: 5000
minRetainBlocks: 10000
Expand Down
39 changes: 28 additions & 11 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource
instanceHeight = height
}
haltHeight := uint64(0)
for i, v := range crd.Spec.ChainSpec.Versions {
for index, v := range crd.Spec.ChainSpec.Versions {
if v.SetHaltHeight {
haltHeight = v.UpgradeHeight
} else {
Expand All @@ -54,13 +54,13 @@ func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource
if instanceHeight < v.UpgradeHeight {
break
}
if i == len(crd.Spec.ChainSpec.Versions)-1 {
if index == len(crd.Spec.ChainSpec.Versions)-1 {
haltHeight = 0
}
}
appCfg.HaltHeight = ptr(haltHeight)
}
if err := addAppToml(buf, data, appCfg); err != nil {
if err := addAppToml(buf, data, appCfg, int(i)); err != nil {
return nil, err
}
buf.Reset()
Expand Down Expand Up @@ -212,7 +212,7 @@ func commaDelimited(s ...string) string {
return strings.Join(lo.Compact(s), ",")
}

func addAppToml(buf *bytes.Buffer, cmData map[string]string, app cosmosv1.SDKAppConfig) error {
func addAppToml(buf *bytes.Buffer, cmData map[string]string, app cosmosv1.SDKAppConfig, ordinal int) error {
base := make(decodedToml)
base["minimum-gas-prices"] = app.MinGasPrice
// Note: The name discrepancy "enable" vs. "enabled" is intentional; a known inconsistency within the app.toml.
Expand All @@ -224,15 +224,32 @@ func addAppToml(buf *bytes.Buffer, cmData map[string]string, app cosmosv1.SDKApp
}

if pruning := app.Pruning; pruning != nil {
intStr := func(n *uint32) string {
v := valOrDefault(n, ptr(uint32(0)))
return strconv.FormatUint(uint64(*v), 10)
intStr := func(n *string, ordinal int) string {
if n == nil {
return "0"
}
if strings.Contains(*n, ",") {
slice := strings.Split(*n, ",")
if len(slice) <= ordinal {
return "0"
}
return slice[ordinal]
}
return *n

// v := valOrDefault(n, "0")
//return strconv.FormatUint(uint64(*v), 10)
}
base["pruning"] = pruning.Strategy
base["pruning-interval"] = intStr(pruning.Interval)
base["pruning-keep-every"] = intStr(pruning.KeepEvery)
base["pruning-keep-recent"] = intStr(pruning.KeepRecent)
base["min-retain-blocks"] = valOrDefault(pruning.MinRetainBlocks, ptr(uint32(0)))
base["pruning-interval"] = intStr(pruning.Interval, ordinal)
base["pruning-keep-every"] = intStr(pruning.KeepEvery, ordinal)
base["pruning-keep-recent"] = intStr(pruning.KeepRecent, ordinal)
retain, err := strconv.ParseInt(intStr(pruning.MinRetainBlocks, ordinal), 10, 32)
if err != nil {
return err
}
base["min-retain-blocks"] = ptr(uint32(retain))
//valOrDefault(pruning.MinRetainBlocks, ptr(uint32(0)))
}

dst := defaultApp()
Expand Down
8 changes: 4 additions & 4 deletions internal/fullnode/configmap_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ func TestBuildConfigMaps(t *testing.T) {
custom.Spec.ChainSpec.App.HaltHeight = ptr(uint64(34567))
custom.Spec.ChainSpec.App.Pruning = &cosmosv1.Pruning{
Strategy: "custom",
Interval: ptr(uint32(222)),
KeepEvery: ptr(uint32(333)),
KeepRecent: ptr(uint32(444)),
MinRetainBlocks: ptr(uint32(271500)),
Interval: ptr("222,232"),
KeepEvery: ptr("333"),
KeepRecent: ptr("444"),
MinRetainBlocks: ptr("271500"),
}

cms, err := BuildConfigMaps(custom, nil)
Expand Down
Loading