0029905d43
Introduce an ECDSA signature verification into btcd in order to mitigate a certain DoS attack and as a performance optimization. The benefits of SigCache are two fold. Firstly, usage of SigCache mitigates a DoS attack wherein an attacker causes a victim's client to hang due to worst-case behavior triggered while processing attacker crafted invalid transactions. A detailed description of the mitigated DoS attack can be found here: https://bitslog.wordpress.com/2013/01/23/fixed-bitcoin-vulnerability-explanation-why-the-signature-cache-is-a-dos-protection/ Secondly, usage of the SigCache introduces a signature verification optimization which speeds up the validation of transactions within a block, if they've already been seen and verified within the mempool. The server itself manages the sigCache instance. The blockManager and txMempool respectively now receive pointers to the created sigCache instance. All read (sig triplet existence) operations on the sigCache will not block unless a separate goroutine is adding an entry (writing) to the sigCache. GetBlockTemplate generation now also utilizes the sigCache in order to avoid unnecessarily double checking signatures when generating a template after previously accepting a txn to the mempool. Consequently, the CPU miner now also employs the same optimization. The maximum number of entries for the sigCache has been introduced as a config parameter in order to allow users to configure the amount of memory consumed by this new additional caching.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
// Copyright (c) 2013-2015 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package blockchain_test
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/blockchain"
|
|
"github.com/btcsuite/btcd/txscript"
|
|
)
|
|
|
|
// TestCheckBlockScripts ensures that validating the all of the scripts in a
|
|
// known-good block doesn't return an error.
|
|
func TestCheckBlockScripts(t *testing.T) {
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
|
testBlockNum := 277647
|
|
blockDataFile := fmt.Sprintf("%d.dat.bz2", testBlockNum)
|
|
blocks, err := loadBlocks(blockDataFile)
|
|
if err != nil {
|
|
t.Errorf("Error loading file: %v\n", err)
|
|
return
|
|
}
|
|
if len(blocks) > 1 {
|
|
t.Errorf("The test block file must only have one block in it")
|
|
}
|
|
|
|
txStoreDataFile := fmt.Sprintf("%d.txstore.bz2", testBlockNum)
|
|
txStore, err := loadTxStore(txStoreDataFile)
|
|
if err != nil {
|
|
t.Errorf("Error loading txstore: %v\n", err)
|
|
return
|
|
}
|
|
|
|
scriptFlags := txscript.ScriptBip16
|
|
err = blockchain.TstCheckBlockScripts(blocks[0], txStore, scriptFlags, nil)
|
|
if err != nil {
|
|
t.Errorf("Transaction script validation failed: %v\n",
|
|
err)
|
|
return
|
|
}
|
|
}
|