Commit Graph

3789 Commits

Author SHA1 Message Date
Donald Adu-Poku
afcf031471 mempool: Refactor pool membership test logic.
This introduces a new pool membership test function to the mempool
testing infrastructure and refactors the tests to make use of it.

It is useful since it is common logic that is not only needed in the
existing tests, but will be needed by most mempool-related tests.
2018-05-04 20:59:05 +00:00
Dave Collins
0921280e6e
multi: Correct clean and expand path handling.
This corrects an issue introduced by commit
c6f9474348 which resulted in empty paths
that were cleaned and expanded being transformed into "." instead of
having no effect as intended.
2018-05-03 16:21:35 -05:00
Dave Collins
d14d9a1174
fullblocktests: Add expired stake tx test.
This adds a test to ensure blocks with an expired transaction in the
stake tree is rejected as expected.

While here, it also updates the existing test for an expired transaction
in the regular tree to be the exact block height which is including it
to help detect any off by one errors.
2018-05-03 14:09:55 -05:00
Dave Collins
6327ed7fab
blockchain: CheckConnectBlockTemplate with tests.
This removes the CheckConnectBlock function in favor of a new function
named CheckConnectBlockTemplate which more accurately reflects its
purpose of testing block template proposals and uses this fact to be
more restrictive about the allowed inputs and to avoid performing the
proof of work check.

In particular, the provided block template must only build from the
current tip or its parent or an error is returned.

All mining code has been updated to call the new function accordingly.

Finally, it also adds a full suite of tests for the new function using
the chaingen framework in order to ensure proper functionality.
2018-05-03 13:53:24 -05:00
Alex Yocom-Piatt
0483c4a069 Fix typo in blockchain typo 2018-05-03 14:37:37 -04:00
vctt94
b789995319 dcrjson: Add Expiry field to CreateRawTransactionCmd 2018-05-02 20:49:03 -05:00
Markus Richter
dfee810f04 addrmgr: Test timestamp update during AddAddress()
Test for codepath that adds the same address twice and is supposed to
update the timestamp.
2018-05-02 20:47:26 -05:00
Markus Richter
5c2768047d addrmgr: Simplify package API.
Hide functions which are only used internally.
2018-05-02 20:35:40 -05:00
hypernoob
b62606dae8
main: Correct mem profile error message. 2018-05-03 08:17:12 +08:00
Dave Collins
1cd987cb44 Sync upstream through 6b8a249. 2018-05-02 17:14:43 -05:00
Donald Adu-Poku
9e65263b9e blockchain: move block validation rule tests into fullblocktests (3/3). 2018-05-02 19:39:04 +00:00
Markus Richter
73b4bd21b0 addrmgr: Skip low quality addresses for getaddr.
The AddressCache() should not propagate addresses of known low quality
to its peers.

Inspired by the Bitcoin Core implementation.
2018-05-01 12:49:25 -05:00
Markus Richter
8d12e29df5 addrmgr: Simplify tests for KnownAddress.
- Remove internal_test.go bridge and test internally instead.
- Used cached result of time.Now() everywhere.
2018-05-01 12:42:07 -05:00
David Hill
5a4f367b66 multi: Remove everything to do about bloom filters. 2018-05-01 11:43:32 -05:00
Dave Collins
b3ce2ad2ad
wire: Remove TxSerializeWitnessSigning.
This removes the TxSerializeWitnessSigning serialization type since
it is no longer required due to implementing it directly in the
signature hash calculation function.  It also removes all related tests.

Although this is technically a change to the wire protocol, the protocol
version is not being bumped because nothing ever sends messages using
this serialization type as it only applied for calculating signature
hashes and really should not have ever been in the wire package to begin
with.
2018-05-01 08:52:18 -05:00
Dave Collins
5717411882
txscript: Decouple and optimize sighash calc.
This modifies the signature hash calculation logic to completely
decouple it from the wire transaction serialization and significantly
optimizes it in the process.  It also significantly improves the
comments to specifically call out the semantics.

This change is highly desirable because it has several beneficial
properties:

- The signature hash semantics are much clearer and specific
- There is no longer a need to copy the entire transaction and modify
  the relevant portions since the necessary substitutions are made on
  the fly
- Allows much faster calculation by serializing directly into byte
  slices and avoiding all of the additional error handling logic
  dedicated to handling network streams
