Commit graph

3244 commits

Author SHA1 Message Date
Dale Rahn
e10cb732fd Fix. 2013-11-07 18:24:27 -05:00
Dave Collins
af311078b4 Correct btcctl getblockhash.
Also run gofmt while here.
2013-11-07 17:07:26 -06:00
Owain G. Ainsworth
d81a2c9067 Check for 0 shas before dereferencing list 2013-11-07 22:26:43 +00: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
Josh Rickmar
ced24946a4 Rework JSON handlers to take a btcjson.Cmd.
This change reworks where the command parsing occurs to be done before
handlers are checked.  Before, the websocket extension handler called
the standard handler with the same message, and if it was unhandled,
would unmarshal it a second time for checking extension handlers.
2013-11-07 13:53:41 -05:00
Josh Rickmar
d403863e2b Don't marshal a function for getbestblockhash replies. 2013-11-07 13:53:22 -05:00
Owain G. Ainsworth
f4a6449ad3 Actually just fail the opcode, not returning an error.
should fix some crazy script on testnet.
2013-11-07 18:23:20 +00:00
Owain G. Ainsworth
f0e7011b6f fix previous.
test patch, commit patch. Not the other way around, dumbass.
2013-11-07 17:32:11 +00:00
Owain G. Ainsworth
3aaafbd7fa handle op_checksig with an empty signature on the stack.
Crash found by jy-p, fix by me.
2013-11-07 17:09:22 +00:00
Josh Rickmar
b97a2145d8 Try to match bitcoind sendrawtransaction RPC errors. 2013-11-07 10:34:55 -05:00
Dave Collins
dd41f7e91a Minor cleanup.
This commit fixes a couple of comments and cleans up a couple of things
golint complained about.
2013-11-07 06:21:44 -06:00
Dave Collins
6f61e0acc2 Add negative tests for updated read/writeElement.
This commit adds tests for the error paths in the updated readElement and
writeElement functions.

This brings the test coverage back up to 100%.
2013-11-07 05:37:48 -06:00
Dave Collins
119a2ddc75 Add tests for updated readElement/writeElement.
This commit adds tests to ensure the new "fast" paths in readElement and
writeElement work properly including proper fallback to the slower
reflection based read/write of the binary package.
2013-11-07 05:17:17 -06:00
Dave Collins
9ee6a8aeb6 Optimize writeElement.
This commit modifies the writeElement function to have a "fast path" which uses type
assertions for all of the types which btcwire write so the more expensive
reflection-based binary.Write can be avoided.

Also, this changes all cases that were writing raw ShaHash (32-byte) arrays (which
requires a stack copy) instead simply passing the pointer.

The following benchmark results show the results for serializing a block header
after these changes:

Before: BenchmarkWriteBlockHeader         500000              5566 ns/op
After:  BenchmarkWriteBlockHeader        1000000               991 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-07 00:56:20 -06:00
Dave Collins
7de20add63 Add benchmark for writeBlockHeader.
This commit adds a benchmark for the writeBlockHeader function.
2013-11-07 00:30:20 -06:00
Dave Collins
bc85a31016 Optimize readElement.
The following benchmark results show the results for deserializing a block header:

Before: BenchmarkReadBlockHeader          500000              5916 ns/op
After:  BenchmarkReadBlockHeader         1000000              2078 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 23:00:17 -06:00
Dave Collins
d21050a8aa Add benchmark for readBlockHeader.
This commit adds a benchmark for the readBlockHeader function.
2013-11-06 20:35:17 -06:00
Dave Collins
9b7e3527b0 Optimize transaction Deserialize.
The benchmark results for the current commit:

Before: BenchmarkDeserializeTx    500000              4018 ns/op
After:  BenchmarkDeserializeTx    500000              3780 ns/op

The cumulative benchmark results since commit b7b700fd5a:

