Commit 51d4357
Optimize Firo Spark mint tx generation and fix fee < vSize error
## Performance
Pre-compute signing keys, addresses, and wallet-owned address set before
the main loop. The original code called getRootHDNode() (expensive
mnemonic-to-seed derivation), a per-UTXO DB lookup for derivationPath,
and a per-output DB lookup for walletOwns, all inside nested loops. For
N inputs across M fee-estimation iterations, this was O(N*M) redundant
work. Also caches getCurrentReceivingSparkAddress() and
getCurrentChangeAddress() since neither can change within the function.
## Fee-less-than-vSize bug fix
The dummy transaction built for fee estimation is signed with real keys
over different data than the final real transaction. bitcoindart's ECDSA
signing (RFC 6979, low-S enforced, low-R not enforced) produces DER
signatures whose length varies by up to ~4 bytes per input depending on
the random r value's high bit. For P2PKH inputs (Firo's default), this
variance counts at full weight, so with 10+ inputs the dummy vs real
vSize can differ by more than the original 10-byte buffer, tripping the
nFeeRet < data.vSize check.
Scale the buffer linearly with input count:
final nBytesBuffer = 10 + 4 * setCoins.length;
This matches what Firo's own C++ wallet does in DummySignatureCreator
(src/wallet/wallet.h:1436): "Helper for producing a bunch of max-sized
low-S signatures (eg 72 bytes)". Extra fee cost: ~4 sats per input at
1 sat/byte.
## Subsidiary fixes
- mintedValue <= BigInt.zero (was == BigInt.zero): catches negative
mintedValue when a UTXO group's total is less than the computed fee
and subtractFeeFromAmount=false. Matches the C++ reference
!MoneyRange(mintedValue) || mintedValue == 0.
- Clarified the fee < vSize error message: the check is effectively a
min-relay-fee check (feeRate < 1 sat/byte), not a fee/size mismatch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 243015b commit 51d4357
1 file changed
Lines changed: 72 additions & 24 deletions
Lines changed: 72 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
1550 | 1551 | | |
1551 | 1552 | | |
1552 | 1553 | | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
1553 | 1592 | | |
1554 | 1593 | | |
1555 | 1594 | | |
| |||
1590 | 1629 | | |
1591 | 1630 | | |
1592 | 1631 | | |
1593 | | - | |
| 1632 | + | |
1594 | 1633 | | |
1595 | 1634 | | |
1596 | 1635 | | |
| |||
1610 | 1649 | | |
1611 | 1650 | | |
1612 | 1651 | | |
1613 | | - | |
| 1652 | + | |
1614 | 1653 | | |
1615 | 1654 | | |
1616 | 1655 | | |
| |||
1694 | 1733 | | |
1695 | 1734 | | |
1696 | 1735 | | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
1701 | 1746 | | |
| 1747 | + | |
| 1748 | + | |
1702 | 1749 | | |
1703 | 1750 | | |
1704 | 1751 | | |
| |||
1720 | 1767 | | |
1721 | 1768 | | |
1722 | 1769 | | |
1723 | | - | |
1724 | 1770 | | |
1725 | 1771 | | |
1726 | 1772 | | |
| |||
1817 | 1863 | | |
1818 | 1864 | | |
1819 | 1865 | | |
1820 | | - | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
1821 | 1873 | | |
1822 | 1874 | | |
1823 | 1875 | | |
1824 | 1876 | | |
1825 | 1877 | | |
1826 | | - | |
| 1878 | + | |
1827 | 1879 | | |
1828 | 1880 | | |
1829 | 1881 | | |
| |||
1984 | 2036 | | |
1985 | 2037 | | |
1986 | 2038 | | |
1987 | | - | |
1988 | | - | |
1989 | | - | |
1990 | | - | |
1991 | | - | |
1992 | | - | |
1993 | | - | |
1994 | | - | |
1995 | | - | |
1996 | | - | |
1997 | | - | |
1998 | | - | |
1999 | | - | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
2000 | 2044 | | |
2001 | 2045 | | |
2002 | 2046 | | |
| |||
2076 | 2120 | | |
2077 | 2121 | | |
2078 | 2122 | | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
2079 | 2126 | | |
2080 | 2127 | | |
2081 | | - | |
| 2128 | + | |
| 2129 | + | |
2082 | 2130 | | |
2083 | | - | |
| 2131 | + | |
2084 | 2132 | | |
2085 | 2133 | | |
2086 | 2134 | | |
| |||
0 commit comments