Skip to content

Commit

Permalink
feat: allow replicas to have different pruning values
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer committed Aug 13, 2024
1 parent 31d6ab0 commit 27ef5d7
Show file tree
Hide file tree
Showing 8 changed files with 6,111 additions and 5,833 deletions.
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
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.

1 change: 1 addition & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
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

0 comments on commit 27ef5d7

Please sign in to comment.