Skip to content

Commit 71a58eb

Browse files
Patch node config toml wrt. enable epochs toml.
1 parent 049cb40 commit 71a58eb

3 files changed

Lines changed: 56 additions & 35 deletions

File tree

multiversx_sdk_cli/localnet/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
FILE_MODE_EXECUTABLE = (
77
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
88
)
9+
10+
# See https://github.com/multiversx/mx-chain-go/blob/master/cmd/node/config/config.toml.
11+
ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO = 5

multiversx_sdk_cli/localnet/node_config_toml.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from typing import Any, Dict
1+
from typing import Any, Dict, Optional
22

33
from multiversx_sdk_cli.localnet.config_root import ConfigRoot
4+
from multiversx_sdk_cli.localnet.constants import ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
45
from multiversx_sdk_cli.localnet.nodes_setup_json import CHAIN_ID
56

67
ConfigDict = Dict[str, Any]
78

89

9-
def patch_config(data: ConfigDict, config: ConfigRoot):
10+
def patch_config(data: ConfigDict, config: ConfigRoot, supernova_activation_epoch: Optional[int] = None):
1011
data["GeneralSettings"]["ChainID"] = CHAIN_ID
1112

1213
# "--operation-mode=historical-balances" is not available for nodes,
@@ -18,33 +19,48 @@ def patch_config(data: ConfigDict, config: ConfigRoot):
1819
data["StoragePruning"]["ObserverCleanOldEpochsData"] = False
1920
data["StoragePruning"]["AccountsTrieCleanOldEpochsData"] = False
2021

21-
# Make epochs shorter
22-
epoch_start_config: ConfigDict = dict()
23-
epoch_start_config["RoundsPerEpoch"] = config.general.rounds_per_epoch
24-
epoch_start_config["MinRoundsBetweenEpochs"] = int(config.general.rounds_per_epoch / 4)
22+
# Some time after the release of Supernova, we should drop this custom (and somehow cumbersome) logic.
23+
if supernova_activation_epoch is None:
24+
# Before Supernova (as software version, not as "era after activation"),
25+
# we alter epoch duration by adjusting "RoundsPerEpoch" and "MinRoundsBetweenEpochs" in section "EpochStartConfig".
26+
# In a Supernova-aware node configuration, these entries do not exist anymore (see "ChainParametersByEpoch").
27+
epoch_start_config: ConfigDict = dict()
28+
epoch_start_config["RoundsPerEpoch"] = config.general.rounds_per_epoch
29+
epoch_start_config["MinRoundsBetweenEpochs"] = int(
30+
config.general.rounds_per_epoch / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
31+
)
32+
33+
data["EpochStartConfig"].update(epoch_start_config)
2534

26-
data["EpochStartConfig"].update(epoch_start_config)
2735
data["WebServerAntiflood"]["VmQueryDelayAfterStartInSec"] = 30
2836

2937
# Always use the latest VM
3038
data["VirtualMachine"]["Execution"]["WasmVMVersions"] = [{"StartEpoch": 0, "Version": "*"}]
3139
data["VirtualMachine"]["Querying"]["WasmVMVersions"] = [{"StartEpoch": 0, "Version": "*"}]
3240

33-
# Adjust "ChainParametersByEpoch" (for Andromeda)
41+
# Adjust "ChainParametersByEpoch"
3442
chain_parameters_by_epoch = data["GeneralSettings"].get("ChainParametersByEpoch", [])
3543

