Commit graph

29 commits

Author SHA1 Message Date
Dave Collins
1626994433 Avoid copying block headers in convenience locals.
This commit modifies local variables that are used for more convenient
access to a block's header to use pointers.  This avoids copying the
header multiple times.
2014-01-19 12:42:45 -06:00
Dave Collins
18ac5c848a Add 2014 to copyright dates. 2014-01-08 23:52:54 -06:00
Dave Collins
5295be070d Make the CheckBlockSanity function context free.
Rather than defining CheckBlockSanity as a member of a BlockChain
instance, define it at the root level so it is truly context free as
intended.  In order to make it context free, the proof of work limit is
now a required parameter.
2013-11-07 16:06:01 -06:00
Dave Collins
09b53a8fca Export the CheckBlockSanity function. 2013-11-07 15:39:48 -06:00
David Hill
36941cc427 Remove the satoshi consts and use them from btcutil instead. 2013-10-29 16:08:12 -04:00
David Hill
8271a11808 add SatoshiPerBitcent constant and export SatoshiPerBitcoin and
MaxSatoshi
2013-10-29 14:57:31 -04:00
Dave Collins
6165e9b95b Convert API to use new btcutil.Tx.
This is part of the ongoing transaction hash optimization effort noted in
conformal/btcd#25.
2013-10-28 15:17:53 -05:00
Dave Collins
b6e4ae4441 Optimize duplicate transaction input check.
Profiling showed the duplicate transaction input check was taking around
6% of the total CheckTransactionSanity processing time.  This was largely
due to using fmt.Sprintf to generate the map key.

This commit modifies the check instead to use the actual output as a map
key.

The following benchmark results show the difference:

Before: BenchmarkOldDuplicatInputCheck    100000     21787 ns/op
After:  BenchmarkNewDuplicatInputCheck   2000000       937 ns/op

Closes #2
2013-10-26 14:31:15 -05:00
Dave Collins
9a29855c16 Convert inability to find input tx to a RuleError.
This commit modifies the errors that result from missing expected input
transactions to a RuleError.  This allows the caller to detect a block was
rejected due to a rule violation as opposed to an unexpected error.
2013-10-13 02:38:46 -05:00
Dave Collins
8be23c89ae Cleanup a few comments. 2013-10-11 10:24:13 -05:00
Dave Collins
e888372019 Optimize transaction lookups.
This commit modifies the transaction lookup code to use a set instead of a
slice (list).  This allows the lookup to automatically prevent duplicate
requests to the database.

Previously, the code simply added every referenced transaction to a list
without checking for duplicates, which led to multiple requests against
the database for the same transaction.  It also meant the request list
could grow quite large with all of the duplicates using far more memory
than required.

While the end result was accurate, operating that way is not as efficient
as only requesting unique transactions.
2013-10-10 12:23:46 -05:00
Dave Collins
0b334bc841 Correct reading of serialized height in coinbase.
This commit corrects the reading of the serialized height in coinbase
transactions for block height of version 2 or greater.  On mainnet, the
serialized height is always 3 bytes and will continue to be so for
something like  another ~159 years, so there was no issue with mainnet.
However on testnet, there are some version 2 blocks which are low enough
in the chain to only take 2 bytes to serialize.

In addition, this commit adds a full tests for the relavant function
including negative tests and variable length serialized lengths for block
heights.

Closes #1.
2013-10-06 14:27:53 -05:00
Dave Collins
e54fb96d80 Test tx lookup validity in CheckInputTransactions.
This commit modifies CheckInputTransactions to ensure that not only must a
transaction exist in the transaction store, it must also not have any
errors associated with it or be nil.
2013-10-02 10:26:44 -05:00
Dave Collins
3c7511a34b Export the CheckTransactionInputs function. 2013-09-30 16:44:01 -05:00
Dave Collins
e576962cb3 Export the CheckTransactionSanity function. 2013-09-30 16:43:10 -05:00
Dave Collins
6695cd15bb Export the IsCoinbase function. 2013-09-30 16:42:28 -05:00
Dave Collins
4eb135618a Export the IsFinalizedTransaction function. 2013-09-30 16:40:19 -05:00
Dave Collins
fc69776371 Expose a transaction store and related functions.
Several of the functions require a map of contextual transaction data to
use as a source for referenced transactions.  This commit exports the
underlying TxData type and creates a new type TxStore, which is a map of
points to the under TxData.  In addition, this commit exposes a new
function, FetchTransactionStore, which returns a transaction store
(TxStore) containing all of the transactions referenced by the passed
transaction, as well as the existing transaction if it already exists.

This paves the way for subsequent commits which will expose some of the
functions which depend on this transaction store.
2013-09-30 16:37:11 -05:00
Dave Collins
117765ba7c Correct error message in other input tx lookup. 2013-08-28 13:50:47 -05:00
Dave Collins
ffa56b437c Correct error msg for missing input transaction.
The error message for missing input transaction had the referenced and
referencing transactions backwards.
2013-08-28 13:46:17 -05:00
Dave Collins
10a62a37a3 Update for latest btcutil, btcscript, and btcwire.
This commit updates the calls into btcutil, btcscript, and btcwire for the
latest API changes which remove the need for the protocol version for
serialization and deserialization of blocks and transactions.
2013-08-05 18:53: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
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
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
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
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
aa5847f3cc Initial implementation. 2013-07-19 08:50:13 -05:00