Commit Graph

5841 Commits

Author SHA1 Message Date
Ryan Staudt
170ba4fc99 multi: Add auto revocations to agenda flags.
This adds AFAutoRevocationsEnabled to blockchain.AgendaFlags, which may
be set to indicate that the automatic ticket revocations agenda should
be considered as active when checking a transaction so that any
additional checks which depend on the agenda being active are applied.

Additionally, this updates all references of blockchain.AgendaFlags to
set AFAutoRevocationsEnabled if the automatic ticket revocations agenda
is active.
2021-09-06 08:48:19 -05:00
Ryan Staudt
83e21aad6e multi: Add mempool IsAutoRevocationsAgendaActive.
This adds an IsAutoRevocationsAgendaActive function to mempool.Config,
which returns whether the automatic ticket revocations agenda is active
or not.
2021-09-06 08:48:19 -05:00
Ryan Staudt
a1435bdb20 blockchain: Test auto revocations deployment.
This adds tests to ensure the deployment of the automatic ticket
revocations agenda activates as expected.
2021-09-06 08:48:19 -05:00
Ryan Staudt
b011118040 blockchain: Check auto revocations agenda state.
This adds functionality to check whether or not the automatic ticket
revocations agenda vote is active.
2021-09-06 08:48:19 -05:00
Ryan Staudt
8c0e8616eb chaincfg: Add agenda for auto ticket revocations.
This adds a new definition for the upcoming agenda vote to enable
automatic ticket revocations as defined in DCP0009.
2021-09-06 08:48:19 -05:00
Ryan Staudt
83d32a4ec0 stake: Export Hash256PRNG UniformRandom. 2021-09-06 08:48:19 -05:00
Ryan Staudt
fcf3f08345 stake: Add CheckSSRtx tests.
This adds full test coverage for CheckSSRtx and updates the existing
tests to follow the newer standard.
2021-09-06 08:48:19 -05:00
Ryan Staudt
e6bc7e5a82 stake: Add CalculateRewards tests.
This adds tests to ensure that ticket output amounts are calculated
correctly under a variety of conditions.

Additionally, it cleans up the code, naming, and documentation to be
more consistent with the consensus code that defines the rules that this
is following.
2021-09-06 08:48:19 -05:00
Dave Collins
4aad374556
mempool: Remove unneeded max tx ver std checks.
This removes the handling for a configurable maximum allowed transaction
version via the standardness policy since it is now enforced via
consensus rules instead.

The following is an overview of the changes:

- Remove the MaxTxVersion field from the Policy struct
- Remove the max tx version checking logic from checkTransactionStandard
- Remove the max tx version param from checkTransactionStandard
- Update the transaction standardness tests accordingly
- Update all callers accordingly
2021-09-06 08:05:45 -05:00
Dave Collins
c1dc9162f5
mempool: Enforce explicit versions.
This adds enforcement of the newly introduced explicit version upgrade
requirements when considering candidate transactions for acceptance to
the mempool, relaying, and inclusion into block templates.

This is acceptable because the aforementioned areas only enforce policy.
Also of note is that the existing policy already rejected transactions
via the standardness policy that will now be rejected at a consensus
level.

It also adds tests to ensure the new enforcement works as intended.
2021-09-06 08:05:45 -05:00
Dave Collins
562aaf1307
blockchain: Implement reject new script vers vote.
This implements the agenda for voting on rejecting new script versions
until they have explicitly been enabled by a consensus rule change as
defined in DCP0008 along with consensus tests.

In particular, once the vote has passed and is active, script versions
greater than 0 will no longer be accepted.

Note that this does not implement block version bumps in the mining and
validation code that will ultimately be needed since another consensus
vote is expected to land before voting begins.

The following is an overview of the changes:

- Modify block validation to enforce the rejection of newer script
  versions in accordance with the state of the vote
- Add tests to ensure proper behavior for new script versions as follows:
  - Ensure stake transactions still require version 0 scripts regardless
    of the state of the agenda
  - Regular transactions with script versions newer than 0 are rejected
    once the agenda is active
  - Transaction outputs that have a non-zero output and script that
    would make the output unspendable if it were version 0 are spendable
    with a nil signature script both before the agenda is active and
    remain spendable after it is active
