Commit Graph

5910 Commits

Author SHA1 Message Date
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
Dave Collins
ed51788eb8
txscript: Test consistency and cleanup.
This updates several of the tests in the script_test.go file to be more
consistent with the format used throughout the vast majority of the
other tests in the package.

The following is an overview of the changes:

- Use more compact format for the test definition tables
- Update the tests to make use of the short form script parsing logic
  rather than manually defining byte slices
- Move the logic for testing various canonical integer and data pushes
  into their respective test funcs
- Add names to the individual test conditions
- Update test failure output to be more consistent
2021-10-14 16:45:27 -05:00
Dave Collins
b77b43b71b
txscript: Add versioned short form parsing.
This adds the ability for the short form script parsing to handle
different script versions and updates all of the tests to use the
version 0 function appropriately.
2021-10-14 16:13:28 -05:00
Ryan Staudt
2f5d6828d5 blockchain: Conditionally log difficulty retarget.
This updates the difficulty retarget logs to only be logged if the chain
believes it is current.  These logs are otherwise very noisy when
syncing headers with the debug log level set.
2021-10-14 12:41:22 -05:00
Ryan Staudt
0529d87a9f addblock: Fix blockchain initialization.
This updates the addblock command to create UtxoBackend and UtxoCache
instances, which are required for initializing the blockchain.
2021-10-14 12:39:55 -05:00
Ryan Staudt
dd077881c3 addblock: Run index subscriber as a goroutine. 2021-10-14 12:39:55 -05:00
Ryan Staudt
1096c2946a findcheckpoint: Fix blockchain initialization.
This updates the findcheckpoint command to create UtxoBackend and
UtxoCache instances, which are required for initializing the blockchain.
2021-10-14 10:47:36 -05:00
Donald Adu-Poku
6f4158262a multi: copy snapshot pkScript.
This refactors finding the lowest index tip height out of CatchUp into
findLowestIndexTipHeight. The prevscripter snapshot now makes copies of
the pkScript to avoid holding on to references too long during the
catch up process.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
66ef012b79 multi: remove spend deps on index disc. notifs.
This integrates the spend pruner's RemoveSpendConsumerDependency method
in the chaing query adapter to allow consumers access to the
functionality. The address index has been updated as such to remove its
spend journal dependencies when it processes block disconnections.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
0c11ab5bd9 multi: avoid using subscriber lifecycle in catchup.
This updates the index subscriber catchup function to update
subscriptions directly with notification instead of going through the
Run lifecycle process which avoids a case of receiving out of sync
index notifications while catch up is in progress.

Multiple typos in error type tests and review issues have also been
fixed in this commit.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
9b9381c7f5 cmd/addblock: update block importer.
This updates the blockImporter to use an IndexSubscriber in order to
leverage async indexes.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
cf6c0470b2 internal/rpcserver: wait for sync on rpc request.
This updates rpc handlers to wait for their associated indexes to sync
if needed before responding to a request.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
77033596a1 multi: integrate index subscriber.
This removes last set of references to IndexManager and integrates the
IndexSubscriber into the chain. All indexes have now been updated to
subscribe to the index subscriber for updates.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
86953c4c0d indexers: async exists address index.
This reworks the ExistsAddressIndex to implement the updated Indexer
interface for asynchoronous index updates. This index subscribes with
no prerequisites.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
35a230790c indexers: update address index.
This updates the AddressIndex to implement the updated Indexer
interface for index updates. The index however subscribes with the
transaction index as a prerequisite.

