1- from typing import Any , Dict
1+ from typing import Any , Dict , Optional
22
33from 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
45from multiversx_sdk_cli .localnet .nodes_setup_json import CHAIN_ID
56
67ConfigDict = 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
5066def patch_api (data : ConfigDict , config : ConfigRoot ):
0 commit comments