@@ -64,6 +64,24 @@ def bytes_to_ascii(value):
64
64
is_not_null = complement (is_null )
65
65
66
66
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
+
67
85
@curry
68
86
def to_hexbytes (num_bytes , val , variable_length = False ):
69
87
if isinstance (val , (str , int , bytes )):
@@ -151,7 +169,7 @@ def to_hexbytes(num_bytes, val, variable_length=False):
151
169
receipt_formatter = apply_formatters_to_dict (RECEIPT_FORMATTERS )
152
170
153
171
BLOCK_FORMATTERS = {
154
- 'extraData' : to_hexbytes (32 , variable_length = True ),
172
+ 'extraData' : compose ( to_hexbytes (32 , variable_length = True ), check_extradata_length ( length = 32 ) ),
155
173
'gasLimit' : to_integer_if_hex ,
156
174
'gasUsed' : to_integer_if_hex ,
157
175
'size' : to_integer_if_hex ,
0 commit comments