Commit Graph

5954 Commits

Author SHA1 Message Date
Dave Collins
def72f32f3
stdscript: Add ProvablyPruneableScriptV0.
This adds a function to generate a provably pruneable version 0 script
that is considered standard since the equivalent variant of it is
eventually going to be removed from txscript given it is a standardness
construct as opposed to a consensus rule.
2021-11-16 17:46:42 -06:00
Dave Collins
8bdccd19d1
stdscript: Add exported MaxDataCarrierSizeV0.
This adds an exported constant for the maximum allowed size of version 0
nulldata scripts to be considered standard and makes use of it instead
of the one from txscript since the constant is eventually going to be
removed from txscript given it is purely a standardness construct as
opposed to a consensus rule.
2021-11-16 17:46:38 -06:00
Ryan Staudt
2cd3941f7b mempool: Test fraud proof handling.
This adds tests to validate that the fraud proof of transaction inputs
is corrected as necessary when entering the mempool under a variety of
conditions.
2021-11-16 12:11:03 -06:00
Ryan Staudt
9bd8d8cb89 mempool: Add blockHeight to AddFakeUTXO for tests.
This adds a blockHeight parameter to the AddFakeUTXO test function so
that it can be mocked rather than always being set to
wire.NullBlockIndex.
2021-11-16 12:11:03 -06:00
Ryan Staudt
1353c8da2f mempool: CheckTransactionInputs check fraud proof.
This updates mempool to now set the check fraud proof flag to true for
blockchain.CheckTransactionInputs since mempool now ensures that the
fraud proof is correct for all transaction inputs prior to this check.
2021-11-16 12:11:03 -06:00
Ryan Staudt
6f3629816b mempool: Update fraud proof data.
This updates the fraud proof data on transaction inputs as necessary
when entering the mempool.  The fraud proof data will ultimately get
filled in properly when miners create a block template.  However,
ensuring that it is filled in properly when entering the mempool is
beneficial so that it is correct when relaying the transaction or
returning it from an RPC API.
2021-11-16 12:11:03 -06:00
Ryan Staudt
7d0f5c0073 mempool: Update test to check hash value.
This updates a mempool test to compare the values of hashes rather than
the pointers as intended.
2021-11-16 12:11:03 -06:00
Donald Adu-Poku
a885d08a78 indexers: synchronize index subscriber ntfn sends/receives.
This synchronizes sends and receives for the index subscriber
by selecting over the quit channel for the subscriber when
calling Notify.
2021-11-15 21:23:24 -06:00
Ryan Staudt
2d7af6b635 multi: Use dcrutil Tx in NewTxDeepTxIns.
This updates dcrutil.NewTxDeepTxIns to take a dcrutil.Tx as a parameter
rather than a wire.MsgTx, which allows for the tree and index set on the
input dcrutil.Tx to be copied to the new dcrutil.Tx.

This is less error prone for callers since the existing implementation
is often used to replace an existing dcrutil.Tx with the deep copy that
this function creates, but a side effect that is easy to miss is that
the new dcrutil.Tx would have reset the tree and index fields which
can lead to unintended behavior.
2021-11-15 20:20:14 -06:00
Ryan Staudt
ab887c0d70 mining: Remove unnecessary tx copy.
This removes an unnecessary transaction copy in the mining code.  It is
not needed since all of the regular transactions have already been
copied prior to this point.
2021-11-15 16:24:28 -06:00
Dave Collins
2b760c17e3
multi: Address some linter complaints.
This makes the following changes pointed out by linting:

- Uses ++ instead of += 1 for incrementing the expiry in mempool test
  code
- Removes an unused function in the rpc test code
- No need to specify variable type since it is inferred
2021-11-15 16:18:41 -06:00
Dave Collins
ac76e08adf
rpc/jsonrpc/types: Prepare v3.0.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/v3.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/dcrjson/v4@v4.0.0

The full list of updated direct dependencies since the previous
rpc/jsonrpc/types/v2.3.0 release are the same as above.
2021-11-11 14:53:34 -06:00
Dave Collins
664f18b86f
docs: Update for rpc/jsonrpc/types v3 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-11-11 14:53:25 -06:00
Dave Collins
debbf873eb
addrmgr: Prepare v2.0.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/v2.0.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/wire@v1.5.0
- github.com/decred/slog@v1.2.0

