Commit graph

23 commits

Author SHA1 Message Date
Dave Collins b69a849114 Import btcchain repo into blockchain directory.
This commit contains the entire btcchain repository along with several
changes needed to move all of the files into the blockchain directory in
order to prepare it for merging.  This does NOT update btcd or any of the
other packages to use the new location as that will be done separately.

- All import paths in the old btcchain test files have been changed to
  the new location
- All references to btcchain as the package name have been changed to
  blockchain
2015-01-30 15:49:59 -06:00
Dave Collins 3f177c9895 Update btcscript import paths to new location. 2015-01-30 12:08:47 -06:00
Dave Collins e90d95358d Update btcscript import paths to new location. 2015-01-16 19:35:05 -06:00
Dave Collins 3a35b009ac Update btcwire import paths to new location. 2015-01-16 13:57:29 -06:00
Dave Collins ee945cdeec Update btcutil import paths to new location. 2015-01-15 10:23:47 -06:00
Dave Collins d58ea754f3 Add test and infrastructure for block scripts.
This commit adds a test for checking known good block scripts in a block
are valid.  As a part of this, it adds the infastructure needed to load a
saved transaction store from a file which contains all of the input
transactions needed.

It also contains some changes from running goimports as well as some other
cleanup.
2015-01-08 05:10:54 -06:00
Jonathan Gillham f60e503308 Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint after btcwire API change. 2014-10-01 13:53:47 +01:00
Tomás Senart 4772d4a1a4 goimports -w . 2014-07-02 19:14:27 -05:00
Tomás Senart 73ed07bd85 Use chan struct{} for semaphores
With semaphores we don't actually care about the value passed in. It
makes sense to use a 0 bytes type in these cases.
There is also the added benefit of compiler optimisations for this
specific use case as described here:
https://docs.google.com/document/d/1yIAYmbvL3JxOKOjuCyon7JhW4cSv1wy5hC0ApeGMV9s/pub
2014-07-02 18:00:47 +02:00
Dave Collins a22da99f91 Convert script errors to RuleErrors.
This commit modifies the error return type for errors during script
validation to use the RuleError so they are consistent with the rest of
the errors.  This also helps the calling code differentiate blocks
rejected due to script parsing and validation errors as opposed to
internal issues such as inability to read from the disk.

To accomplish this, two new two new RuleErrors, ErrScriptMalformed and
ErrScriptValidation, have been added.

Also, the errors for script parsing issues and script validation errors
have been improved to include both transaction hashes and indexes involved
in the validation effort.  Previously script parsing issues had almost no
additional information as to which transaction input/outputs the failing
script came from.
2014-06-26 23:47:14 -05:00
Dave Collins bb4ea7d59a Include in/out script bytes in script val error. 2014-02-03 20:27:13 -06:00
Dave Collins b7ef1f0946 Include transaction hash in failed input val error. 2014-02-03 20:03:06 -06:00
Dave Collins 84f6089bc9 Rework and improve async script validation logic.
The previous script validation logic entailed starting up a hard-coded
number of goroutines to process the transaction scripts in parallel.  In
particular, one goroutine (up to 8 max) was started per transaction in a
block and another one was started for each input script pair in the
each transaction.  This resulted in 64 goroutines simultaneously running
scripts and verifying cryptographic signatures.  This could easily lead to
the overall system feeling sluggish.

Further the previous design could also result in bursty behavior since the
number of inputs to a transaction as well as its complexity can vary
widely between transactions.  For example, starting 2 goroutines (one to
process the transaction and one for actual script pair validation) to
verify a transaction with a single input was not desirable.

Finally, the previous design validated all transactions and inputs
regardless of a failure in one of the other scripts.  This really didn't
have a big impact since it's quite rare that blocks with invalid
verifications are being processed, but it was a potential way DoS vector.

This commit changes the logic in a few ways to improve things:

- The max number of validation goroutines is now based on the number of
  cores in the system
- All transaction inputs from all transactions in the block are collated
  into a single list which is fed through the aforementioned validation
  goroutines
- The validation CPU usage is much more consistent due to the collation of
  inputs
- A validation error in any goroutine immediately stops validation of all
  remaining inputs
- The errors have been improved to include context about what tx script
  pair failed as opposed to showing the information as a warning

This closes conformal/btcd#59.
2014-01-16 20:02:30 -06:00
Dave Collins 18ac5c848a Add 2014 to copyright dates. 2014-01-08 23:52:54 -06:00
Owain G. Ainsworth 8a19f269ca use passed in parameter and not global in log message.
Should shut up the race detector (and make the printf more correct)
2013-11-21 18:23:45 +00: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 89d86d07ac ValidateTransactionScripts now accepts script flags.
This commit modifies the ValidateTransactionScripts API to accept the
recently added ScriptFlags from btcscript.  This provides flexibility to
the caller to choose validation behavior based on those new flags.
2013-10-25 10:49:06 -05:00
Dale Rahn b680d3539f Revive old validate Tx in parallel code, faster...
requested by davec, cleanup/polish in-tree.
2013-10-11 18:31:54 -04:00
Dave Collins baa4c36618 Export ValdiateTransactionScript function.
This function allows the caller to execute and validate all scripts for
the passed transaction (which includes signature verification).
2013-09-30 16:47:37 -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 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 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 aa5847f3cc Initial implementation. 2013-07-19 08:50:13 -05:00