Commit Graph

5207 Commits

Author SHA1 Message Date
Dave Collins
84d59c01ac
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: 0x00000000000000000000000000000000000000000013e6909b5a73128d52fc6f
testnet: 0x000000000000000000000000000000000000000000000000e41955f181d00f59
2020-09-25 11:51:35 -05:00
Dave Collins
1d134a2125
chaincfg: Add checkpoints for upcoming release.
This adds checkpoints at the following heights:

mainnet:

- 237310
- 277940
- 318020
- 340120
- 362120
- 404170
- 424170
- 444170
- 464170
- 483600

testnet:

- 148320
- 213120
- 347140
- 411940
- 476740
- 515730

Note that this also includes some historical checkpoints to limit the
size of the gaps between each checkpoint to be around 3 months max.
This is being done because recent optimizations have sped up processing
to the point that larger gaps can trigger peers to get banned during IBD
in some cases.
2020-09-25 11:49:00 -05:00
Matheus Degiovani
1ddab08c53 rpctest: Make votingwallet txs standard
Tickets and votes were being issued with tx version 0, which is
non-standard.
2020-09-24 15:21:48 -05:00
Ryan Staudt
df141bbff3 txscript: Proactively evict SigCache entries.
This adds functionality to proactively evict SigCache entries when they
are nearly guaranteed to no longer be useful.  It accomplishes this by
evicting entries related to transactions in the block that is 2 levels
deep from a newly processed block.

Proactively evicting entries reduces the likelihood of the SigCache
reaching maximum capacity quickly and then relying on random eviction,
which may randomly evict entries that are still useful.
2020-09-24 12:19:59 -05:00
Ryan Staudt
380c8d512b txscript: Store short tx hash in sigcache.
This adds a uint64 short transaction hash to sigcache entries.  This can
be used to proactively evict entries from the sigcache based on the
transaction that they are associated with.
2020-09-24 12:19:59 -05:00
Ryan Staudt
349822959a txscript: Add shortTxHash.
This defines a shortTxHash method that generates a short 64-bit hash
from the standard 128-bit hash.  It accomplishes this by using the
SipHash-2-4 hash function.

This is being introduced to track the transaction associated with a
signature cache entry at a reduced memory overhead.
2020-09-24 12:19:59 -05:00
Matheus Degiovani
56257e00d2 rpcserver: Verify tbase values in treasury rpctest
This adds assertions to the existing treasury rpctest to verify that
treasury base transactions have the correct value even when the block
containing them has less than the maximum allowed of vote (SSGen)
transactions.
2020-09-24 12:19:12 -05:00
Matheus Degiovani
be15f2de6f rpctest: Add ability to limit VotingWallet votes
This adds the ability for the voting wallet to limit the total number of
votes issued, which is useful for some testing scenarios involving
blocks with less than the maximum number of votes.

Due to how the rpctest VotingWallet is currently structured
(specifically, the fact that it only tracks the absolute minimum amount
of tickets to advance the chain) it can't keep advancing the chain
indefinitely after limiting the number of votes for some blocks.

This is less than ideal, but sufficient for the tests that will be
introduced in future commits.
2020-09-24 12:19:12 -05:00
Matheus Degiovani
1de796404f docs: Add missing gettreasurybalance documentation
This adds documentation for the gettreasurybalance RPC call, which was
missing on the original treasury commit.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
d57d5156b2 rpcserver: Assert vote counts in treasury rpctest
This adds assertions in the TestTreasury rpctest that verify the correct
behavior of the recently introduced gettreasuryspendvotes rpc command.

It also serves to ensure vote tallying of the underlying blockchain
corresponds to the expected ones.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
c7f58531ca rpcserver: Add support for gettreasuryspendvotes
The new gettreasuryspendvotes rpc command is useful to keep track of the
voting progress of treasury spend transactions as well as to query for
the status of old tspends.

When invoked without any parameters, the command tallies the vote counts
for all tspends currently in the node's mempool up to the current tip
block.