This also adds the spend consumer for use by indexers that need to
lookup spend journal entries.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
eeaa6d71dc indexers: async transaction index.
This reworks the TransactionIndex to implement the updated Indexer
interface for asynchoronous index updates. This index subscribes with
no prequisites.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
3e1090e0cc indexers: refactor interfaces.
This removes the IndexManager interface and reworks the ChainQueryer
and Indexer interfaces to facilitate index notification subscriptions
and asynchronous index notifications.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
81c42c78cf indexers: add index subscriber.
This adds the IndexSubscriber which allows subscribing for index
notifications as well as specifying an index notification dependency
or prerequisite for a subscriber.
2021-10-12 18:52:50 -05:00
Donald Adu-Poku
ec3472b23a indexers: remove index manager.
This removes index manager and moves helper functions defined with the
manager to common.go.
2021-10-12 18:52:50 -05:00
Ryan Staudt
931a579e12 blockchain: Handle genesis auto revocation agenda.
This updates the IsAutoRevocationsAgendaActive function to return false
for the genesis block.
2021-10-05 16:07:07 -05:00
JoeGruffins
7b184ab3fd
rpctest: Remove unused BlockVersion const. 2021-09-25 10:49:31 -05:00
Ryan Staudt
207f895349 mempool: Add tests with auto revocations enabled.
This adds tests to ensure that revocations are accepted and rejected by
the mempool as expected with the automatic ticket revocations agenda
enabled.
2021-09-20 18:02:19 -05:00
Ryan Staudt
20300ed0bc mining: Add auto revocation block template tests.
This adds tests to ensure that creating new block templates works as
expected when the automatic ticket revocations agenda is enabled.
2021-09-20 18:02:19 -05:00
Ryan Staudt
16b3d5ce02 blockchain: Add auto revocation validation tests.
This adds tests to ensure that all of the validation rules associated
with the automatic ticket revocations agenda work as expected.
2021-09-20 18:02:19 -05:00
Ryan Staudt
45a02b0093 blockchain: Add checkTicketRedeemers tests.
This adds full test coverage for the checkTicketRedeemers function to
ensure that all ticket redeemer consensus rule checks work as expected.
2021-09-20 18:02:19 -05:00
Ryan Staudt
db7b0decfd blockchain: Add calcTicketReturnAmounts tests.
This adds full test coverage for the calcTicketReturnAmounts function
to ensure that ticket return amounts are calculated correctly under a
variety of conditions.
2021-09-20 18:02:19 -05:00
Ryan Staudt
75c9844599 multi: DCP0009 Auto revocations consensus change.
This introduces automatic ticket revocations as defined in DCP0009,
including:
- Allowing tickets to be revoked by anyone instead of requiring a valid
  signature from the voting address
- Requiring blocks to contain ticket revocation transactions for all
  tickets that become missed or expired as of that block

An overview of the changes is as follows:

- blockchain/scriptval.go
  - ValidateTransactionScripts, checkBlockScripts
    - Skip script validation for version 2 revocations if the automatic
      ticket revocations agenda is active
- blockchain/stake/staketx.go, blockchain/stake/staketx_test.go
  - Introduce TxVersionAutoRevocations const for version 2 revocations
  - CalculateRewards, CalculateRevocationRewards
    - Add CalculateRevocationRewards to handle the required updates for
      revocations while leaving CalculateRewards as-is for votes
    - If the automatic ticket revocations agenda is active, and there is
      a remainder after distributing the returns, then select a
      uniformly pseudorandom output index to receive each remaining
      atom
    - Add additional tests to cover the new code paths
  - CheckSSRtx
    - Add checks to ensure that the input does not have a signature
      script and does not have a fee if the automatic ticket revocations
      agenda is active
    - Add additional tests to cover the new code paths
- blockchain/validate.go, blockchain/validate_test.go
  - checkTransactionContext
    - Add rule that revocation transactions MUST be version 2 if the
      automatic ticket revocations agenda is active.
  - checkTicketRedeemers
    - Add rule that if the automatic ticket revocations agenda is
      active, then the block MUST contain revocation transactions for
      all tickets that will become missed or expired as of that block
    - Add rule that if the automatic ticket revocations agenda is
      active, then revocations can spend tickets that will become missed
      or expired as of that block (previously they could not be spent
      until the block following the block where they became missed or
      expired)
    - Update to accept the referenced ticket hashes rather than the
      overall block to simplify adding comprehensive unit tests for the
      function
  - calcTicketReturnAmounts
    - Update to calculate the amounts for all outputs rather than a
      single output
    - For revocations, if the automatic ticket revocations agenda is active,
      and there is a remainder after distributing the returns, then select a
      uniformly pseudorandom output index to receive each remaining
      atom
  - checkTicketRedeemerCommitments
    - Add rule that if the transaction is a version 2 revocation and the
      automatic ticket revocation agenda is active, then the fee MUST be
      zero
    - Use the updated calcTicketReturnAmounts function so that returns
      include the full amount, which allows for ensuring a truly zero
      fee
  - checkRevocationInputs
    - Add rule that if the automatic ticket revocations agenda is
      active, then revocations can spend tickets after ticket maturity
      + 1 blocks (in the block that they become missed or expired)
      rather than after ticket maturity + 2 blocks (in the block AFTER
      they become missed or expired)
- internal/mempool/mempool.go, internal/mempool/mempool_test.go
  - Pass best block header to CheckTransactionInputs
  - Pass isAutoRevocationsEnabled to ValidateTransactionScripts
