This modifies the block node structure to include only the specifically used fields, some of which in a more compact format, as opposed to copying the entire header and updates all code and tests accordingly. Not only is this a more efficient approach that helps pave the way for future optimizations, it is also consistent with the upstream code which helps minimize the differences to facilitate easier syncs due to less merge conflicts. In particular, since the merkle and stake roots, number of revocations, size, nonce, and extradata fields aren't used currently, they are no longer copied into the block node. Also, the block node already had a height field, which is also in the header, so this change also removes that duplication. Another change is that the block node now stores the timestamp as an int64 unix-style timestamp which is only 8 bytes versus the old timestamp that was in the header which is a time.Time and thus 24 bytes. It should be noted that future optimizations will very likely end up adding most of the omitted header fields back to the block node as individual fields so the headers can be efficiently reconstructed from memory, however, these changes are still beneficial due to the ability to decouple the block node storage format from the header struct which allows more compact representations and reording of the fields for optimal struct packing. Ultimately, the need for the parent hash can also be removed, which will save an additional 32 bytes which would not be possible without this decoupling.
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Copyright (c) 2015-2018 The Decred developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
/*
|
|
This test file is part of the blockchain package rather than than the
|
|
blockchain_test package so it can bridge access to the internals to properly
|
|
test cases which are either not possible or can't reliably be tested via the
|
|
public interface. The functions are only exported while the tests are being
|
|
run.
|
|
*/
|
|
|
|
package blockchain
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/decred/dcrd/blockchain/stake"
|
|
"github.com/decred/dcrd/wire"
|
|
)
|
|
|
|
// TstTimeSorter makes the internal timeSorter type available to the test
|
|
// package.
|
|
func TstTimeSorter(times []int64) sort.Interface {
|
|
return timeSorter(times)
|
|
}
|
|
|
|
// TstSetMaxMedianTimeEntries makes the ability to set the maximum number of
|
|
// median time entries available to the test package.
|
|
func TstSetMaxMedianTimeEntries(val int) {
|
|
maxMedianTimeEntries = val
|
|
}
|
|
|
|
// TstCheckBlockHeaderContext makes the internal checkBlockHeaderContext
|
|
// function available to the test package.
|
|
func (b *BlockChain) TstCheckBlockHeaderContext(header *wire.BlockHeader, prevNode *blockNode, flags BehaviorFlags) error {
|
|
return b.checkBlockHeaderContext(header, prevNode, flags)
|
|
}
|
|
|
|
// TstNewBlockNode makes the internal newBlockNode function available to the
|
|
// test package.
|
|
func TstNewBlockNode(blockHeader *wire.BlockHeader, spentTickets *stake.SpentTicketsInBlock) *blockNode {
|
|
return newBlockNode(blockHeader, spentTickets)
|
|
}
|