Commit graph

163 commits

Author SHA1 Message Date
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
0e1f6a6628 Export MaxBlockHeaderPayload. 2014-03-11 20:22:32 -05:00
Dave Collins
e5d15b0fa8 Export MaxVarIntPayload. 2014-03-11 20:09:55 -05:00
Dave Collins
b9c21bd518 Export VarIntSerializeSize function.
This commit exports the VarIntSerializeSize function to provide callers
with an easy method to determine how many bytes it would take to serialize
the passed value as a variable length integer.
2014-03-03 18:43:09 -06:00
Dave Collins
1623818c12 Export a new constant for MaxPrevOutIndex.
This commit exports a new constant for the maximum index a previous
outpoint can contain.
2014-02-25 16:00:03 -06:00
Dave Collins
13e0b0e7b9 Limit generated timestamps to one second precision.
This commit changes all cases which generate default timestamps to
time.Now to limit the timestamp to one second precision.  The code which
serializes and deserializes timestamps already does this, but it is useful
to make sure defaults don't exceed the precision of the protocol either.

With this change there is less chance that developers using defaults will
end up with structures that have a higher time precision than what will
ultimately be sent across the wire.
2014-02-24 09:55:02 -06:00
David Hill
f6b03bf8a8 gofmt 2014-02-04 16:14:08 -05:00
David Hill
d0dfff8292 fix typo in test: use %s for strings 2014-02-04 14:35:38 -05:00
Dave Collins
ff783faf53 Add Read/WriteMessageN to return number of bytes.
This commit adds two new funtions named ReadMessageN and WriteMessageN
which return an additional paramter for the number of bytes read or written,
respectively.

It also adds tests to ensure the number of bytes read and written are the
expected values both for successful reads/writes and unsuccessful ones.

Closes #6.
2014-02-03 23:12:43 -06:00
Dave Collins
6672f71d68 Add tests for new Serialize/Deserialize functions. 2014-01-18 21:43:11 -06:00
Dave Collins
06d1236d49 Add Serialize/Deserialize for BlockHeader.
This commit introduces two new functions for Blockheader named Serialize
and Deserialize.  The functions provide a stable mechanism for serializing
and deserializing block headers to and from disk.  The main benefit here
is deserialization of the header since typically only full blocks are
serialized to disk.  Then when a header is needed, only the header portion
of the block is read and deserialized.
2014-01-18 21:42:43 -06:00
Dave Collins
d6aea22adb Remove deprecated InvType_* constants.
This closes #13.
2014-01-18 20:53:50 -06:00
Dave Collins
144822d4bf Remove BlockHeader.TxnCount field.
This commit removes the TxnCount field from the BlockHeader type and
updates the tests accordingly.  Note that this change does not affect the
actual wire protocol encoding in any way.

The reason the field has been removed is it really doesn't belong there
even though the wire protocol wiki entry on the official bitcoin wiki
implies it does.  The implication is an artifact from the way the
reference implementation serializes headers (MsgHeaders) messages.  It
includes the transaction count, which is naturally always 0 for headers,
along with every header.  However, in reality, a block header does not
include the transaction count.  This can be evidenced by looking at how a
block hash is calculated.  It is only up to and including the Nonce field
(a total of 80 bytes).

From an API standpoint, having the field as part of the BlockHeader type
results in several odd cases.

For example, the transaction count for MsgBlocks (the only place that
actually has a real transaction count since MsgHeaders does not) is
available by taking the len of the Transactions slice.  As such, having
the extra field in the BlockHeader is really a useless field that could
potentially get out of sync and cause the encode to fail.

Another example is related to deserializing a block header from the
database in order to serve it in response to a getheaders (MsgGetheaders)
request.  If a block header is assumed to have the transaction count as a
part of it, then derserializing a block header not only consumes more than
the 80 bytes that actually comprise the header as stated above, but you
then need to change the transaction count to 0 before sending the headers
(MsgHeaders) message.  So, not only are you reading and deserializing more
bytes than needed, but worse, you generally have to make a copy of it so
you can change the transaction count without busting cached headers.

This is part 1 of #13.
2014-01-18 20:53:20 -06:00
Dave Collins
6c7f45fdb7 Add 2014 to copyright dates. 2014-01-08 23:44:08 -06:00
Dave Collins
2458841855 Add tests for new size hint functions.
This brings the test coverage back up to 100%.
2014-01-08 17:43:18 -06:00
Dave Collins
497aac6d4a Add new funcs to allow size hints on getdata/inv.
This commit adds two new functions named NewMsgGetDataSizeHint and
NewMsgInvSizeHint.  These are intended to allow callers which know in
advance how large the inventory lists will grow the ability to provides
that information when creating the message.  This in turn provides a
mechanism to avoid the need to perform several grow operations of the
backing array when adding large number of inventory vectors.
2014-01-08 17:21:51 -06:00
Dave Collins
e64e6f0757 Add tests for new BitcoinNet Stringer. 2014-01-03 08:36:11 -06:00
Dave Collins
626662fb5f Add Stringer to BitcoinNet. 2014-01-03 08:32:43 -06:00
Dave Collins
e5a09bdfaa Configure TravisCI to pull pkgs needed for tests. 2013-12-10 16:13:08 -06:00
Dave Collins
977d47641f Add support for TravisCI.
Also add TravisCI build status badge to README.md.
2013-12-09 05:41:54 -06:00
Marco Peereboom
6ad853019a use fastsha256 2013-11-19 09:26:22 -06: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
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