Commit Graph

4638 Commits

Author SHA1 Message Date
Omkar Bhat
2f15b50213 Add docker compose file 2019-10-11 10:09:12 -04:00
Dave Collins
ee4a0e2e2a
multi: Use dcrec/edwards/v2 module.
This updates the following modules to use the dcrec/edwards/v2 module:

- chaincfg/v2
- dcrutil/v2
- txscript/v2
2019-10-08 10:43:08 -05:00
Dave Collins
6e647f731f
multi: Use crypto/ripemd160 module.
This updates the main, dcrutil, and blockchain modules to make use of
the new crypto/ripemd160 module.
2019-10-08 10:21:03 -05:00
Dave Collins
eb3fa80a66
docs: Update for secp256k1 v2 module. 2019-10-08 10:14:16 -05:00
Dave Collins
cebab1ef64
multi: Use secp256k1/v2 module.
This updates the following modules to use the secp256k1/v2 module:

- blockchain
- chaincfg/v2
- dcrutil/v2
- hdkeychain/v2
- mempool/v3
- txscript/v2
- main

The hdkeychain/v3 and txscript/v2 modules both use types from secp256k1
in their public API.

Consequently, in order avoid forcing them to bump their major versions,
secp256k1/v1.0.3 was released with the types redefined in terms of the
secp256k1/v2 module so callers still using v1 of the module that are not
ready to upgrade to the v2 module yet can interoperate by updating to
the latest patch version.
2019-10-08 10:14:13 -05:00
David Hill
474b7cb168 connmgr: support resolving ipv6 hosts over Tor 2019-10-08 09:53:16 -05:00
David Hill
eb5bb6d419 crypto: import ripemd160 2019-10-07 19:54:15 -05:00
Dave Collins
8e258be2f3
gcs: Improve package documentation. 2019-10-07 18:40:08 -05:00
Dave Collins
abe43b0928
secp256k1: Prepare v2.0.0.
This updates the dcrec/secp256k1 module dependencies and serves as a
base for dcrec/secp256k1/v2.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2

The full list of updated direct dependencies since the previous
dcrec/secp256k1/v1.0.2 release are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2
2019-10-07 15:24:46 -05:00
Dave Collins
e5647c02b7
gcs: Prevent empty data elements in v2 filters.
This ensures any empty/nil data elements in the input array to version 2
filter construction are not added to the filter since empty elements do
not make sense given how the filters are used.  It also updates the
tests to ensure proper behavior.

The single match function already failed attempts to match an empty
element as intended, however, prior to this change, it was possible to
match an empty item in the multi-item matching path.  This is not
desirable since the matching behavior must be consistent in both the
single and multi-match cases.
2019-10-07 11:17:41 -05:00
Donald Adu-Poku
b8dff59d4c dcrec: fix examples links. 2019-10-07 09:58:39 -05:00
David Hill
93dc592615 go.mod: sync 2019-10-07 09:13:58 -05:00
David Hill
e4a6c19fba rpctest: use errgroup to catch errors from go routines 2019-10-07 09:13:58 -05:00
David Hill
9465b06cc5 rpctest: remove always-nil error 2019-10-07 09:13:58 -05:00
David Hill
29064448cb rpcclient: close the unused response body 2019-09-21 13:09:21 -05:00
Dave Collins
3e2208f8c1
build: Replace TravisCI with CI via Github actions. 2019-09-20 19:59:04 -05:00
Donald Adu-Poku
9d89be74da cpuminer: fix race. 2019-09-20 19:51:30 -05:00
Dave Collins
4fcf24f02c
build: Setup github actions for CI. 2019-09-20 12:40:49 -05:00
Matheus Degiovani
450a680097 mempool: Add ErrorCode to returned TxRuleErrors
This adds the ErrorCode member to TxRuleError, filling it with
appropriate values throughout the mempool package. This allows clients
of the package to correctly identify error causes with a greater
granularity and respond appropriately.

It also deprecates the RejectCode attribute and ErrToRejectError
functions, to be removed in the next major version update of the
package.

All call sites that inspect mempool errors were updated to use the new
error codes instead of using RejectionCodes. Additional mempool tests
were added to ensure the correct behavior on some relevant cases.

