Fix MEV Shield era anchoring#3397
Open
loom-agent wants to merge 1 commit into
Open
Conversation
Anchor MEV Shield mortal eras to the best chain head so short chain-enforced eras remain valid when finality lags. Apply the same explicit anchor to both the inner signed extrinsic and the outer submit_encrypted extrinsic.
f54251d to
3d40a2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I am Loom Agent - an autonomous AI agent set up by my maintainer to help contribute to this repository. This pull request was prepared autonomously under human supervision. Feedback is very welcome - I will do my best to address review comments promptly.
Bug
Closes #3395.
commit_timelocked_weights_extrinsic(..., mev_protection=True)is intermittently rejected at pool admission withTransaction is outdated(InvalidTransaction::Stale) whenever finality lags the best head by the MEV Shield era period (8 blocks). The extrinsic is valid by construction but arrives already expired.Description of the Change
create_signed_extrinsic(async-substrate-interface) anchors a mortal era with no explicitcurrentat the finalized head, but the transaction pool evaluates era mortality against the node's best head. With the chain-enforcedMAX_MEV_SHIELD_PERIOD = 8, any moment wherebest_head - finalized_head >= 8makes the extrinsic dead on arrival.This anchors both the inner MEV Shield signed extrinsic and the outer
submit_encryptedto the best head instead:bittensor/core/async_subtensor.pyandbittensor/core/subtensor.py:sign_and_send_extrinsicaccepts an optionalera_current(best-head block number) and forwards it into the era when provided.bittensor/core/extrinsics/asyncex/mev_shield.pyandbittensor/core/extrinsics/mev_shield.py: resolve the best-head block number and pass it asera_current, so the era becomes{"period": effective_period, "current": best_block}.The era is now anchored at the head the pool actually checks mortality against.
era_currentis optional and defaults to the existing behaviour, so non-MEV extrinsics are unaffected.Alternate Designs
The issue suggested three directions; this PR combines (1) anchor at the best head - the direct fix - with (2) exposing the anchor as an opt-in parameter (
era_current). Direction (3), a reactive retry onInvalidTransaction::Stale, was not taken: the anchored window is valid by construction, so a retry would only paper over the symptom, add latency, and could itself land in the next lag spike.Scoping the change to the MEV Shield path (rather than every extrinsic) is deliberate: MEV Shield is the only path whose era period can be as short as the typical finality lag, so it is the only path where the finalized-head anchor can produce a zero-length validity window.
Possible Drawbacks
Verification Process
Reproduced the project's CI on a clean clone of
staging(Python 3.12, mypy 1.20.2, ruff 0.15.12, matching.github/workflows):New regression tests assert the era carries both
periodandcurrenton the sync and async MEV Shield paths, so the anchoring cannot silently regress to the finalized head.Release Notes
submit_encryptedbeing intermittently rejected as "Transaction is outdated" when finality lagged the best head by the era period.Branch Acknowledgement
[x] I am acknowledging that I am opening this branch against
staging