Skip to content

Commit 04b7354

Browse files
authored
Merge pull request #242 from opentensor/feat/mev-extrinsic-handling
2 parents 7326628 + 69d1de0 commit 04b7354

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ async def process_events(self):
274274
has_transaction_fee_paid_event = True
275275

276276
# Process other events
277+
possible_success = False
277278
for event in await self.triggered_events:
278279
# Check events
279280
if (
280281
event["event"]["module_id"] == "System"
281282
and event["event"]["event_id"] == "ExtrinsicSuccess"
282283
):
283-
self.__is_success = True
284-
self.__error_message = None
284+
possible_success = True
285285

286286
if "dispatch_info" in event["event"]["attributes"]:
287287
self.__weight = event["event"]["attributes"]["dispatch_info"][
@@ -294,13 +294,26 @@ async def process_events(self):
294294
elif (
295295
event["event"]["module_id"] == "System"
296296
and event["event"]["event_id"] == "ExtrinsicFailed"
297+
) or (
298+
event["event"]["module_id"] == "MevShield"
299+
and event["event"]["event_id"] == "DecryptedRejected"
297300
):
301+
possible_success = False
298302
self.__is_success = False
299303

300-
dispatch_info = event["event"]["attributes"]["dispatch_info"]
301-
dispatch_error = event["event"]["attributes"]["dispatch_error"]
302-
303-
self.__weight = dispatch_info["weight"]
304+
if event["event"]["module_id"] == "System":
305+
dispatch_info = event["event"]["attributes"]["dispatch_info"]
306+
dispatch_error = event["event"]["attributes"]["dispatch_error"]
307+
self.__weight = dispatch_info["weight"]
308+
else:
309+
# MEV shield extrinsics
310+
dispatch_info = event["event"]["attributes"]["reason"][
311+
"post_info"
312+
]
313+
dispatch_error = event["event"]["attributes"]["reason"]["error"]
314+
self.__weight = event["event"]["attributes"]["reason"][
315+
"post_info"
316+
]["actual_weight"]
304317

305318
if "Module" in dispatch_error:
306319
if isinstance(dispatch_error["Module"], tuple):
@@ -366,6 +379,10 @@ async def process_events(self):
366379
and event["event"]["event_id"] == "Deposit"
367380
):
368381
self.__total_fee_amount += event.value["attributes"]["amount"]
382+
if possible_success is True and self.__error_message is None:
383+
# we delay the positive setting of the __is_success flag until we have finished iteration of the
384+
# events and have ensured nothing has set an error message
385+
self.__is_success = True
369386

370387
@property
371388
async def is_success(self) -> bool:

async_substrate_interface/sync_substrate.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ def process_events(self):
235235
has_transaction_fee_paid_event = True
236236

237237
# Process other events
238+
possible_success = False
238239
for event in self.triggered_events:
239240
# Check events
240241
if (
241242
event["event"]["module_id"] == "System"
242243
and event["event"]["event_id"] == "ExtrinsicSuccess"
243244
):
244-
self.__is_success = True
245-
self.__error_message = None
245+
possible_success = True
246246

247247
if "dispatch_info" in event["event"]["attributes"]:
248248
self.__weight = event["event"]["attributes"]["dispatch_info"][
@@ -255,13 +255,26 @@ def process_events(self):
255255
elif (
256256
event["event"]["module_id"] == "System"
257257
and event["event"]["event_id"] == "ExtrinsicFailed"
258+
) or (
259+
event["event"]["module_id"] == "MevShield"
260+
and event["event"]["event_id"] == "DecryptedRejected"
258261
):
262+
possible_success = False
259263
self.__is_success = False
260264

261-
dispatch_info = event["event"]["attributes"]["dispatch_info"]
262-
dispatch_error = event["event"]["attributes"]["dispatch_error"]
263-
264-
self.__weight = dispatch_info["weight"]
265+
if event["event"]["module_id"] == "System":
266+
dispatch_info = event["event"]["attributes"]["dispatch_info"]
267+
dispatch_error = event["event"]["attributes"]["dispatch_error"]
268+
self.__weight = dispatch_info["weight"]
269+
else:
270+
# MEV shield extrinsics
271+
dispatch_info = event["event"]["attributes"]["reason"][
272+
"post_info"
273+
]
274+
dispatch_error = event["event"]["attributes"]["reason"]["error"]
275+
self.__weight = event["event"]["attributes"]["reason"][
276+
"post_info"
277+
]["actual_weight"]
265278

266279
if "Module" in dispatch_error:
267280
if isinstance(dispatch_error["Module"], tuple):
@@ -319,6 +332,10 @@ def process_events(self):
319332
and event["event"]["event_id"] == "Deposit"
320333
):
321334
self.__total_fee_amount += event.value["attributes"]["amount"]
335+
if possible_success is True and self.__error_message is None:
336+
# we delay the positive setting of the __is_success flag until we have finished iteration of the
337+
# events and have ensured nothing has set an error message
338+
self.__is_success = True
322339

323340
@property
324341
def is_success(self) -> bool:

0 commit comments

Comments
 (0)