Commit Graph

5246 Commits

Author SHA1 Message Date
Dave Collins
7a67caa4fb
docs: Update for blockchain/standalone v2 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version and the
removal of the chaincfg dependency.
2020-09-30 11:23:33 -05:00
Dave Collins
69e46f99cc
standalone: Misc comment consistency cleanup. 2020-09-30 11:20:55 -05:00
Dave Collins
ee391c90f8
standalone: Add IsTreasuryBase tests. 2020-09-30 11:20:55 -05:00
Dave Collins
bb1c2a6764
standalone: Add InsideTSpendWindow tests. 2020-09-30 11:20:54 -05:00
Dave Collins
943b2a8fbe
standalone: Rework and add CalcTSpendExpiry tests. 2020-09-30 11:20:54 -05:00
Dave Collins
ab42d8d814
standalone: Add IsTreasuryVoteInterval tests. 2020-09-30 11:20:54 -05:00
Dave Collins
fee0eefb54
standalone: IsTVI code consistency pass.
This improves the accuracy of the comment on the IsTreasuryVoteInterval
function and also makes all code related to it more consistent with the
rest of the codebase.
2020-09-30 11:20:53 -05:00
Dave Collins
ea6a7aa69e
standalone: Rename CalcTSpendExpiry.
This renames CalculateTSpendExpiry to CalcTSpendExpiry so it is more
consistent with all the other funcs in the package which are prefixed
with Calc and updates the comment accordingly along with correcting some
typos.

It also updates all of the callers in the repo accordingly.
2020-09-30 11:20:50 -05:00
zhizhong
94cd10e24a
contrib: More restrictive dcrd service privileges. 2020-09-30 02:42:18 -05:00
Ryan Staudt
b6884166a3 rpcserver: Fix race in TestHandleTSpendVotes.
This fixes a race that occurs when running TestHandleTSpendVotes test
cases in parallel.  It fixes the race by specifying a new *dcrutil.Block
per test since *dcrutil.Block can't be safely shared across goroutines.
2020-09-29 14:19:10 -05:00
Dave Collins
94a87b73cf
hdkeycahin: Prepare v3.0.0.
This updates the hdkeychain module dependencies, the copyright year in
the files modified since the previous release, and serves as a base for
hdkeychain/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0

The full list of updated direct dependencies since the previous
hdkeychain/v2.1.0 release are as follows:

- github.com/decred/base58@v1.0.3
- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/crypto/blake256@v1.0.0
- github.com/decred/dcrd/crypto/ripemd160@v1.0.1
- github.com/decred/dcrd/dcrec/secp256k1/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0

Further, the following dependencies that were required in the previous
hdkeychain/v2.1.0 release are no longer required:

- github.com/decred/dcrd/chaincfg/chainhash
2020-09-29 12:11:10 -05:00
Dave Collins
cf2a9f5976
docs: Update for hdkeychain v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version and the
removal of the chaincfg dependency.
2020-09-29 12:11:07 -05:00
Dave Collins
bf57746c3b
standalone: Introduce CalcTSpendWindow.
This existing code for calculating treasury spend window values, namely
CalculateTSpendWindowStart and CalculateTSpendWindowEnd, has a couple of
footguns:

- The starting value calculation returns totally invalid values without
  an error when provided with a expiry that is prior to the first voting
  window
- Expiry values that are invalid for the start calc are valid for the
  end calc even though they should not be

As a result, the code for handling the error paths in the rpc server and
mining code produces error messages that don't make sense in some cases
because they blindly print the start value without checking the error.

To remove the aforementioned footguns and also address the incorrect
error messages, the following overview of changes are made:

- Replaces the CalculateTSpendWindowStart and CalculateTSpendWindowEnd
  functions with a single combined CalcTSpendWindow function that
  properly checks for expiries before the first possible voting interval
- Modifies the returned errors to match the new reality
- Shortens the prefix to Calc to match the rest of the function names in
  the package
- Updates the incorrect error handling paths to avoid reporting the
  values that are not guaranteed to be meaningful and modifies the error
  messages to be more consistent
- Adds a comprehensive set of tests for the new function

Note that in addition to addressing the aforementioned issues, this
approach has at least a couple of other benefits:

- It is more efficient to have a single function with a single bounds
  check
- Almost all callers outside of the tests need both the start and end
  value anyway, so it allows more compact code

Finally, this updates all callers in the repository accordingly.
2020-09-29 11:32:13 -05:00
Dave Collins
e6c0a43e84
standalone: Retain coinbase detection semantics.
This modifies the IsCoinBaseTx function to retain the existing semantics
regarding coinbase detection logic once the treasury agenda activates.

