Skip to content

Commit

Permalink
248 lite mode (0xSpaceShard#249)
Browse files Browse the repository at this point in the history
* Semi working solution, I just need to fix assert_block

* update workflow and remove lite workflow file

* Remove block-hash and deploy-hash from lite-mode

* Update readme.md

* Quickfix

* Add changes after format script

* Update of readme.md

* Disable lite-mode in general workflow test for now

* Comment EXPECTED_SALTY_DEPLOY_HASH_LITE_MODE for linter

* Delete typescript

* Add warning and remove deprecated tests

* Update add_argument information

* Update devnet_config.py

* Update README.md

[skip ci]
  • Loading branch information
mikiw authored Sep 6, 2022
1 parent f150787 commit 7e979b8
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 205 deletions.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ optional arguments:
--dump-path DUMP_PATH
Specify the path to dump to
--dump-on DUMP_ON Specify when to dump; can dump on: exit, transaction
--lite-mode Applies all lite-mode-* optimizations by disabling some features.
--lite-mode-block-hash
Disables block hash calculation
--lite-mode-deploy-hash
Disables deploy tx hash calculation
--lite-mode Applies lite-mode optimizations by disabling some features. (In the current version, lite-mode doesn't affect performance)
--accounts ACCOUNTS Specify the number of accounts to be predeployed;
defaults to 10
--initial-balance INITIAL_BALANCE, -e INITIAL_BALANCE
Expand Down Expand Up @@ -388,14 +384,8 @@ Response:

To improve Devnet performance, instead of calculating the actual hash of deployment transactions and blocks, sequential numbering can be used (0x0, 0x1, 0x2, ...).

Consider passing these CLI flags on Devnet startup:

- `--lite-mode` enables all of the optimizations described below (same as using all of the flags below)
- `--lite-mode-deploy-hash`
- disables the calculation of transaction hash for deploy transactions
- `--lite-mode-block-hash`
- disables the calculation of block hash
- disables get_state_update functionality
Consider passing this CLI flag on Devnet startup:
- `--lite-mode` enables optimizations

## Restart

Expand Down
20 changes: 2 additions & 18 deletions starknet_devnet/devnet_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,7 @@ def parse_args(raw_args: List[str]):
parser.add_argument(
"--lite-mode",
action="store_true",
help="Applies all lite-mode-* optimizations by disabling some features.",
)
parser.add_argument(
"--lite-mode-block-hash",
action="store_true",
help="Disables block hash calculation",
)
parser.add_argument(
"--lite-mode-deploy-hash",
action="store_true",
help="Disables deploy tx hash calculation",
help="Applies lite-mode optimizations by disabling some features. (In the current version, lite-mode doesn't affect performance)",
)
parser.add_argument(
"--accounts",
Expand Down Expand Up @@ -178,10 +168,4 @@ def __init__(self, args: argparse.Namespace = None):
self.seed = self.args.seed
self.start_time = self.args.start_time
self.gas_price = self.args.gas_price

if self.args.lite_mode:
self.lite_mode_block_hash = True
self.lite_mode_deploy_hash = True
else:
self.lite_mode_block_hash = self.args.lite_mode_block_hash
self.lite_mode_deploy_hash = self.args.lite_mode_deploy_hash
self.lite_mode = self.args.lite_mode
7 changes: 7 additions & 0 deletions starknet_devnet/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ def main():
# starknet_wrapper.origin = origin

args = parse_args(sys.argv[1:])

if args.lite_mode:
print(
"Warning: In the current version, lite-mode doesn't affect performance.",
file=sys.stderr,
)

try:
if args.load_path:
state.load(args.load_path)
Expand Down
8 changes: 4 additions & 4 deletions starknet_devnet/starknet_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, config: DevnetConfig):
"""Origin chain that this devnet was forked from."""

self.block_info_generator = BlockInfoGenerator()
self.blocks = DevnetBlocks(self.origin, lite=config.lite_mode_block_hash)
self.blocks = DevnetBlocks(self.origin, lite=config.lite_mode)
self.config = config
self.contracts = DevnetContracts(self.origin)
self.l1l2 = DevnetL1L2()
Expand Down Expand Up @@ -129,7 +129,7 @@ async def __update_state(self):
general_config=state.general_config,
)

if not self.config.lite_mode_block_hash:
if not self.config.lite_mode:
# This is the most time-intensive part of the function.
# With only skipping it in lite-mode, we still get the time benefit.
# In regular mode it's needed for state update calculation and block state_root calculation.
Expand Down Expand Up @@ -191,7 +191,7 @@ def set_config(self, config: DevnetConfig):
Sets the configuration of the devnet.
"""
self.config = config
self.blocks.lite = config.lite_mode_block_hash
self.blocks.lite = config.lite_mode

async def declare(self, declare_transaction: Declare) -> Tuple[int, int]:
"""
Expand Down Expand Up @@ -260,7 +260,7 @@ async def deploy(self, deploy_transaction: Deploy) -> Tuple[int, int]:
tx_hash = self.contracts.get_by_address(contract_address).deployment_tx_hash
return contract_address, tx_hash

if self.config.lite_mode_deploy_hash:
if self.config.lite_mode:
tx_hash = self.transactions.get_count()
else:
tx_hash = internal_tx.hash_value
Expand Down
8 changes: 8 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import pytest


@pytest.fixture(name="expected_hash")
def fixture_expected_hash(request):
"""
Fixture to return values of expected hash
"""
return request.param


@pytest.fixture(name="run_devnet_in_background")
def fixture_run_devnet_in_background(request) -> None:
"""
Expand Down
1 change: 1 addition & 0 deletions test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
EXPECTED_SALTY_DEPLOY_HASH = (
"0x23801cc34aa43f4e2bf3e74a838fe45dd1b1ad316a2d3545aaef7efe1f39b21"
)
EXPECTED_SALTY_DEPLOY_HASH_LITE_MODE = "0x2"
EXPECTED_CLASS_HASH = "0x757a84aa38bf4ad191a7dfea2e8146fc7f3c4aa6090a8f0bddd7b688f0b24c"

NONEXISTENT_TX_HASH = "0x1"
Expand Down
8 changes: 0 additions & 8 deletions test/test_block_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
BLOCK_NUMBER_ABI_PATH = f"{ARTIFACTS_PATH}/block_number.cairo/block_number_abi.json"


@pytest.fixture(name="expected_hash")
def fixture_expected_hash(request):
"""
Fixture to return values of expected hash
"""
return request.param


def my_get_block_number(address: str):
"""Execute my_get_block_number on block_number.cairo contract deployed at `address`"""
return call(
Expand Down
19 changes: 13 additions & 6 deletions test/test_general_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
assert_negative_block_input,
assert_transaction_not_received,
assert_transaction_receipt_not_received,
devnet_in_background,
assert_block,
assert_contract_code,
assert_equal,
Expand All @@ -36,15 +35,23 @@
EVENTS_CONTRACT_PATH,
EXPECTED_SALTY_DEPLOY_ADDRESS,
EXPECTED_SALTY_DEPLOY_HASH,
# EXPECTED_SALTY_DEPLOY_HASH_LITE_MODE,
FAILING_CONTRACT_PATH,
GENESIS_BLOCK_NUMBER,
NONEXISTENT_TX_HASH,
)


@pytest.mark.general_workflow
@devnet_in_background()
def test_general_workflow():
@pytest.mark.usefixtures("run_devnet_in_background")
@pytest.mark.parametrize(
"run_devnet_in_background, expected_hash",
[
([], EXPECTED_SALTY_DEPLOY_HASH),
# (["--lite-mode"], EXPECTED_SALTY_DEPLOY_HASH_LITE_MODE),
],
indirect=True,
)
def test_general_workflow(expected_hash):
"""Test devnet with CLI"""
deploy_info = deploy(CONTRACT_PATH, ["0"])

Expand Down Expand Up @@ -107,7 +114,7 @@ def test_general_workflow():
inputs=None,
expected_status="ACCEPTED_ON_L2",
expected_address=EXPECTED_SALTY_DEPLOY_ADDRESS,
expected_tx_hash=EXPECTED_SALTY_DEPLOY_HASH,
expected_tx_hash=expected_hash,
)

assert_salty_deploy(
Expand All @@ -116,7 +123,7 @@ def test_general_workflow():
inputs=None,
expected_status="ACCEPTED_ON_L2",
expected_address=EXPECTED_SALTY_DEPLOY_ADDRESS,
expected_tx_hash=EXPECTED_SALTY_DEPLOY_HASH,
expected_tx_hash=expected_hash,
)

salty_invoke_tx_hash = invoke(
Expand Down
53 changes: 0 additions & 53 deletions test/test_general_workflow_lite.py

This file was deleted.

56 changes: 0 additions & 56 deletions test/test_general_workflow_lite_block_hash.py

This file was deleted.

47 changes: 0 additions & 47 deletions test/test_general_workflow_lite_deploy_hash.py

This file was deleted.

0 comments on commit 7e979b8

Please sign in to comment.