Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge in btcd commit 27c0f9f8d1af6a44423b03a2e4f03d4a87a1ac40 #369

Merged
merged 4 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ type BlockChain struct {

// These fields are related to the memory block index. They are
// protected by the chain lock.
root *blockNode
bestNode *blockNode
index map[chainhash.Hash]*blockNode
depNodes map[chainhash.Hash][]*blockNode
Expand Down Expand Up @@ -615,7 +614,6 @@ func (b *BlockChain) loadBlockNode(dbTx database.Tx,
for _, childNode := range childNodes {
childNode.parent = node
node.children = append(node.children, childNode)
b.root = node
}
} else {
// Case 3 -- The node doesn't have a parent and is not the
Expand Down Expand Up @@ -914,9 +912,6 @@ func (b *BlockChain) pruneBlockNodes() error {
}
}

// Set the new root node.
b.root = newRootNode

return nil
}

Expand Down Expand Up @@ -2120,7 +2115,6 @@ func New(config *Config) (*BlockChain, error) {
notifications: config.Notifications,
sigCache: config.SigCache,
indexManager: config.IndexManager,
root: nil,
bestNode: nil,
index: make(map[chainhash.Hash]*blockNode),
depNodes: make(map[chainhash.Hash][]*blockNode),
Expand Down
10 changes: 3 additions & 7 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,14 +1268,12 @@ func dbPutBestState(dbTx database.Tx, snapshot *BestState,
// genesis block. This includes creating the necessary buckets and inserting
// the genesis block, so it must only be called on an uninitialized database.
func (b *BlockChain) createChainState() error {
// Create a new node from the genesis block and set it as both the root
// node and the best node.
// Create a new node from the genesis block and set it as the best node.
genesisBlock := dcrutil.NewBlock(b.chainParams.GenesisBlock)
header := &genesisBlock.MsgBlock().Header
node := newBlockNode(header, genesisBlock.Sha(), 0, []uint16{})
node.inMainChain = true
b.bestNode = node
b.root = node

// Add the new node to the index which is used for faster lookups.
b.index[*node.hash] = node
Expand Down Expand Up @@ -1424,17 +1422,15 @@ func (b *BlockChain) initChainState() error {
return err
}

// Create a new node and set it as both the root node and the
// best node. The preceding nodes will be loaded on demand as
// needed.
// Create a new node and set it as the best node. The preceding
// nodes will be loaded on demand as needed.
// TODO CJ Get vote bits from db
header := &block.Header
node := newBlockNode(header, &state.hash, int64(state.height),
[]uint16{})
node.inMainChain = true
node.workSum = state.workSum
b.bestNode = node
b.root = node

// Add the new node to the indices for faster lookups.
prevHash := &node.header.PrevBlock
Expand Down
33 changes: 31 additions & 2 deletions wire/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func BenchmarkWriteTxIn(b *testing.B) {
}

// BenchmarkDeserializeTx performs a benchmark on how long it takes to
// deserialize a transaction.
func BenchmarkDeserializeTx(b *testing.B) {
// deserialize a small transaction.
func BenchmarkDeserializeTxSmall(b *testing.B) {
buf := []byte{
0x01, 0x00, 0x00, 0x00, // Version
0x01, // Varint for number of input transactions
Expand Down Expand Up @@ -341,7 +341,36 @@ func BenchmarkDeserializeTx(b *testing.B) {
var tx MsgTx
for i := 0; i < b.N; i++ {
tx.Deserialize(bytes.NewReader(buf))
}
}

// BenchmarkDeserializeTxLarge performs a benchmark on how long it takes to
// deserialize a very large transaction.
func BenchmarkDeserializeTxLarge(b *testing.B) {
bigTx := new(MsgTx)
bigTx.Version = DefaultMsgTxVersion()
inputsLen := 1000
outputsLen := 2000
bigTx.TxIn = make([]*TxIn, inputsLen)
bigTx.TxOut = make([]*TxOut, outputsLen)
for i := 0; i < inputsLen; i++ {
bigTx.TxIn[i] = &TxIn{
SignatureScript: bytes.Repeat([]byte{0x12}, 120),
}
}
for i := 0; i < outputsLen; i++ {
bigTx.TxOut[i] = &TxOut{
PkScript: bytes.Repeat([]byte{0x34}, 30),
}
}
bigTxB, err := bigTx.Bytes()
if err != nil {
b.Fatalf("%v", err.Error())
}

var tx MsgTx
for i := 0; i < b.N; i++ {
tx.Deserialize(bytes.NewReader(bigTxB))
}
}

Expand Down