Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localnet: compatibility with Node 1.7 (Vega) #426

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions multiversx_sdk_cli/localnet/genesis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from multiversx_sdk_core.address import Address, AddressComputer

from multiversx_sdk_cli.constants import NUMBER_OF_SHARDS
from multiversx_sdk_cli.localnet import wallets


Expand All @@ -9,18 +6,5 @@ def get_owner_of_genesis_contracts():
return users["alice"]


def get_delegation_address() -> Address:
owner = get_owner_of_genesis_contracts()
owner.nonce = 0

address_computer = AddressComputer(NUMBER_OF_SHARDS)
address = address_computer.compute_contract_address(owner.address, owner.nonce)
return address


def is_last_user(nickname: str) -> bool:
return nickname == "mike"


def is_foundational_node(nickname: str) -> bool:
return nickname == "validator00"
23 changes: 6 additions & 17 deletions multiversx_sdk_cli/localnet/genesis_json.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from typing import Any, Dict, List

from multiversx_sdk_core import Address

from multiversx_sdk_cli.accounts import Account
from multiversx_sdk_cli.localnet import wallets
from multiversx_sdk_cli.localnet.config_root import ConfigRoot
from multiversx_sdk_cli.localnet.genesis import (get_delegation_address,
is_foundational_node,
is_last_user)
from multiversx_sdk_cli.localnet.genesis import is_last_user

ENTIRE_SUPPLY = 20000000000000000000000000
# For localnet, we delegate for 1 node
Expand All @@ -18,13 +14,8 @@ def build(config: ConfigRoot) -> List[Any]:
num_validators = config.num_all_validators()
genesis_items: List[Dict[str, Any]] = []
remaining_supply = ENTIRE_SUPPLY
remaining_to_delegate = DELEGATED_VALUE
delegation_address = get_delegation_address()

for nickname, account in wallets.get_validator_wallets(num_validators).items():
if is_foundational_node(nickname):
continue

value = 2500000000000000000000
entry = _build_validator_entry(nickname, account, value)
genesis_items.append(entry)
Expand All @@ -33,11 +24,9 @@ def build(config: ConfigRoot) -> List[Any]:
for nickname, account in wallets.get_users().items():
# The last user (mike) gets all remaining tokens
value = remaining_supply if is_last_user(nickname) else 100000000000000000000000
delegated_value = remaining_to_delegate if is_last_user(nickname) else 100000000000000000000
entry = _build_user_entry(nickname, account, value, delegated_value, delegation_address)
entry = _build_user_entry(nickname, account, value)
genesis_items.append(entry)
remaining_supply -= value
remaining_to_delegate -= delegated_value

return genesis_items

Expand All @@ -56,15 +45,15 @@ def _build_validator_entry(nickname: str, account: Account, value: int) -> Dict[
}


def _build_user_entry(nickname: str, account: Account, value: int, delegated_value: int, delegation_address: Address) -> Dict[str, Any]:
def _build_user_entry(nickname: str, account: Account, value: int) -> Dict[str, Any]:
return {
"nickname": nickname,
"address": account.address.to_bech32(),
"supply": str(value),
"balance": str(value - delegated_value),
"balance": str(value),
"stakingvalue": "0",
"delegation": {
"address": delegation_address.to_bech32(),
"value": str(delegated_value)
"address": "",
"value": "0"
}
}
29 changes: 14 additions & 15 deletions multiversx_sdk_cli/localnet/node_config_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@


def patch_config(data: ConfigDict, config: ConfigRoot):
data['DbLookupExtensions']['Enabled'] = True

general_settings: ConfigDict = dict()
general_settings['ChainID'] = CHAIN_ID
general_settings['StartInEpochEnabled'] = False
general_settings['SetGuardianEpochsDelay'] = 1
data['GeneralSettings']['ChainID'] = CHAIN_ID

data['GeneralSettings'].update(general_settings)
# "--operation-mode=historical-balances" is not available for nodes,
# since << validator cannot be a full archive node >>,
# but we attempt to set the "deep-history" mode as follows:
data['DbLookupExtensions']['Enabled'] = True
data['GeneralSettings']['StartInEpochEnabled'] = False
data['StateTriesConfig']['AccountsStatePruningEnabled'] = False
data['StoragePruning']['ObserverCleanOldEpochsData'] = False
data['StoragePruning']['AccountsTrieCleanOldEpochsData'] = False

# Make epochs shorter
epoch_start_config: ConfigDict = dict()
Expand All @@ -41,17 +43,14 @@ def patch_api(data: ConfigDict, config: ConfigRoot):