The first parameter ("Blocks") can be used to limit the block up to
which the tallies are performed, which is useful for historical queries.

The second parameter ("TSpends") can be used to narrow down the list of
tspends that should be queried. It can be used to query for tspends that
have already been mined.

A set of unit tests ensures proper behavior for the new command.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
4856e957d7 rpcclient: Add GetTreasurySpendVotes command
This allows clients to query an underlying node for the vote counts of a
set of tspend transactions as of some specific block height.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
a9dd3614c9 blockchain: Add exported TSpendCountVotes func
This allows external callers to tally the number of votes a given
treasury spend transaction has received.

This will be used in a future commit to allow the rpc server to offer
tspend vote counts via a new gettreasuryspendvotes command.
2020-09-24 11:46:21 -05:00
Matheus Degiovani
f6f35ceb74 jsonrpc: Add gettreasuryspendvotes types
This adds the command and result types for the upcoming
gettreasuryspendvotes rpc command.
2020-09-24 11:46:21 -05:00
Ryan Staudt
08d1372548 main: go mod tidy. 2020-09-23 20:57:55 -05:00
Matheus Degiovani
3fbdfea739 server: Send and respond to InitState msgs
This changes the server to support the most recent protocol version (v8
or InitStateVersion).

On this version, instead of using the getminingstate/miningstate pair of
messages, peers use getinitstate/initstate messages which allow for
finer grained control over what information is sent upon startup.

The older protocol versions are still supported so that the node may
continue to both request and serve initial mining state to older nodes
of the network.
2020-09-23 14:01:30 -05:00
Matheus Degiovani
ebec672f0b peer: Handle InitState messages
This modifies the peer package to handle GetInitState/InitState
messages by adding the appropriate listeners. It also bumps the max
supported protocol version to version 8, which is needed to be able to
decode the messages.

Note this modifies the peer package's go.mod to use the local copy of
the wire module in order to have access to the new messages.
2020-09-23 14:01:30 -05:00
Matheus Degiovani
1869aea8e5 wire: Introduce InitState messages
This adds the GetInitState and InitState messages along with appropriate
tests. It also adds a new protocol version (version 8) and bumps the
current wire version to it.

This set of messages will be used to allow peers to exchange ephemeral
startup information in a more general manner than the current existing
GetMiningState/MiningState pair.

In particular, peers will be able to selectively request only the
specific startup info they're insterested in so that different types of
nodes (such as SPV clients) may only request relevant startup
information.

Compared to the existing MiningState message, the InitState message
already offers a new type of data: tspend hashes, that nodes may use to
fetch tspend transactions for inspecting, generating templates and
voting on their approval.
2020-09-23 14:01:30 -05:00
Matheus Degiovani
888a2c397a mempool: Fix wrong tx type in error message 2020-09-21 15:00:02 -05:00
Matheus Degiovani
4409e62440 mempool: Improve tspend expiry handling and tests
This improves handling of tspend expiries within the mempool and adds
relevant tests.

TSpends are tested for a correct expiry and are limited to enter the
mempool only when their voting starts less than two full voting
intervals in the future.

We add tests to ensure expired tspends can't enter the mempool and that
the tspend _can_ enter up to the last allowable height where it can be
included in a block.
2020-09-21 15:00:02 -05:00
Matheus Degiovani
b0f753d639 mempool: Add TAdd Tests
This adds tests to ensure TAdds can enter the mempool.
2020-09-21 15:00:02 -05:00
Matheus Degiovani
0e0f57eee3 mempool: Special case tspends for insertion
TSpends have non-standard input signature scripts. Specifically, they
are not push-only, due to the presence of OP_TSPEND.

This commit special-cases tspends so that the mempool will accept them
even when configured to reject non-standard transactions.

We also add a set of tests to ensure tspends can enter the mempool
correctly.
2020-09-21 15:00:02 -05:00
Matheus Degiovani
f42c4d376e mempool: Track tspends separately
This allows easier discovery of the current treasury spend transactions
in the mempool.

