Commit Graph

6167 Commits

Author SHA1 Message Date
Dave Collins
5a461dae5c
server: Force PoW upgrade to v9.
This modifies the vote notification logic so that wallets will no longer
vote on mainnet blocks once height 635775 has been reached and the block
version is prior to 9.

This change is being made to make use of the staking system to force
proof-of-work miners to upgrade to the latest version in a timely
fashion so voting on the new consensus changes can commence.
2022-01-20 11:59:38 -06:00
Donald Adu-Poku
dbe244d8c5 server: sync peer handling sends/receives.
This synchronizes sends and receives for peer handling channels by selecting
over the quit channel for the server when sending and closing it when the
peer handler terminates. The peer handler's channel draining block has been
removed as a result.
2022-01-15 12:30:23 -06:00
Dave Collins
79f15b7f72
edwards: More strict pubkey parsing.
This modifies the public key parsing method to make it more strict by
rejecting public keys that are not exactly the required length as
opposed to silently truncating or padding them and adds tests
accordingly.

This helps prevent misuse by callers and makes it behave more
consistently with the secp256k1 public key parsing.

Note that this does not affect consensus code since the only place it is
called is during the signature verification opcode where the consensus
rules ensure the the key is the correct length before parsing it.
2022-01-13 11:28:48 -06:00
Dave Collins
151d21e64f
mining: Use test net block ver on simnet.
This modifies the mining code to produce blocks on the simulation
network with the same block version as other test networks as opposed to
the block version used on the main network.
2022-01-11 15:50:59 -06:00
Josh Rickmar
8525c7d98d contrib: Use bash builtins instead of seq.
seq is not portable (for example, the command is not provided by
OpenBSD and would need to be installed as a package).

Since the script already assumes bash, use the numeric builtins to
iterate NUM times instead of using seq.
2022-01-11 21:36:18 +00:00
Dave Collins
754b7cc287
rpcserver: Update websocket ping timeout handling.
Currently, timeouts when responding to a websocket ping control message
with a pong message cause the websocket client to be disconnected, but
these types of failures are nearly always temporary network errors due
to things such as congestion and thus should not result in
disconnection.

In order to make that the case, this modifies the websocket ping handler
to ignore timeout network errors when attempting to respond with a pong
and also takes this opportunity to increase the timeout to 5 seconds
from 1 second to support multi-continent communication.
2022-01-07 23:10:49 -06:00
Dave Collins
9969b8f306
txscript: Support min int64 script num encoding.
This modifies the encoding logic for script numbers to support encoding
min int64s.  This was previously not supported since the type was not
public and it is not possible to achieve a min int64 within the context
of the script system itself due to the strict limits it imposes.

However, now that script numbers are exported for external use and
callers are not bound by the aforementioned strictness, it should be
possible to encode the entire range for completeness.

In practice, callers should never realistically need to encode the value
since the purpose of the type is to create encoded numbers for scripts
and the value in question will be rejected upon any attempt to use it as
a number when verifying scripts given it is out of range.
2022-01-01 03:14:42 -06:00
Dave Collins
2e8abf6bf3
dcrutil: Limit WIF decode to max possible size.
This modifies DecodeWIF to reject any attempts to decode strings that
are larger than the max possible size early since there is no reason to
waste time and memory doing the base 58 decode when it is guaranteed to
be invalid anyway.

It also adds an associated test to ensure proper functionality.
2022-01-01 03:09:16 -06:00
Dave Collins
d6eebbc57b
dcrutil: Rework WIF tests.
This reworks the WIF tests to provide full coverage for both positive
and negative paths, to test for the explicit reason for the failure to
ensure that each test is actually testing the intended condition, and to
make them more consistent with modern practices in the code.
2022-01-01 03:09:16 -06:00
Dave Collins
e703e2ffe4
hdkeychain: Limit decode to max possible size.
This modifies NewKeyFromString to reject any attempts to decode strings
that are larger than the max possible size early since there is no
reason to waste time and memory doing the base 58 decode when it is
guaranteed to be invalid anyway.

