Commit graph

185 commits

Author SHA1 Message Date
Dave Collins
3951e75a3f Update btcchain import paths to new location. 2015-01-16 18:40:47 -06:00
Dave Collins
14056ad2ca Update btcdb import paths to new location. 2015-01-16 18:29:19 -06:00
Dave Collins
9bb251f530 Update btcnet import paths to new location. 2015-01-16 17:28:19 -06:00
Dave Collins
3a35b009ac Update btcwire import paths to new location. 2015-01-16 13:57:29 -06:00
Dave Collins
37d0e1918b Update btclog import paths to new location. 2015-01-16 11:13:42 -06:00
David Hill
81b6031236 Enable the race detector for TravisCI. 2015-01-15 17:14:03 -05:00
Dave Collins
ee945cdeec Update btcutil import paths to new location. 2015-01-15 10:23:47 -06:00
Dave Collins
4e41922fe8 Merge branch 'jrick_double_spend_err' of https://github.com/jrick/btcchain into jrick-jrick_double_spend_err 2015-01-08 05:42:40 -06:00
Dave Collins
be91008dc5 Update badges in README.md to SVG.
Also add a license badge while here.
2015-01-08 05:36:41 -06:00
Dave Collins
bf3195e4ae Update TravisCI to goclean script.
- Also update to use the new container-based builds
2015-01-08 05:25:26 -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
Josh Rickmar
8945620a84 Improve double spend error strings.
The error message now includes both the previous tx hash and output
index, rather than simply the transaction with the already spent
output.
2015-01-06 20:11:42 -05:00
Dave Collins
6af9302374 More false positive prevention in new time tests.
This commit extends the same logic in the previous commit to the
comparison of offsets returned from the median time source in the tests.

In particular it modifies the tests to allow for the offsets to differ by
a second due to a boundary condition to prevent false positives.
2014-10-11 18:06:41 -05:00
Dave Collins
b4c55aee28 Update new time tests to prevent false positives.
The new median time tests perform a comparsion of the adjusted time
returned from the median time source to the expected value.  However,
since time is always moving, it is possible the current time between the
call to the adjusted time function and the current time taken in the tests
for comparison just after the call differ by a second due to a boundary
condition.  So, this commit modifies the tests to allow for this
condition.
2014-10-11 14:53:27 -05:00
Dave Collins
e1c622c4cf Modify the time sorter tests to make golint happy.
This commit changes the internal testing mechanism from returning the
unexported timeSorter type directly to insted returning sort.Interface.
This has been done because the latest version of golint complains about
return unexported types.
2014-10-11 13:30:08 -05:00
Dave Collins
208d4d79d7 Add 100% test coverage for new median time code. 2014-10-10 01:23:39 -05:00
Dave Collins
df065eee19 Provide a new median time source API.
This commit provides a new interface, MedianTimeSource, along with a
concrete implementation which allows improved accuracy of time by making
use of the median network time as calculated from multiple time samples.

The time samples are to be provided by callers and are intended to come
from remote clients.

The calculations performed in this implementation exactly mirror those in
Bitcoin Core because time calculations are part of the consensus rules and
hence need to match exactly.
2014-10-10 01:12:39 -05:00
Jonathan Gillham
f60e503308 Changed TxIn.PreviousOutpoint to TxIn.PreviousOutPoint after btcwire API change. 2014-10-01 13:53:47 +01:00
John C. Vernaleo
f5f03e8172 Match error names to btcdb updates. 2014-09-16 15:08:53 -04:00
John C. Vernaleo
351a2a5f5e Add vet, lint, and 1.2 builds to travis. 2014-09-16 08:21:34 -04:00
David Hill
c3abafc7eb Println -> Printf when using formatting directives.
This makes go vet happy.
2014-08-28 10:23:46 -04:00
Dave Collins
ff4d01765f Split time too old error into two distinct errors.
This commit splits the two rule validation errors related to the timestamp
being too old into two distince errors rather than grouping them under the
same one.  Thus there is now a new ErrCheckpointTimeTooNew in addition to
the existing ErrTimeTooNew error.

This allows the caller to detect the when a block is rejected due to a
time-related checkpoint failure whereas before the combined error did not.
2014-07-11 09:48:36 -05:00
Dave Collins
cc315d045e Use a more specific license adjective in README.md. 2014-07-08 10:32:29 -05:00
Dave Collins
01fa7fa069 Add BigToCompact example. 2014-07-08 07:57:22 -05:00
Dave Collins
1a2baa3099 Add CompactToBig example. 2014-07-08 02:15:41 -05:00
Dave Collins
62c14b7001 Name new example so it shows up properly on godoc. 2014-07-08 01:49:48 -05:00
Dave Collins
94845326b5 Use testable example and update doc.go README.md.
This commit moves the ProcessBlock example to a test file so it integrates
nicely with Go's example tooling.

This allows the example output to be tested as a part of running the
normal Go tests to help ensure it doesn't get out of date with the code.
It is also nice to have the example in one place rather than repeating it
in doc.go and README.md.

