For CLTV coins check the lock value relative to the current time rather than the bid creation time.

2024-05-20_merge
tecnovert 2 years ago
parent 18974d9458
commit 50ed1bfccf
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 6
      basicswap/basicswap.py
  2. 1
      basicswap/protocols/atomic_swap_1.py

@ -4136,13 +4136,13 @@ class BasicSwap(BaseApp):
ensure(script_lock_value == expect_sequence, 'sequence mismatch') ensure(script_lock_value == expect_sequence, 'sequence mismatch')
else: else:
if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS: if offer.lock_type == TxLockTypes.ABS_LOCK_BLOCKS:
block_header_from = ci_from.getBlockHeaderAt(bid.created_at) block_header_from = ci_from.getBlockHeaderAt(now)
chain_height_at_bid_creation = block_header_from['height'] chain_height_at_bid_creation = block_header_from['height']
ensure(script_lock_value <= chain_height_at_bid_creation + offer.lock_value + atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too high') ensure(script_lock_value <= chain_height_at_bid_creation + offer.lock_value + atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too high')
ensure(script_lock_value >= chain_height_at_bid_creation + offer.lock_value - atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too low') ensure(script_lock_value >= chain_height_at_bid_creation + offer.lock_value - atomic_swap_1.ABS_LOCK_BLOCKS_LEEWAY, 'script lock height too low')
else: else:
ensure(script_lock_value <= bid.created_at + offer.lock_value + atomic_swap_1.INITIATE_TX_TIMEOUT, 'script lock time too high') ensure(script_lock_value <= now + offer.lock_value + atomic_swap_1.INITIATE_TX_TIMEOUT, 'script lock time too high')
ensure(script_lock_value >= bid.created_at + offer.lock_value, 'script lock time too low') ensure(script_lock_value >= now + offer.lock_value - atomic_swap_1.ABS_LOCK_TIME_LEEWAY, 'script lock time too low')
ensure(len(scriptvalues[3]) == 40, 'pkhash_refund bad length') ensure(len(scriptvalues[3]) == 40, 'pkhash_refund bad length')

@ -12,6 +12,7 @@ from basicswap.script import (
) )
INITIATE_TX_TIMEOUT = 40 * 60 # TODO: make variable per coin INITIATE_TX_TIMEOUT = 40 * 60 # TODO: make variable per coin
ABS_LOCK_TIME_LEEWAY = 10 * 60
def buildContractScript(lock_val, secret_hash, pkh_redeem, pkh_refund, op_lock=OpCodes.OP_CHECKSEQUENCEVERIFY): def buildContractScript(lock_val, secret_hash, pkh_redeem, pkh_refund, op_lock=OpCodes.OP_CHECKSEQUENCEVERIFY):

Loading…
Cancel
Save