Commit cf8525d
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 cf8525d
1 file changed
Lines changed: 83 additions & 24 deletions
Lines changed: 83 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 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1553 | 1603 | | |
1554 | 1604 | | |
1555 | 1605 | | |
| |||
1590 | 1640 | | |
1591 | 1641 | | |
1592 | 1642 | | |
1593 | | - | |
| 1643 | + | |
1594 | 1644 | | |
1595 | 1645 | | |
1596 | 1646 | | |
| |||
1610 | 1660 | | |
1611 | 1661 | | |
1612 | 1662 | | |
1613 | | - | |
| 1663 | + | |
1614 | 1664 | | |
1615 | 1665 | | |
1616 | 1666 | | |
| |||
1694 | 1744 | | |
1695 | 1745 | | |
1696 | 1746 | | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
1701 | 1757 | | |
| 1758 | + | |
| 1759 | + | |
1702 | 1760 | | |
1703 | 1761 | | |
1704 | 1762 | | |
| |||
1720 | 1778 | | |
1721 | 1779 | | |
1722 | 1780 | | |
1723 | | - | |
1724 | 1781 | | |
1725 | 1782 | | |
1726 | 1783 | | |
| |||
1817 | 1874 | | |
1818 | 1875 | | |
1819 | 1876 | | |
1820 | | - | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
1821 | 1884 | | |
1822 | 1885 | | |
1823 | 1886 | | |
1824 | 1887 | | |
1825 | 1888 | | |
1826 | | - | |
| 1889 | + | |
1827 | 1890 | | |
1828 | 1891 | | |
1829 | 1892 | | |
| |||
1984 | 2047 | | |
1985 | 2048 | | |
1986 | 2049 | | |
1987 | | - | |
1988 | | - | |
1989 | | - | |
1990 | | - | |
1991 | | - | |
1992 | | - | |
1993 | | - | |
1994 | | - | |
1995 | | - | |
1996 | | - | |
1997 | | - | |
1998 | | - | |
1999 | | - | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
2000 | 2055 | | |
2001 | 2056 | | |
2002 | 2057 | | |
| |||
2076 | 2131 | | |
2077 | 2132 | | |
2078 | 2133 | | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
2079 | 2137 | | |
2080 | 2138 | | |
2081 | | - | |
| 2139 | + | |
| 2140 | + | |
2082 | 2141 | | |
2083 | | - | |
| 2142 | + | |
2084 | 2143 | | |
2085 | 2144 | | |
2086 | 2145 | | |
| |||
0 commit comments