Skip to content

Commit 89d8503

Browse files
committed
added a check for POA extraData
1 parent 296a25f commit 89d8503

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

web3/middleware/pythonic.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ def bytes_to_ascii(value):
6464
is_not_null = complement(is_null)
6565

6666

67+
@curry
68+
def check_extradata_length(val, length):
69+
if not isinstance(val, (str, int, bytes)):
70+
return val
71+
result = HexBytes(val)
72+
if len(result) > length:
73+
raise ValueError(
74+
"The field extraData: %r is %d bytes, but should be %d. "
75+
"It is quite likely that you are connected to a POA chain. "
76+
"Refer "
77+
"http://web3py.readthedocs.io/en/latest/middleware.html#geth-style-proof-of-authority "
78+
"for more details" % (
79+
result, len(result), length
80+
)
81+
)
82+
return val
83+
84+
6785
@curry
6886
def to_hexbytes(num_bytes, val, variable_length=False):
6987
if isinstance(val, (str, int, bytes)):
@@ -151,7 +169,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
151169
receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS)
152170

153171
BLOCK_FORMATTERS = {
154-
'extraData': to_hexbytes(32, variable_length=True),
172+
'extraData': compose(to_hexbytes(32, variable_length=True), check_extradata_length(length=32)),
155173
'gasLimit': to_integer_if_hex,
156174
'gasUsed': to_integer_if_hex,
157175
'size': to_integer_if_hex,

0 commit comments

Comments
 (0)