Skip to content

Commit b3d6cda

Browse files
committed
Use the last irreversible block for tapos ref params
1 parent 1026f72 commit b3d6cda

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "minor",
3+
"description": "Use the last irreversible block for tapos ref params"
4+
}

graphenebase/transactions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
timeformat = "%Y-%m-%dT%H:%M:%S%Z"
1717

1818

19-
def getBlockParams(ws):
19+
def getBlockParams(ws, use_head_block=False):
2020
""" Auxiliary method to obtain ``ref_block_num`` and
2121
``ref_block_prefix``. Requires a websocket connection to a
2222
witness node!
2323
"""
24-
dynBCParams = ws.get_dynamic_global_properties()
25-
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
26-
ref_block_prefix = struct.unpack_from(
27-
"<I", unhexlify(dynBCParams["head_block_id"]), 4
28-
)[0]
29-
return ref_block_num, ref_block_prefix
24+
raise DeprecationWarning(
25+
"This method shouldn't be called anymore. It is part of "
26+
"transactionbuilder now"
27+
)
3028

3129

3230
def formatTimeFromNow(secs=0):

graphenecommon/transactionbuilder.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,25 @@ def constructTx(self):
405405
dict.update(self, self.tx.json())
406406
self._unset_require_reconstruction()
407407

408-
def get_block_params(self):
408+
def get_block_params(self, use_head_block=False):
409409
""" Auxiliary method to obtain ``ref_block_num`` and
410410
``ref_block_prefix``. Requires a websocket connection to a
411411
witness node!
412412
"""
413413
ws = self.blockchain.rpc
414414
dynBCParams = ws.get_dynamic_global_properties()
415-
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
416-
ref_block_prefix = struct.unpack_from(
417-
"<I", unhexlify(dynBCParams["head_block_id"]), 4
418-
)[0]
415+
if use_head_block:
416+
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
417+
ref_block_prefix = struct.unpack_from(
418+
"<I", unhexlify(dynBCParams["head_block_id"]), 4
419+
)[0]
420+
else:
421+
# need to get subsequent block because block head doesn't return 'id' - stupid
422+
block = ws.get_block_header(int(dynBCParams["last_irreversible_block_num"])+1)
423+
ref_block_num = dynBCParams["last_irreversible_block_num"] & 0xFFFF
424+
ref_block_prefix = struct.unpack_from(
425+
"<I", unhexlify(block["previous"]), 4
426+
)[0]
419427
return ref_block_num, ref_block_prefix
420428

421429
def sign(self):

0 commit comments

Comments
 (0)