Commit Graph

3677 Commits

Author SHA1 Message Date
Dave Collins
7647b2594d
checkdevpremine: Remove utility.
This tool is no longer necessary now that the agreed upon period of time
has passed.
2018-02-23 09:38:21 -06:00
Josh Rickmar
c6f9474348 Expand ~ to correct home directory on all OSes.
This fixes the behavior of expanding ~ on Windows and macOS, as well
as adding support for ~otheruser to expand to the home directory of
otheruser.

Modify the default sample config to reflect the change in the meaning
of ~ on Windows, and the unintended meaning of ~ on macOS.  Include
defaults for all 3 of the major operating system classes since
uncommenting the default Unix option on macOS or Windows would change
the blockchain data directory to a non-default location.
2018-02-22 20:35:44 -06:00
Dave Collins
7056c67835
blockchain: Migrate to new block index and use it.
This adds code to migrate the existing block index in ffldb to the new
format managed by the blockchain package and updates the code to use the
new infrastructure.
2018-02-22 13:57:23 -06:00
Dave Collins
132eb4b150
blockchain: Add block validation status to index.
This adds a new field to the block node struct named status that
consists of bit flags for keeping tracking of the validation state of
each block.  The status is only stored in memory as of this commit, but
it will be stored as a part of the block index in the upcoming block
index migration code.

Since the field will be updated after node creation, this also
introduces some new functions for interacting with the status field in a
concurrent-safe fashion.

This is largely based on upstream commits 2492af0 and fb0d13c; however,
it does not include some of the logic in the reorganization paths those
commits include as that approach doesn't match the intended direction
this package is moving towards.
2018-02-22 13:57:15 -06:00
Dave Collins
b20abce609
blockchain: Infrastructure to manage block index.
This adds infrastructure necessary for blockchain to independently
manage and persist a full block index in a bucket.  Note that the
new infrastructure is not used yet as it will be integrated in future
commits after migrating existing databases has been done.

The purpose of this infrastructure is to significantly speed up startup
time which currently has to load a bunch of the most recent blocks in
order to rebuild the stake state and also to pave the way towards being
able to have the full block index in memory allows for a lot of
optimizations and greatly simplified code.

This also includes a full suite of tests to ensure proper serialization
and deserialization functionality.
2018-02-22 01:34:19 -06:00
Dave Collins
d8c1ea3345
blockchain: Simplify add/remove node logic.
This simplifies and consolidates the logic for adding and removing nodes
to and from the block index by moving the initial add into
maybeAcceptBlock just after the node is created, adding the child
connection logic to the AddNode function, and introducing a RemoveNode
function that is called in dry run mode which undoes the aforementioned
changes.

In addition to being simpler logic to follow, it helps make it clear
that all blocks which are written to the database end up with a block
index entry, even if they ultimately fail to connect.
2018-02-22 01:33:03 -06:00
Dave Collins
79689af3a8
blockchain: Correct error stringer tests.
This adds missing error entries to the tests and also adds an additional
check to ensure that all possibilities are tested to prevent drift in the
future.
2018-02-21 18:26:54 -06:00
Dave Collins
64d6be623e Sync upstream though e606259. 2018-02-21 16:59:38 -06:00
Dave Collins
17f957ff54
blockchain: Calculate the lottery IV on demand.
This provides a function to calculate the lottery initialization vector
for a node on demand versus calculating it at node creation time and
storing the result.

This is being done because it saves an additional 32 bytes in the block
node structure and the ultimate goal is to move towards having all block
nodes in memory to greatly simplify and optimize the code.  Since there
will be a lot of nodes in memory, these extra bytes can add up to
significant savings.
2018-02-21 16:44:54 -06:00
Dave Collins
0536ed4db6
blockchain: Combine ErrDoubleSpend & ErrMissingTx.
This replaces the ErrDoubleSpend and ErrMissingTx error codes with a
single error code named ErrMissingTxOut and updates the relevant errors
and expected test results accordingly.

Once upon a time, the code relied on a transaction index, so it was able
to definitively differentiate between a transaction output that
legitimately did not exist and one that had already been spent.

