-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
L1-218: Refector and cleanup in pallet-balances-maintenance.py (#1752)
# Description This PR cleans up unneeded functionality in the storage maintenance script. I also moved functions across modules. It's mostly code removal: ``` marcin@marcin-Latitude-3520 ~/g/a/s/accounts-invariants (L1-218-part1)> git ci (base) [L1-218-part1 3e8af98e] L1-218: Refector and cleanup in pallet-balances-maintenance.py 5 files changed, 110 insertions(+), 772 deletions(-) create mode 100644 scripts/accounts-invariants/aleph_chain_version.py rename scripts/accounts-invariants/{common.py => chain_operations.py} (60%) create mode 100644 scripts/accounts-invariants/contracts.py create mode 100644 scripts/accounts-invariants/logger.py ``` ## Type of change Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected)
- Loading branch information
1 parent
af38601
commit 53512b9
Showing
5 changed files
with
128 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import enum | ||
|
||
|
||
class AlephChainVersion(enum.IntEnum): | ||
VERSION_11_4 = 65, | ||
VERSION_12_0 = 67, | ||
VERSION_12_2 = 68, | ||
VERSION_13_0 = 70, | ||
VERSION_13_2 = 71, | ||
VERSION_12_3 = 72, | ||
VERSION_13_3 = 73, | ||
VERSION_14_X = 14000000, | ||
|
||
@classmethod | ||
def from_spec_version(cls, spec_version): | ||
return cls(spec_version) | ||
|
||
|
||
def get_aleph_chain_version(chain_connection, block_hash): | ||
""" | ||
Retrieves spec_version from chain and returns an `AlephChainVersion` enum | ||
:param chain_connection: WS handler | ||
:param block_hash: Block hash to query state from | ||
:return: AlephChainVersion | ||
""" | ||
runtime_version = chain_connection.get_block_runtime_version(block_hash) | ||
spec_version = runtime_version['specVersion'] | ||
return AlephChainVersion.from_spec_version(spec_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
from tqdm import tqdm | ||
import sys | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
def query_contract_and_code_owners_accounts(chain_connection, block_hash): | ||
""" | ||
Returns contract accounts and code owners. | ||
""" | ||
code_owners = set() | ||
contract_accounts = set() | ||
|
||
log.info(f"Querying code owners.") | ||
code_info_of_query = chain_connection.query_map(module='Contracts', | ||
storage_function='CodeInfoOf', | ||
page_size=500, | ||
block_hash=block_hash) | ||
|
||
for (i, (account_id, info)) in tqdm(iterable=enumerate(code_info_of_query), | ||
desc="CodeInfoOfs checked", | ||
unit="", | ||
file=sys.stdout): | ||
code_owners.add(info.serialize()['owner']) | ||
|
||
log.info(f"Total code owners is {len(code_owners)}") | ||
log.debug(f"Code owners: {code_owners}") | ||
|
||
log.info(f"Querying contract accounts.") | ||
contract_info_of_query = chain_connection.query_map(module='Contracts', | ||
storage_function='ContractInfoOf', | ||
page_size=1000, | ||
block_hash=block_hash) | ||
for (i, (account_id, info)) in tqdm(iterable=enumerate(contract_info_of_query), | ||
desc="ContractInfoOfs checked", | ||
unit="", | ||
file=sys.stdout): | ||
contract_accounts.add(account_id.value) | ||
|
||
log.info(f"Total contracts count is {len(contract_accounts)}") | ||
log.debug(f"Contract accounts: {contract_accounts}") | ||
|
||
return code_owners, contract_accounts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
import datetime | ||
|
||
|
||
def setup_global_logger(): | ||
log_formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") | ||
root_logger = logging.getLogger() | ||
root_logger.setLevel('DEBUG') | ||
|
||
time_now = datetime.datetime.now().strftime("%d-%m-%Y_%H:%M:%S") | ||
file_handler = logging.FileHandler(f"pallet-balances-maintenance-{time_now}.log") | ||
file_handler.setFormatter(log_formatter) | ||
file_handler.setLevel(logging.DEBUG) | ||
root_logger.addHandler(file_handler) | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(log_formatter) | ||
console_handler.setLevel(logging.INFO) | ||
root_logger.addHandler(console_handler) |
Oops, something went wrong.