11from typing import Any , Dict
22
33from multiversx_sdk_cli .localnet .config_root import ConfigRoot
4+ from multiversx_sdk_cli .localnet .constants import (
5+ NUM_ROUNDS_BETWEEN_SUPERNOVA_ACTIVATION_EPOCH_AND_ACTIVATION_ROUND ,
6+ ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO ,
7+ )
48from multiversx_sdk_cli .localnet .nodes_setup_json import CHAIN_ID
59
610ConfigDict = Dict [str , Any ]
711
812
9- def patch_config (data : ConfigDict , config : ConfigRoot ):
13+ def patch_config (data : ConfigDict , config : ConfigRoot , enable_epochs_config : ConfigDict ):
14+ supernova_activation_epoch = enable_epochs_config ["EnableEpochs" ].get ("SupernovaEnableEpoch" , None )
15+
1016 data ["GeneralSettings" ]["ChainID" ] = CHAIN_ID
1117
1218 # "--operation-mode=historical-balances" is not available for nodes,
@@ -18,33 +24,58 @@ def patch_config(data: ConfigDict, config: ConfigRoot):
1824 data ["StoragePruning" ]["ObserverCleanOldEpochsData" ] = False
1925 data ["StoragePruning" ]["AccountsTrieCleanOldEpochsData" ] = False
2026
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 )
27+ # Some time after the release of Supernova, we should drop this custom (and somewhat cumbersome) logic.
28+ if supernova_activation_epoch is None :
29+ # Before Supernova (as software version, not as "era after activation"),
30+ # we alter epoch duration by adjusting "RoundsPerEpoch" and "MinRoundsBetweenEpochs" in section "EpochStartConfig".
31+ # In a Supernova-aware node configuration, these entries do not exist anymore (see "ChainParametersByEpoch").
32+ epoch_start_config : ConfigDict = dict ()
33+ epoch_start_config ["RoundsPerEpoch" ] = config .general .rounds_per_epoch
34+ epoch_start_config ["MinRoundsBetweenEpochs" ] = int (
35+ config .general .rounds_per_epoch / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
36+ )
37+
38+ data ["EpochStartConfig" ].update (epoch_start_config )
2539
26- data ["EpochStartConfig" ].update (epoch_start_config )
2740 data ["WebServerAntiflood" ]["VmQueryDelayAfterStartInSec" ] = 30
2841
2942 # Always use the latest VM
3043 data ["VirtualMachine" ]["Execution" ]["WasmVMVersions" ] = [{"StartEpoch" : 0 , "Version" : "*" }]
3144 data ["VirtualMachine" ]["Querying" ]["WasmVMVersions" ] = [{"StartEpoch" : 0 , "Version" : "*" }]
3245
33- # Adjust "ChainParametersByEpoch" (for Andromeda)
46+ # Adjust "ChainParametersByEpoch"
3447 chain_parameters_by_epoch = data ["GeneralSettings" ].get ("ChainParametersByEpoch" , [])
3548
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 ({})
49+ for item in chain_parameters_by_epoch :
50+ enable_epoch = item ["EnableEpoch" ]
51+
52+ is_supernova_enabled = supernova_activation_epoch is not None and enable_epoch >= supernova_activation_epoch
53+ if is_supernova_enabled :
54+ item ["RoundDuration" ] = config .general .round_duration_milliseconds_in_supernova
55+ item ["RoundsPerEpoch" ] = config .general .rounds_per_epoch_in_supernova
56+ item ["MinRoundsBetweenEpochs" ] = int (
57+ config .general .rounds_per_epoch_in_supernova / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
58+ )
59+ else :
60+ item ["RoundDuration" ] = config .general .round_duration_milliseconds
61+ item ["RoundsPerEpoch" ] = config .general .rounds_per_epoch
62+ item ["MinRoundsBetweenEpochs" ] = int (
63+ config .general .rounds_per_epoch / ROUNDS_PER_EPOCH_TO_MIN_ROUNDS_BETWEEN_EPOCHS_RATIO
64+ )
65+
66+ item ["ShardConsensusGroupSize" ] = config .shards .consensus_size
67+ item ["ShardMinNumNodes" ] = config .shards .num_validators_per_shard
68+ item ["MetachainConsensusGroupSize" ] = config .metashard .consensus_size
69+ item ["MetachainMinNumNodes" ] = config .metashard .num_validators
4070
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
71+ # Adjust "Versions" (of blocks)
72+ versions_by_epoch = data ["Versions" ].get ("VersionsByEpochs" , [])
73+
74+ for item in versions_by_epoch :
75+ enable_epoch = item ["StartEpoch" ]
76+
77+ if enable_epoch == supernova_activation_epoch :
78+ item ["StartRound" ] = _compute_supernova_activation_round (config , supernova_activation_epoch )
4879
4980
5081def patch_api (data : ConfigDict , config : ConfigRoot ):
@@ -55,10 +86,6 @@ def patch_api(data: ConfigDict, config: ConfigRoot):
5586
5687def patch_enable_epochs (data : ConfigDict , config : ConfigRoot ):
5788 enable_epochs = data ["EnableEpochs" ]
58- enable_epochs ["SCDeployEnableEpoch" ] = 0
59- enable_epochs ["BuiltInFunctionsEnableEpoch" ] = 0
60- enable_epochs ["RelayedTransactionsEnableEpoch" ] = 0
61- enable_epochs ["PenalizedTooMuchGasEnableEpoch" ] = 0
6289 enable_epochs ["AheadOfTimeGasUsageEnableEpoch" ] = 0
6390 enable_epochs ["GasPriceModifierEnableEpoch" ] = 0
6491 enable_epochs ["RepairCallbackEnableEpoch" ] = 0
@@ -69,15 +96,34 @@ def patch_enable_epochs(data: ConfigDict, config: ConfigRoot):
6996 enable_epochs ["ESDTMultiTransferEnableEpoch" ] = 0
7097 enable_epochs ["GlobalMintBurnDisableEpoch" ] = 0
7198 enable_epochs ["ESDTTransferRoleEnableEpoch" ] = 0
72- enable_epochs ["BuiltInFunctionOnMetaEnableEpoch" ] = 0
7399 enable_epochs ["MultiESDTTransferFixOnCallBackOnEnableEpoch" ] = 0
74100 enable_epochs ["ESDTNFTCreateOnMultiShard" ] = 0
75101 enable_epochs ["MetaESDTSetEnableEpoch" ] = 0
76102 enable_epochs ["DelegationManagerEnableEpoch" ] = 0
77103
104+ # Adjust "MaxNumNodes":
78105 max_nodes_change_enable_epoch = enable_epochs ["MaxNodesChangeEnableEpoch" ]
79106 last_entry = max_nodes_change_enable_epoch [- 1 ]
80107 penultimate_entry = max_nodes_change_enable_epoch [- 2 ]
81108 last_entry ["MaxNumNodes" ] = (
82109 penultimate_entry ["MaxNumNodes" ] - (config .shards .num_shards + 1 ) * penultimate_entry ["NodesToShufflePerShard" ]
83110 )
111+
112+
113+ def patch_enable_rounds (data : ConfigDict , config : ConfigRoot , enable_epochs_config : ConfigDict ):
114+ supernova_activation_epoch = enable_epochs_config ["EnableEpochs" ].get ("SupernovaEnableEpoch" , None )
115+
116+ activations = data ["RoundActivations" ]
117+ supernova_entry = activations .get ("SupernovaEnableRound" )
118+
119+ if supernova_entry and supernova_activation_epoch is not None :
120+ supernova_computed_activation_round = _compute_supernova_activation_round (config , supernova_activation_epoch )
121+ supernova_entry ["Round" ] = str (supernova_computed_activation_round )
122+
123+
124+ def _compute_supernova_activation_round (config : ConfigRoot , supernova_activation_epoch : int ) -> int :
125+ # Epochs are zero-indexed.
126+ return (
127+ config .general .rounds_per_epoch * supernova_activation_epoch
128+ + NUM_ROUNDS_BETWEEN_SUPERNOVA_ACTIVATION_EPOCH_AND_ACTIVATION_ROUND
129+ )
0 commit comments