The full list of updated direct dependencies since the previous
addrmgr/v1.2.0 release are the same as above.

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2021-11-11 13:31:52 -06:00
Dave Collins
fbc87ac8cb
docs: Update for addrmgr v2 module.
This updates the docs/README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-11-11 13:31:52 -06:00
Dave Collins
adab1d21d4
chaincfg: Prepare v3.1.0.
This updates the chaincfg module dependencies and serves as a base for
chaincfg/v3.1.0.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/chainhash@v1.0.3
- github.com/decred/dcrd/wire@v1.5.0

The full list of updated direct dependencies since the previous
chaincfg/v3.0.0 release are the same as above.

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2021-11-11 13:23:10 -06:00
Ryan Staudt
58c9224445 blockchain: Handle zero-length UTXO backend state.
This updates FetchState for the UTXO backend to return nil if the
serialized state in the database has zero-length.  This is not expected
in normal circumstances, however, due to a bug in upgrade code in a
previous commit, it could end up this way.
2021-11-11 13:08:54 -06:00
Ryan Staudt
8e25000b70 blockchain: UTXO database migration fix.
This fixes an edge case within the UTXO database migration logic.  In
the upgrade that migrates the UTXO data to use simple key prefixes
rather than buckets, old entries will still be copied to the new
location even if they are nil, which incorrectly creates an empty entry
in the new location.
2021-11-11 13:08:54 -06:00
Dave Collins
6daa1a709a
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: 0x0000000000000000000000000000000000000000001d987ec2c7f4bc1199489e
testnet: 0x000000000000000000000000000000000000000000000000e419ae4d750d4484
2021-11-11 12:37:56 -06:00
Dave Collins
c3368c5298
chaincfg: Update checkpoint for upcoming release.
This updates the checkpoints to the blocks at the heights as follows:

mainnet: 601900
testnet: 803810
2021-11-11 12:05:19 -06:00
Dave Collins
3a458e1490
peer: Offset ping interval from idle timeout.
This modifies the ping interval to be defined in terms of the default
idle timeout such that it is shorter and relatively prime to it to help
prevent undesirable disconnects in higher latency scenarios.
2021-11-10 15:47:09 -06:00
Dave Collins
1487c03b53
blockchain: Correct treasury spend vote data.
This adds code to correct the ticket database and block index treasury
spend vote data due to the issue in FindSpentTicketsInBlock described by
the previous commit.

It involves unwinding all of the blocks from the current tip back to the
known good point in the ticket database and replaying them to apply the
the correct information to the various buckets in the ticket database as
well as the relevant entries in the block index.  The process can be
interrupted at any point and future invocations will resume from the
point it was interrupted.

Also, since the next release of the software will include a vote to
change the consensus rules, all of the blocks previously marked as
having failed validation need to be unmarked so they are eligible for
which ensures clients that did not update prior to new rules activating
are able to automatically recover under the new rules without having to
download the entire chain again.

Since both cases require a database version bump, this takes advantage
of the database version bump to do both a single version bump.
2021-11-10 07:32:13 -06:00
Dave Collins
e53d26e01d
stake: Correct treasury enabled vote discovery.
This modifies FindSpentTicketsInBlock to also properly detect votes that
include information to vote on treasury spends as intended.

It should be noted that this commit only corrects the function and the
issue does not affect consensus in a way that could lead to an
unintended fork.

However, the incorrect behavior does mean the stake ticket database and
block index now have invalid entries in them that will be corrected via
a database migration in a separate commit.

More specifically, the behavior has resulted in the ticket database
incorrectly marking the associated tickets as missed instead of voted,
but that information is only used for serving RPC data.  The live ticket
pool is still accurate and all votes and payouts are unaffected.

Further, the associated data in the block index is only used when
tallying vote information and since an upgrade is required before a new
vote can start anyway, it will necessarily be resolved prior to that
point.
2021-11-10 07:32:11 -06:00
Dave Collins
e430a7fe45
wire: Write message header directly.
This modifies the message writing code that writes out message headers
to write the fields directly instead of creating a copy of the data
first.