2021-09-06 08:05:44 -05:00
Dave Collins
adfab345b1
blockchain: Implement reject new tx vers vote.
This implements the agenda for voting on rejecting new transaction
versions until they have explicitly been enabled by a consensus rule
change as defined in DCP0008 along with consensus tests.

In particular, once the vote has passed and is active, transaction
versions greater than 3 will no longer be accepted.

This does not include the script version portion of the DCP as that will
be done in a future commit.  This implies that it is important for both
this commit and the aforementioned future commit to be merged at the
same time.

Also note that this does not implement block version bumps in the mining
and validation code that will ultimately be needed since another
consensus vote is expected to land before voting begins.

The following is an overview of the changes:

- Introduce a convenience function for determining if the vote passed
  and is now active
- Modify block validation to enforce the rejection of newer transaction
  versions in accordance with the state of the vote
- Add tests for determining if the agenda is active for both mainnet and
  testnet
- Add tests to ensure proper behavior for new transaction versions as follows:
  - New regular and stake transaction versions are rejected once the
    agenda is active
  - Existing regular and stake outputs created with newer tx versions
    are spendable before the agenda is active and remain spendable after
    it is active
2021-09-06 08:05:44 -05:00
Dave Collins
48775ed50a
blockchain: 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-09-06 08:05:39 -05:00
Dave Collins
8830d9c9cd
docs: Add accuracy and reliability to README.md.
This adds some additional text to the section regarding why running a
full node is desirable to specifically call out that it is also ideal
for providing the most reliable and accurate data about transactions.
2021-09-01 10:27:45 -05:00
Dave Collins
7e5fa8fe11
database: Correct README rpcclient link. 2021-09-01 10:18:45 -05:00
Dave Collins
8a125449c1
docs: Correct generate description. 2021-09-01 10:13:44 -05:00
jholdstock
960f9e8895 docs: Update go versions in README.md
Since the release of go 1.17, the supported versions listed in the
README should be 1.16 and 1.17.
2021-09-01 06:09:37 -05:00
jholdstock
43dfb5529a build: Don't manually test changing go.{mod,sum}.
As of go 1.16, "go build" and "go test" now exit with an error rather
than silently modifying go.mod or go.sum files. As a result, we don't
need to manually check for altered mod/sum files in the test script.
2021-09-01 06:09:37 -05:00
jholdstock
e3f7f58a68 multi: Don't use deprecated ioutil package.
As of go 1.16, the "io/ioutil" package is deprecated. All functionality
from "io/ioutil" has been moved to either the "io" or "os" packages.
2021-09-01 06:09:37 -05:00
jholdstock
067a6b5d5b build: Don't set GO111MODULE unnecessarily.
As of go 1.16, the GO111MODULE environment variable defaults to "on",
so it doesn't need to be set explicitly when building or testing.
2021-09-01 06:09:37 -05:00
jholdstock
cc6f9035b6 build: Use go 1.17 in Dockerfiles.
Update Dockerfiles to use golang:1.17 as their base/build image, rather
then golang:1.15.
2021-09-01 06:09:37 -05:00
Dave Collins
2086029e46
mempool: Accept test mungers for create tickets.
This modifies CreateTicketPurchase to accept a spendable output (instead
of a transaction) as well as munge functions similar to how
CreateSignedTx works and then introduces a new method named
CreateTicketPurchaseFromTx which keeps the existing signature and is
defined in terms of the aforementioned.

This allows the test code to more easily mutate the transactions as
desired prior to them being signed which provides greater flexibility.
2021-09-01 05:52:43 -05:00
Josh Rickmar
f9e382ecf8 sampleconfig: Add missing log options.
This adds the three currently missing config values related to logging
to the "Debug" section of the sample config, and renames the section
to "Logging" instead.