36-
if chain_parameters_by_epoch:
37-
# For convenience, keep a single entry ...
38-
chain_parameters_by_epoch.clear()
39-
chain_parameters_by_epoch.append({})
40-
41-
# ... and set the activation epoch to 0
42-
chain_parameters_by_epoch[0]["EnableEpoch"] = 0
43-
chain_parameters_by_epoch[0]["RoundDuration"] = config.general.round_duration_milliseconds
44-
chain_parameters_by_epoch[0]["ShardConsensusGroupSize"] = config.shards.consensus_size
45-
chain_parameters_by_epoch[0]["ShardMinNumNodes"] = config.shards.num_validators_per_shard
46-
chain_parameters_by_epoch[0]["MetachainConsensusGroupSize"] = config.metashard.consensus_size
47-
chain_parameters_by_epoch[0]["MetachainMinNumNodes"] = config.metashard.num_validators
44+
for item in chain_parameters_by_epoch:
45+
enable_epoch = item["EnableEpoch"]
46+
47+
if supernova_activation_epoch and enable_epoch >= supernova_activation_epoch:
48+
item["RoundDuration"] = config.general.round_duration_milliseconds_in_supernova
49+
item["RoundsPerEpoch"] = config.general.rounds_per_epoch_in_supernova
50+
item["MinRoundsBetweenEpochs"] = (
51+
config.general.rounds_per_epoch_in_supernova / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
52+
)
53+
else:
54+
item["RoundDuration"] = config.general.round_duration_milliseconds
55+
item["RoundsPerEpoch"] = config.general.rounds_per_epoch
56+
item["MinRoundsBetweenEpochs"] = (
57+
config.general.rounds_per_epoch / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
58+
)
59+
60+
item["ShardConsensusGroupSize"] = config.shards.consensus_size
61+
item["ShardMinNumNodes"] = config.shards.num_validators_per_shard
62+
item["MetachainConsensusGroupSize"] = config.metashard.consensus_size
63+
item["MetachainMinNumNodes"] = config.metashard.num_validators
4864

4965

5066
def patch_api(data: ConfigDict, config: ConfigRoot):

multiversx_sdk_cli/localnet/step_config.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,26 @@ def copy_validator_keys(config: ConfigRoot):
101101
def patch_node_config(config: ConfigRoot):
102102
for node_config in config.all_nodes_config_folders():
103103
node_config_file = node_config / "config.toml"
104-
data = utils.read_toml_file(node_config_file)
105-
node_config_toml.patch_config(data, config)
106-
utils.write_toml_file(node_config_file, data)
107-
108104
api_config_file = node_config / "api.toml"
109-
data = utils.read_toml_file(api_config_file)
110-
node_config_toml.patch_api(data, config)
111-
utils.write_toml_file(api_config_file, data)
112-
113105
enable_epochs_config_file = node_config / "enableEpochs.toml"
114-
data = utils.read_toml_file(enable_epochs_config_file)
115-
node_config_toml.patch_enable_epochs(data, config)
116-
utils.write_toml_file(enable_epochs_config_file, data)
117-
118106
genesis_smart_contracts_file = node_config / "genesisSmartContracts.json"
119-
data = utils.read_json_file(genesis_smart_contracts_file)
120-
genesis_smart_contracts_json.patch(data, config)
121-
utils.write_json_file(genesis_smart_contracts_file, data)
107+
108+
node_config_data = utils.read_toml_file(node_config_file)
109+
api_config_data = utils.read_toml_file(api_config_file)
110+
enable_epochs_config_data = utils.read_toml_file(enable_epochs_config_file)
111+
genesis_smart_contracts_data = utils.read_json_file(genesis_smart_contracts_file)
112+
113+
supernova_activation_epoch = enable_epochs_config_data["EnableEpochs"].get("SupernovaEnableEpoch", None)
114+
115+
node_config_toml.patch_config(node_config_data, config, supernova_activation_epoch)
116+
node_config_toml.patch_api(api_config_data, config)
117+
node_config_toml.patch_enable_epochs(enable_epochs_config_data, config)
118+
genesis_smart_contracts_json.patch(genesis_smart_contracts_data, config)
119+
120+
utils.write_toml_file(node_config_file, node_config_data)
121+
utils.write_toml_file(api_config_file, api_config_data)
122+
utils.write_toml_file(enable_epochs_config_file, enable_epochs_config_data)
123+
utils.write_json_file(genesis_smart_contracts_file, genesis_smart_contracts_data)
122124

123125

124126
def copy_config_to_seednode(config: ConfigRoot):

0 commit comments

Comments
 (0)