Commit graph

3509 commits

Author SHA1 Message Date
David Hill
eecea4180a Preallocate the tx serialization buffer.
Benchmarking shows this is slightly faster due to avoiding the extra
garbage collection in addition to less peak memory usage.

ok @davecgh
2014-03-20 15:33:09 -04:00
Dave Collins
f1a4dfb86d Update chain state with best block.
Rather than updating the new chain state with the hash and height of the
block that was just processed, query the database for the best block.
This is needed because the block that was just processed might be a side
chain block or have caused a reorg.
2014-03-20 14:08:46 -05:00
David Hill
b6e6fc25db Preallocate memory for the message header in WriteMessageN and the
serialization buffer in MsgTx's TxSha().

Benchmarking shows this is slightly faster due to avoiding the extra
garbage collection in addition to less peak memory usage.

Before: BenchmarkTxShaOld  500000         5626 ns/op
After:  BenchmarkTxShaNew  500000         5457 ns/op
2014-03-20 14:33:44 -04:00
Dave Collins
2de1b73d12 Add a benchmark for TxSha.
This commit adds a benchmark for the TxSha function of a MsgTx.
2014-03-20 10:46:36 -05:00
Dave Collins
1d674905e0 Introduce a chain state to block manager.
This commit introduces a chain state that is updated as blocks are
processed into the block chain instance associated with the block manager.

This has been done because btcchain is currently not safe for concurrent
access and the block manager is typically quite busy processing block and
inventory.  This approach allows fast access to most chain information in
a concurrent safe fashion.
2014-03-20 01:06:59 -05:00
Dave Collins
ee19fd79e4 Fix comment typo in addblock. 2014-03-20 00:37:35 -05:00
Dave Collins
9f1382f03c Use defaults in config struct for btcctl.
Rather than doing a lot of if/else in the configuration load for btcctl,
set the default for the RPC server to localhost and the RPC cert to the
btcd cert, then override them as needed depending on the --wallet and
--testnet flags.
2014-03-19 23:52:22 -05:00
David Hill
a94ca01cf4 add --testnet and --wallet options to btcctl.
Closes #112
2014-03-20 00:17:26 -04:00
Dave Collins
e3f3918242 Use increment on p.retryCount to make golint happy. 2014-03-19 17:58:58 -05:00
Dave Collins
ae89f7aa82 Expand btcctl RPC cert path to from config file.
This commit allows paths in the btcctl config file to use environment
variables and ~ as a shortcut for the home directory.

Closes #113.
2014-03-19 15:24:14 -05:00
Dave Collins
083f5e007c Correct the new addblock progress logging.
The code was not resetting the counters when logging a message, so the
stats kept increasing rather than showing the number of items processed
since the last log message.

This has been resolved by copying the log function directly from btcd and
modifying it slightly to work with the importer.
2014-03-19 15:11:50 -05:00
Dave Collins
0b73e14e79 Remove extraneous space and go fmt. 2014-03-19 09:47:49 -05:00
Jimmy Song
b12e2fc1db Issue #90: Improve addblock logging by reporting every 10 seconds instead of X number of blocks
blockImporter now has these new properties:

txProcessed - number of transactions processed by the importer
lastHeight - height of the last imported block
lastBlockTime - block time of the last imported block
lastLogTime - last timestamp of when a progress message was shown

the p/progress option in addblocks now indicates how often you want the progress message to appear
2014-03-19 09:35:19 -05:00
Dave Collins
3b9b11cb41 Update for recent btcutil.Address API change. 2014-03-18 20:44:03 -05:00
Owain G. Ainsworth
8ec60d4678 Quick and dirty tests harnesses using some bitcoind test data.
Both the script tests (positive and negative) and tx texts (ditto) are
present.  Some of the tx tests in the negative section have been
replaced by a comment line explaining why that test is elided, to add in
diffing. The reasons were always that they test things handled by other
parts of the btcd stack (normally chain). For example MAX_MONEY, number
of outputs, coinbase sizes etc.