However, since the code now uses a pruned utxoset, it is no longer
possible to reliably differentiate since once all outputs of a
transaction are spent, it is removed from the utxoset completely.
Consequently, a missing transaction could be either because the
transaction never existed or because it is fully spent.

Also, while here, consistently use the LookupEntry function on the
UtxoView instead of directly accessing the internal map as intended.
2018-02-21 14:01:05 -06:00
Donald Adu-Poku
0dbfca4f79
dcrjson: include summary totals in GetBalanceResult.
this adds a collection of summary total fields to the GetBalanceResult
struct which allows providing a summary of totals for all wallet
accounts when using `getbalance "*"`.
2018-02-21 10:10:35 -06:00
Dave Collins
7e2a6932e1
sampleconfig: Correct comment. 2018-02-21 10:02:44 -06:00
Donald Adu-Poku
3603aeadb2 mempool: Add docs.go and flesh out README.md. 2018-02-21 12:27:31 +00:00
Dave Collins
cb40146dc7
blockchain: Accept parent in blockNode constructor.
This modifies the newBlockNode function to accept the parent as an
argument to automatically connect the newly created node.  When it is
not nil, the work sum will automatically be summed and the parent of the
new node will be set accordingly.

This simplifies the block node construction a bit and allows some
redundant code to be removed.  It also paves the way for easier simpler
full block index construction in the future.
2018-02-18 20:45:22 -06:00
Dave Collins
ca9ff29d9f
blockchain: Separate node ticket info population.
This separates the logic for populating the stake information in a block
node from the construction of the node in order to better delineate the
difference between the two and to pave the way for that information to
be stored separately in the database versus needing to load full blocks
to retrieve it.
2018-02-18 20:45:20 -06:00
Dave Collins
cc6f0cbff4
blockchain: Do not accept orphans/genesis block.
This modifies the code in maybeAcceptBlock to return an error if there
is no previous entry in the block index for a given block indicating it
is either an orphan or the genesis block.

The function should never be called in either circumstance since the
genesis block is valid by definition and orphans are handled prior to
calling the function.
2018-02-18 20:25:21 -06:00
David Hill
39e5af860b stake: optimize FindSpentTicketsInBlock slightly 2018-02-18 19:07:49 -06:00
Dave Collins
babc40a722
blockchain: Remove old version information.
This removes the legacy version details from the database to ensure that
loading older versions of the software after the database has been
upgraded fails as desired.

This is important because otherwise, the database could actually be
using a new version that has been upgraded via the new scheme, but old
software would still see this old information and believe the database
was still on that older version.
2018-02-18 12:33:07 -06:00
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
Dave Collins
1a62f72f40
blockchain/indexers: Allow interrupts.
This propagates the interrupt channel through to blockchain and the
indexers so that it is possible to interrupt long-running operations
such as catching up indexes.
2018-02-18 11:18:52 -06:00
Dave Collins
a0fc0806ec
blockchain: Don't require chain for db upgrades.
This modifies the database upgrade logic to avoid needing the chain and
moves it earlier in the initialization process just after the initial
database creation (if needed), but prior the final struct instance
population from the database.

It is much simpler logic to have an already upgraded database prior to
populating the initial chain state so all of the initial setup happens
in one place.
2018-02-18 11:18:27 -06:00
Dave Collins
eaa59edc88
blockchain: Rework database versioning.
This modifies the database versioning to use separate keys within the
version bucket for each component in order to simplify upgrade logic.

Having a single key for the various versions of the database components
makes it difficult to use because the version isn't known until the data
is read, however, modifying the format necessarily means the version is
needed before that point to know which format to read.

While here, it uses a uint64 to store the date instead of a uint32 so
the timestamp continues to work past 2106.

Also, it removes the upgrade started logic since it should be possible
to stop in the middle of an upgrade and resume later.  Forcing a
completely new database to be created because an upgrade was stopped in
the middle is not ideal.
2018-02-18 11:17:08 -06:00
Dave Collins
c4e4f07d18
blockchain: Simplify initial chain state.
Prior to this commit, the chain data structures were initialized in two
separate places depending on whether or not the database state had
already been created.

This simplifies that logic so that the initialization of the data
structures happens in a single place.

In order to accomplish this, the logic has been split into three phases:

