Update setConfig.ts for coinstatsindex

This commit is contained in:
copy2018 2025-03-07 08:32:19 +00:00 committed by GitHub
parent eabdcb071b
commit 0ff4a3f566
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,36 +1,39 @@
import {
matches,
compat,
types,
YAML
} from "../dependencies.ts";
const { number, shape, boolean } = matches;
import { matches, types, YAML } from "../dependencies.ts";
const { number } = matches;
export const setConfig: types.ExpectedExports.setConfig = async (
effects: types.Effects,
// deno-lint-ignore no-explicit-any
newConfig: any,
newConfig: any
) => {
if (!(newConfig?.rpc?.enable || !(newConfig.advanced?.pruning?.mode === "manual"))) {
if (newConfig.advanced.pruning.mode === "manual" && !newConfig.rpc.enable) {
return {
error: "RPC must be enabled for manual.",
error: "RPC must be enabled for manual pruning.",
};
}
if (
!(!newConfig.txindex || (newConfig.advanced?.pruning?.mode === "disabled"))
) {
if (newConfig.txindex && newConfig.advanced.pruning.mode !== "disabled") {
return {
error: "Txindex not allowed on pruned nodes.",
};
}
// true, false only fail case
if (
!(!newConfig.advanced.blockfilters.peerblockfilters ||
(newConfig.advanced.blockfilters.blockfilterindex))
newConfig.coinstatsindex &&
newConfig.advanced.pruning.mode !== "disabled"
) {
return {
error: "Coinstats index not allowed on pruned nodes.",
};
}
if (
newConfig.advanced.blockfilters.peerblockfilters &&
!newConfig.advanced.blockfilters.blockfilterindex
) {
return {
error:
"'Compute Compact Block Filters' must be enabled if 'Serve Compact Block Filters to Peers' is enabled.",
'"Compute Compact Block Filters" must be enabled if "Serve Compact Block Filters to Peers" is enabled.',
};
}
@ -41,10 +44,12 @@ export const setConfig: types.ExpectedExports.setConfig = async (
// config-set.sh
const oldConfig = await effects.readFile({
path: "start9/config.yaml",
volumeId: "main",
}).catch(() => null);
const oldConfig = await effects
.readFile({
path: "start9/config.yaml",
volumeId: "main",
})
.catch(() => null);
if (oldConfig) {
await effects.writeFile({
path: "start9/config-old.yaml",
@ -56,7 +61,7 @@ export const setConfig: types.ExpectedExports.setConfig = async (
let oldPruningSize = 0;
if (oldPruningTl !== "disabled") {
oldPruningSize = number.unsafeCast(
oldConfigParsed?.advanced?.pruning?.size,
oldConfigParsed?.advanced?.pruning?.size
);
}
const newPruningTl = newConfig.advanced.pruning.mode;
@ -67,7 +72,8 @@ export const setConfig: types.ExpectedExports.setConfig = async (
if (oldPruningTl == "disabled" || !oldPruningTl) {
effects.debug("No reindex required");
} else if (
oldPruningTl === newPruningTl && oldPruningSize >= newPruningSize
oldPruningTl === newPruningTl &&
oldPruningSize >= newPruningSize
) {
effects.debug("No reindex required");
} else {
@ -81,7 +87,7 @@ export const setConfig: types.ExpectedExports.setConfig = async (
} else {
effects.debug("No reindex required");
}
await effects.writeFile({
path: "start9/config.yaml",
toWrite: YAML.stringify(newConfig),