Specifically, the existing consensus logic regarding the fast heuristic
for detecting whether or not a transaction is likely to be coinbase has
no restrictions regarding the number of outputs nor the the lengths of
the scripts.

Later, once a coinbase is actually validated by consensus, it is
required to have a payout to the treasury as well as a provably-prunable
output that identifies the block height.

This means that it is technically possible for a miner to create a
coinbase that burns coins if they so choose, even though, in practice,
it is exceedingly unlikely.

Since the new treasury spend transaction type looks similar enough to
existing coinbase transactions, they are also detected as coinbases
under the existing code.

To combat this, the new treasury code introduces logic which consists of
exempting transactions that look like treasury spends from being
identified as a coinbase.  Unfortunately, the logic reports that a
transaction is not a coinbase when _any_ of the conditions that lead up
to the transaction being identified as a treasury spend are met instead
of when _all_ of the conditions are met.

The result is that the aforementioned semantics are changed which should
not be the case.

This resolves that by modifying the logic accordingly such that the
heuristic retains the same semantics for all transactions that are not
specifically identified to likely be a treasury spend.

It also adds tests to ensure the new behavior works as intended bringing
the test coverage of the function back up to 100%.
2020-09-29 11:16:08 -05:00
Dave Collins
20889d0842
database: Prepare v2.0.2.
This updates the database module dependencies and serves as a base for
database/v2.0.2.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0
- github.com/decred/slog@v1.1.0
- github.com/syndtr/goleveldb@v1.0.1-0.20200815110645-5c35d600f0ca

The full list of updated direct dependencies since the previous
dcrutil/v2.0.1 release are as follows:

- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0
- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0
- github.com/syndtr/goleveldb@v1.0.1-0.20200815110645-5c35d600f0ca

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2020-09-28 12:50:29 -05:00
Dave Collins
0ae1634cff
blockchain/standalone: Remove txscript dep.
The purpose of the standalone module is to avoid extra dependencies.
The treasury work unfortunately went against that goal and introduced a
dependency on txscript.  This remedies that by defining the necessary
opcodes directly which is perfectly acceptable because they are used in
consensus code and thus can't be changed without a vote.
2020-09-27 21:31:42 -05:00
Donald Adu-Poku
acedac5085 multi: update blockchain/standalone error types.
This updates the standalone error types to leverage go
1.13 errors.Is/As functionality as well as conform
to the error infrastructure best practices.
2020-09-27 21:30:48 -05:00
David Hill
6fc441fb42 dcrd: trickle mempool response to peer.
QueueInventory also has the benefit of skipping known inventory.
2020-09-27 14:03:53 -05:00
David Hill
e46e0d2165 rpcclient: Update unreleased requires to master
This should fix consumers requiring the rpcclient module at dcrd
master. Previously, this would fail, due to various undefined
treasury types, which has not been released.
2020-09-27 14:02:22 -05:00
Dave Collins
a34e4204cc
txscript: Prepare v3.0.0.
This updates the txscript module dependencies and serves as a base for
txscript/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0
- github.com/decred/slog@v1.1.0

The full list of updated direct dependencies since the previous
txscript/v2.1.0 release are as follows:

- github.com/dchest/siphash@v1.2.1
- github.com/decred/dcrd/chaincfg/v3@v3.0.0
- github.com/decred/dcrd/crypto/ripemd160@v1.0.1
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.1
- github.com/decred/dcrd/dcrec/secp256k1/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v3@v3.0.0
- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0

Finally, all modules in the repository that depend on txscript are
tidied to ensure they are updated to use the latest versions hoisted
forward as a result.
2020-09-26 13:26:40 -05:00
Dave Collins
9dbd555d20
docs: Update for txscript v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version and the
removal of the chaincfg dependency.
2020-09-26 13:25:25 -05:00
Ryan Staudt
7de1958979 rpcserver: Add searchrawtransactions count limit.
This adds a reasonable limit to the maximum number of transactions that
can be requested through searchrawtransactions.
2020-09-26 12:11:15 -05:00
Dave Collins
db0c4bd165
rpc/jsonrpc/types: Prepare v2.1.0.
This updates the rpc/jsonrpc/types module dependencies, the copyright
year in the files modified since the previous release, and serves as a
base for rpc/jsonrpc/types/v2.1.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/dcrjson@v3.1.0

The full list of updated direct dependencies since the previous
rpc/jsonrpc/types/v2.0.0 release are as follows:

- github.com/decred/dcrd/dcrjson@v3.1.0

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2020-09-26 11:16:08 -05:00
Matheus Degiovani
1a977a64ec multi: Fix treasury-related comments 2020-09-25 20:16:08 -05:00
Matheus Degiovani
2c50fdc415 blockchain: Remove need to RLock some treasury funcs
This removes the need to RLock() the blockchain index when calling
tSpendCountVotes() and sumPastTreasuryExpenditure() by switching the
lookupNode call for a direct reference to the parent node while
iterating the chain backwards.
2020-09-25 20:16:08 -05:00
Dave Collins
a8272f876d
dcrutil: Prepare v3.0.0.
This updates the dcrutil module dependencies and serves as a base for
dcrutil/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/crypto/ripemd160@v1.0.1
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.1
- github.com/decred/dcrd/dcrec/secp256k1/v3@v3.0.0

The full list of updated direct dependencies since the previous
dcrutil/v2.0.1 release are as follows:

- github.com/decred/base58@v1.0.3
- github.com/decred/dcrd/crypto/ripemd160@v1.0.1
- github.com/decred/dcrd/dcrec/edwards/v2@v2.0.1
- github.com/decred/dcrd/dcrec/secp256k1/v3@v3.0.0
- github.com/decred/dcrd/wire@v1.4.0

Further, the following dependencies that were previously required in the
dcrutil/v2.0.1 release are no longer required:

- github.com/decred/dcrd/chaincfg/v2

Finally, all modules in the repository that depend on dcrutil are tidied
to ensure they are updated to use the latest versions hoisted forward as
a result.
2020-09-25 16:00:44 -05:00
Dave Collins
59c3692a6b
docs: Update for dcrutil v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version and the
removal of the chaincfg dependency.
2020-09-25 16:00:39 -05:00
Dave Collins
d48bce9f4f
dcrutil: Update example to avoid chaincfg dep.
This modifies the example to make use of mock parameters instead of
actual parameters from chaincfg in order to avoid the otherwise
unnecessary dependency on it.
2020-09-25 15:46:31 -05:00
Dave Collins
8e82835f78
dcrutil: Cleanup verify tests and use mock params.
This cleans up the tests for verify message and also modifies them to
use the available mock parameters to avoid an otherwise unnecessary dep
on chaincfg.
2020-09-25 14:31:25 -05:00
Dave Collins
637bad557d
chaincfg: Prepare v3.0.0.
This updates the chaincfg module dependencies and serves as a base for
chaincfg/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/wire@v1.4.0

The full list of updated direct dependencies since the previous
chaincfg/v2.3.0 release are as follows:

- github.com/decred/dcrd/wire@v1.4.0

Further, the following dependencies that were previously required in the
previous chaincfg/v2.3.0 release are no longer required:

- github.com/decred/dcrd/dcrec/edwards/v2
- github.com/decred/dcrd/dcrec/secp256k1/v2
2020-09-25 13:53:10 -05:00
Dave Collins
4612a0a12c
docs: Update for chaincfg v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2020-09-25 13:53:10 -05:00
Dave Collins
f7af0ddb01
multi: Update chaincfg dependers to wire/v1.4.0. 2020-09-25 13:50:06 -05:00
Dave Collins
4bf2df3451
config: Consolidate error reporting.
This modifies the initial configuration error handling logic to avoid a
bunch of duplicate code and fix some cases that were not logging the
errors as expected.

It accomplishes this by consolidating the error reporting in a single
place in the caller and introducing a custom error type which signals
that the usage message should be suppressed in order to retain the
primary behavior the originally was the reason for the prints being in
the config function to begin with.

Also, the application name is passed into the function now since it is
needed in both places.
2020-09-25 12:44:37 -05:00
Dave Collins
1e44e8674b
rpcserver: Forward HTTP server err msgs to logger.
The standard library HTTP server writes all errors using standard error
by default when and error logger is not configured.  Currently, an error
logger is not being set which means the errors completely bypass the
logging system.

Since the required error logger must be from the standard library
logging package and a custom logger is used instead, this creates a shim
to forward the log messages from a standard lib logger to the RPC server
logger and configures the HTTP server to use it accordingly.
2020-09-25 12:40:02 -05:00
Dave Collins
3ec740163c
docs: Update for dcrec/secp256k1/v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2020-09-25 12:33:15 -05:00
Dave Collins
3cc3fa6bbf
connmgr: Prepare v3.0.0.
This updates the connmgr module dependencies and serves as a base for
connmgr/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0

The full list of updated direct dependencies since the previous
connmgr/v2.1.0 release are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0
2020-09-25 12:21:48 -05:00
Dave Collins
0c9c0687eb
docs: Update for connmgr v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2020-09-25 12:21:47 -05:00
Dave Collins
0ecab1bc63
addrmgr: Prepare v1.2.0.
This updates the addrmgr module dependencies, the copyright year in the
files modified since the previous release, and serves as a base for
addrmgr/v1.2.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0

The full list of updated direct dependencies since the previous
addrmgr/v1.1.0 release are as follows:

- github.com/decred/dcrd/wire@v1.4.0
- github.com/decred/slog@v1.1.0
2020-09-25 12:14:00 -05:00
Dave Collins
db58bb306c
dcrjson: Prepare v3.1.0.
This updates the copyright year in the files modified since the previous
dcrjson/v3.0.1 release and serves as a base for dcrjson/v3.1.0.
2020-09-25 12:06:26 -05:00
Dave Collins
84d59c01ac
chaincfg: Update min known chain work for release.
This updates the minimum known chain work values for the main and test
networks as follows:

mainnet: 0x00000000000000000000000000000000000000000013e6909b5a73128d52fc6f
testnet: 0x000000000000000000000000000000000000000000000000e41955f181d00f59
2020-09-25 11:51:35 -05:00
Dave Collins
1d134a2125
chaincfg: Add checkpoints for upcoming release.
This adds checkpoints at the following heights:

mainnet:

- 237310
- 277940
- 318020
- 340120
- 362120
- 404170
- 424170
- 444170
- 464170
- 483600

testnet:

- 148320
- 213120
- 347140
- 411940
- 476740
- 515730

Note that this also includes some historical checkpoints to limit the
size of the gaps between each checkpoint to be around 3 months max.
This is being done because recent optimizations have sped up processing
to the point that larger gaps can trigger peers to get banned during IBD
in some cases.
2020-09-25 11:49:00 -05:00
Matheus Degiovani
1ddab08c53 rpctest: Make votingwallet txs standard
Tickets and votes were being issued with tx version 0, which is
non-standard.
2020-09-24 15:21:48 -05:00
Ryan Staudt
df141bbff3 txscript: Proactively evict SigCache entries.
This adds functionality to proactively evict SigCache entries when they
are nearly guaranteed to no longer be useful.  It accomplishes this by
evicting entries related to transactions in the block that is 2 levels
deep from a newly processed block.

Proactively evicting entries reduces the likelihood of the SigCache
reaching maximum capacity quickly and then relying on random eviction,
which may randomly evict entries that are still useful.
2020-09-24 12:19:59 -05:00
Ryan Staudt
380c8d512b txscript: Store short tx hash in sigcache.
This adds a uint64 short transaction hash to sigcache entries.  This can
be used to proactively evict entries from the sigcache based on the
transaction that they are associated with.
2020-09-24 12:19:59 -05:00
Ryan Staudt
349822959a txscript: Add shortTxHash.
This defines a shortTxHash method that generates a short 64-bit hash
from the standard 128-bit hash.  It accomplishes this by using the
SipHash-2-4 hash function.

This is being introduced to track the transaction associated with a
signature cache entry at a reduced memory overhead.
2020-09-24 12:19:59 -05:00
Matheus Degiovani
56257e00d2 rpcserver: Verify tbase values in treasury rpctest
This adds assertions to the existing treasury rpctest to verify that
treasury base transactions have the correct value even when the block
containing them has less than the maximum allowed of vote (SSGen)
transactions.
2020-09-24 12:19:12 -05:00
Matheus Degiovani
be15f2de6f rpctest: Add ability to limit VotingWallet votes
This adds the ability for the voting wallet to limit the total number of
votes issued, which is useful for some testing scenarios involving
blocks with less than the maximum number of votes.

Due to how the rpctest VotingWallet is currently structured
(specifically, the fact that it only tracks the absolute minimum amount
of tickets to advance the chain) it can't keep advancing the chain
indefinitely after limiting the number of votes for some blocks.

This is less than ideal, but sufficient for the tests that will be
introduced in future commits.
2020-09-24 12:19:12 -05:00
Matheus Degiovani
1de796404f docs: Add missing gettreasurybalance documentation
This adds documentation for the gettreasurybalance RPC call, which was
missing on the original treasury commit.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
d57d5156b2 rpcserver: Assert vote counts in treasury rpctest
This adds assertions in the TestTreasury rpctest that verify the correct
behavior of the recently introduced gettreasuryspendvotes rpc command.

It also serves to ensure vote tallying of the underlying blockchain
corresponds to the expected ones.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
c7f58531ca rpcserver: Add support for gettreasuryspendvotes
The new gettreasuryspendvotes rpc command is useful to keep track of the
voting progress of treasury spend transactions as well as to query for
the status of old tspends.

When invoked without any parameters, the command tallies the vote counts
for all tspends currently in the node's mempool up to the current tip
block.

The first parameter ("Blocks") can be used to limit the block up to
which the tallies are performed, which is useful for historical queries.

The second parameter ("TSpends") can be used to narrow down the list of
tspends that should be queried. It can be used to query for tspends that
have already been mined.

A set of unit tests ensures proper behavior for the new command.
2020-09-24 11:46:21 -05:00