The description of the debuglevel option is also modified to describe
it as configuring the log verbosity, since it is not only related to
enabling debug logs.
2021-08-30 19:15:39 -05:00
Dave Collins
bda174f38f
chaingen: Add spendable coinbase out snapshots.
This adds the ability to snapshot the current spendable coinbase output
state of the generator with a name and restore it later.  This will
allow more efficient tests to be created since they will be able to use
invalidation along with restoring the spendable outputs state to avoid
the need to go through the entire vote activation process multiple
times.
2021-08-27 14:09:04 -05:00
Dave Collins
e5ba0f6bd9
chaincfg: Introduce explicit ver upgrades agenda.
This adds a new definition for the upcoming agenda vote to reject new
transaction and script versions until they are explicitly enabled via a
consensus vote as defined by DCP0008.  It does not include any code to
make decisions or bump the versions.  It is only the definition.
2021-08-27 13:31:19 -05:00
Ryan Staudt
08b7b89b25 rpcserver: Use CreateRevocationFromTicket.
This reworks the createrawssrtx handler to use the
CreateRevocationFromTicket function from the stake package rather than
creating the transaction directly.

It also adds additional error handling on the transaction input:
  - The input must be a ticket submission output (output index 0)
  - The input amount must equal the ticket submission amount
2021-08-27 13:33:08 -05:00
Ryan Staudt
24a7bed319 stake: Add func to create revocation from ticket.
This adds a new function, CreateRevocationFromTicket, and associated
tests for creating a revocation transaction for a given ticket.
2021-08-27 13:33:08 -05:00
Josh Rickmar
b4861dd9f0 config: Add logsize config option.
The logsize option enables configuration of the currently-hardcoded
value of 10MiB log files before they are rotated and compressed. The
default remains 10MiB.

This is a string option and requires using a suffix such as K, M, or
G to specify the units as kibibytes, mebibytes, or gibibytes.
2021-08-27 09:00:34 -05:00
Ryan Staudt
00830fa570 multi: Add FetchUtxoEntry to mining Config.
This adds a FetchUtxoEntry method to the mining Config.  This allows the
template generation logic to fetch unspent transaction outputs from the
point of view of the main chain tip.  This has not been necessary in the
past since typically, the mining code uses FetchUtxoView to construct a
viewpoint for transactions that it includes in a block template.
However, with the automatic ticket revocations agenda, the template
generation code will need to create new revocation transactions, which
will require fetching utxos for the input tickets.
2021-08-26 17:04:41 -05:00
Ryan Staudt
18ac610212 blockchain: Add NextExpiringTickets to BestState.
This adds a NextExpiringTickets field to the BestState type, which
represents the tickets that will expire in the next block.  This allows
consumers, such as mining template generation, to determine the tickets
that are about to expire when validating or constructing a new block.

This will be used for the automatic ticket revocations agenda since one
of the new rules for that agenda is that blocks must contain revocations
for expired tickets in the block that they become expired.
2021-08-26 16:31:45 -05:00
Ryan Staudt
9f87f432b8 blockchain: Add checkTicketRedeemers.
This combines the checkAllowedVotes and checkAllowedRevocations
methods into a checkTicketRedeemers function.  This reduces the number
of iterations through the stake transactions and subsequently reduces
the number of checks to determine the stake transaction type.