This will be needed in order to provide tspends to remote peers upon a
getinitstate message.
2020-09-21 15:00:02 -05:00
Josh Rickmar
6d75c7ec11 blockchain: Update unreleased requires to master
This should fix consumers requiring the blockchain module at dcrd
master.  Previously, this would fail, due to an invalid require on the
released v2.0.0 version of standalone/v2, which has not yet been
released.
2020-09-21 13:52:35 -05:00
Dave Collins
67245079e9
blockchain: Decentralized Treasury db migration.
This adds code to migrate the database to the new schema required by the
decentralized treasury implementation.

It involves updating the utxo set and spend journal entries to account
for the change of the position of the fully spent bit within the flags
from bit 4 to bit 6.  The process can be interrupted at any point and
future invocations will resume from the point it was interrupted.
2020-09-21 12:37:33 -05:00
Marco Peereboom
80f5feb1db
multi: Add decentralized treasury support.
This is based on https://proposals.decred.org/proposals/c96290a but was
modified in order to deal with realities that were unknown at the time
of the specification draft.

It is large and could not really be broken apart due to the pervasive
use of the isTreasuryEnabled flag. It was primarily authored by
* Marco Peereboom <marco@peereboom.us>
* Dave Collins <davec@conformal.com>
* Matheus Degiovani <opensource@matheusd.com>

With additional contributions from
* Donald Adu-Poku <donald.adu@gmail.com>
* Jamie Holdstock <jholdstock@decred.org>

Major changes:
* Add decentralized treasury agenda, as specified in DCP0006, to all supported
  nets.
* Add functions to determine if the decentralized treasury agenda is active at
  given block.
* Add new opcode OP_TADD that is a nop in txscript but is used to tag scripts
  that credit the treasury account. This opcode is overloaded for treasurybase
  and for normal transactions.
* Add new opcode OP_TSPEND that is a nop in txscript but is used to tag scripts
  that debit the treasury account.
* Add new opcode OP_TGEN that is a nop in txscript but is used to tag P2PKH and
  P2SH outputs in a TSpend transaction.
* Add functions that detect if a transaction is a valid TAdd, TSpend
  or treasurybase transaction.
* Add error codes that return specific treasurybase/TAdd/TSpend consensus
  violations.
* Modify countSpentOutputs to deal with treasury opcodes accordingly.
* Modify indexBlock to skip treasury transactions that do not have inputs.
* Add IsTreasuryEnabled call to ChainQueryer interface.
* Add treasury logger for debugging and logging the decentralized treasury
  subsystem.
* Add IsTreasuryActive flag to BlockConnectedNtfnsData and
  BlockDisconnectedNtfnsData.
* Modify OP_SSGEN to allow an optional output that contains votes for a TSpend
  transaction hash.
* Add function that returns TSpend votes from an SSGen transaction.
* Modify CalcStakeVoteSubsidy so that treasurybase, unlike coinbase, is always
  awarded the full percentage of the assigned block reward.
* Add helper functions to do all TSpend math so that callers don't roll their
  own.
* Modify IsCoinBaseTx to not mistake a TSpend transaction as a coinbase.
* Add checkTreasuryBase function that verifies that a treasurybase is properly
  constructed and pays the right amount to the treasury account.
* Add functions to calculate treasury balance for the provided block hash/node.
* Add function that verifies if a TSpend has a valid signature.
* Add functions to determine if a TSpend is not overspending.
* Add function to determine if a TSpend has been mined on the provided chain.
* Add functions that count and verifies treasury spend votes.
* Modify connectTransaction and disconnectTransactions to deal with the various
  treasury transactions.
* Split CheckTransactionSanity in two functions
  checkTransactionSanityContextFree and checkTransactionSanityContextual. This
  is done in order to keep the decentralized treasury, which is always
  contextual, from infecting the context free checks.
* Modify checkTransactionSanityContextual to recognize and verify treasury
  transactions.
* Modify CheckTransactionSanity to deal with treasury transactions.
* Split checkBlockSanity in two functions checkBlockSanityContextFree and
  checkBlockSanityContextual. This is done in order to keep the decentralized
  treasury, which is always contextual, from infecting the context free checks.
