Konubinix' opinionated web of thoughts

Pytezos Error When Sending a Transaction at Start

Fleeting

pytezos error when sending a transaction at start

clk tzc --network jakarta sandbox flextesa start
clk tzc sandbox flextesa generate-bootstrap-account-command alice
{
    "address": "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
    "alias": "alice",
    "public_key": "edpkvGfYw3LyB1UcCahKQk4rF2tvbMUk8GFiTuMjL75uGXrpvKXhjn",
    "secret_key": "unencrypted:edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq"
}
clk tzc sandbox flextesa generate-bootstrap-account-command konubinix
{
    "address": "tz1UJHuqwkEuHbomaKvzs2XT6evFesPHERKK",
    "alias": "konubinix",
    "public_key": "edpkuBLoWpFZh2dTUbgoDUDpPMPFczzYfCHr2jGeLURkBmTUNdgUsU",
    "secret_key": "unencrypted:edsk3VDZzC1Bp46Fj1oaJFUkVyVT37JtaxTHBq2Hzez4Lkpwmxba2J"
}
from pytezos import pytezos

alice = pytezos.using(shell="http://172.17.0.1:18731", key="edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq")
konubinix = pytezos.using(shell="http://172.17.0.1:18731", key="edsk3VDZzC1Bp46Fj1oaJFUkVyVT37JtaxTHBq2Hzez4Lkpwmxba2J")
alice.transaction(konubinix.key.public_key_hash(), 2000).send(min_confirmations=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sam/tmp/pyLzxjWv", line 9, in <module>
  File "<string>", line 5, in <module>
  File "/home/sam/test/pytezos/src/pytezos/operation/group.py", line 354, in send
    opg = self.autofill(gas_reserve=gas_reserve, burn_reserve=burn_reserve, ttl=ttl).sign()
  File "/home/sam/test/pytezos/src/pytezos/operation/group.py", line 246, in autofill
    opg = self.fill(counter=counter, ttl=ttl)
  File "/home/sam/test/pytezos/src/pytezos/operation/group.py", line 134, in fill
    branch = self.branch or self.shell.blocks[f'head~{MAX_OPERATIONS_TTL - ttl}'].hash()
  File "/home/sam/test/pytezos/src/pytezos/rpc/query.py", line 101, in __call__
    return self.node.get(
  File "/home/sam/test/pytezos/src/pytezos/rpc/node.py", line 130, in get
    return self.request('GET', path, params=params, timeout=timeout).json()
  File "/home/sam/test/pytezos/src/pytezos/rpc/node.py", line 116, in request
    raise RpcError(f'Not found: {path}')
pytezos.rpc.node.RpcError: ('Not found: /chains/main/blocks/head~115/hash',)

This line indeed tried to get access to the (MAX_OPERATIONS_TTL - ttl) ancestor of HEAD. With ttl=5 by default, and MAX_OPERATIONS_TTL=120, it tries to reach the 115th ancestor. Even with fast block time (I use a default of 3 seconds), the level 115 takes some time to be reached.

from pytezos import pytezos
alice = pytezos.using(shell="http://172.17.0.1:18731", key="edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq")

alice.shell.head()["metadata"]["level_info"]
{'level': 17, 'level_position': 16, 'cycle': 2, 'cycle_position': 0, 'expected_commitment': False}

I don’t know what pytezos tries to do here, but the workaround during my tests was to simply provide the value of MAX_OPERATIONS_TTL in the ttl value.

Notes linking here