- Provides the possibility of changing the wire format without breaking
  signature hash calculation
  - Note that the caching portion still relies on the wire format, but
    that can be addressed in future commits since it is merely an
    optimization that can also be decoupled

The following is a before and after comparison of signature hash
calculation for both speed and memory allocations for a transaction with
many inputs:

benchmark                old ns/op     new ns/op     delta
------------------------------------------------------------
BenchmarkCalcSigHash     6299714       1551740       -75.37%

benchmark                old allocs    new allocs    delta
------------------------------------------------------------
BenchmarkCalcSigHash     18601         1691          -90.91%
2018-05-01 08:51:41 -05:00
Dave Collins
b51a3bb396
txscript: Add benchmark for sighash calculation. 2018-05-01 08:51:38 -05:00
Dave Collins
a068101639
txscript: Correct JSON-based signature hash tests.
This updates the recently-added JSON-based signature hash test data to
actually test the SigHashAnyOneCanPay flag in the non-fuzzer
transactions as intended.

The flag is 0x80, but the JSON test data specifies the signature hash
type in decimal, so SigHashAll|SigHashAnyOneCanPay, which is 0x81,
should've been specified as 129 decimal instead of 81 decimal.  The same
applies to all combinations with the SigHashAnyOneCanPay flag.
2018-04-30 18:18:18 -05:00
Dave Collins
47cbc26b93
txscript: Add JSON-based signature hash tests.
This adds a significant number of JSON-based tests with various
transactions, scripts, and hash types, to ensure the signature hash
calculated generates the expected hash in each case.

It specifically tests some specialized transactions such as coinbase,
ticket purchase, vote, and revocation.  It also includes carefully
created tests for all combinations of defined hash types along with
triggering an error due to improper use of SigHashSingle.

Finally, it also includes fuzz testing by providing a selection of 100
regular transactions with various numbers of inputs and outputs along
with randomly generated (including undefined) signature hash types and
input indexes.  Due to the way that masking of the signature hash type
works, a couple of the fuzzer tests also hit the improper use of
SigHashSingle.

The test data was generated as JSON in order to make it easier for
developers of software in other languages and platforms that need to
deal with generating signature hashes to consume and prove correctness
of their implementation as well.
2018-04-30 12:14:14 -05:00
Dave Collins
2cb2d9a22a
txscript: Consolidate tests into txscript package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much and it also
gets rid of the need for internal_test.go to bridge.

Also, do some light cleanup on a few tests while here.
2018-04-30 10:34:59 -05:00
Dave Collins
7ba7cd62a3
hdkeychain: Satisfy fmt.Stringer interface.
This reverts changes to the String function on ExtendedKey to match the
upstream code so that it satisfies the fmt.Stringer interface as
intended.
2018-04-30 10:33:33 -05:00
Dave Collins
467b154b41
wire: Remove TxSerializeWitnessValueSigning.
This removes the TxSerializeWitnessValueSigning serialization type since
it is no longer required due to the removal of the SigHashAllValue
signature hash type.  It also removes all related tests.

Although this is technically a change to the wire protocol, the protocol
version is not being bumped because nothing ever sends messages using
this serialization type as it only applied for calculating signature
hashes and really should not have ever been in the wire package to begin
with.
2018-04-30 10:21:19 -05:00
Dave Collins
6fe33fc277
txscript: Remove SigHashAllValue.
This removes the SigHashAllValue signature hash type.  This is being
done because it is not currently usable without a consensus change due
to a consensus rule which enforces strict signature encoding disallowing
the hash type.

While it would be possible to change the consensus rule in question to
include SigHashAllValue, that would obviously require a consensus vote
since it constitutes a change to the consensus rules.  Given that a vote
is required to make any changes in regards to this, it is ideal to
completely change the algorithm altogether to not only address this
issue, but also to address other shortcomings in regards to efficiency
and complexity of the current algorithm in addition to committing to all
input amounts per the aforementioned description.
2018-04-30 09:10:02 -05:00
Dave Collins
f6be618a1b
txscript: Move sig hash logic to separate file.
This moves the logic to calculate the signature hash and the associated
test to separate files.  Since there will ultimately be a new signature
algorithm, it makes sense to separate all logic related to signature
hashes for better code organization.

