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
1 change: 1 addition & 0 deletions allways/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Swap:
user_source_address: str
user_dest_address: str
miner_source_address: str = ''
miner_dest_address: str = ''
rate: str = ''
source_tx_hash: str = ''
source_tx_block: int = 0
Expand Down
5 changes: 5 additions & 0 deletions allways/contract_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
('source_tx_block', 'u32'),
('dest_amount', 'u128'),
('miner_source_address', 'str'),
('miner_dest_address', 'str'),
('rate', 'str'),
],
'vote_activate': [('miner', 'AccountId')],
Expand Down Expand Up @@ -584,6 +585,7 @@ def _decode_swap_data(self, data: bytes, offset: int = 0) -> Optional[Swap]:
user_source_address, o = self._decode_string(data, o)
user_dest_address, o = self._decode_string(data, o)
miner_source_address, o = self._decode_string(data, o)
miner_dest_address, o = self._decode_string(data, o)
rate, o = self._decode_string(data, o)
source_tx_hash, o = self._decode_string(data, o)
source_tx_block = struct.unpack_from('<I', data, o)[0]
Expand Down Expand Up @@ -615,6 +617,7 @@ def _decode_swap_data(self, data: bytes, offset: int = 0) -> Optional[Swap]:
user_source_address=user_source_address,
user_dest_address=user_dest_address,
miner_source_address=miner_source_address,
miner_dest_address=miner_dest_address,
rate=rate,
source_tx_hash=source_tx_hash,
source_tx_block=source_tx_block,
Expand Down Expand Up @@ -997,6 +1000,7 @@ def vote_initiate(
source_tx_block: int = 0,
dest_amount: int = 0,
miner_source_address: str = '',
miner_dest_address: str = '',
rate: str = '',
) -> str:
"""Vote to initiate a swap. On quorum, swap is created on contract."""
Expand All @@ -1017,6 +1021,7 @@ def vote_initiate(
'source_tx_block': source_tx_block,
'dest_amount': dest_amount,
'miner_source_address': miner_source_address,
'miner_dest_address': miner_dest_address,
'rate': rate,
},
keypair=wallet.hotkey,
Expand Down
5 changes: 5 additions & 0 deletions allways/validator/axon_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ async def handle_swap_confirm(
miner_deposit_address = (
commitment.source_address if swap_source_chain == commitment.source_chain else commitment.dest_address
)
miner_fulfillment_address = (
commitment.dest_address if swap_source_chain == commitment.source_chain else commitment.source_address
)

provider = validator.axon_chain_providers.get(swap_source_chain)
if provider is None:
Expand Down Expand Up @@ -424,6 +427,7 @@ async def handle_swap_confirm(
source_amount=res_source_amount,
dest_amount=res_dest_amount,
miner_deposit_address=miner_deposit_address,
miner_dest_address=miner_fulfillment_address,
rate_str=commitment.rate_str,
reserved_until=reserved_until,
)
Expand Down Expand Up @@ -468,6 +472,7 @@ async def handle_swap_confirm(
source_tx_block=tx_info.block_number or 0,
dest_amount=res_dest_amount,
miner_source_address=miner_deposit_address,
miner_dest_address=miner_fulfillment_address,
rate=commitment.rate_str,
)
synapse.accepted = True
Expand Down
19 changes: 17 additions & 2 deletions allways/validator/chain_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ def __init__(
self._last_logged_confs: Dict[str, int] = {} # swap_id:chain -> confs

def _verify_tx(
self, swap: Swap, chain: str, tx_hash: str, expected_recipient: str, expected_amount: int, block_hint: int = 0
self,
swap: Swap,
chain: str,
tx_hash: str,
expected_recipient: str,
expected_amount: int,
block_hint: int = 0,
expected_sender: str = '',
) -> bool:
"""Verify a confirmed transaction on a specific chain."""
provider = self.providers.get(chain)
Expand Down Expand Up @@ -67,7 +74,14 @@ def _verify_tx(
f'(confs={tx_info.confirmations} tx={tx_hash[:16]}... '
f'addr={expected_recipient[:16]}... expected={expected_amount})'
)
return tx_info is not None and tx_info.confirmed
if tx_info is None or not tx_info.confirmed:
return False
if expected_sender and tx_info.sender != expected_sender:
bt.logging.warning(
f'Swap {swap.id}: sender mismatch on {chain} — expected {expected_sender}, got {tx_info.sender}'
)
return False
return True
except Exception as e:
bt.logging.error(f'Swap {swap.id}: verification error on {chain}: {e}')
return False
Expand Down Expand Up @@ -113,6 +127,7 @@ async def is_swap_complete(self, swap: Swap) -> bool:
swap.user_dest_address,
expected_user_receives,
swap.dest_tx_block,
swap.miner_dest_address,
)

return source_ok and dest_ok
1 change: 1 addition & 0 deletions allways/validator/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _process_pending_confirms(self: Validator) -> None:
source_tx_block=tx_info.block_number or 0,
dest_amount=item.dest_amount,
miner_source_address=item.miner_deposit_address,
miner_dest_address=item.miner_dest_address,
rate=item.rate_str,
)
bt.logging.success(
Expand Down
1 change: 1 addition & 0 deletions allways/validator/pending_confirms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PendingConfirm:
source_amount: int
dest_amount: int
miner_deposit_address: str
miner_dest_address: str
rate_str: str
reserved_until: int
queued_at: float = field(default_factory=time.time)
Expand Down
4 changes: 3 additions & 1 deletion smart-contracts/ink/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ mod allways_swap_manager {
source_tx_block: u32,
dest_amount: Balance,
miner_source_address: String,
miner_dest_address: String,
rate: String,
) -> Result<(), Error> {
self.ensure_validator()?;
Expand All @@ -567,7 +568,7 @@ mod allways_swap_manager {
if source_amount == 0 || tao_amount == 0 {
return Err(Error::InvalidAmount);
}
if source_tx_hash.is_empty() || miner_source_address.is_empty() || rate.is_empty() {
if source_tx_hash.is_empty() || miner_source_address.is_empty() || miner_dest_address.is_empty() || rate.is_empty() {
return Err(Error::InputEmpty);
}
if source_tx_hash.len() > 128 {
Expand Down Expand Up @@ -625,6 +626,7 @@ mod allways_swap_manager {
user_source_address,
user_dest_address,
miner_source_address,
miner_dest_address,
rate,
source_tx_hash: source_tx_hash.clone(),
source_tx_block,
Expand Down
1 change: 1 addition & 0 deletions smart-contracts/ink/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct SwapData {
pub user_source_address: String,
pub user_dest_address: String,
pub miner_source_address: String,
pub miner_dest_address: String,
pub rate: String,
pub source_tx_hash: String,
pub source_tx_block: u32,
Expand Down
Loading