Much of the inital test logic from @dajohi using hand transcribed tables
for selected tests. The json parsers, script format parser and a lot of
cleaning up/bugfixing from your truly. @davecgh had some input too.
2014-03-19 01:06:19 +00:00
Owain G. Ainsworth
5f6de02eb8 use bytes.Repeat instead of my perlscript generated lists of zeros.
Pointed out by davec. I'd forgotten about it. Kills just over 10k lines
from the test file.
2014-03-19 00:43:21 +00:00
Owain G. Ainsworth
1b1fef7369 Make removeOpcodeByData only search canonical pushes.
Matches bitcoind behaviour. Pointed out by one of their tx_invalid tests.
2014-03-18 18:28:09 +00:00
Josh Rickmar
239e13c0a5 Add createencryptedwallet to wallet request set. 2014-03-18 10:52:43 -05:00
Josh Rickmar
675f967d4a Add createencryptedwallet support to btcctl.
This is a btcwallet extension and will not work when talking to btcd
or bitcoind.
2014-03-18 10:50:38 -05:00
David Hill
ebf5a3e850 add peer to block and tx rejection debug messages.
ok @davecgh
2014-03-17 22:52:55 -04:00
Owain G. Ainsworth
76339baf6c Make removeOpcodeByData in line with bitcoind behaviour.
It should remove the opcode and data is the data is contained within the data
pushed, not just if it is equal to it. Found by bitcoind tx tests.
2014-03-18 00:49:24 +00:00
Dave Collins
e5afb5e984 Improve error return from sendrawtransaction.
Rather than simply returning "TX rejected" to the RPC client which
submitted a sendrawtransaction that fails, include the reason the it
failed.
2014-03-17 17:34:25 -05:00
Dave Collins
7a885b3cf6 Reject orphan transactions from sendrawtransaction.
This commit modifies the sendrawtransaction RPC to reject transactions
which are orphans.  This mirrors the behavior of the reference
implementation.
2014-03-17 17:32:30 -05:00
Owain G. Ainsworth
de670bd5b2 check for 0 length strings in pubkey parser.
We check length later, but we assumed it was always 1 bytes long. Not
always the case. I'm a little depressed that this bug was there.
2014-03-17 18:07:43 +00:00
Dave Collins
c570830104 Update README.md example to use leveldb.
SQLite is now fully deprecated and has been removed.  Spotted and reported
by @jolan.

Closes #3.
2014-03-17 12:58:22 -05:00
Owain G. Ainsworth
dab2a7cb0f Don't possibly dereference bad signatures in OP_CHECKMULTISIG.
We do all the preprocessing in one loop. Fixes a bug introduced a while ago to
handle invalid signatures. Found by more tests from bitcoind.
2014-03-17 17:46:56 +00:00
Dave Collins
c8332cc9a7 Correct num expected inputs calc for multisig.
This commit corrects the number of expected inputs for a multi-sig script
to include the additional item that is popped from the stack due to the
OP_CHECKMULTISIG consensus bug (which is required and properly performed).

Note this issue did NOT affect the consensus critical code and hence would
not cause a chain fork.  It did however, cause standard p2sh multisig txns
to be rejected from the mempool as nonstandard.

The tx rejected as non-standard which prompted this was spotted by
@mbelshe on IRC.

ok @owainga
2014-03-17 10:47:02 -05:00
Dave Collins
a87e6fbdea Change rate limit debug messages to trace level. 2014-03-17 00:23:08 -05:00
Dave Collins
93140802ba Improve non-standard tx error message.
This commit removes the word "only" from the non-standard transaction
error message when the number of items on the stack does not match the
number of expected items.