It also adds an associated test to ensure proper functionality.
2022-01-01 03:09:15 -06:00
Dave Collins
1961854e1e
stdaddr: Limit v0 addr decode to max possible size.
This modifies DecodeAddressV0 to reject any attempts to decode strings
that are larger than the max possible size early since there is no
reason to waste time and memory doing the base 58 decode when it is
guaranteed to be invalid anyway.

It also adds an associated test to ensure proper functionality.
2022-01-01 03:09:11 -06:00
Dave Collins
cc74183435
stdscript: Reject multisig neg thresholds.
This modifies the MultiSigScriptV0 convenience func for creating a
multisig script to return an error if the caller improperly calls it
with a negative threshold.
2022-01-01 01:22:07 -06:00
Ryan Staudt
1f679932c4 blockchain: Change tspend pass log level to debug.
This changes the tspend passed log level from info to debug since info
level doesn't typically log this level of detail.
2022-01-01 01:20:12 -06:00
Dave Collins
64aabc0283
release: Bump for 1.8 release cycle. 2021-12-17 17:39:24 -06:00
Dave Collins
9a1062a838
main: Update to use all new module versions.
This updates all code in the main module to use the latest module
versions to pull in the latest updates.
2021-12-17 14:48:51 -06:00
Ryan Staudt
941ec25e6f mining: Update to latest block vers for HFV.
This updates the block versions created by the mining code to produce
the latest versions needed to trigger the hard fork vote for DCP0007,
DCP0008, and DCP0009.
2021-12-17 14:22:48 -06:00
Josh Rickmar
bdee08b7c1 version: Include VCS build info in version string.
VCS build info is only available when built from a VCS checkout using
Go 1.18 or later.
2021-12-17 14:21:21 -06:00
Dave Collins
36ef9c0dae
rpcclient: Prepare v7.0.0.
This updates the rpcclient module dependencies, the copyright year in
the files modified since the previous release, and serves as a base for
rpcclient/v7.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/gcs/v3@v3.0.0
- github.com/decred/dcrd/rpc/jsonrpc/types/v3@v3.0.0

The full list of updated direct dependencies since the previous
rpcclient/v6.0.2 release are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/dcrjson/v4@v4.0.0
- github.com/decred/dcrd/dcrutil/v4@v4.0.0
- github.com/decred/dcrd/gcs/v3@v3.0.0
- github.com/decred/dcrd/rpc/jsonrpc/types/v3@v3.0.0
- github.com/decred/dcrd/txscript/v4@v4.0.0
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

Finally, all modules in the repository that depend on the module are
tidied to ensure they are updated to use the latest versions hoisted
forward as a result.
2021-12-17 13:58:35 -06:00
Dave Collins
57c711cf3c
docs: Update for rpcclient v7 module.
This updates the following to reflect the new module version:

* The rpcclient/README.md file
* The docs/README.md file
* The JSON-RPC API documentation
* The module hierarchy graphviz
* The module hierarchy diagram
2021-12-17 13:58:30 -06:00
Dave Collins
baf32f0cfc
blockchain: Prepare v4.0.0.
This updates the blockchain module dependencies, the copyright year in
the files modified since the previous release, and serves as a base for
blockchain/v4.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/blockchain/stake/v4@v4.0.0
- github.com/decred/dcrd/blockchain/standalone/v2@v2.1.0
- github.com/decred/dcrd/database/v3@v3.0.0
- github.com/decred/dcrd/dcrutil/v4@v4.0.0
- github.com/decred/dcrd/gcs/v3@v3.0.0
- github.com/decred/dcrd/lru@v1.1.1
- github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7

The full list of updated direct dependencies since the previous
blockchain/v3.0.3 release are as follows:

- github.com/decred/dcrd/blockchain/stake/v4@v4.0.0
- github.com/decred/dcrd/blockchain/standalone/v2@v2.1.0
- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/chaincfg/v3@v3.1.0
- github.com/decred/dcrd/database/v3@v3.0.0
- github.com/decred/dcrd/dcrec/secp256k1/v4@v4.0.1
- github.com/decred/dcrd/dcrutil/v4@v4.0.0
- github.com/decred/dcrd/gcs/v3@v3.0.0
- github.com/decred/dcrd/lru@v1.1.1
- github.com/decred/dcrd/txscript/v4@v4.0.0
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0
- github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7

Finally, all modules in the repository that depend on the module are
tidied to ensure they are updated to use the latest versions hoisted
forward as a result.
2021-12-17 13:37:03 -06:00
Dave Collins
b1d6e55f17
docs: Update for blockchain v4 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-12-17 13:27:07 -06:00
Dave Collins
259b51be4b
docs: Update simnet env docs for subsidy split.
This updates the simnet environment documentation to account for the
different expected initial balances due to the subsidy split agenda
since it is always active on simnet.
2021-12-16 12:26:21 -06:00
Dave Collins
e972ac4e84
multi: Implement DCP0010 subsidy consensus vote.
This implements the agenda for voting on the modified subsidy split
defined in DCP0010 along with consensus tests.

In particular, once the vote has passed and is active, the PoW subsidy
will be 10% of the block reward and the PoS subsidy will be 80%.  The
Treasury subsidy will remain at 10%.

In terms of the overall effects, this includes updates to:
- The validation logic for votes, coinbases, and overall block subsidy
- Enforcement when considering candidate votes for acceptance to the
  mempool, relaying, and inclusion into block templates
- Mining template generation
- The output of the getblocksubsidy RPC

Also note that this does not implement the block version bump that will
ultimately be needed by the mining code since there are multiple
consensus votes gated behind it and will therefore be done separately.

The following is an overview of the changes:

- Introduce a convenience function for determining if the vote passed
  and is now active
- Add new methods to blockchain/standalone for calculating the work and
  stake vote subsidies according to either the original or modified
  values per a provided flag
- Modify vote validation to enforce the new stake vote subsidy in
  accordance with the state of the vote
- Modify coinbase validation to enforce the new work subsidy in
  accordance with the state of the vote
- Modify block validation logic to enforce the total overall subsidy in
  accordance with the state of the vote
- Add tests for determining if the agenda is active for both mainnet and
  testnet
- Add tests for getblocksubsidy RPC
- Add tests to ensure proper behavior for the modified subsidy splits as
  follows:
  - Ensure new blockchain validation semantics are enforced once the
    agenda is active
  - Ensure mempool correctly accepts and rejects votes in accordance
    with the state of the vote
2021-12-16 12:26:21 -06:00
Dave Collins
c4d1094a0e
chaingen: Add vote subsidy munger.
This adds a new munger to the test chain generator named
ReplaceVoteSubsidies which modifies a block by replacing the subsidy of
all votes contained in the block to a given value.
2021-12-15 12:07:57 -06:00
Dave Collins
d8527c0443
standalone: Add modified subsidy split calcs.
This adds two new exported functions to the subsidy cache in
blockchain/standalone to calculate calculate the work and stake vote
subsidies according to either the original or modified values defined in
DCP0010 per a provided flag along with tests to ensure expected
behavior.

It should be noted that the values for the modified split are hard coded
as opposed to using the subsidy in order to avoid the need for a major
module bump that would be required if the subsidy params interface were
changed.  The values are the same for all networks, so no additional
logic is necessary on a per-network basis.
2021-12-15 12:07:57 -06:00
Dave Collins
2f2ec08d60
chaincfg: Introduce subsidy split change agenda.
This adds a new definition for the upcoming agenda vote to change the
subsidy split to 10% PoW, 80% PoS, and 10% Treasury defined in DCP0010
along with two new parameters for the modified values.

It does not include any code to make decisions based on the status of
the agenda or bump block versions.  It only adds the definition for the
agenda.
2021-12-14 11:56:39 -06:00
Dave Collins
5b68754a42
mempool: Consolidate tx check flag construction.
This consolidates the logic for constructing the agenda flags to use for
checking transactions into a separate method versus building them inline
in multiple different places.

