Commit Graph

5927 Commits

Author SHA1 Message Date
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
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