1) Query to determine the current state of the database
2) Optionally initialize the database by creating all buckets and
   populating it with the genesis block and associated state if it
   has not already been done
3) Initialize the data structures using the data loaded from the
   database
2018-02-18 10:33:55 -06:00
Dave Collins
d967408df6
blockchain: Store side chain blocks in database.
This modifies the blockchain code to store all blocks that have passed
proof-of-work and contextual validity tests in the database even if they
may ultimately fail to connect.

This eliminates the need to store those blocks in memory, allows them to
be available as orphans later even if they were never part of the main
chain, and helps pave the way toward being able to separate the download
logic from the connection logic.

Note that it also updates the blockExists function since the code base
is currently in the process of changing over to decouple download and
connection logic, but not all of the necessary parts are updated yet,
to ensure blocks that are in the database, but do not have an associated
main chain block index entry, are treated as if they do not exist for
the purposes of chain connection and selection logic.
2018-02-18 10:31:40 -06:00
David Hill
a261760b9b travis: test in docker container 2018-02-18 10:27:18 -06:00
David Hill
2b03537689 mempool: cleaner 2018-02-17 12:42:14 -06:00
David Hill
3a78a1086d travis: drop docker 2018-02-16 22:06:22 -06:00
Dave Collins
e65a8da145
blockchain: Remove unused struct. 2018-02-16 17:28:20 -06:00
Dave Collins
a8e73f696c
blockchain: Correct a few log statements. 2018-02-16 17:07:22 -06:00
Josh Rickmar
5eb3296508 Require atomic swap contracts to specify the secret size.
This allows redeeming parties to audit the secret size and ensure it
will be usable once revealed.
2018-02-16 15:14:27 -06:00
Dave Collins
6b36299994
blockchain/stake: Rename tix spent to tix voted.
This renames the fields dealing with the hashes of tickets that have
been voted on from ticketsSpent to ticketsVoted to more accurately
differentiate them from revocations which also technically spend
tickets.
2018-02-15 21:22:55 -06:00
Dave Collins
f4d5baab46
blockchain: Validate allowed revokes in blk contxt.
This moves the test for validating the revocations in the block are
actually eligible to be revoked per the results of the ticket lottery
into the checkBlockContext function where it more naturally belongs
since it is only dependent on the block and its contextual position
within the chain.

While here, it also refactors the check into a separate function named
checkAllowedRevocations to improve readability.  Also, since this was
the final check in the CheckBlockStakeSanity function, that entire
function has been removed along with its call site.
2018-02-15 16:33:57 -06:00
Dave Collins
6086f988db
blockchain: Validate allowed votes in block context.
This moves the test for validating the votes in the block are eligible
votes per the results of the ticket lottery into the checkBlockContext
function where it more naturally belongs since it is only dependent on
the block and its contextual position within the chain.

While here, it also refactors the check into a separate function named
checkAllowedVotes to improve readability.
2018-02-15 16:24:49 -06:00
Dave Collins
890fc38581
blockchain: Allowed stake txns in block sanity.
This moves the check for validating that only ticket purchases, votes,
and revocations are included in the stake tree to the checkBlockSanity
function where it more naturally belongs since it does not require
access to any previous chain context.
2018-02-15 15:03:02 -06:00
Dave Collins
8eda558666
blockchain: Max revocations in block sanity.
This moves the check for validating that the number of revocations does
not exceed the maximum allowed to the checkBlockSanity function where it
more naturally belongs since it does not require access to any previous
chain context.

It should be noted that this check previously used math.MaxUint8 and was
rather implicitly limited by the fact the header uses a uint8 for the
field, so this makes the requirement more explicit by defining a
constant.
2018-02-15 12:43:41 -06:00
Dave Collins
c3aa5319e4
blockchain: Validate final state in header context.
This moves the test for validating the final state specified by the
header matches the calculated final state into the
checkBlockHeaderContext function where it more naturally belongs since
it is only dependent on the header and its contextual position within
the chain.
2018-02-15 09:53:25 -06:00
Dave Collins
305a88cc4d
fullblocktests: Add tests for early final state.
This adds tests for the new consensus check which ensures the final
state is zero prior to stake validation height.
2018-02-15 09:53:09 -06:00
Dave Collins
693fc12e39
blockchain: Validate early final state is zero.
This modifies the checkBlockHeaderSanity function to include an
additional check which ensures the final state is zero prior to stake
validation height.