Before: BenchmarkDeserializeTx    200000             10665 ns/op
After:  BenchmarkDeserializeTx    500000              3780 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 18:41:41 -06:00
Dave Collins
92b2f9e6b3 Add benchmarks for transaction Deserialize.
This commit adds a benchmark for the MsgTx.BtcDecode/Deserialize
functions.
2013-11-06 18:01:29 -06:00
Dave Collins
a81e081cc4 Optimize transaction Serialize.
The benchmark results for the current commit:

Before: BenchmarkSerializeTx     1000000              1233 ns/op
After:  BenchmarkSerializeTx     1000000              1083 ns/op

The cumulative benchmark results since commit b7b700fd5a:

Before: BenchmarkSerializeTx     1000000              5437 ns/op
After:  BenchmarkSerializeTx     1000000              1083 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 17:43:44 -06:00
Dave Collins
fe713b8013 Add benchmarks for transaction Serialize.
This commit adds a benchmark for the MsgTx.BtcEncode/Serialize functions.
2013-11-06 16:56:42 -06:00
Dave Collins
1a1f93865f Optimize writeTxIn.
Before: BenchmarkWriteTxIn       5000000               422 ns/op
After:  BenchmarkWriteTxIn       5000000               389 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 16:38:51 -06:00
Dave Collins
63cc0851e5 Add benchmarks for writeTxIn.
This commit adds a benchmark for the writeTxIn function.
2013-11-06 16:21:49 -06:00
Dave Collins
59da692131 Optimize readTxIn.
Before: BenchmarkReadTxIn        1000000              2435 ns/op
After:  BenchmarkReadTxIn        1000000              1427 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 16:18:15 -06:00
Dave Collins
1fe9f9e165 Add benchmarks for readTxIn.
This commit adds a benchmark for the readTxIn function.
2013-11-06 16:06:53 -06:00
Dave Collins
cece305f78 Optimize readTxOut.
Before: BenchmarkReadTxOut        500000              4576 ns/op
After:  BenchmarkReadTxOut       2000000               871 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 15:49:26 -06:00
Dave Collins
0228508172 Add benchmarks for readTxOut.
This commit adds a benchmark for the readTxOut function.
2013-11-06 15:40:46 -06:00
Dave Collins
a7e3ee6aeb Optimize writeTxOut.
Before: BenchmarkWriteTxOut       500000              4050 ns/op
After:  BenchmarkWriteTxOut     10000000               248 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 15:29:39 -06:00
Dave Collins
ab8c8e2d39 Add benchmarks for writeTxOut.
This commit adds a benchmark for the writeTxOut function.
2013-11-06 15:21:37 -06:00
Owain G. Ainsworth
c1a1e6b6b2 keep track of connected groups as we gain and lose outbound peers.
Instead of recalculating every time we go to look for more peers. Should
save a few cycles.
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth
6949a4f940 Have a list per class of peer instead of just one.
persistentpeers and outbound(nonpersistent) peers get their own lists,
so iterating over them can be much simpler (and quicker when you have
125 peer of which 8 are outbound).
2013-11-06 19:08:06 +00:00
Owain G. Ainsworth
4d80750afe Move all local data to peerhandler into a peerState structure
Pass peerstate around instead of indivdual bits.
2013-11-06 18:52:58 +00:00
Owain G. Ainsworth
d8c5222474 Rework the way we send notifications over the websocket
Redo the datastructures we search so that we only do one lookup per txin and
txout instead of doing a loop per wallet connection.

Don't send spent data on tx notifications, this can be worked out in wallet and
it is expensiveish to calculate. However we DO check upon getting a notification
request if the output is already spent, and in which case we send an immediate
notification to force a rescan.

MinedTxNotfications are handled separately to the connected block messages
largely to enable this to scale rather better.

Tested by jrick (who found one bug i had introduced, thanks!)

Additionally (accidentally squashed in):

Add handlers for all known commands.

We have handlers for all wallet-requiring commands that will return a suitable
error.