This makes it easier to add new agendas in the future while keeping the
flags consistent.
2021-12-14 11:16:18 -06:00
Jonathan Chappelow
0673eb5c80 hdkeychain: Add a strict BIP32 child derivation method.
This creates a new ExtendedKey child derivation method, ChildBIP32Std,
which creates an ExtendedKey with leading zeroes retained for strict
compliance with BIP32. This is not intended for Decred wallet use.
2021-12-13 22:46:25 -06:00
Ryan Staudt
c6dc5e05fb multi: Add assumevalid config option.
This adds an assumevalid config option which allows for specifying a
hash of an assumed valid block or disabling assume valid.

The usage is as follows:

* (flag not specified): defaults to the hard-coded value in source
* --assumevalid=0: disable AssumeValid
* --assumevalid=[blockhash]: set AssumeValid to the specified block hash
2021-12-11 01:07:58 -06:00
Ryan Staudt
526d33c873 blockchain: Add AssumeValid tests.
This adds tests that validate that it is correctly determined whether or
not a node is an ancestor of an assumed valid node under a variety of
conditions.
2021-12-11 01:07:58 -06:00
Ryan Staudt
8962ce7f18 blockchain: Bulk import skip script validation.
This updates block validation to not run scripts if bulk import mode is
enabled.  Bulk import mode is only enabled when importing blocks that
are already known to be valid.
2021-12-11 01:07:58 -06:00
Ryan Staudt
23c8ff6385 blockchain: Assume valid skip script validation.
This updates block validation to not run scripts if a block is both an
ancestor of the assumed valid block and an ancestor of the best header.
2021-12-11 01:07:58 -06:00
Ryan Staudt
f41f2798ef blockchain: Set BFFastAdd based on assume valid.
This updates BlockChain to set the BFFastAdd flag if a block is both an
ancestor of the assumed valid block and an ancestor of the best header.

A helper function isAssumeValidAncestor is introduced that determines
whether the provided node is both an ancestor of the assumed valid node
and an ancestor of the best header.  False is returned when the assume
valid node has not been discovered or when assume valid is disabled.

The assumed valid node is clamped back as needed to ensure that it is at
least 2 weeks worth of blocks behind the best header.  This protects
against malicious actors trying to play games by tricking users into
using an assumed valid hash near the tip.
2021-12-11 01:07:58 -06:00
Ryan Staudt
ee4c197d1f blockchain: Track assumed valid node.
This adds tracking of the assumed valid node to BlockChain.  The assumed
valid node will be used in place of checkpoints to set the BFFastAdd
flag in a subsequent commit.
2021-12-11 01:07:58 -06:00
Ryan Staudt
679e4ac5d4 multi: Add assumeValid to BlockChain.
This adds an assumeValid field to BlockChain and sets it based on the
AssumeValid chain parameter.
2021-12-11 01:07:58 -06:00
Ryan Staudt
583c8fdad0 chaincfg: Add AssumeValid param.
This introduces an AssumeValid parameter that is the hash of a block
that has been externally verified to be valid.  In a subsequent commit,
it will be used to allow several validation checks to be skipped for
blocks that are both an ancestor of the assumed valid block and an
ancestor of the best header.

Note that the AssumeValid block hash that is specified for mainnet and
testnet is for the same block that was used for MinKnownChainWork.
Using the same block for both of these slightly simplifies the process
for external verification of the values when they are updated
periodically with new releases.
2021-12-11 01:07:58 -06:00
Dave Collins
3b8efba395
math/uint256: Prepare v1.0.0.
While the original plan was to keep uint256 as a part of the primitives
module, there has been interest in using the uint256 code now and the
primitives module will not be complete and ready for release for quite
some time.

Also, after further discussion, the general preference is for a separate
module that lives at math/uint256 for this code since the primitives
module will ultimately be squarely aimed at Decred-specific things while
math/uint256 is more generally useful, including many projects outside
of Decred as well.

