Closed kcalvinalvin closed 11 months ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
blockchain/merkle.go | 4 | 5 | 80.0% | ||
rpcserver.go | 0 | 2 | 0.0% | ||
blockchain/rolling_merkle.go | 81 | 88 | 92.05% | ||
mining/mining.go | 0 | 35 | 0.0% | ||
<!-- | Total: | 87 | 132 | 65.91% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
mining/mining.go | 2 | 8.08% | ||
blockchain/merkle.go | 7 | 31.34% | ||
<!-- | Total: | 9 | --> |
Totals | |
---|---|
Change from base Build 5525483102: | 0.02% |
Covered Lines: | 26767 |
Relevant Lines: | 48440 |
There was still some Utreexo specific stuff that made it calculate wrong roots. I fixed it in the latest force push.
Still the same results from the benchmarks so the benchstat results are valid.
EDIT: Later push was for witness merkle root calculation.
Concept ACK, great work building on the other optimization with some of the utreexo derived fine tuning!
Ready for reviews now!
@Roasbeef
I do think there are certain API changes that are necessary for the RMTS to be broadly useful, rather that solely tailored to the block tree verification process.
I strongly disagree making this function more broadly useful as the merkle tree function used for calculating the tx commitment is flawed and has a vulnerability (CVE-2012-2459). It's possible to create a collision using duplicate leaves and it's described in detail at: https://github.com/bitcoin/bitcoin/blob/79e8247ddb166f9b980f40249b7372a502402a4d/src/consensus/merkle.cpp#L8-L41
If anyone wants to use the following code for merkle tree stuff, they should just use https://github.com/utreexo/utreexo as it's essentially the same.
Completed sync tests on mainnet+testnet as a final sanity check!
I saw #1421 and noticed that it was slower than the current function for calculating merkle roots. Just looking to see if the direction I took here is ok.
I replaced everything in
rolling_merkle.go
with Utreexo structs/functions. The comments and struct names should probably change. FWIW, the main functionadd
is using the same algorithm as the one found in blake3 hash.Here's the benchstat results. It's about the same/slightly faster than the current merkle root function and allocates even less memory than the function in #1421. The added code is a lot smaller as well.