Unimplemented commands temporarily return an error stating so.
2013-11-06 18:47:06 +00:00
Josh Rickmar
8c2b9ae06e Begin using btcws.
This change adds support for the unmarshaling custom commands sent by
btcwallet and supported in the btcws package.
2013-11-06 11:20:36 -05:00
Josh Rickmar
b57628ea9f Initial commit. 2013-11-06 11:11:04 -05:00
Dave Collins
48c350f379 Update test coverage report. 2013-11-06 07:44:51 -06:00
Dave Collins
73f4ee623b Optimize readOutPoint.
Before: BenchmarkReadOutPoint     500000              2946 ns/op
After:  BenchmarkReadOutPoint    5000000               582 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 07:37:34 -06:00
Dave Collins
d63e0dd455 Add benchmarks for readOutPoint.
This commit adds a benchmark for the readOutPoint function.
2013-11-06 07:33:37 -06:00
Dave Collins
f54b010e4b Optimize writeOutPoint.
Before: BenchmarkWriteOutPoint    500000              2664 ns/op
After:  BenchmarkWriteOutPoint  10000000               151 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-06 00:47:57 -06:00
Dave Collins
547b648702 Add benchmarks for writeOutPoint.
This commit adds a benchmark for the writeOutPoint function.
2013-11-06 00:45:30 -06:00
Dave Collins
8a1828a2d6 Optimize writeVarString.
Before:

BenchmarkWriteVarStr4    1000000              1114 ns/op
BenchmarkWriteVarStr10   1000000              1352 ns/op

After:

BenchmarkWriteVarStr4    5000000               291 ns/op
BenchmarkWriteVarStr10  10000000               248 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-05 23:59:40 -06:00
Dave Collins
fa8f666e8c Add benchmarks for writeVarString.
This commit adds a couple of benchmarks for the writeVarString function.
2013-11-05 23:49:34 -06:00
Dave Collins
4002051a22 Optimize readVarString.
Before:

BenchmarkReadVarStr4     1000000              1698 ns/op
BenchmarkReadVarStr10    1000000              1812 ns/op

After:

BenchmarkReadVarStr4     2000000               853 ns/op
BenchmarkReadVarStr10    5000000               712 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-05 23:33:21 -06:00
Dave Collins
b830e2ddf3 Add benchmarks for readVarString.
This commit adds a few benchmarks for the readVarString function.
2013-11-05 23:09:44 -06:00
Dave Collins
052c2ca8d3 Correct benchmark comments. 2013-11-05 23:03:54 -06:00
Dave Collins
6263efcc71 Slightly optimize readVarInt.
This commit slightly optimizes the readVarInt function in the case of
multiple-byte variable length integers.  It also reduces the amount of
memory garbage it generates.

Before:

BenchmarkReadVarInt1     5000000               386 ns/op
BenchmarkReadVarInt3     5000000               693 ns/op
BenchmarkReadVarInt5     2000000               793 ns/op
BenchmarkReadVarInt9     5000000               709 ns/op

After:

BenchmarkReadVarInt1     5000000               387 ns/op
BenchmarkReadVarInt3     5000000               471 ns/op
BenchmarkReadVarInt5     5000000               575 ns/op
BenchmarkReadVarInt9     5000000               473 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-05 22:09:03 -06:00
Dave Collins
87ce23d679 Add benchmarks for readVarInt.
This commit adds a few benchmarks for the readVarInt function.
2013-11-05 21:35:28 -06:00
Dave Collins
50c10faf4e Optimize writeVarInt.
Before:

BenchmarkWriteVarInt1   10000000               173 ns/op
BenchmarkWriteVarInt3    2000000               965 ns/op
BenchmarkWriteVarInt5    2000000               966 ns/op
BenchmarkWriteVarInt9    2000000               968 ns/op

After:

BenchmarkWriteVarInt1   20000000               101 ns/op
BenchmarkWriteVarInt3   20000000               136 ns/op
BenchmarkWriteVarInt5   10000000               142 ns/op
BenchmarkWriteVarInt9   10000000               156 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-11-05 20:33:14 -06:00
Dave Collins
900db0b444 Add benchmarks for writeVarInt.
This commit adds a few benchmarks for the writeVarInt function.
2013-11-05 19:56:12 -06:00