Skip to content

Commit

Permalink
Fixed protocol parameters for sandboxed node
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Feb 21, 2024
1 parent 1b81f29 commit 8114a03
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Fixed

* Fixed protocol parameters for sandboxed node

## [3.11.1](https://github.com/baking-bad/pytezos/compare/3.11.0...3.11.1) (2024-02-07)

### Added
Expand Down
8 changes: 3 additions & 5 deletions src/pytezos/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pytezos.sandbox.node import TEZOS_NODE_PORT
from pytezos.sandbox.node import SandboxedNodeContainer
from pytezos.sandbox.node import get_next_baker_key
from pytezos.sandbox.parameters import KATHMANDU
from pytezos.sandbox.parameters import protocol_hashes

kernel_js_path = join(dirname(dirname(__file__)), 'assets', 'kernel.js')
kernel_json = {
Expand Down Expand Up @@ -340,7 +340,7 @@ def smartpy_compile(

@cli.command(help='Run containerized sandbox node')
@click.option('--image', type=str, help='Docker image to use', default=DOCKER_IMAGE)
@click.option('--protocol', type=click.Choice(['kathmandu']), help='Protocol to use', default='kathmandu')
@click.option('--protocol', type=click.Choice(['oxford']), help='Protocol to use', default='oxford')
@click.option('--port', '-p', type=int, help='Port to expose', default=TEZOS_NODE_PORT)
@click.option('--interval', '-i', type=float, help='Interval between baked blocks (in seconds)', default=1.0)
@click.option('--blocks', '-b', type=int, help='Number of blocks to bake before exit')
Expand All @@ -353,9 +353,7 @@ def sandbox(
interval: float,
blocks: int,
):
protocol_hash = {
'kathmandu': KATHMANDU,
}[protocol]
protocol_hash = protocol_hashes[protocol]

node = SandboxedNodeContainer(image=image, port=port)
with node:
Expand Down
6 changes: 3 additions & 3 deletions src/pytezos/sandbox/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
from pytezos.sandbox.parameters import LATEST
from pytezos.sandbox.parameters import sandbox_addresses

DOCKER_IMAGE = 'bakingbad/sandboxed-node:v19.0-1'
MAX_ATTEMPTS = 100
ATTEMPT_DELAY = 0.1
DOCKER_IMAGE = 'bakingbad/sandboxed-node:v19.1-2'
MAX_ATTEMPTS = 60
ATTEMPT_DELAY = 0.5
TEZOS_NODE_PORT = 8732


Expand Down
30 changes: 24 additions & 6 deletions src/pytezos/sandbox/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@
OXFORD = 'ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH'
LATEST = OXFORD

protocol_hashes = {
'edo': EDO,
'florence': FLORENCE,
'granada': GRANADA,
'hangzhou': HANGZHOU,
'ithaca': ITHACA,
'jakarta': JAKARTA,
'kathmandu': KATHMANDU,
'lima': LIMA,
'mumbai': MUMBAI,
'nairobi': NAIROBI,
'oxford': OXFORD,
}

protocol_version = {
EDO: 8,
FLORENCE: 9,
Expand Down Expand Up @@ -64,6 +78,7 @@
'bootstrap1': 'tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx',
}

# https://gitlab.com/tezos/tezos/-/blob/master/src/proto_018_Proxford/lib_parameters/default_parameters.ml#L283
sandbox_params: Dict[str, Any] = {
# NOTE: Built-in accounts
'bootstrap_accounts': [
Expand All @@ -81,17 +96,20 @@
],
],
# NOTE: Shorter cycles and voting periods
'preserved_cycles': 0,
'preserved_cycles': 2,
'blocks_per_cycle': 8,
'blocks_per_commitment': 4,
'nonce_revelation_threshold': 1,
'blocks_per_stake_snapshot': 8,
'cycles_per_voting_period': 64,
'nonce_revelation_threshold': 4,
'blocks_per_stake_snapshot': 4,
'cycles_per_voting_period': 8,
'proof_of_work_threshold': str((1 << 63) - 1),
# NOTE: Faster block time. Otherwise, fails with round_of_past_timestamp/malformed_period. Yes, it's a string.
'vdf_difficulty': '50000',
'minimal_block_delay': '1',
# NOTE: proto.018-Proxford.validate.block.not_enough_attestations
'delay_increment_per_round': '1',
'consensus_committee_size': 256,
'consensus_threshold': 0,
'limit_of_delegation_over_baking': 19,
'max_operations_time_to_live': 8,
}

# NOTE: https://rpc.tzkt.io/oxfordnet/chains/main/blocks/head/context/constants/parametric
Expand Down
3 changes: 1 addition & 2 deletions tests/sandbox_tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def test_3_create_transaction(self) -> None:
def test_4_bake_block(self) -> None:
self.bake_block()
bootstrap3 = self.client.shell.contracts[sandbox_addresses['bootstrap3']]()
# FIXME: 400_000_000_000 frozen deposits, 42 transaction, and 1 what?
self.assertEqual(3_600_000_300_000 + 42 - 1, int(bootstrap3['balance']))
self.assertEqual(3800000316708, int(bootstrap3['balance']))

def test_5_activate_account(self) -> None:
client = self.get_client(key=sandbox_commitment)
Expand Down
2 changes: 1 addition & 1 deletion tests/sandbox_tests/test_wait_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def test_1_send_multiple_transactions(self) -> None:
prev_hash=head_hash,
)
bootstrap5 = self.client.shell.contracts[sandbox_addresses['bootstrap5']]()
self.assertEqual('3600000004000', bootstrap5['balance'])
self.assertEqual('3800000004000', bootstrap5['balance'])

0 comments on commit 8114a03

Please sign in to comment.