It should be noted that this is technically a hard fork since before
this change it was possible to use any value for the final state prior
to stake validation height.  However, no blocks on mainnet nor testnet
ever used non-zero final states for blocks in that range and they are
buried behind checkpoints in the minimum required version of the
software due to the previous consensus votes, so it isn't possible to
trigger a reorg that would fork old nodes off the network anyways, so it
is safe to retroactively apply this check.
2018-02-15 09:52:34 -06:00
Dave Collins
eac315e8a0
Sync upstream through 26e2279. 2018-02-15 09:39:44 -06:00
Dave Collins
79d3f08b2b
blockchain: Vote commitments in block sanity.
This moves the checks for validating that votes commit to the parent of
the block they are contained in and the vote bits specified by the
header match the result of the actual votes included in the block to the
checkBlockSanity function where they more naturally belong since they do
not require access to any previous chain context.
2018-02-14 20:27:31 -06:00
Dave Collins
a57df141f9
chaingen: Update vote commitments on hdr updates.
This modifies the NextBlock function to account for changes made to the
block height or previous block hash in munge functions and update the
commitments in all votes accordingly.
2018-02-14 14:27:13 -06:00
Dave Collins
c5a7115bbb
blockchain: Validate pool size in header context.
This moves the test for validating the pool size specified by the header
matches the calculated size into the checkBlockHeaderContext function
where it more naturally belongs since it is only dependent on the header
and its contextual position within the chain.
2018-02-14 13:11:53 -06:00
Dave Collins
21e9a85fdb
blockchain/mining: Full checks in CCB.
This modifies the exported CheckConnectBlock function to call the
checkBlockSanity and checkBlockContext functions to ensure all
validation rules are enforced from the mining code.

Since both the mining code and tests typically work with unsolved
blocks, this also introduces a new parameter on CheckConnectBlock to
pass behavior flags which allows the caller to skip the proof of work
check.

It also modifies forceHeadReorganization to call checkBlockContext for
the same reason.

Finally, all tests and call sites are updated with the appropriate
flags and various tests are updated for the changes accordingly.
2018-02-14 13:10:33 -06:00
Donald Adu-Poku
e48b9ab823 mempool: Rename RelayNonStd config option.
This renames the mempool.Config.RelayNonStd option to AcceptNonStd which
more accurately describes its behavior since the mempool was refactored
into a separate package.

The reasoning for this change is that the mempool is not responsible for
relaying transactions (nor should it be).  Its job is to maintain a pool
of unmined transactions that are validated according to consensus and
policy configuration options which are then used to provide a source of
transactions that need to be mined.

Instead, it is the server that is responsible for relaying transactions.
While it is true that the current server code currently only relays txns
that were accepted to the mempool, this does not necessarily have to
be the case.  It would be entirely possible (and perhaps even a good
idea as something do in the future), to separate the relay policy from
the mempool acceptance policy (and thus indirectly the mining policy).
2018-02-14 15:55:22 +00:00
Donald Adu-Poku
a0438c81c3 rpcserver: add batched request support (json 2.0) 2018-02-13 17:12:08 -06:00
David Hill
1755f5190f connmgr: convert state to atomic 2018-02-13 14:50:33 -06:00
David Hill
393a95c079 multi: fix some maligned linter warnings 2018-02-13 14:50:33 -06:00
Andrew Chiw
516f300863 peer: rename inventorymap to inventorycache
It's a cache, butt it is implemented with a map.
2018-02-13 13:56:50 -06:00
Andrew Chiw
b9225dcb66 peer: rename noncemap to noncecache
It's a cache, but it is implemented with a map.
2018-02-13 13:56:50 -06:00
Andrew Chiw
70dd37e644 peer: rename mruinvmap, mrunoncemap to lruinvmap, lrunoncemap
The names mean that the caches contain the Most Recently Used entries.
But they behave in a Least Recently Used fashion.
2018-02-13 13:56:50 -06:00