Finally, given the introduction and use of a new public field, the main
module was updated to use an as-of-yet unfinished mempool v3.1.0, which
will include the required functionality.
2019-09-18 14:27:20 -05:00
Donald Adu-Poku
13ee7e50f1 docs: document module breaking changes process.
This adds a section outlining the process to follow
going forward with regards to making breaking changes
to modules.
2019-09-11 11:28:59 -05:00
David Hill
65a467e0cf mining: fix data race
use a local prng variable
2019-09-11 10:35:24 -05:00
David Hill
5604ecd689 travis: bump golangci-lint to v1.18.0 2019-09-11 10:12:04 -05:00
David Hill
78fd2b33a4 mining: fix data race
Use the read template.
2019-09-11 10:11:36 -05:00
Donald Adu-Poku
a05c85008d rpcserver: update rpcAskWallet rpc set.
This updates the rpc ask wallet set with missing entries.
The set has been ordered alphabetically and some
entries have been removed because they are yet to be
implemented by the wallet.
2019-09-11 09:48:11 -05:00
Dave Collins
2b0f3ceeab
mining: Remove unused error codes. 2019-09-09 13:28:44 -05:00
Dave Collins
cffc300c6a
mining: Minor cleanup of aggressive mining path.
This combines the two conditions for the aggressive mining path into a
single condition and does a bit of light cleanup to remove the template
copies that are no longer necessary due to the removal of the old style
template caching.
2019-09-09 12:19:53 -05:00
Dave Collins
280ccb732c
mining: Remove unused extra nonce update code.
This removes the UpdateExtraNonce function which updated an extra nonce
in the coinbase transaction and recalculated the merkle root since it is
not necessary and wasteful for Decred due to the extra nonce being
available the block header.

Further, due to the aforementioned and the fact the template doesn't
have a height set, it isn't currently actually being called anyway as
can be seen by diffing the decoded output of subsequent getwork calls
and noting the only thing that is being updated in between full
regeneration of new templates is the timestamp as expected.

$ diff -uNp work1.txt work2.txt
--- work1.txt   2019-09-07 08:18:58.410917100 -0500
+++ work2.txt   2019-09-07 08:19:01.216456300 -0500
@@ -16,7 +16,7 @@
     "sbits": 0.00021026,
     "height": 98,
     "size": 7221,
-    "time": 1567862338,
+    "time": 1567862341,
     "nonce": 0,
     "extradata": "0000000000000000000000000000000000000000000000000000000000000000",
     "stakeversion": 0,
2019-09-09 11:57:29 -05:00
Dave Collins
48c0585e6b
mining: Remove dead code.
This removes all of the code related to setting and updating cached
templates in the block manager since they are no longer used.

It is easy to see this is the case by considering that the only places
that set cachedCurrentTemplate and cachedParentTemplate set them to nil.
2019-09-09 11:51:04 -05:00
Donald Adu-Poku
45888b8bcd rpcserver: don't use activeNetParams.
This modifies all of the RPC code to use the chain
parameters that are associated with the RPC server
instead of the global activeNetParams and thus
moves one step closer to being able to split the
RPC server out into a separate package.
2019-09-09 09:43:37 -05:00
Jamie Holdstock
2f0c4ecada docs: Link to btc whitepaper on decred.org
We already host the whitepaper on decred.org, so no need to link to
bitcoin.org.
2019-09-08 07:52:56 -05:00
Josh Rickmar
9eed83b813 rpcserver: Match tx filter on ticket commitments
When a transaction is checked for relevance to a websocket client with
a loaded transaction filter, a call to ExtractPkScriptAddrs is not
enough.  Commitments in tickets are encoded in an OP_RETURN output
which require an additional parse of the script to check for a
committed P2PKH or P2SH HASH160.
2019-09-05 22:30:40 -05:00
David Hill
0781162661 multi: remove unused funcs and vars 2019-09-05 10:13:18 -05:00
Donald Adu-Poku
1e7fe1fe31 multi: use chain ref. from blockmanager config.
This removes the chain field from the block
manager in favour of the chain field in the
block manager config.
2019-09-05 10:13:01 -05:00
Donald Adu-Poku
1bae334dd9 multi: remove getblocktemplate.
This removes the getblocktemplate and its helpers from the codebase.
Ongoing mining updates focused on the voting/block validation process
 with respect to generating block templates  for getwork makes it the
better option for decred.  Also getblocktemplate rpc was buggy and
has been disabled for a while.

