Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions allways/validator/axon_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ async def handle_swap_reserve(
)

try:
# Halt blocks reservations contract-side; fast-reject here so a halt
# can't flood doomed vote_reserve extrinsics that starve confirm/timeout
# votes. halted() fails open, so an RPC blip falls through to the contract.
if validator.bounds_cache.halted():
reject_synapse(synapse, 'System is halted — reservations paused', ctx)
return synapse

# Cheap, local checks BEFORE axon_lock — invalid signatures, missing fields,
# and bad direction are rejected without serializing on the substrate websocket.
if not synapse.from_address or not synapse.from_address_proof:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_axon_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def make_reserve_validator(
validator.bounds_cache.min_collateral.return_value = 0
validator.bounds_cache.min_swap_amount.return_value = 0
validator.bounds_cache.max_swap_amount.return_value = 0
validator.bounds_cache.halted.return_value = False
validator.wallet = MagicMock()
return validator

Expand Down Expand Up @@ -994,3 +995,22 @@ def test_handle_miner_activate_rejects_sentinel_commitment(self):
assert mock_read.call_args.kwargs['min_swap_rao'] == 500_000_000
assert mock_read.call_args.kwargs['max_swap_rao'] == 5_000_000_000
validator.axon_contract_client.vote_activate.assert_not_called()


class TestHaltFastReject:
"""A halted system rejects reservations without submitting any extrinsic."""

def test_halted_rejects_without_voting(self):
validator = make_reserve_validator()
validator.bounds_cache.halted.return_value = True
result = run_reserve_handler(validator, make_reserve_synapse())
assert result.accepted is False
assert 'halt' in (result.rejection_reason or '').lower()
validator.axon_contract_client.vote_reserve.assert_not_called()

def test_halted_short_circuits_before_substrate_work(self):
validator = make_reserve_validator()
validator.bounds_cache.halted.return_value = True
with patch('allways.validator.axon_handlers.read_miner_commitment') as read_cmt:
asyncio.run(handle_swap_reserve(validator, make_reserve_synapse()))
read_cmt.assert_not_called()
Loading