Commit graph

34 commits

Author SHA1 Message Date
Dave Collins
1a5683e220 Add optimized initial block index load function.
This commit adds a new optional function named GenerateInitialIndex.  It
generates the required number of initial block nodes in an optimized
fashion.  Since the memory block index is sparse and previous nodes are
dynamically loaded as needed, this function is not stricty needed.
However, during initial startup (when there are no nodes in memory yet),
dynamically loading all of the required nodes on the fly in the usual way
is much slower than preloading them.
2013-08-01 18:00:35 -05:00
Dave Collins
716075d0d0 Remove tesnet specific rules unsupported blurb.
The testnet specific rules have been supported since commit
9787f46f6a.
2013-08-01 17:10:59 -05:00
Dave Collins
5b697947a7 Optimize getPrevNodeFromNode.
The recent pruning code made the parent hash for a node available directly
as a field in the node.  Make use of this in the getPrevNodeFromNode
function to avoid having to load the full block data associated with the
node to get the parent hash.
2013-08-01 12:34:59 -05:00
Dave Collins
2988289d2e Implement memory chain pruning.
This commit implements pruning for the block nodes that form the memory
chain which are no longer needed.  The validation of a block only requires
information from a set number of previous nodes.  The initial code did not
prune old nodes as they were no longer needed, but the vast majority of
the infrastructure to support it was already in place as that was always
the goal.  This commit finishes implementing the missing bits to make it
a reality.
2013-08-01 11:31:52 -05:00
Dave Collins
2d6a664d9d Greatly optimize best chain selection work values.
Previously, the code was using big rational numbers for work values which
resulted in carrying way too much precision around (and ultimately a lot
of extra memory and computation to carry that precision).  This commit
converts the work values to big integers and calculates them with integer
division.  This is acceptable because the numerator is multiplied by 2^256
which is higher than the maximum possible proof of work.  Therefore
anything after the decimal is superfluous precision for the purposes of
chain selection.