Some lint related issues have been addressed as well.
2019-09-05 09:23:56 -05:00
Dave Collins
38203c8f4d
travis: Test go1.13 and drop go1.11. 2019-09-03 15:08:35 -05:00
Dave Collins
fefb993956
peer: Ensure listener tests sync with messages.
This adds an additional read from the ok channel in the peer listener
tests to ensure the version message is consumed as well as the verack so
that the remaining tests line up with the messages that are being tested.
2019-09-03 12:24:38 -05:00
Dave Collins
2d09391768
blockchain: Cleanup subsidy cache init order.
This modifies the order in which the subsidy cache is created when not
provided by a caller to happen before the blockchain instance is created
to be more consistent.
2019-09-03 11:38:45 -05:00
Donald Adu-Poku
a80134fa29 multi: make rebroadcast winners & missed ws only. 2019-09-03 11:36:44 -05:00
Donald Adu-Poku
baac7efb44 multi: update limited user rpcs. 2019-09-03 10:41:52 -05:00
Dave Collins
2c3a4e3054
gcs: Implement version 2 filters.
This implements new version 2 filters which have 4 changes as compared
to version 1 filters:

- Support for independently specifying the false positive rate and
  Golomb coding bin size which allows minimizing the filter size
- A faster (incompatible with version 1) reduction function
- A more compact serialization for the number of members in the set
- Deduplication of all hash collisions prior to reducing and serializing
  the deltas

In addition, it adds a full set of tests and updates the benchmarks to
use the new version 2 filters.

The primary motivating factor for these changes is the ability to
minimize the size of the filters, however, the following is a before and
after comparison of version 1 and 2 filters in terms of performance and
allocations.

It is interesting to note the results for attempting to match a single
item is not very representative due to the fact the actual hash value
itself dominates to the point it can significantly vary due to the very
low ns timings involved.  Those differences average out when matching
multiple items, which is the much more realistic scenario, and the
performance increase is in line with the expected values.  It is also
worth nothing that filter construction now takes a bit longer due to the
additional deduplication step.  While the performance numbers for filter
construction are about 25% larger in relative terms, it is only a few ms
difference in practice and therefore is an acceptable trade off for the
size savings provided.

benchmark                      old ns/op    new ns/op    delta
-----------------------------------------------------------------
BenchmarkFilterBuild50000      16194920     20279043     +25.22%
BenchmarkFilterBuild100000     32609930     41629998     +27.66%
BenchmarkFilterMatch           620          593          -4.35%
BenchmarkFilterMatchAny        2687         2302         -14.33%

benchmark                      old allocs   new allocs   delta
-----------------------------------------------------------------
BenchmarkFilterBuild50000      6            17           +183.33%
BenchmarkFilterBuild100000     6            18           +200.00%
BenchmarkFilterMatch           0            0            +0.00%
BenchmarkFilterMatchAny        0            0            +0.00%

benchmark                      old bytes    new bytes    delta
-----------------------------------------------------------------
BenchmarkFilterBuild50000      688366       2074653      +201.39%
BenchmarkFilterBuild100000     1360064      4132627      +203.86%
BenchmarkFilterMatch           0            0            +0.00%
BenchmarkFilterMatchAny        0            0            +0.00%
2019-09-03 10:30:31 -05:00
Donald Adu-Poku
b8864c39dc multi: update rpc documentation.
This adds missing documentation for rpcs
and orders them alphabetically.
2019-09-02 11:01:38 -05:00
Dave Collins
eab0e4c2a7
blockchain: Refactor best chain state init.
This refactors the best chain state and block index loading code into
separate functions so they are available to upcoming database update
code to build version 2 gcs filters.
2019-09-02 01:24:23 -05:00
Aaron Campbell
adff6a0bac cpuminer: Fix off-by-one issues in nonce handling.
During 32-bit nonce iteration, if a block solution wasn't found, the
iterator variable would overflow back to 0, creating an infinite loop,
thus continuing the puzzle search without ever updating the extra
nonce field.  This bug has never been triggered in practice because
the code in question has only ever been used with difficulties where
a solution exists within the regular nonce space.

The extra nonce iteration logic itself was also imperfect in that it
wouldn't test a value of exactly 2^64 - 1.

