diff --git a/README.md b/README.md index cf7eb3f8..264ee3a1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/blockchain/chainio.go b/blockchain/chainio.go index d57c8814..24093fc0 100644 --- a/blockchain/chainio.go +++ b/blockchain/chainio.go @@ -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 diff --git a/blockchain/chainio_test.go b/blockchain/chainio_test.go index 52af8c96..c70602c2 100644 --- a/blockchain/chainio_test.go +++ b/blockchain/chainio_test.go @@ -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) { diff --git a/blockchain/common_test.go b/blockchain/common_test.go index 3fdcc540..5437dafc 100644 --- a/blockchain/common_test.go +++ b/blockchain/common_test.go @@ -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 { diff --git a/blockchain/difficulty.go b/blockchain/difficulty.go index 55253718..92ccf1a6 100644 --- a/blockchain/difficulty.go +++ b/blockchain/difficulty.go @@ -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 { diff --git a/blockchain/fullblocks_test.go b/blockchain/fullblocks_test.go index 0b64ccda..1a1a3ed9 100644 --- a/blockchain/fullblocks_test.go +++ b/blockchain/fullblocks_test.go @@ -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 { diff --git a/blockchain/stake/staketx.go b/blockchain/stake/staketx.go index 98b2ae9b..d84cd2fc 100644 --- a/blockchain/stake/staketx.go +++ b/blockchain/stake/staketx.go @@ -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 diff --git a/blockchain/stakeversion.go b/blockchain/stakeversion.go index ecdbfed9..a767a15d 100644 --- a/blockchain/stakeversion.go +++ b/blockchain/stakeversion.go @@ -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 diff --git a/blockchain/stakeversion_test.go b/blockchain/stakeversion_test.go index 1e3a27a2..421412c3 100644 --- a/blockchain/stakeversion_test.go +++ b/blockchain/stakeversion_test.go @@ -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 ... diff --git a/database/ffldb/interface_test.go b/database/ffldb/interface_test.go index b3ca606e..4e1d8ff5 100644 --- a/database/ffldb/interface_test.go +++ b/database/ffldb/interface_test.go @@ -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) diff --git a/database/internal/treap/treapiter.go b/database/internal/treap/treapiter.go index 6be1865a..d009f1cb 100644 --- a/database/internal/treap/treapiter.go +++ b/database/internal/treap/treapiter.go @@ -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 diff --git a/hdkeychain/README.md b/hdkeychain/README.md index 0ecadf6c..880690a4 100644 --- a/hdkeychain/README.md +++ b/hdkeychain/README.md @@ -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 diff --git a/txscript/data/script_tests.json b/txscript/data/script_tests.json index b18c71d9..299a0e02 100644 --- a/txscript/data/script_tests.json +++ b/txscript/data/script_tests.json @@ -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"],