* Modify checkBlockSanityContextual to enforce treasurybase and TAdd consensus
  checks.
* Modify checkBlockPositional by unindenting it and adding TSpend consensus
  enforcement.
* Modify checkCoinbaseUniqueHeightWithAddress to deal with the removal of the
  project subsidy from output 0.
* Add checkCoinbaseUniqueHeightWithTreasuryBase that verifies coinbase and
  treasurybase in the provided block.
* Unindent checkBlockContext.
* Modify checkTicketRedeemerCommitments and checkVoteInputs to deal with
  potential tspend votes.
* Modify CheckTransactionInputs to skip treasurybase transactions.
* Modify CheckTransactionInputs to deal with TSpend transactions. Ensure the
  provided Pi key is valid and that the signature is valid for the transaction.
  Ensure that treasury TAdd and TSpend transaction utxo can only be spent after
  coinbase maturity.
* Modify CountSigOps to deal with treasury transactions.
* Modify CountP2SHSigOps to deal with treasury transactions.
* Modify getStakeTreeFees to skip treasury transactions. Modify
  totalOutputs to subtract ValueIn 0 for TSpend and treasurybase transactions.
* Modify checkTransactionsAndConnect to deal with modified amounts.
* Add tspendChecks function that verifies an entire TSpend transaction
  validity at the point of the provided block. It ensures a TSpend is on a TVI.
  It ensures the TSpend is in the valid window. It verifies that a TSpend In
  and Out amounts match. It ensures a TSpend has the ValueIn amount encoded in
  the OP_RETURN in Out 0. It ensures a TSpend has not been mined before on this
  chain. It ensures a TSpend has the requisite votes. It ensures a TSpend is
  not overspending.
* Modify checkConnectBlock to call checkTreasuryBase and tspendChecks when
  treasury agenda is active.
* Add two tables to the database. Table "treasury" records the balance as of
  this block and balance changes that occurred in this block which will become
  active in CoinbaseMaturity blocks. Table "tspend" records all block hashes
  where a TSpend has been mined this is to detect forks and prevent a Tspend
  from being mined more than once.
* Modify handleBlockchainNotification to communicate if the treasury agenda is
  active and skip treasurybase transaction when needed.
* Add various Treasury parameters to chaincfg params.
* Add hardcoded Tspend signatures in dcr_tmux_simnet_setup.sh.
* Add notifytspend and stoptspend calls to the RPC server. notifytspend
  notifies the mempool when a TSpend transaction arrives.
* Modify commit filters V2 to recognize TAdd and TSpend transactions. It was
  possible to modify V2 instead of introducing V3 because nothing changes from
  the viewpoint of the wallet and treasury opcodes are disallowed prior to
  agenda activation.
* Modify AddMemPoolTransaction to skip TSpend transactions that would throw the
  fee estimator off.
* Add IsTreasuryAgendaActive, OnTSpendReceived and TSpendMinedOnAncestor to
  mempool.Config in order to reject/accept TSpends in the mempool.
* Modify checkPoolDoubleSpend to ignore treasurybase.
* Modify mempool.maybeAcceptTransaction to enforce treasury standardness rules.
  Don't allow TSpend transactions prior to stake validation height. Skip
  treasurybase and tspend transactions in the orphan test. Ensure a tspend is
  in a valid window. Ensure not more than 7 TSpends are active in the mempool.
  Ensure TSpend has a well-known Pi key. Ensure The provided Pi key was used to
  sign the transaction. Ensure TSpend was not mined in an ancestor block.
  Notify subscribers that a valid TSpend was received.
* Add standardCoinbaseOpReturn and standardTreasurybaseOpReturn to create an
  OP_RETURN followed by a data push that little endian encodes the height of
  the block. Then there are a number of random bytes to ensure that the
  transaction hash is always random.
* Modify createCoinbaseTx to create a coinbase that is valid when treasury is
  enabled or not. Additionally, alter the transaction version if treasury is
  enabled.