It contains no functional changes.
2018-04-30 08:54:07 -05:00
Josh Rickmar
3149946b23 hdkeychain: Correct hash algorithm in comment 2018-04-25 17:34:47 -05:00
githubsands
fd99f572cf dcrjson: Add VerifySeedCmd. 2018-03-30 14:00:41 -05:00
Josh Rickmar
71500c80f2 multi: Add initial committed filter (CF) support
This change begins the work of bringing committed filters to the
network consensus daemon.  Committed filters are designed to enable
light wallets without many of the privacy issues associated with
server-side bloom filtering.

The new gcs package provides the primitives for creating and matching
against Golomb-coded sets (GCS) filters while the blockcf package
provides creation of filters and filter entries for data structures
found in blocks.

The wire package has been updated to define a new protocol version and
service flag for advertising CF support and includes types for the
following new messages: cfheaders, cfilter, cftypes, getcfheaders,
getcfilter, getcftypes.  The peer package and server implementation
have been updated to include support for the new protocol version and
messages.

Filters are created using a collision probability of 2^-20 and are
saved to a new optional database index when running with committed
filter support enabled (the default).  At first startup, if support is
not disabled, the index will be created and populated with filters and
filter headers for all preexisting blocks, and new filters will be
recorded for processed blocks.

Multiple filter types are supported.  The regular filter commits to
output scripts and previous outpoints that any non-voting wallet will
require access to.  Scripts and previous outpoints that can only be
spent by votes and revocations are not committed to the filter.  The
extended filter is a supplementary filter which commits to all
transaction hashes and script data pushes from the input scripts of
non-coinbase regular and ticket purchase transactions.  Creating these
filters is based on the algorithm defined by BIP0158 but is modified
to only commit "regular" data in stake transactions to prevent
committed filters from being used to create SPV voting wallets.
2018-03-30 13:52:12 -04:00
David Hill
8c0d28864c multi: remove MsgAlert
It is currently unused and does not fit into decentralization.
2018-03-29 14:47:55 -04:00
Josh Rickmar
b092705295 indexers: Provide interface for index removal.
Indexes may now optionally provide their own implementation for
dropping the index, with a fallback to simply removing the index
bucket and metadata if not implemented.

Using an interface and dynamically dispatching to the correct drop
implementation also allowed removing a special case for deletion of
the transaction index from the common drop code.
2018-03-27 18:50:03 -04:00
Donald Adu-Poku
0fc55252f9 rpcserver: fix jsonRPCRead data race. 2018-03-24 02:05:52 -05:00
Dave Collins
ddae30b5a3
blockchain: Only fetch inputs once in connect txns.
This modifies the connectTransactions function to only fetch the stake
inputs once instead of for every stake transaction in the tree.
2018-03-21 20:13:37 -05:00
Josh Rickmar
e944badc9b chainec/dcrec: Remove hybrid pubkey support
This is a follow-up to a previous change which removed the ability to
create a dcrutil.Address from a hybrid pubkey.  It removes all
secp256k1 hybrid pubkey support from the chainec/dcrec packages since
these pubkeys are not usable when evaluated by OP_CHECKSIG or
OP_CHECKMULTISIG.

While ParsePubKey is called by consensus code and its behavior has
been changed to error when encountering a hybrid secp256k1 pubkey,
this is not a consensus change as every use of ParsePubKey in
consensus code either checks beforehand that the pubkey is compressed
or uncompressed, requires a parsed address to be P2PKH or P2SH, or
checks an address string against the premine ledger (which only
contains P2PKH addresses).
2018-03-20 17:45:09 -04:00
Josh Rickmar
dcc58786d3 dcrutil: Disallow creation of hybrid P2PK addrs.
Hybrid pubkeys, which are a relic of OpenSSL used in Bitcoin Core, are
not usable with OP_CHECKSIG and we can potentially prevent creating
unspendable outputs by never allowing the creation of P2PK (or derived
P2PKH) addresses for these pubkeys.
2018-03-20 17:44:25 -04:00
Donald Adu-Poku
f74e80c9ae rpcserver: Improve JSON-RPC compatibility
Avoid compatibility issues with software that relies on the behavior of
bitcoind's JSON-RPC implementation.

The JSON-RPC 1.0 spec defines that notifications must have their "id"
set to null and states that notifications do not have a response.