The primary motivation for this change is that the hdr.command field is
assigned and never used in the existing code because the size-limited
array variant of the command field is used instead when writing the
elements.  Since that field is unused, rather than creating a local
partially-filled message header, and copying data into it only to turn
around and write that data immediately, it makes more sense to just
write the data directly.
2021-11-10 07:27:31 -06:00
Dave Collins
5ae5760010
version: Use uint32 for major/minor/patch.
This modifies the semver handling to specifically use uint32 instead of
architecture-dependent uint so bounds checking is consistent across
architectures and only needs to be done in one place.
2021-11-10 07:08:23 -06:00
Ryan Staudt
ade6c7380c blockchain: Remove flags maybeAcceptBlockHeader.
This removes the flags param from the maybeAcceptBlockHeader function in
blockchain since it is now passed in as BFNone in all instances.  The
appropriate flags will now be determined internally within blockchain.
2021-11-10 06:59:19 -06:00
Ryan Staudt
8b5618ed59 multi: Remove flags from ProcessBlockHeader.
This removes the flags param from the ProcessBlockHeader function in
blockchain since it is now passed in as BFNone in all instances.  The
appropriate flags will now be determined internally within blockchain.
2021-11-10 06:58:53 -06:00
Ryan Staudt
402eba3477 multi: Remove flags from blockchain ProcessBlock.
This removes the flags param from the ProcessBlock function in
blockchain since it is now passed in as BFNone in all instances.  The
appropriate flags will now be determined internally within blockchain.
2021-11-10 06:56:24 -06:00
Ryan Staudt
147ffbc583 netsync: Remove flags from processBlockMsg.
This removes the flags param from processBlockMsg and processBlock in
SyncManager since it  is passed in as BFNone in all instances.  The
appropriate flags will be determined internally within blockchain.
2021-11-10 06:56:24 -06:00
Ryan Staudt
040c22b5f1 multi: Remove flags from SyncManager ProcessBlock.
This removes the flags param from ProcessBlock in SyncManager since it
is passed in as BFNone in all instances.  The appropriate flags will be
determined internally within blockchain.
2021-11-10 06:56:24 -06:00
Ryan Staudt
022e587e23 addblock: Use chain bulk import mode.
This updates the block importer to enable bulk import mode on the chain
rather than passing in the blockchain.BFFastAdd parameter when
processing each block.
This will allow the blockchain.BehaviorFlags parameter to be removed
from the process block function in a subsequent commit.
2021-11-09 22:30:07 -06:00
Ryan Staudt
c3e1031717 blockchain: Add bulk import mode.
This adds a bulk import mode that provides a mechanism to indicate that
several validation checks can be avoided when bulk importing blocks
already known to be valid.  It will be used by the block importer in a
subsequent commit.

This provides an alternative mechanism to the current solution of
passing a BehaviorFlags parameter around, which is inconvenient and
makes it harder to determine where flags are being set.
2021-11-09 22:30:07 -06:00
Ryan Staudt
03ddfd45ab blockchain: Update a few BFFastAdd comments.
This updates a few comments related to the BFFastAdd flag to accurately
represent the current behavior.
2021-11-09 22:29:13 -06:00
Donald Adu-Poku
8f5270b707 sampleconfig: update rpc credentials documentation.
This updates the sample config documentation related to rpc credentials
to indicate they are only needed if the authorization type is basic.
2021-11-05 21:36:46 -05:00
Donald Adu-Poku
e1ef614185 config: conditionally generate rpc credentials.
This updates the config to only generate random rpc credentials
when the authorization type is basic.
2021-11-05 21:36:46 -05:00
Dave Collins
ec6a4a8d66
blockchain: Further decouple upgrade code.
This modifies the upgrade code related to block index entries to further
decouple it from the primary code base to help ensure legacy upgrade
paths remain stable as the primary code evolves.