* Add createTreasuryBaseTx that creates a standard treasurybase.
* Modify maybeInsertStakeTx to recognize treasurybase and TSpend transactions.
* Modify handleTooFewVoters to call createTreasuryBaseTx when the treasury
  agenda is active. Skip copying treasurybase.
* Modify NewBlockTemplate to recognize and deal with treasury transactions.
  Skip TSpend transaction if block is not a TVI. Skip TSpend transaction if it
  is not in the proper window. Skip TSpend transaction if a TSpend does not
  have enough yes votes. Skip TSpend transaction if it overspends the treasury
  account. Skip TAdd if there are more than 20 TAdds in the block. Create
  treasurybase if required. Insert valid TAdd/TSpend transactions into stake
  tree.
* Add TreasuryBalance and IsTreasuryAgendaActive to rpcserver Chain interface.
* Add gettreasurybalance, sendfromtreasury and sendtotreasury calls to RPC
  server.
* Add notifytspend and stopnotifytspend to RPC websocket commands.
* Add simnet miner to generate large number of blocks during rpctests without
  triggering PoW difficulty increases. This is used to verify various treasury
  and tspend conditions during CI/CT.
* Modify RPC voting wallet to also vote on TSpends.
* Add json tests to verify all new opcodes and corner cases in the script
  engine.
* Modify isStakeOpcode to recognize treasury opcodes.
* Modify countSigOpsV0 to count TSpends.
* Modify handleStakeOutSign to deal with TSpends.
* Modify SignTxOutput to recognize TSpends.
* Add TSpendSignatureScript that signs a TSpend transaction.
* Add TreasuryAddTy and TreasurySpendTy types to the standard scripts.
* Add isTreasuryAddScript and isTreasurySpendScript functions that recognize
  a form of TAdd and TSpend transactions.
* Modify ExtractPkScriptAddrs to deal with TAdd and TSpend outputs.
* Add TxVersionSeqLock = 2 and TxVersionTreasury = 3 to wire. This is
  used to discriminate between treasury and non-treasury scripts.
* Rig up all functions that need the isTreasuryEnabledflag directly or
  indirectly.
* Shuffle various functions around and export them when they were needed to be
  called from other packages.
* Added and modified numerous tests to verify (hopefully) all corner cases that
  the decentralized treasury agenda has added.
2020-09-21 12:15:31 -05:00
Dave Collins
9fa98a8a94
server: Consolidate ban disable/whitelist logic.
This consolidates the logic for handling the disable banning flag as
well as whitelisted peers into the BanPeer function on the server and
updates all of the direct banning from the callbacks accordingly.

This consolidation will help prevent the possibility of banning without
properly checking those flags.
2020-09-21 11:30:06 -05:00
Dave Collins
290736e4ea
docs: Update README CLI suite link to ref latest. 2020-09-19 19:02:23 -05:00
Dave Collins
daf84ebd36
server: Check whitelist before ban on read errs.
This modifies the code that was fairly recently added to ban peers
sending messages that do not conform to the wire protocol to only apply
when they are not whitelisted.
2020-09-19 17:57:09 -05:00
Dave Collins
2f8ae33148
docs: Update rebroadcast JSON-RPC docs.
This updates the rebroadcastmissed and rebroadcastwinners entries to be
properly categorized under the Websocket Methods section and updates
them to properly call out the associated notifications they generate.
2020-09-16 14:55:03 -05:00
Dave Collins
9f6d93e9f1
jsonrpc/types: Register rebroadcast as websocket.
This moves the rebroadcastmissed and rebroadcastwinners commands from
the regular chain server file to the websocket chain server file so they
are only registered as available to websocket clients.
2020-09-16 14:54:58 -05:00
Dave Collins
3cc62f8f20
txscript: Correct JSON test data comment. 2020-09-09 17:25:34 -05:00
Dave Collins
f235b26dea
docs: Add release notes for v1.5.2. 2020-09-04 16:30:24 -05:00
Matheus Degiovani
3c2f8ad6a3 chaincfg: Make simnet votes standard txs
This allows simnet nodes to run with --rejectnonstd and still receive
votes and advance the network past SVH.