A JSON-RPC 2.0 notification is a request with "json-rpc":"2.0", and
without an "id" member. The specification states that notifications
must not be responded to. JSON-RPC 2.0 permits the null value as a
valid request id, therefore such requests are not notifications.

Bitcoin Core serves requests with "id":null or even an absent "id", and
responds to such requests with "id":null in the response.

Btcd does not respond to any request without and "id" or with "id":null,
regardless the indicated JSON-RPC protocol version.

In order to avoid compatibility issues with software relying on
Core's behavior, this commit implements "quirks mode" as follows:
 - quirks mode can be enabled via configuration (disabled by default)
 - If no JSON-RPC version is indicated in the request, accept and
respond to request with "id":null
 - If no JSON-RPC version is indicated in the request, accept and
respond to requests without an "id" member
 - In both cases above, use "id":null in the response
 - Do not respond to request without an "id" or with "id":null when
JSON-RPC version is indicated in the request (process as notification)
2018-03-13 00:20:36 +00:00
Donald Adu-Poku
15c0466be9 rpcserver: Improve JSON-RPC compatibility
In order to avoid compatibility issues with software relying on
Core's behavior, terminate HTTP POST JSON-RPC responses with a newline.
2018-03-13 00:16:36 +00:00
Donald Adu-Poku
4e01f768cb dcrjson: fix StopAutoBuyerCmd registration bug. 2018-03-12 18:42:02 -05:00
Donald Adu-Poku
27fad14a1d dcrjson: require passphrase for StartAutoBuyerCmd. 2018-03-10 20:41:12 -06:00
Donald Adu-Poku
0f9c0cdb3e dcrjson: fix typo for StartAutoBuyerCmd (PoolAddres -> PoolAddress). 2018-03-11 01:11:10 +00:00
Markus Richter
8deac318d0 docs: Fix links for internal packages.
dcrrpclient and dcrjson have been merged into dcrd.
Adjust links accordingly.
2018-03-09 16:16:58 +00:00
Dave Collins
1329f871c1
release: Bump for v1.2.0. 2018-03-07 13:19:37 -06:00
Dave Collins
06b824601c
chaincfg: Add testnet checkpoint at height 249802. 2018-03-07 13:19:00 -06:00
Dave Collins
b69b21bf4e
chaincfg: Add mainnet checkpoint at height 214672. 2018-03-07 13:18:58 -06:00
Markus Richter
95557ac772 addrmgr: Improve isBad() performance.
Caching the result of time.Now() increases performance by around 50%
in the happy case (measured for last return statement).
2018-03-06 21:50:18 -06:00
Markus Richter
04c607e6fc addrmgr: Factor out common code.
Address a TODO in the code. The rest of the code is sufficiently
different to justify code duplication.
2018-03-07 01:13:50 +00:00
Markus Richter
c49a9bd261 addrmgr: Test removal of corrupt peers file.
Add unit test to ensure the removal of corrupt peers files.

Also fix some typos.
2018-03-06 00:03:56 +00:00
Dave Collins
969ae993d5
main: Allow semver prerel via linker flags.
This changes the appPreRelease definition from a constant to a variable
so it can be set via the linker when creating release candidates.
2018-03-05 15:19:42 -06:00
Markus Richter
625878976c addrmgr: Save peers file only if necessary.
Currently the peers file is (re-)written every ten minutes no matter
what.

Keep track of changes to the address manager state and write the peers
file only if something changed.
2018-03-05 14:17:42 -06:00
Markus Richter
81a2774bca addrmgr: Make writing of peers file safer.
Overwriting the peers file immediately might lead to a situation where
the old file is lost and the new file could not be written completely.

Write to a temporary peers file instead and then move it into place with
os.Rename (which should be atomic).
2018-03-05 14:13:23 -06:00
Markus Richter
c6d8121c6d addrmgr: Improve documentation.
Document internal structure of AddrManager.
Also use internal PRNG everywhere.
2018-03-05 13:16:43 -06:00
Dave Collins
baa289d3c9
cpuminer: Use header for extra nonce.
This updates the cpuminer code for Decred to use the extra data space in
the header for the extra nonce space instead of putting it in the
coinbase as is required in the upstream code.
2018-03-05 12:59:32 -06:00