multi: Remove unused code.

This commit is contained in:
David Hill 2018-10-31 21:46:59 -04:00
parent 98e645d274
commit 5f8081761d
13 changed files with 64 additions and 91 deletions

View File

@ -31,7 +31,7 @@ transactions to other Decred nodes around the world.
This software is currently under active development. It is extremely stable and
has been in production use since February 2016.
The sofware was originally forked from [btcd](https://github.com/btcsuite/btcd),
The software was originally forked from [btcd](https://github.com/btcsuite/btcd),
which is a bitcoin full node implementation that is still under active
development. To gain the benefit of btcd's ongoing upgrades, including improved
peer and connection handling, database optimization, and other blockchain
@ -66,7 +66,7 @@ lightweight clients, such as Simplified Payment Verification (SPV) wallets.
Without enough full nodes, the network could be unable to expediently serve
users of lightweight clients which could force them to have to rely on
centralized services that significantly reduce privacy and are vulernable to
centralized services that significantly reduce privacy and are vulnerable to
censorship.
In terms of individual benefits, since dcrd fully validates every block and

View File

@ -45,13 +45,6 @@ func (e errNotInMainChain) Error() string {
return string(e)
}
// isNotInMainChainErr returns whether or not the passed error is an
// errNotInMainChain error.
func isNotInMainChainErr(err error) bool {
_, ok := err.(errNotInMainChain)
return ok
}
// errDeserialize signifies that a problem was encountered when deserializing
// data.
type errDeserialize string

View File

@ -65,6 +65,13 @@ func hexToExtraData(s string) [32]byte {
return extraData
}
// isNotInMainChainErr returns whether or not the passed error is an
// errNotInMainChain error.
func isNotInMainChainErr(err error) bool {
_, ok := err.(errNotInMainChain)
return ok
}
// TestErrNotInMainChain ensures the functions related to errNotInMainChain work
// as expected.
func TestErrNotInMainChain(t *testing.T) {

View File

@ -29,16 +29,6 @@ const (
blockDataNet = wire.MainNet
)
// filesExists returns whether or not the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// isSupportedDbType returns whether or not the passed database type is
// currently supported.
func isSupportedDbType(dbType string) bool {

View File

@ -29,10 +29,6 @@ var (
oneLsh256 = new(big.Int).Lsh(bigOne, 256)
)
// maxShift is the maximum shift for a difficulty that resets (e.g.
// testnet difficulty).
const maxShift = uint(256)
// HashToBig converts a chainhash.Hash into a big.Int that can be used to
// perform math comparisons.
func HashToBig(hash *chainhash.Hash) *big.Int {

View File

@ -30,16 +30,6 @@ const (
blockDataNet = wire.MainNet
)
// filesExists returns whether or not the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
// isSupportedDbType returns whether or not the passed database type is
// currently supported.
func isSupportedDbType(dbType string) bool {

View File

@ -180,10 +180,6 @@ var (
// a package level variable to avoid the need to create a new instance
// every time a check is needed.
zeroHash = &chainhash.Hash{}
// rangeLimitMax is the maximum bitshift for a fees limit on an
// sstx commitment output.
rangeLimitMax = uint16(63)
)
// VoteBits is a field representing the mandatory 2-byte field of voteBits along

View File

@ -70,55 +70,6 @@ func (b *BlockChain) findStakeVersionPriorNode(prevNode *blockNode) *blockNode {
return prevNode.Ancestor(wantHeight)
}
// isVoterMajorityVersion determines if minVer requirement is met based on
// prevNode. The function always uses the voter versions of the prior window.
// For example, if StakeVersionInterval = 11 and StakeValidationHeight = 13 the
// windows start at 13 + 11 -1 = 24 and are as follows: 24-34, 35-45, 46-56 ...
// If height comes in at 35 we use the 24-34 window, up to height 45.
// If height comes in at 46 we use the 35-45 window, up to height 56 etc.
//
// This function MUST be called with the chain state lock held (for writes).
func (b *BlockChain) isVoterMajorityVersion(minVer uint32, prevNode *blockNode) bool {
// Walk blockchain backwards to calculate version.
node := b.findStakeVersionPriorNode(prevNode)
if node == nil {
return 0 >= minVer
}
// Generate map key and look up cached result.
key := stakeMajorityCacheVersionKey(minVer, &node.hash)
if result, ok := b.isVoterMajorityVersionCache[key]; ok {
return result
}
// Tally both the total number of votes in the previous stake version validation
// interval and how many of those votes are at least the requested minimum
// version.
totalVotesFound := int32(0)
versionCount := int32(0)
iterNode := node
for i := int64(0); i < b.chainParams.StakeVersionInterval && iterNode != nil; i++ {
totalVotesFound += int32(len(iterNode.votes))
for _, v := range iterNode.votes {
if v.Version >= minVer {
versionCount++
}
}
iterNode = iterNode.parent
}
// Determine the required amount of votes to reach supermajority.
numRequired := totalVotesFound * b.chainParams.StakeMajorityMultiplier /
b.chainParams.StakeMajorityDivisor
// Cache value.
result := versionCount >= numRequired
b.isVoterMajorityVersionCache[key] = result
return result
}
// isStakeMajorityVersion determines if minVer requirement is met based on
// prevNode. The function always uses the stake versions of the prior window.
// For example, if StakeVersionInterval = 11 and StakeValidationHeight = 13 the

View File

@ -13,6 +13,55 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
)
// isVoterMajorityVersion determines if minVer requirement is met based on
// prevNode. The function always uses the voter versions of the prior window.
// For example, if StakeVersionInterval = 11 and StakeValidationHeight = 13 the
// windows start at 13 + 11 -1 = 24 and are as follows: 24-34, 35-45, 46-56 ...
// If height comes in at 35 we use the 24-34 window, up to height 45.
// If height comes in at 46 we use the 35-45 window, up to height 56 etc.
//
// This function MUST be called with the chain state lock held (for writes).
func (b *BlockChain) isVoterMajorityVersion(minVer uint32, prevNode *blockNode) bool {
// Walk blockchain backwards to calculate version.
node := b.findStakeVersionPriorNode(prevNode)
if node == nil {
return 0 >= minVer
}
// Generate map key and look up cached result.
key := stakeMajorityCacheVersionKey(minVer, &node.hash)
if result, ok := b.isVoterMajorityVersionCache[key]; ok {
return result
}
// Tally both the total number of votes in the previous stake version validation
// interval and how many of those votes are at least the requested minimum
// version.
totalVotesFound := int32(0)
versionCount := int32(0)
iterNode := node
for i := int64(0); i < b.chainParams.StakeVersionInterval && iterNode != nil; i++ {
totalVotesFound += int32(len(iterNode.votes))
for _, v := range iterNode.votes {
if v.Version >= minVer {
versionCount++
}
}
iterNode = iterNode.parent
}
// Determine the required amount of votes to reach supermajority.
numRequired := totalVotesFound * b.chainParams.StakeMajorityMultiplier /
b.chainParams.StakeMajorityDivisor
// Cache value.
result := versionCount >= numRequired
b.isVoterMajorityVersionCache[key] = result
return result
}
func TestCalcWantHeight(t *testing.T) {
// For example, if StakeVersionInterval = 11 and StakeValidationHeight = 13 the
// windows start at 13 + (11 * 2) 25 and are as follows: 24-34, 35-45, 46-56 ...

View File

@ -729,7 +729,8 @@ func testMetadataManualTxInterface(tc *testContext) bool {
deleteValues := func(values []keyPair) bool {
tx, err := tc.db.Begin(true)
if err != nil {
tc.t.Errorf("Begin: unexpected error %v", err)
return false
}
defer rollbackOnPanic(tc.t, tx)

View File

@ -225,7 +225,7 @@ func (iter *Iterator) Prev() bool {
// When there is no left node walk the parents until the parent's left
// node is not equal to the previous child. This will be the previous
// node.
for iter.node.left == nil {
if iter.node.left == nil {
parent := iter.parents.Pop()
for parent != nil && parent.left == iter.node {
iter.node = parent

View File

@ -26,7 +26,7 @@ report.
- Obtaining the underlying EC pubkeys, EC privkeys, and associated decred
addresses ties in seamlessly with existing btcec and dcrutil types which
provide powerful tools for working with them to do things like sign
transations and generate payment scripts
transactions and generate payment scripts
- Uses the btcec package which is highly optimized for secp256k1
- Code examples including:
- Generating a cryptographically secure random seed and deriving a

View File

@ -1524,7 +1524,7 @@
["8 3", "MOD 2 EQUAL", "NONE", "OK", "MOD must produce expected result (8%3)"],
["6 3", "MOD 0 EQUAL", "NONE", "OK", "MOD must support a positive dividend and divisor"],
["-7 3", "MOD -1 EQUAL", "NONE", "OK", "MOD must support a negative dividend with positive divisor with negative result"],
["7 -3", "MOD 1 EQUAL", "NONE", "OK", "MOD must support a positive dividend with negative divisor with positve result"],
["7 -3", "MOD 1 EQUAL", "NONE", "OK", "MOD must support a positive dividend with negative divisor with positive result"],
["-7 -3", "MOD -1 EQUAL", "NONE", "OK", "MOD must support a negative dividend and divisor with negative result"],
["-2147483647 1073741823", "MOD -1 EQUAL", "NONE", "OK", "MOD must support 4-byte negative int32"],
["", "MOD TRUE", "NONE", "ERR_INVALID_STACK_OPERATION", "MOD requires a divisor"],
@ -1786,7 +1786,7 @@
["NOP", "MIN", "NONE", "ERR_INVALID_STACK_OPERATION", "MIN requires two items on the stack and NOP must not be treated as one"],
["", "MIN", "NONE", "ERR_INVALID_STACK_OPERATION", "MIN requires two items on the stack, stack has no items"],
["0", "MIN", "NONE", "ERR_INVALID_STACK_OPERATION", "MIN requires two items on the stack, stack has one item"],
["1 0 MIN", "0 NUMEQUAL", "NONE", "OK", "MIN must compare the first two numeric stack items and return the mimimum"],
["1 0 MIN", "0 NUMEQUAL", "NONE", "OK", "MIN must compare the first two numeric stack items and return the minimum"],
["0 1 MIN", "0 NUMEQUAL", "NONE", "OK"],
["-1 0 MIN", "-1 NUMEQUAL", "NONE", "OK"],
["0 -2147483647 MIN", "-2147483647 NUMEQUAL", "NONE", "OK"],