def patch_enable_epochs(data: ConfigDict, config: ConfigRoot):
enable_epochs: ConfigDict = dict()
enable_epochs = data["EnableEpochs"]
enable_epochs['SCDeployEnableEpoch'] = 0
enable_epochs['BuiltInFunctionsEnableEpoch'] = 0
enable_epochs['RelayedTransactionsEnableEpoch'] = 0
enable_epochs['PenalizedTooMuchGasEnableEpoch'] = 0
enable_epochs['SwitchJailWaitingEnableEpoch'] = 0
enable_epochs['BelowSignedThresholdEnableEpoch'] = 0
enable_epochs['AheadOfTimeGasUsageEnableEpoch'] = 0
enable_epochs['GasPriceModifierEnableEpoch'] = 0
enable_epochs['RepairCallbackEnableEpoch'] = 0
enable_epochs['BlockGasAndFeesReCheckEnableEpoch'] = 0
enable_epochs['ReturnDataToLastTransferEnableEpoch'] = 0
enable_epochs['SenderInOutTransferEnableEpoch'] = 0
enable_epochs['ESDTEnableEpoch'] = 0
Expand All @@ -62,10 +61,10 @@ def patch_enable_epochs(data: ConfigDict, config: ConfigRoot):
enable_epochs['BuiltInFunctionOnMetaEnableEpoch'] = 0
enable_epochs['MultiESDTTransferFixOnCallBackOnEnableEpoch'] = 0
enable_epochs['ESDTNFTCreateOnMultiShard'] = 0
enable_epochs['RemoveNonUpdatedStorageEnableEpoch'] = 0
enable_epochs['FixOOGReturnCodeEnableEpoch'] = 0
enable_epochs['CorrectFirstQueuedEpoch'] = 0
enable_epochs['MetaESDTSetEnableEpoch'] = 0
enable_epochs['DelegationManagerEnableEpoch'] = 0

data['EnableEpochs'].update(enable_epochs)
max_nodes_change_enable_epoch = enable_epochs['MaxNodesChangeEnableEpoch']
last_entry = max_nodes_change_enable_epoch[-1]
penultimate_entry = max_nodes_change_enable_epoch[-2]
last_entry['MaxNumNodes'] = penultimate_entry['MaxNumNodes'] - (config.shards.num_shards + 1) * penultimate_entry['NodesToShufflePerShard']
Comment on lines +67 to +70
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Staking v4.

20 changes: 6 additions & 14 deletions multiversx_sdk_cli/localnet/nodes_setup_json.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import Any, Dict, List

from multiversx_sdk_cli.accounts import Account
from multiversx_sdk_cli.localnet import wallets
from multiversx_sdk_cli.localnet.config_root import ConfigRoot
from multiversx_sdk_cli.localnet.genesis import (get_delegation_address,
is_foundational_node)

CHAIN_ID = "localnet"

Expand All @@ -14,7 +11,12 @@ def build(config: ConfigRoot) -> Any:
initial_nodes: List[Dict[str, str]] = []

for nickname, [pubkey, account] in wallets.get_validators(num_validators).items():
entry = _build_initial_nodes_entry(nickname, pubkey, account)
entry = {
"nickname": nickname,
"address": account.address.to_bech32(),
"pubkey": pubkey,
}

initial_nodes.append(entry)

# Then, patch the list of initial nodes, so that higher indexes will become metachain nodes.
Expand All @@ -35,13 +37,3 @@ def build(config: ConfigRoot) -> Any:
"minTransactionVersion": 1,
"initialNodes": initial_nodes
}


def _build_initial_nodes_entry(nickname: str, pubkey: str, account: Account) -> Dict[str, str]:
address = get_delegation_address().bech32() if is_foundational_node(nickname) else account.address.bech32()

return {
"nickname": nickname,
"address": address,
"pubkey": pubkey,
}
3 changes: 2 additions & 1 deletion multiversx_sdk_cli/localnet/step_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ async def do_start(configfile: Path, stop_after_seconds: int):
f"--log-level={loglevel}",
"--log-logger-name",
f"--destination-shard-as-observer={observer.shard}",
f"--rest-api-interface={observer.api_interface()}"
f"--rest-api-interface={observer.api_interface()}",
"--operation-mode=historical-balances"
], cwd=observer.folder, delay=NODES_START_DELAY))

# Validators
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "multiversx-sdk-cli"
version = "9.5.5"
version = "9.6.0"
authors = [
{ name="MultiversX" },
]
Expand Down