mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-21 18:42:40 +02:00
revocation: switch to tadge's bit-shifting to figure out log2 instead of using math
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
@ -71,11 +70,11 @@ func derive(from, to uint64, startingHash [32]byte) [32]byte {
|
|||||||
nextHash := startingHash
|
nextHash := startingHash
|
||||||
|
|
||||||
numBranches := from ^ to
|
numBranches := from ^ to
|
||||||
toDerive := uint64(math.Log2(float64(numBranches))) // uh.....
|
|
||||||
// math? floats? nahhh! :) bit-flipp-y way to do it:
|
// The number of branches we need to derive is log2(numBranches)
|
||||||
for toDerive = 0; numBranches>>toDerive > 0; toDerive++ {
|
toDerive := 0
|
||||||
|
for ; numBranches>>uint(toDerive) > 0; toDerive++ {
|
||||||
}
|
}
|
||||||
// ^^^this rounds up instead of down, may be off by 1?
|
|
||||||
toDerive-- // needed?
|
toDerive-- // needed?
|
||||||
|
|
||||||
for i := int(toDerive - 1); i >= 0; i-- {
|
for i := int(toDerive - 1); i >= 0; i-- {
|
||||||
|
Reference in New Issue
Block a user