- internal/mining/mining.go, internal/mining/mining_harness_test.go,
  internal/mining/mining_test.go, internal/mining/mining_view_test.go
  - Add a helper function, createRevocationFromTicket, to create a
    revocation transaction from a ticket hash
  - If the automatic ticket revocations agenda is active, then create
    version 2 revocation transactions for all tickets that will become
    missed or expired as of the block being created
  - Create and insert these revocations into the priority queue AFTER
    votes are done being added to ensure that revocations are added for
    votes that fail validation checks or are otherwise not included into
    the block
  - Pass best block header to CheckTransactionInputs
  - Pass isAutoRevocationsEnabled to ValidateTransactionScripts
- internal/rpcserver/interface.go, internal/rpcserver/rpcserver.go,
  internal/rpcserver/rpcserverhandlers_test.go
  - handleCreateRawSSRtx
    - If the automatic ticket revocations agenda is active:
      - Validate that the fee is zero
      - Set the transaction version to 2
    - Pass previous header bytes and isAutoRevocationsEnabled flag to
      CreateRevocationFromTicket in order to create version 2 revocation
      transactions properly with the updated rules
    - Add additional tests to cover the new code paths
- server.go
  - Pass previous block header to CheckTransactionInputs
  - Pass isAutoRevocationsEnabled to ValidateTransactionScripts
2021-09-20 18:02:19 -05:00
Ryan Staudt
7bedd7dc0a mempool: Add HeaderByHash to Config.
This adds a HeaderByHash method to the mempool Config.  This will be
used as part of the automatic ticket revocations changes in a subsequent
commit.
2021-09-20 18:02:19 -05:00
Ryan Staudt
08921f6e46 mining: Add HeaderByHash to Config.
This adds a HeaderByHash method to the mining Config.  This will be used
as part of the automatic ticket revocations changes in a subsequent
commit.
2021-09-20 18:02:19 -05:00
Dave Collins
563e89099e
build/contrib: Improve docker support.
This significantly reworks the docker support to provide build a
lightweight non-root distroless container image based on scratch.  It
employs a multi-stage build that downloads and builds the latest source
code, compresses the resulting binaries, and then produces the final
image based on scratch that only includes the Decred-specific binaries.

It must be noted that there are some still remaining TODO items in the
documentation as well as the Dockerfile that will need to be handled by
a future commit, but the changes are being submitted now to allow
another contributor to finish up those aspects.

The following is an overview of the changes:

- Removes existing Dockerfile and Dockerfile.alpine
- Introduces a new Dockerfile under contrib/docker with the following
  properties:
  - Runs as a non-root user
  - Uses a static UID:GID of 10000:10000
    - Note that using UIDs/GIDs below 10000 for container users is a
      security risk on several systems since a hypothetical attack which
      allows escalation outside of the container might otherwise
      coincide with an existing user's UID or existing group's GID which
      has additional permissions
  - The image is based on scratch image (aka completely empty) and only
    includes the Decred-specific binaries which means there is no shell
    or any other binaries available if an attacker were to somehow
    manage to find a remote execution vulnerability exploit in a Decred
    binary
- Introduces code to build an entrypoint for the image since it is based
  on scratch and thus has no shell for that purpose
- Adds contrib/docker/README.md
- Updates README.md in the main directory to account for changes
  - There is still outstanding work to be done here and thus has several
    TODOs
- Updates contrib/README.md to call out the new addition
2021-09-18 13:17:41 -05:00
Dave Collins
0457b3809c
blockchain: workSorterLess -> betterCandidate.
This renames the workSorterLess function to betterCandidate and reverses
the semantics accordingly.

It was originally named workSorterLess because it doubled as the less
function for a sorting implementation, but the sorting component was
removed in favor of just finding the best candidate.  Also, the function
considers more than cumulative work for making the determination
(although cumulative work is the most important and primary criteria),
so it makes more sense to rename the function to more closely match its
intended purpose.
2021-09-17 19:26:16 -05:00
Naveen
e22b4e4b4d
build: Pin GitHub Actions to SHA.
* The actions tags can be moved. So pinned the actions based on SHA.
 https://julienrenaux.fr/2019/12/20/github-actions-security-risk/
2021-09-17 11:26:59 -05:00
Ryan Staudt
7474441bbe multi: Update gcs prerel version.
This modifies some recently-updated modules to use a valid gcs
prerelease version so they can be used in require statements in consumer
code that is also under development.

The updated direct dependencies are as follows:

