Skip to content

Commit

Permalink
sm: correct Cancel tx size
Browse files Browse the repository at this point in the history
Units were mixed up. Correct and clarify the code to avoid another
overlook.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior committed Sep 7, 2021
1 parent c713ef9 commit 2d82d3b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Model/statemachine.py
Expand Up @@ -162,18 +162,10 @@ def _feerate_to_fee(self, feerate, tx_type, n_fb_inputs):
"""
if tx_type not in ["cancel", "emergency", "unemergency"]:
raise ValueError("Invalid tx_type")
# feerate in satoshis/vbyte, weights in WU == 4vbytes, so feerate*weight/4 gives satoshis
return round(
feerate
* (
int(
CANCEL_TX_WEIGHT[self.n_stk][self.n_man]
+ n_fb_inputs * P2WPKH_INPUT_SIZE
)
/ 4
),
0,
)
# feerate is in satoshis/vbyte
cancel_tx_size_no_fb = (CANCEL_TX_WEIGHT[self.n_stk][self.n_man] + 3) // 4
cancel_tx_size = cancel_tx_size_no_fb + n_fb_inputs * P2WPKH_INPUT_SIZE
return cancel_tx_size * feerate

def fee_reserve_per_vault(self, block_height):
return self._feerate_to_fee(
Expand Down

0 comments on commit 2d82d3b

Please sign in to comment.