Also, add a check for negative difficulty values when calculating the work
value.  Negative values won't occur in practice with valid blocks, but
it's possible an invalid block could trigger the code path, so be safe and
check for it.
2013-07-31 13:07:06 -05:00
Dave Collins
455c92a716 Correct reg test proof of work limit comment. 2013-07-31 09:20:11 -05:00
Dave Collins
72feef5194 Clarify reg test proof of work limit comment. 2013-07-31 09:14:02 -05:00
Dave Collins
bb7f5da609 Print transaction hash in script val errors.
The txsha variable is already a pointer to the hash, so print the
variable, not the address of it.
2013-07-30 18:04:58 -05:00
Dave Collins
357160257c Allow checkpoints to work with all networks.
Previously the main network checkpoints were being used for unrecognized
networks.  This commit changes the code so that no checkpoints are used in
that scenario.
2013-07-30 15:29:15 -05:00
Dave Collins
1e891b4e0b Optimize proof of work limit bits handling.
Rather than converting the proof of work limit to its compact
representation multiple times during operation, do it once at package
initialization time and export it via the chain parameters.
2013-07-30 12:59:50 -05:00
Dave Collins
cef901ebad Export chain parameters.
This commit exports the chain parameters used depending on the specific
bitcoin network so callers can have access to this information if desired.
2013-07-30 12:38:27 -05:00
Dave Collins
0e7791058a Add logging for chain forks and reorgs.
This commit adds info level log statements when a block causes a chain
fork, extends a side chain (fork), or causes a reorganize.  When a reorg
happens, the new and old chain heads along with the fork point are logged.
2013-07-29 22:32:12 -05:00
Dave Collins
e5eaaee91c Remove a couple of error logs that are not needed. 2013-07-29 22:31:05 -05:00
Dave Collins
829f187e47 Use network-specific genesis hash.
The test in checkConnectBlock for whether or not the node is the genesis
block needs to account for the genesis block of the specified network.
2013-07-29 20:21:24 -05:00
Dave Collins
04d88d01ec Clarify mismatched merkle root error message. 2013-07-29 19:50:00 -05:00
Dave Collins
077e1ec336 Improve second coinbase error message.
Include the index at which the second coinbase transaction was found.
2013-07-29 17:02:42 -05:00
Dave Collins
882d1c1687 Ensure height is set on block as well as the node.
Even though the code currently makes heavy use of nodes which will have
the appropriate height, blocks which did not come from the database will
not have a height set.  As a result, this could possibly result in a
height of 0 being used when unintended.  By setting the block height in
the block as soon as its known (regardless of the source), we can future
proof against bugs that would likely be hard to track down.
2013-07-29 16:58:48 -05:00
Dave Collins
6409879e14 Modify count sigops calls for new btcscript API.
The btcscript API for GetSigOpCount and GetPreciseSigOpCount
recently changed to no longer return an error.  This change was necessary
to mirror the behavior of bitcoind signature operations counting.  This
commit modifies the code accordingly to use the new API.
2013-07-29 16:21:33 -05:00
Dave Collins
c3b330e42d Allow tx inputs to use txns earlier in same block.
It is acceptable for a transaction input in a block to reference the
output of another transaction in the same block only if the referenced
transaction comes before the transaction referencing it.
2013-07-29 15:48:52 -05:00
Dave Collins
e82c97be3b Update examples for recent btcdb changes.
Since creating a new database with btcdb no longer automatically inserts
the main network genesis block, update the examples accordingly.
2013-07-29 12:35:01 -05:00
Dave Collins
761f666c44 Use consistent form for Checkpoint comment. 2013-07-27 16:46:46 -05:00
Dave Collins
ace58495c8 Comment CheckpointConfirmations. 2013-07-27 16:45:59 -05:00
Dave Collins
b282678d9a Spend outputs while checking transaction inputs.
This commit modifies the double spend detection to handle double spends
within the same block as well as side chains when doing the checks before
reorganizing the chain.
2013-07-26 11:51:13 -05:00
Dave Collins
9787f46f6a Implement testnet specific rules.
This commit adds support for testnet specific rules when a new BlockChain
is created against testnet.
2013-07-24 17:03:29 -05:00
Dave Collins
1deeb05627 Add a few log error messages.
In addition to returning errors to the caller, log the error with a prefix
in a few key places that helps identify the origin for errors.  In some
cases, the underlying error comes from a different subsystem such as the
SQL database driver and the error messages can be fairly generic.
2013-07-24 12:31:14 -05:00
Dave Collins
f219ed5baf Add support for params based on active network.
This commit modifies the code to use params based on the active network
which paves the way for supporting the special rules and different genesis
blocks used by the test networks.
2013-07-24 12:26:17 -05:00
Dave Collins
3c4292fae3 Add parent to info print when adding orphans. 2013-07-24 11:12:25 -05:00
Dave Collins
ebd4af80f0 Make CheckpointConfirmations 2016.
After discussing the criteria used by the core developers on #btc-dev IRC
channel, gmaxwell indicated they like to see at least 2016 blocks.  This
commit updates the checkpoint confirmations accordingly.
2013-07-22 03:20:00 -05:00
Dave Collins
f3e542ff92 Add negative test for duplicate block.
This commit adds tests for the error path when processing a block that is
already in the main chain.
2013-07-22 01:06:53 -05:00
Dave Collins
d6d2b15901 Clarify BIP0034 is supported in package doco. 2013-07-20 02:39:07 -05:00
Dave Collins
20f7c2ecd0 Add tests for TimeSorter. 2013-07-19 12:49:11 -05:00
Dave Collins
355502c970 Update documentation for IsCheckpointCandidate.
The bulleted list was not indented which caused godoc to show the
documentation improperly.
2013-07-19 10:08:09 -05:00
Dave Collins
aa5847f3cc Initial implementation. 2013-07-19 08:50:13 -05:00
Dave Collins
180c827db3 Initial commit. 2013-07-18 09:39:30 -05:00