Links and information about the example have been incldued in doc.go and
README.md in place of the example.
2014-07-08 01:45:28 -05:00
Dave Collins
7e875e7952 Add godoc reference badge to README.md. 2014-07-07 23:00:13 -05:00
Dave Collins
5a4242cb03 Update doc.go and README.md examples to use memdb.
Since the code is only intended to be example code, there is no reason to
use a database which actually writes to disk.
2014-07-07 22:52:36 -05:00
Dave Collins
73228aaebe Update for recent btcdb API changes.
Since the underlying database driver can now return an error when looking
up if blocks and transactions exist, the HaveBlock function now includes
an error return to allow any underlying errors to be exposed.
2014-07-07 11:48:41 -05: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
Tomás Senart
e29f40274d Replace map[a]bool with map[a]struct{}
The later uses no memory storage for values and provides the same
functionality.
2014-07-02 17:56:22 +02:00
Dave Collins
933cdf50e8 Export constant for the maximum time offset.
This commit creates and exports a new constant, MaxTimeOffsetSeconds,
which is the maximum number of seconds a block timestamp is allowed to be
ahead of the current time.

Previously this value was hard coded into the consensus rule path, however
it is useful better to have it defined as a constant and exported so other
callers can access it.

No consensus rules have been changed with this commit.
2014-06-30 12:14:58 -05:00
Dave Collins
dbca1d59c3 Add a new behavior flag to provide a dry run.
This commit adds a new behavior flag, BFDryRun which allows the caller
to indicate all checks should be performed against the block as normal
except it will not modify any state.  This is useful to test that a block
is valid without actually modifying the current chain or memory state.

This commit also adds a few additional checks which were elided before
since they are implicitly handled by btcwire.  However, with the ability
to propose blocks which didn't necessarily come through the btcwire path,
these checks need to be enforced in the chain code as well.

As a part of adding the checks, three new error codes named
ErrBlockTooBig, ErrTooManyTransactions, and ErrTxTooBig have been
introduced.

Closes #5.
2014-06-29 17:49:16 -05:00
Dave Collins
ae51c3e6e0 Update test coverage report. 2014-06-27 00:01:33 -05: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
cf3ad14d4d Remove TODO that is complete. 2014-06-26 20:31:32 -05:00
Dave Collins
ad275b34a8 Add a new behavior flag to disable the pow check.
This commit adds a new behavior flag, BFNoPoWCheck which allows the caller
to indicate the check which ensures a block hashes to a value less than
required target should not be performed.
2014-06-26 17:25:47 -05:00
Dave Collins
67394ec45d Modify ProcessBlock to accept behavior flags.
This commit change the ProcessBlock function to accept a new type named
BehaviorFlags in place of the current fastAdd parameter.

This has been done to pave the way for adding more control over the checks
that are performed such as avoiding the proof of work checks which will be
in an upcoming commit.  A bitmask was chosen because it will allow the
ProcessBlock API to remain a little more stable since new flag additions
that change the behavior are only likely to be used by new code because
adding flags does not change the existing behavior.

ok @jrick
2014-06-26 17:17:32 -05:00
Dave Collins
7d84d801d7 Make golint happy. 2014-06-26 16:10:10 -05:00
Dave Collins
415ac4596a Make orphan ntfns to a return val on ProcessBlock.
This commit changes the way that orphan blocks are identified by adding a
new boolean return value on ProcessBlock and removing the notification for
NTOrphanBlock.

This allows the calling code to identify orphan blocks immediately instead
of having to setup a seperate callback handler and implementing some type
of state tracking.  This, in turn, allows cleaner code for handling them.

In addition, the tests have been updated for the new function signature
and also now check that each block is or is not an orphan as expected
which makes the tests more robust.

ok @jrick
2014-06-25 17:46:00 -05:00
Dave Collins
0550bbbdc5 Add tests for new RuleError and ErrorCode types. 2014-06-24 19:14:30 -05:00
Dave Collins
6e0aab52df Improve the RuleError type to include error codes.
This commit changes the RuleError type to a struct which consists of an
error code and human-readable description.

From a usage perspective, existing code should not break since type
asserting an error to a RuleError still works in the same manner.  The
difference is the caller can now take that type asserted RuleError and
access the .ErrorCode field on it to programmatically identify the
specific rule that was violated.

ok @jrick
2014-06-24 19:14:24 -05:00
Dave Collins
87bef61b30 Update tests to use btcnet genesis params. 2014-05-28 00:56:57 -05:00
Dave Collins
b0b090009a Update README.md for btcnet changes.
The sample code in doc.go was updated for the recent btcnet changes,
however the sample code in the README.md was not.
2014-05-28 00:56:06 -05:00
Dave Collins
f37a5e76b5 Update tests for recent API changes. 2014-05-27 10:15:35 -05:00
Dave Collins
4579cfb71b Refactor several network-specific params to btcnet.
This commit refactors the code to make use of the btcnet package for
network-specific parameters instead of switching on the specific network.

For example, the percentage of the network that needs to run version 2
blocks is different between testnet and mainnet.  Previously the code was
using a switch to choose these values.  With this refactor, those
parameters are part of the network parameters provided when creating a new
chain instance.

Another example is checkpoints, which have been moved to btcnet so they
can be specified by the caller instead of hard coded into this package.
As a result, the checkpoints for the standard networks are now specified
in the btcnet package.

This makes it easier to add new networks such as a testnet4 should it
become needed.  It also allows callers to define their own custom network
parameters without having to modify the code of the package to add new
switch cases for the custom network.
2014-05-27 10:11:55 -05:00
Dave Collins
d4082e4f24 Add checkpoint at block height 300255. 2014-05-23 13:44:23 -05:00
David Hill
0cdaefd4cc export HashMerkleBranches
ok @davecgh
2014-05-22 13:29:39 -04:00