- github.com/decred/dcrd/gcs/v3 v3.0.0-20210916172859-ca03de05ecd0
2021-09-16 13:16:21 -05:00
Ryan Staudt
ca03de05ec gcs: Prerel module release ver updates.
This modifies the recently-updated gcs module to use a valid prerelease
version of the blockchain/stake module so it can be used in require
statements in consumer code that is also under development.

The updated direct dependencies are as follows:

- github.com/decred/dcrd/blockchain/stake/v4 v4.0.0-20210906140327-598bf66f24a6
2021-09-16 12:28:59 -05:00
Dave Collins
9428512e77
docs: Update for new modules.
This updates the main README.md file, module hierarchy graphviz, and
module hierarchy diagram to reflect new modules introduced.
2021-09-16 11:12:51 -05:00
Ryan Staudt
b59ccb10b3 blockchain: Fix several typos. 2021-09-16 11:10:08 -05:00
Ryan Staudt
c578cbd0b1 blockchain: Prerel module release ver updates.
This modifies the recently-updated blockchain module to use a valid
prerelease version of the blockchain/stake and chaincfg modules so it
can be used in require statements in consumer code that is also under
development.

The updated direct dependencies are as follows:

- github.com/decred/dcrd/blockchain/stake/v4 v4.0.0-20210906140327-598bf66f24a6
- github.com/decred/dcrd/chaincfg/v3 v3.0.1-0.20210906134819-8c0e8616ebda
2021-09-16 11:08:11 -05:00
Donald Adu-Poku
723d86274b multi: synchronize spend prunes and notifications.
- This updates the spend pruner to use a single notification
channel to keep the order and processing of connectiong
and disconnections deterministic.
- The process lock is now held when spend journal entries
being removed by the pruner to ensure.
- The spend pruners lifecycle process uses an unbuffered
channel to recieve and process notifications. Notifications are
sent via goroutines to avoid blocking as a result.
- Comment related wrapping issues have been resolved.
2021-09-14 16:26:51 -05:00
Donald Adu-Poku
95bc8d0270 multi: add spend pruner.
This adds a spend journal pruner to the blockchain.
Associated tests have also been added.
2021-09-14 16:26:51 -05:00
Dave Collins
2efb9bda71
dcrjson: Prepare v4.0.0.
This updates the dcrjson module dependencies, the copyright year in the
files modified since the previous release and serves as a base for
dcrjson/v4.0.0.

The updated direct dependencies in this commit are as follows:

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

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

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

Finally, all modules in the repository are tidied to ensure they are
updated to use the latest versions hoisted forward as a result.
2021-09-14 14:30:33 -05:00
Dave Collins
1eac4b6260
docs: Update for dcrjson v4 module.
This updates the various README.md files, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version.
2021-09-14 14:30:31 -05:00
Dave Collins
bd94ed5ee9
secp256k1: Prepare v4.0.0.
This updates the secp256k1 copyright year in the files modified since
the previous release and serves as a base for dcrec/secp256k1/v4.0.0.

There are no updated direct dependencies in this commit.

The following direct dependencies are no longer required as compared to
the previous dcrec/secp256k1/v3.0.0 release:

- github.com/decred/dcrd/chaincfg/chainhash
2021-09-14 14:23:26 -05:00
Dave Collins
c715b8e308
docs: Update for secp256k1 v4 module.
This updates the various README.md files, module hierarchy graphviz, and
module hierarchy diagram to reflect the new module version and the
removal of the chaincfg/chainhash dependency.
2021-09-14 14:23:23 -05:00
Dave Collins
99c8255da3
dcrjson: Introduce v4 module.
The current latest code for dcrjson already has breaking changes
compared to the last release and was unfortunately not preceded by
starting a new major version module per the standard process.

Fortunately, the two modules in this repo that use dcrjson, namely
rpcclient and rpc/json/rpctypes, use any of its types directly in their
public API nor have any replacements to the code that contains the
changes that require a new major version, so neither require a major
version bump as a result.

Therefore, this is able to mostly follow the process for introducing
major API breaks as follows:

- Bump the major version in the go.mod of the affected module if not
  already done since the last release tag
- Add a replacement to the go.mod in the main module if not already done
  since the last release tag
- Update all imports in the repo to use the new major version as
  necessary
- Make necessary modifications to allow all other modules to use the new
  version in the same commit
2021-09-14 13:38:54 -05:00
Dave Collins
a547a7a17f
blockchain: Remove inapplicable comment.
It looks like this was leftover from development, but it no longer
applies in any case.
2021-09-14 13:34:31 -05:00