The behavior we actually want is to loop through the entire unsigned
integer space for both the regular and extra nonces, and for this
process to continue forever until a solution is found.  Note that
periodic updates to the block header timestamp during iteration ensure
that unique hashes are generated for subsequent generations of the
same nonce values.
2019-08-26 11:09:05 -05:00
Dave Collins
cb79063ef8
gcs: Add tests for bit reader/writer. 2019-08-22 11:37:53 -05:00
Dave Collins
952bd7bba3
gcs: Support independent fp rate and bin size.
This modifies the code to support an independent false positive rate and
Golomb coding bin size.  Among other things, this permits more optimal
parameters for minimizing the filter size to be specified.

This capability will be used in the upcoming version 2 filters that will
ultimately be included in header commitments.

For a concrete example, the current version 1 filter for block 89341 on
mainnet contains 2470 items resulting in a full serialized size of 6,669
bytes.  In contrast, if the optimal parameters were specified as
described by the comments in this commit, with no other changes to the
items included in the filter, that same filter would be 6,505 bytes,
which is a size reduction of about 2.46%.  This might not seem like a
significant amount, but consider that there is a filter for every block,
so it really adds up.

Since the internal filter no longer directly has a P parameter, this
moves the method to obtain it to the FilterV1 type and adds a new test
to ensure it is returned properly.

Additionally, all of the tests are converted to use the parameters while
retaining the same effective parameters to help prove correctness of the
new code.

Finally, it also significantly reduces the number of allocations
required to construct a filter resulting in faster filter construction
and reduced pressure on the GC and does some other minor consistency
cleanup while here.

In terms of the reduction in allocations, the following is a before and
after comparison of building filters with 50k and 100k elements:

benchmark                    old ns/op    new ns/op     delta
--------------------------------------------------------------
BenchmarkFilterBuild50000    18095111     15680001     -13.35%
BenchmarkFilterBuild100000   31980156     31389892     -1.85%

benchmark                    old allocs   new allocs   delta
--------------------------------------------------------------
BenchmarkFilterBuild50000    31           6            -80.65%
BenchmarkFilterBuild100000   34           6            -82.35%

benchmark                    old bytes    new bytes    delta
--------------------------------------------------------------
BenchmarkFilterBuild50000    1202343      688271       -42.76%
BenchmarkFilterBuild100000   2488472      1360000      -45.35%
2019-08-22 10:33:25 -05:00
Dave Collins
3305fcb3fa
gcs: Group V1 filter funcs after filter defs.
This simply rearranges the funcs so they are more logically grouped in
order to provide cleaner diffs for upcoming changes.  There are no
functional changes.
2019-08-22 10:31:47 -05:00
Dave Collins
b67fb74fbc
gcs: Optimize Hash.
This optimizes the Hash method of gcs filters by making use of the new
zero-alloc hashing funcs available in crypto/blake256.

The following is a before and after comparison:

benchmark       old ns/op   new ns/op    delta
-------------------------------------------------
BenchmarkHash   1786        1315         -26.37%

benchmark       old allocs  new allocs   delta
-------------------------------------------------
BenchmarkHash   2           0            -100.00%

benchmark       old bytes   new bytes    delta
-------------------------------------------------
BenchmarkHash   176         0            -100.00%
2019-08-22 10:22:08 -05:00
Dave Collins
6b9f78e58e
gcs: Add benchmark for filter hashing. 2019-08-22 10:22:04 -05:00
Aaron Campbell
8be96a8729 multi: Correct typos.
Correct typos found by reading code, ispell, and creative grepping.
2019-08-22 10:20:03 -05:00
Dave Collins
665ab37c68
gcs: Standardize serialization on a single format.
Currently, the filters provide two different serialization formats per
version.  The first is the raw filter bytes without the number of items
in its data set and is implemented by the Bytes and FromBytesV1
functions.  The second includes that information and is implemented by
the NBytes and FromNBytesV1 functions.

In practice, the ability to serialize the filter independently from the
number of items in its data set is not very useful since that
information is required to be able to query the filter and, unlike the
other parameters which are fixed (e.g. false positive rate and key), the
number of items varies per filter.  For this reason, all usage in
practice calls NBytes and FromNBytesV1.

Consequently, this simplifies the API for working with filters by
standardizing on a single serialization format per filter version which
includes the number of items in its data set.

In order to accomplish this, the current Bytes and FromBytesV1 functions
are removed and the NBytes and FromNBytesV1 functions are renamed to
take their place.

This also updates all tests and callers in the repo accordingly.
2019-08-22 09:50:29 -05:00