Skip to content

Commit

Permalink
Parse author for AURA consensus (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjanz authored Sep 26, 2022
1 parent f390638 commit 5c39642
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ eth_utils>=1.3.0,<3
pycryptodome>=3.11.0,<4
PyNaCl>=1.0.1,<2

scalecodec>=1.0.42,<2
scalecodec>=1.0.43,<2
py-sr25519-bindings>=0.1.4,<1
py-ed25519-zebra-bindings>=1.0,<2
py-bip39-bindings>=0.1.9,<1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
'eth_utils>=1.3.0,<3',
'pycryptodome>=3.11.0,<4',
'PyNaCl>=1.0.1,<2',
'scalecodec>=1.0.42,<2',
'scalecodec>=1.0.43,<2',
'py-sr25519-bindings>=0.1.4,<1',
'py-ed25519-zebra-bindings>=1.0,<2',
'py-bip39-bindings>=0.1.9,<1'
Expand Down
22 changes: 19 additions & 3 deletions substrateinterface/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2606,20 +2606,36 @@ def decode_block(block_data, block_data_hash=None):
if include_author and 'PreRuntime' in log_digest.value:

if self.implements_scaleinfo():
if log_digest.value['PreRuntime'][0] == f"0x{b'BABE'.hex()}":

engine = bytes(log_digest[1][0])
# Retrieve validator set
validator_set = self.query("Session", "Validators", block_hash=block_hash)

if engine == b'BABE':
babe_predigest = self.runtime_config.create_scale_object(
type_string='RawBabePreDigest',
data=ScaleBytes(log_digest.value['PreRuntime'][1])
data=ScaleBytes(log_digest[1][1])
)

babe_predigest.decode()

validator_set = self.query("Session", "Validators", block_hash=block_hash)
rank_validator = babe_predigest[1].value['authority_index']

block_author = validator_set[rank_validator]
block_data['author'] = block_author.value

elif engine == b'aura':
aura_predigest = self.runtime_config.create_scale_object(
type_string='RawAuraPreDigest',
data=ScaleBytes(bytes(log_digest[1][1]))
)

aura_predigest.decode()

rank_validator = aura_predigest.value['slot_number'] % len(validator_set)

block_author = validator_set[rank_validator]
block_data['author'] = block_author.value
else:
raise NotImplementedError(
f"Cannot extract author for engine {log_digest.value['PreRuntime'][0]}"
Expand Down

0 comments on commit 5c39642

Please sign in to comment.