Thus, this moves the new uint256 package from the internal staging area
to math/uint256 where it will serve as a base for a new math/uint256
module release.

Finally, it updates all relevant paths and package README.md
accordingly.
2021-12-09 17:25:56 -06:00
Dave Collins
4aadab7260
docs: Update for math/uint256 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module.
2021-12-09 17:25:55 -06:00
Dave Collins
a29d9339db
uint256: Correct base 10 output formatting.
The corrects a formatting issue where the base 10 output is not always
printing the expected results.

It also adds a test which triggers the condition as well as a new
randomized test to compare the output of random values against the big
int output for all of the supported bases.
2021-12-09 17:17:35 -06:00
Donald Adu-Poku
3bcb7d9c14 internal/staging: add ban manager.
This refactors peer banning functionality and ban score tracking into a
ban manager. Associated tests have been added.
2021-12-09 17:02:01 -06:00
Dave Collins
44d5aea13e
mining: Prevent unnecessary reorg with equal votes.
This corrects the logic related to preventing unnecessary reorgs in the
function that sorts parents based the number of votes available for them
and the current tip block and adds tests to ensure proper functionality.
2021-12-08 18:29:42 -06:00
Ryan Staudt
1c40d5abe8 blockchain: Wrap at max line length.
This updates several files to wrap lines at 80 columns, with tabs
counted as 4 columns, unless it makes sense to be longer for
readability purposes.
2021-12-08 18:25:38 -06:00
Ryan Staudt
fa3518bb2c docs: Add max line length and wrapping guidelines.
This adds maximum line length and wrapping guidelines to the code
contribution guidelines documentation.
2021-12-08 18:25:38 -06:00
Ryan Staudt
4d25573b77 docs: Fix typos and trailing whitespace.
This fixes a few typos and removes trailing whitespace.
2021-12-08 18:25:38 -06:00
Dave Collins
08528c28b7
netsync: Remove unused tx submission processing.
This removes the code related to submitting transactions through the
network sync manager since it is no longer used.
2021-12-05 02:58:49 -06:00
Dave Collins
df67eca18e
rpcserver: Submit transactions directly.
This modifies the adaptor that the RPC server uses for transaction
submission to process the transaction directly instead of piping through
the netsync package.  There is no longer any reason to incur the extra
overhead since the mempool is concurrent safe the initial reasons for
piping it through netsync no longer apply.  This can be seen by noting
that the net sync manager doesn't do anything except call the mempool
method.
2021-12-05 02:58:48 -06:00
Dave Collins
71b0a793ba
rpcserver: Rename var to make linter happy. 2021-12-05 02:58:48 -06:00
Donald Adu-Poku
daf6c25c9f indexers: update indexer error types.
This updates the wire error types to leverage go 1.13 errors.Is/As
functionality as well as confirm to the error infrastructure best
practices outlined in #2181.
2021-12-05 01:38:15 -06:00
Dave Collins
17ded215f3
primitives: Add inclusion proof benchmarks.
BenchmarkGenerateInclusionProof
-------------------------------
64_leaves     31101     38577 ns/op    2240 B/op   2 allocs/op
128_leaves    15512     77140 ns/op    4320 B/op   2 allocs/op
256_leaves     7999    155127 ns/op    8448 B/op   2 allocs/op
2048_leaves     975   1237867 ns/op   65888 B/op   2 allocs/op

BenchmarkVerifyInclusionProof
-----------------------------
64_leaves     333319   3999 ns/op   0 B/op   0 allocs/op
128_leaves    287670   4187 ns/op   0 B/op   0 allocs/op
256_leaves    249007   4841 ns/op   0 B/op   0 allocs/op
2048_leaves   181994   6683 ns/op   0 B/op   0 allocs/op
2021-12-04 17:57:18 -06:00
Dave Collins
9bda0b173a
primitives: Add inclusion proof funcs.
This adds new functions for generating and verifying inclusion proofs
along with associated tests.

The functions are direct ports of the functions of the same names from
blockchain/standalone.

It also updates the documentation.
2021-12-04 17:57:15 -06:00