Previously the simnet used a non-push-only signature script, so this
conflicted with the --rejectnonstd mempool policy.
2020-09-03 13:06:23 -05:00
Dave Collins
7743476bdb
cpuminer: Improve already discrete mining error.
This modifies the error return from generate command when mining is
already in progress to properly differentiate between the discrete mining
and CPU mining cases.
2020-09-02 13:24:51 -05:00
Dave Collins
be936bb622
sampleconfig: Make constant a function instead.
This modifies the sampleconfig package to contain a single function
named FileContents instead of a constant.

This is being done because changing a constant is technically a major
semver breaking change while changing the contents returned by a
function is not and the goal is to ultimately make the root module
semver compliant.
2020-09-02 13:21:37 -05:00
Dave Collins
7bad7f81aa
main: Unexport main package exports.
This ensures that all code in the main package of root module is not
exported since none of it should be accessed outside of the main package
itself.

While here, it also updates the NAT discover func to avoid using named
variables which ensures error are not shadowed and eaten.
2020-09-02 13:21:13 -05:00
JoeGruff
1e962addda rpcserver: Add handleGenerate test. 2020-09-02 13:17:20 -05:00
Ryan Staudt
d2f6d92124 server: Remove unnecessary rpcadaptors.
This removes a few rpcadaptors that are unnecessary since the underlying
types that server provides satisfies those interfaces themselves.  It
also restructures how nil interfaces are passed to rpcserver.Config to
be more straightforward and a bit less code.
2020-09-02 01:07:00 -05:00
Ryan Staudt
fed6edd63b docs: Update searchrawtransactions JSON-RPC docs. 2020-08-29 22:03:04 -05:00
Ryan Staudt
bcb9673771 rpcserver: Add handleSearchRawTransactions tests. 2020-08-29 22:03:04 -05:00
Ryan Staudt
d02e1f4bea rpcserver: Add testDB and testDatabaseTx.
This adds testDB and testDatabaseTx structs that provide mock
implementations of the database.DB and database.Tx interfaces for
testing purposes.
2020-08-29 22:03:04 -05:00
Ryan Staudt
fccd11e0ab rpcserver: Add TxIndexer interface.
This adds a TxIndexer interface to rpcserver, which decouples rpcserver
from the implementation of the transaction index and allows a mocked
version to be provided for testing.
2020-08-29 22:03:04 -05:00
Ryan Staudt
95e2312369 rpcserver: Add AddrIndexer interface.
This adds an AddrIndexer interface to rpcserver, which decouples
rpcserver from the implementation of the address index and allows a
mocked version to be provided for testing.
2020-08-29 22:03:04 -05:00
Dave Collins
5925ed5a38
blockchain: Add test func to remove deployment.
This adds a function to the common test infrastructure to remove
deployments for a given vote ID from parameters for use in testing cases
where it is useful to ensure behavior is correct on networks for which
an agenda is already active before heights that are not possible to hit
when the agenda has to be voted in.

Note that it is intentionally unused at this point, but future commits
will make use of it.
2020-08-28 15:30:21 -05:00
Dave Collins
98f0dd457b
docs: Update README.md to require Go 1.14/1.15. 2020-08-20 01:54:32 -05:00
Dave Collins
871ca33c60
docker: Update image to golang:1.15 2020-08-20 01:54:29 -05:00
Dave Collins
3c7913dbb6
connmgr: Enforce max http seeder response size.
This imposes a limit on the response size from the http seeder such that
each returned entry is allowed to have max size of 256 bytes.  Since
there is also a limit of 16 entries per response, it amounts to a max
overall response size of 4KiB.
2020-08-19 17:58:53 -05:00
David Hill
f0530fbd17 dcrd: use a context w/ timeout when fetching seeds. 2020-08-19 16:30:50 -05:00
David Hill
01b3cd1e26 connmgr: limit addresses returned by seeders 2020-08-19 16:30:50 -05:00