This was suggested by @mbelshe.
2014-03-17 00:19:53 -05:00
Francis Lam
24028ad37f Updated getinfo to return new RelayFee and use btcjson.InfoResult 2014-03-16 13:31:17 -05:00
John C. Vernaleo
71e31f03a2 Update coverage report. 2014-03-16 14:18:43 -04:00
Dave Collins
3c2a3e9f54 Update install command to also install utilities.
This commit updates the install command under the Installation section in
README.md to include all subdirectories thereby including the utilities
such as addblock and btcctl.
2014-03-15 22:32:45 -05:00
Dave Collins
96f9b88935 Export CalcPastMedianTime function.
This commit makes a slight variant of the existing calcPastMedianTime
function available to external callers.  The new exported version
calculates the past median time from the end of the current main chain
versus an arbitrary block node.
2014-03-15 15:04:59 -05:00
Dave Collins
6dd7785276 Export coinbase script length limits.
This commit exports the MinCoinbaseScriptLen and MaxCoinbaseScriptLen
constants.
2014-03-15 15:03:03 -05:00
Francis Lam
8f69a0bf69 Added new RelayFee field and missing TimeOffset field to InfoResult 2014-03-15 15:34:55 -04:00
Owain G. Ainsworth
9375c8dc48 move data extraction fof OP_PUSHDATA into main function.
This allows us to centralise the error checking to simplify things a bit.
2014-03-14 22:46:41 +00:00
Owain G. Ainsworth
02ee7762e4 AddData([]byte{}) is valid and should push empty to the stack.
Doing so is perfectly idiomatic.  Fixes the last of the valid bitcoind
script tests. (by fixing the script parser :)
2014-03-14 22:46:15 +00:00
Owain G. Ainsworth
299dcc2fad PushDataN with a 0 length is valid, we were too tight here.
Found by bitcoind positive tests. (but of course that is noncanonical
anyway, it should be OP_0 ;).
2014-03-14 22:46:14 +00:00
Owain G. Ainsworth
42f6576b02 Enforce max script length of 10000.
Detected by bitcoind negative script tests. Note that this length is only for
*executing* scripts, this is why it is in NewScript.
2014-03-14 22:45:14 +00:00
Owain G. Ainsworth
dec16d7ff2 Enforce a combined max stack depth of 1000 after every opcode.
This limit is for the sum of main and alt stacks. Found by bitcoind
negative tests.
2014-03-14 21:06:08 +00:00
Owain G. Ainsworth
d6d755e411 Always return reserved opcode for always-illegal ops. 2014-03-14 21:06:08 +00:00
Owain G. Ainsworth
8beb0dec54 Make opcode.Exec run a bunch of unconditional checks
Add push length and number of operations to this to match bitcoind behaviour.
found that we differed here by their negative tests.
2014-03-14 21:06:05 +00:00
Owain G. Ainsworth
f80c3255a3 PopInt now guarantees that number will be 32 bit.
So remove later checks that need this.
2014-03-14 21:05:29 +00:00
Owain G. Ainsworth
c7d5102954 Alt stack should be purged between scripts.
Found by bitcoind negative scripts.
2014-03-14 21:05:25 +00:00
Owain G. Ainsworth
a5e7e9ebb6 Disabled opcodes are `fail if pc passes' not fail if execute.
Detected by bitcoind negative tests.
2014-03-14 21:04:59 +00:00
Owain G. Ainsworth
c1a6e47f38 Conditionals must not straddle two scripts.
Found by tests dhill is working on. We checked that ifs were closed at the end
of execution but not at script switching time, we now move this to just after
finishing a single script.
2014-03-14 21:04:37 +00:00
Owain G. Ainsworth
8df0af32d6 Encountering OP_VERIF and OP_VERNOTIF in execution is always an error.
I honestly thought we already handled this, but some tests dhill is
working on shows that we didn't.
2014-03-14 20:28:23 +00:00
jolan
1bc63bfd5d recieve->receive 2014-03-14 15:08:51 -05:00
Owain G. Ainsworth
201d6651c9 Fix tests after IsForNet addition to btcutil.Address interface.
dhill pointed this out to me.
2014-03-13 17:20:45 +00:00
Dave Collins
510a44bdd9 Fix some comment typos. 2014-03-13 08:45:41 -05:00