Further, additional validation rules for the votes and revocations in a
block will be added to this method for the upcoming automatic ticket
revocations agenda.
2021-08-26 04:12:01 -05:00
Matheus Degiovani
46a420572a blockchain: Test new max expenditure policy.
This adds a test that verifies the behavior of the maximum expenditure
check if the DCP0007 vote is active.
2021-08-25 16:51:44 -05:00
Matheus Degiovani
f1177087dc blockchain: Use new expenditure policy if activated.
This switches the blockchain to use the maximum treasury expenditure
policy defined in DCP0007 if the corresponding vote is approved in the
chain.
2021-08-25 16:51:44 -05:00
Matheus Degiovani
fbde3b7fce blockchain: Add maxTreasuryExpenditureDCP0007.
This adds the function that calculates the maximum treasury expenditure
policy as defined by DCP0007.
2021-08-25 16:51:44 -05:00
Matheus Degiovani
4eecbfe694 blockchain: Sum amounts added to treasury.
This changes the internal function that calculates the past treasury
expenditure to also return the sum of treasury add and treasurybase
transactions.
2021-08-25 16:51:44 -05:00
Matheus Degiovani
27de46118c blockchain: Switch to treasuryValueType.IsDebit
This centralizes the logic used to determine whether a given value type
should be negative or not to a single place, making refactorings easier.
2021-08-25 16:51:44 -05:00
degeri
dabe6074e4
docs: Add SECURITY.md file. 2021-08-25 03:45:36 -05:00
Dave Collins
169a21f184
blockchain: Correct test harness err msg.
This corrects the error message in the AdvanceFromSVHToActiveAgendas
test harness code to accurately state when the harness is not at SVH as
required.
2021-08-24 09:55:42 -05:00
Josh Rickmar
1f138a24ad rpcserver: Use duplicate tx error for recently mined transactions
Attempting to publish a recently-mined transaction using the
sendrawtransaction JSON-RPC method will now use the same error code as
for duplicate transactions currently present in the mempool, rather
than a generic error for double spending or spending unknown inputs.

There is a very small chance that this check results in a false
positive and that a transaction rejected for other reasons is reported
as a duplicate when it had never been mined at all.
2021-08-24 09:52:20 -05:00
Ryan Staudt
d8222412cc stake: Pre-allocate lottery ticket index slice.
This sets the initial capacity of the slice that is created in
`findTicketIdxs` to `n` to avoid extra allocations since it is a known
fixed size.
2021-08-23 19:56:47 -05:00
David Hill
48627ee18c
build: Test against Go 1.17. 2021-08-19 10:46:02 -05:00
Matheus Degiovani
5444fa50b9 rpctest: Add P2PAddress() function.
This allows returning the P2P address of the given harness node, which
is needed when trying to test third party services that connect via the
P2P network via rpctest (e.g. SPV wallets).
2021-08-16 13:15:53 -05:00
Matheus Degiovani
2c08eab97f rpcclient: Add GetNetworkInfo call.
This is already supported in the server and was missing from rpcclient.
2021-08-16 10:41:45 -05:00
Ryan Staudt
011d3049c0 stake: Add ExpiringNextBlock method to Node.
This adds an ExpiringNextBlock method on the Node type, which returns
the tickets that will expire in the next block.  This allows consumers
to determine the tickets that are about to expire when validating or
constructing a new block.

This will be used for the automatic ticket revocations agenda since one
of the new rules for that agenda is that blocks must contain revocations
for expired tickets in the block that they become expired.
2021-08-14 05:56:24 -05:00
Matheus Degiovani
9b4d8f9c0d rpcserver: Tune large tspend test amount
This changes the amount used for the large tspend in the rpc treasury
simnet test so that it is compatible to the new expenditure policy and
fails as expected.
2021-08-13 00:45:56 -05:00
Matheus Degiovani
8e92d3a2a3 blockchain: Single out treasury policy test.
This is purely a code move.
2021-08-13 00:45:56 -05:00
Matheus Degiovani
c531535a6d blockchain: Rename max expenditure funcs.
This renames the existing maxTreasuryExpenditure function to
maxTreasuryExpenditureDCP0006 to identify it as the one implementing the
legacy policy.

A future commit will add a new policy and selection of the active one
will be based on the results of an on-chain voting.
2021-08-13 00:45:56 -05:00
Matheus Degiovani
cf4ecd90be blockchain: Support voting multiple agendas in test.
This allows creating tests that require multiple agendas to be activated
simultaneously.
2021-08-13 00:45:56 -05:00
Matheus Degiovani
52c6bd033b blockchain: Verify state of DCP0007 voting.
This adds functions to verify the state of voting for the DCP0007
"revert treasury maximum expenditure policy" agenda.
2021-08-13 00:45:56 -05:00
Matheus Degiovani
7d65361e4c blockchain: Add replace to chaincfg dependency.
This switches the current blockchain go.mod file to use a replace
directive for the chaincfg code, which is needed due to the new agenda
introduced in a previous commit.
2021-08-13 00:45:56 -05:00