multi: replace usage of fastsha256 with crypto/sha256
This commit removes all instances of the fastsha256 library and replaces it with the sha256 library in the standard library. This change should see a number of performance improvements as the standard library has highly optimized assembly instructions with use vectorized instructions as the platform supports.
This commit is contained in:
16 files changed
+53
-55
No files matched your search
@@ -2,6 +2,7 @@ package channeldb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"math/big"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
@@ -554,7 +554,7 @@ func TestGraphTraversal(t *testing.T) {
|
||||
const numChannels = 5
|
||||
chanIndex := map[uint64]struct{}{}
|
||||
for i := 0; i < numChannels; i++ {
|
||||
txHash := fastsha256.Sum256([]byte{byte(i)})
|
||||
txHash := sha256.Sum256([]byte{byte(i)})
|
||||
chanID := uint64(i + 1)
|
||||
op := wire.OutPoint{
|
||||
Hash: txHash,
|
||||
@@ -706,7 +706,7 @@ func TestGraphPruning(t *testing.T) {
|
||||
// between them.
|
||||
channelPoints := make([]*wire.OutPoint, 0, numNodes-1)
|
||||
for i := 0; i < numNodes-1; i++ {
|
||||
txHash := fastsha256.Sum256([]byte{byte(i)})
|
||||
txHash := sha256.Sum256([]byte{byte(i)})
|
||||
chanID := uint64(i + 1)
|
||||
op := wire.OutPoint{
|
||||
Hash: txHash,
|
||||
@@ -781,12 +781,12 @@ func TestGraphPruning(t *testing.T) {
|
||||
|
||||
// Next we'll create a block that doesn't close any channels within the
|
||||
// graph to test the negative error case.
|
||||
fakeHash := fastsha256.Sum256([]byte("test prune"))
|
||||
fakeHash := sha256.Sum256([]byte("test prune"))
|
||||
nonChannel := &wire.OutPoint{
|
||||
Hash: fakeHash,
|
||||
Index: 9,
|
||||
}
|
||||
blockHash = fastsha256.Sum256(blockHash[:])
|
||||
blockHash = sha256.Sum256(blockHash[:])
|
||||
blockHeight = 2
|
||||
prunedChans, err = graph.PruneGraph([]*wire.OutPoint{nonChannel},
|
||||
&blockHash, blockHeight)
|
||||
@@ -805,7 +805,7 @@ func TestGraphPruning(t *testing.T) {
|
||||
|
||||
// Finally, create a block that prunes the remainder of the channels
|
||||
// from the graph.
|
||||
blockHash = fastsha256.Sum256(blockHash[:])
|
||||
blockHash = sha256.Sum256(blockHash[:])
|
||||
blockHeight = 3
|
||||
prunedChans, err = graph.PruneGraph(channelPoints[2:], &blockHash,
|
||||
blockHeight)
|
||||
|
||||
@@ -2,11 +2,11 @@ package channeldb
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
@@ -58,7 +58,7 @@ func TestInvoiceWorkflow(t *testing.T) {
|
||||
// Attempt to retrieve the invoice which was just added to the
|
||||
// database. It should be found, and the invoice returned should be
|
||||
// identical to the one created above.
|
||||
paymentHash := fastsha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
|
||||
paymentHash := sha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
|
||||
dbInvoice, err := db.LookupInvoice(paymentHash)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to find invoice: %v", err)
|
||||
|
||||
@@ -2,12 +2,12 @@ package channeldb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
@@ -132,7 +132,7 @@ func (d *DB) AddInvoice(i *Invoice) error {
|
||||
|
||||
// Ensure that an invoice an identical payment hash doesn't
|
||||
// already exist within the index.
|
||||
paymentHash := fastsha256.Sum256(i.Terms.PaymentPreimage[:])
|
||||
paymentHash := sha256.Sum256(i.Terms.PaymentPreimage[:])
|
||||
if invoiceIndex.Get(paymentHash[:]) != nil {
|
||||
return ErrDuplicateInvoice
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func putInvoice(invoices *bolt.Bucket, invoiceIndex *bolt.Bucket,
|
||||
// Add the payment hash to the invoice index. This'll let us quickly
|
||||
// identify if we can settle an incoming payment, and also to possibly
|
||||
// allow a single invoice to have multiple payment installations.
|
||||
paymentHash := fastsha256.Sum256(i.Terms.PaymentPreimage[:])
|
||||
paymentHash := sha256.Sum256(i.Terms.PaymentPreimage[:])
|
||||
if err := invoiceIndex.Put(paymentHash[:], invoiceKey[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package channeldb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/fastsha256"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
@@ -33,7 +33,7 @@ func makeFakePayment() *OutgoingPayment {
|
||||
Fee: 101,
|
||||
Path: fakePath,
|
||||
TimeLockLength: 1000,
|
||||
PaymentHash: fastsha256.Sum256(rev[:]),
|
||||
PaymentHash: sha256.Sum256(rev[:]),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func makeRandomFakePayment() (*OutgoingPayment, error) {
|
||||
copy(fakePath[i][:], b)
|
||||
}
|
||||
|
||||
rHash := fastsha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
|
||||
rHash := sha256.Sum256(fakeInvoice.Terms.PaymentPreimage[:])
|
||||
fakePayment := &OutgoingPayment{
|
||||
Invoice: *fakeInvoice,
|
||||
Fee: btcutil.Amount(rand.Intn(1001)),
|
||||
|
||||
Reference in new issue
Block a user