The addition of the separate version 3 block index bits will also be
useful in future upgrade code as well.
2021-11-03 14:07:46 -05:00
Dave Collins
1eff7272fd
secp256k1: Correct 96-bit accum double overflow.
This corrects the internal 96-bit accumulator used during modular
reduction over the curve order (ModNScalar) to properly handle the case
when both words of the multi-word addition overflow and adds accumulator
tests for all potential overflow conditions to ensure correctness.
2021-11-03 06:56:47 -05:00
Dave Collins
7368e0d791
blockchain: Remove unused next lottery data func.
This removes NextLotteryData since it is no longer used by anything now
that the information is available via the best state snapshot.
2021-10-30 13:30:58 -05:00
Dave Collins
5108035c52
blockchain: Remove unused latest blk locator func.
This removes LatestBlockLocator since it is no longer used by anything
now that the desired hashes are always known from having all of the
headers available.
2021-10-30 13:30:12 -05:00
Dave Collins
f5663dd603
blockchain: Use new ancestor of convenience func.
This updates the various blockchain call sites that deal with
determining if a node is an ancestor (or descendant) to make use of the
new IsAncestorOf convenience func.
2021-10-29 12:37:24 -05:00
Dave Collins
b816f16545
blockchain: Add convenience ancestor of func.
This adds a convenience func to block nodes named IsAncestorOf for
determining whether or not a node is an ancestor of a given target node
along with tests to ensure proper functionality.
2021-10-29 12:37:06 -05:00
Ryan Staudt
8fd2406b11 blockchain: Fix ticket db disconnect revocations.
This addresses an issue in the ticket database when disconnecting a
block that contains an automatic revocation.

When the automatic ticket revocations agenda is enabled, a ticket can
become missed and revoked in the same block.  When connecting that block
to the ticket database, this is recorded as two separate entries in the
undo data (the first moving it to missed, and the second moving it to
revoked).  Therefore, when disconnecting the block, the undo data needs
to be applied in reverse order.
2021-10-28 03:13:27 -05:00
jholdstock
a5be90a2d1 blockchain: Don't use deprecated ioutil package.
Replace usage of ioutil.TempDir with os.MkdirTemp as suggested by go 1.16
release notes.
2021-10-28 03:13:14 -05:00
Ryan Staudt
22316ade85 multi: Flush cache before fetching UTXO stats.
This updates the UTXO cache to flush all entries to the backend before
UTXO stats are fetched.  This ensures that the UTXO stats are always in
sync with the current best block.

This also does not impact the effectiveness of the UTXO cache since
entries are still only evicted if necessary.
2021-10-22 06:28:06 -05:00
Donald Adu-Poku
0076cea6ff server: fix wireToAddrmgrNetAddress data race.
This fixes a data race for the network address passed into
wireToAddrmgrNetAddress.
2021-10-20 06:43:40 -05:00
Donald Adu-Poku
cdf881d9ce multi: source index notif. from block notif.
This updates the index subscriber to use block notifications as the
source of index notifications.
2021-10-19 21:46:51 -05:00
Donald Adu-Poku
5c74266e3b multi: update build tags to pref. go1.17 syntax. 2021-10-19 20:21:44 -05:00
Dave Collins
c98c610def
blockchain: Move diff retarget log to connect.
The method that calculates the next required difficulty currently logs
difficulty retargets which means it has side effects when it really
should free from them given its purpose.

This can be evidenced by the fact the logging is actually slightly
incorrect in a couple of ways due to those side effects.  Namely, it can
potentially log when checking block templates when it shouldn't and it
is also currently logging when the headers are connected as opposed to
when the blocks themselves are actually connected which was the original
intention prior to the new headers-first logic.

Thus, this moves the debug logging for difficulty retargets from the
required difficulty calculation function to the block connection
function and also takes the opportunity to impose a new condition to
only log when the difficulty actually changes as opposed to the current
behavior of always logging on a retarget interval regardless.
2021-10-19 20:07:30 -05:00
Ryan Staudt
73c33c79e2 multi: Use single latest checkpoint.
This updates the blockchain checkpoints logic to use a single latest
checkpoint rather than multiple checkpoints.  The intermediate
checkpoints are no longer necessary because headers first syncing was
introduced, which discovers the most recent checkpoint before block
syncing even starts.
2021-10-15 21:05:28 -05:00
Ryan Staudt
53f3e1484b chaincfg: Use single latest checkpoint.
This updates the Checkpoints param for mainnet and testnet to specify a
single latest checkpoint rather than multiple checkpoints.  The
intermediate checkpoints are no longer necessary because headers first
syncing was introduced, which discovers the most recent checkpoint
before block syncing even starts.
2021-10-15 20:32:31 -05:00