Commit Graph

363 Commits

Author SHA1 Message Date
Miron Cuperman (devrandom)
0bc87e5804 Fix bug in Utils.copyOf 2011-10-19 21:14:21 +00:00
Miron Cuperman (devrandom)
cb4067da09 Remove dependency on Java 1.6 2011-10-19 21:05:39 +00:00
Miron Cuperman (devrandom)
a4a711e2df Fix serialization UIDs, other cleanup 2011-10-19 18:42:38 +00:00
Miron Cuperman (devrandom)
228f30f663 Fix length and parseLazy handling. Resolves issue 92 2011-10-18 17:06:12 +00:00
Miron Cuperman (devrandom)
37a63265ef Disable assert in Message causing failing tests 2011-10-17 19:18:02 +00:00
Mike Hearn
fb5915e4c4 Reformat the codebase, this is pretty much whatever IntelliJ thinks the code should look like.
This will unfortunately break all patches, but it has to be done at some point.
2011-10-14 13:06:54 +00:00
Mike Hearn
84f738763f Patch 11 from Steves lazy parsing patchset.
Cache checksum for non-empty messages.

VersionMessage and AddressMessage require some special handling.  VersionMessage because it's never lazy parsed or cached.  AddressMessage because when serializing PeerAddresses the time field is dynamic.

Checksum byte array is currently transient so no gains for a message extracted from java serialization then bitcoinSerialized.  I don't think this would ever happen in real life but if it does then it could also be included in the serialized object.
2011-10-14 12:41:36 +00:00
Mike Hearn
f336a89984 Patch 10 from Steves lazy parsing patchset.
Customize Sha256Hash.hashCode() method to only use first n bytes of the backing array.  This provides uniqueness to 256^n combinations.  As hashcode is not required to be guaranteed unique this fulfills the contract and reduces hashing time.

Use case is for applications that do a lot of mapping by Sha256Hash.  Each put and get require several hashcode operations.  Cached hashcode is already implemented in 8.patch.

Similar changes to this yielded huge performance benefits in poolserverj.

There is no point implementing a FastEquals version of equals given the bytes are essentially random and no byte is any more likely unique than another.
2011-10-14 12:39:11 +00:00
Mike Hearn
ee083d6fac Patch 9 from Steves lazy parsing patchset.
Add UnsafeByteArrayOutputStream.  ByteArrayOutputStreams are used extensively and result in a lot of short lived byte arrays.

This patch contains two optimizations

1/ attempt to provide the final length to ByteArrayOutputStream constructor to avoid constantly resizing the backing array.  Default size is 32 which means larger messages may require several array reallocations and almost all will require at least one.

2/ provides the UnsafeByteArrayOutputStream class which eliminates method synchronization.  The toByteArray() will return the backing array rather than a copy if the correct length was provided in the constructor.

In the worst case scenario this cuts array allocations from 3 to 2.
In the most common worst case from 3 to 1.
In most best cases where final array size is greater than 128 bytes from > 4 to 1.
2011-10-14 12:37:27 +00:00
Mike Hearn
27b6b5ab97 Patch 8 from Steves lazy parsing patchset.
More optimizations: pre-calculate or guess various array sizes to avoid needlessly re-sizing them later.

Sha256Hash caches the hashCode.

Message classes now track their (estimated) length even when not using deserialization-related constructors.
2011-10-14 12:33:47 +00:00
Mike Hearn
8bf12acb2b Patch 7 from Steves lazy parsing patchset:
Some changes to SpeedTest. This code can be removed later.
2011-10-14 12:28:13 +00:00
Mike Hearn
06ad3e5bb1 Patch 6 from Steves lazy parsing patchset:
Deduping related optimizations. This code will be removed later.
2011-10-14 12:27:16 +00:00
Mike Hearn
ab8227882d Patch 5 from Steves lazy parsing patchset:
Optimise BitcoinSerialiser for Transactions.  When calculating checksum on deserialize use it prepopulate the transaction's hash.  Likewise on serialize check if the Transaction already has a hash and use that to write checksum bytes.  This yields performance improvesment up to 400% by saving on a double hash.

Don't parse all the subcomponents of a Transaction purely to calculate its length, instead do the minimal work possible.

Recaching on a call to bitcoinSerialise().  Prevents double serialization of transactions and inputs/outputs when calculating a merkleroot during block serialization.  Also makes it more likely the original larger byte array can be GC'd
2011-10-14 12:25:05 +00:00
Mike Hearn
afef6bc029 Second part of Steves lazy parsing patchset:
1) Added getters and setters to many objects that lacked them.
2) Introduce a parseLite method that is called even in "lazy parse" mode. This calculates the length of the message so children can be skipped when parsing a container object.
3) Full serialization for AddressMessage
4) Added a (huge, standalone) SpeedTest.
5) Add unit tests for the matrix of lazy parsing modes.

A bunch of review comments are added to the TODO list for completion after the patch series is checked in. This is to avoid large numbers of merge conflicts as later parts of the patch-series are committed.
2011-10-11 17:24:50 +00:00
Mike Hearn
34fea86708 First part of Steves changes in preparation for a high performance multiplexing proxy:
1) Introduce partial support for caching the underlying byte arrays during message deserialization, so re-serialization can be skipped in the case where a message is not modified.
 
 2) Add c'tors that allow a message to be configured to lazily parse on-demand.
 
 Note that the getters/setters that make lazy parsing transparent are coming in future commits.
2011-10-11 13:08:54 +00:00
Mike Hearn
ba2351f5aa Simplify EmptyMessage. Gets to patch 0 from Steve. 2011-10-11 11:43:32 +00:00
Mike Hearn
25e7456888 Add EmptyMessage class that was missing from previous commit. 2011-10-10 09:44:45 +00:00
Mike Hearn
619325e993 Some minor changes:
- Introduce an EmptyMessage class.
 - Make Message.bitcoinSerialize() method final.
 
Patch 1 of the lazy parsing patchset by Steve.
2011-10-10 08:53:23 +00:00
Mike Hearn
318afef956 Patch from Gary and Jonny to switch the Maven config to a new Nexus-based build server. Changes how SLF44J is imported to avoid forcing a particular implementation on the user. Remove redundant or unnecessary parts of the POM. 2011-09-25 20:32:22 +00:00
Mike Hearn
03647dbb7e Add a getTransactions() method that returns a set of all transactions, optionally including those which are dead and inactive. Add an argument for returning dead transactions in getRecentTransactions(). Updates issue 3. 2011-09-18 21:08:39 +00:00
Mike Hearn
5f2029e21b Introduce a mock clock, use it to improve the getRecentTransactions unit tests. Fix a seconds/milliseconds confusion pointed out by Andreas. Resolves issue 43. 2011-09-18 20:54:23 +00:00
Mike Hearn
a3a4a927af Always pass the wallet into the event listeners on every event. 2011-09-18 20:14:14 +00:00
Mike Hearn
bbe133be88 Make WalletEventListener an interface with a no-op implementation. Add an onChange() method to the default implementation that is called by the others, for cases where you don't care about what specifically changed, just that a change happened. 2011-09-18 20:09:26 +00:00
Mike Hearn
6f36e96f66 Fix the Wallet unit tests by allowing null blocks in Wallet.receive() again. 2011-09-18 20:01:57 +00:00
Mike Hearn
42b5a0d0ed Implement a couple of (weak) hashCode methods to go with equals(). Resolves issue 82. 2011-09-18 19:54:03 +00:00
Mike Hearn
ba2255a185 Second part ... refresh timestamp when confirming a spend to the wallet. 2011-09-18 19:46:25 +00:00
Mike Hearn
3191d5684b Implement a way of getting a list of transactions in the wallet, ordered by recency. This doesn't yet support pending transactions, as those can't (yet) be added to the wallet. 2011-09-18 19:40:04 +00:00
Mike Hearn
2ef36efcce Add Steve to the AUTHORS file. 2011-09-16 07:50:22 +00:00
Mike Hearn
6963eb0ca9 Throw a ProtocolException instead of ClassCastException if connecting to a bad peer that does not send a version message on new connections. Resolves issue 81. 2011-09-15 16:41:33 +00:00
Mike Hearn
9009b83af5 Fix Message.readStr(). Implement a unit test and some equals() methods. Resolves issue 79. 2011-09-15 16:38:32 +00:00
Mike Hearn
99385e7aee Make a field static. Resolves comments by Miron on r194. 2011-09-15 16:22:33 +00:00
Mike Hearn
0315b3a5e6 Add a create method to Sha256Hash.
Don't deserialize block or tx messages that were already seen, to avoid wasting battery and causing memory spikes that can trigger OOM conditions. Updates issue 73.
2011-09-15 16:11:32 +00:00
Mike Hearn
10b40cbb48 Split out parsing of header and payload. This is useful for high-performance programs that don't always need to parse the payload. Patch from shadders (CLA agreement pending). 2011-09-15 15:03:15 +00:00
Mike Hearn
bf7b8f133c Fix a minor bug in OP_PUSHDATA2 (not used). Resolves issue 80. 2011-09-15 15:02:13 +00:00
Mike Hearn
ea7741d3e0 Only do Bouncy Castle shading for a newly created Android-specific build. This should resolve issues with JAR signature check failures. Patch from Gary Rowe. 2011-09-15 14:40:16 +00:00
Mike Hearn
133dad7305 Tweak PeerGroup thread priority. Resolves issue 67. 2011-09-10 09:56:34 +00:00
Mike Hearn
24b87d8d6e Add a serialVersionUID to Sha256Hash. Resolves issue 77. 2011-09-10 09:55:13 +00:00
Mike Hearn
892dffd732 Update README. 2011-09-10 09:53:41 +00:00
Mike Hearn
a22a0fd2bf Remove stray import. Gotta love IDEs. Resolves issue 78. 2011-09-10 09:53:00 +00:00
Miron Cuperman (devrandom)
2ce328aa0b Use RandomAccessFile in DiskBlockStore to fix corruption. Resolves issue 76 2011-09-06 20:40:15 +00:00
Mike Hearn
eae1130a31 Make PeerGroup remember discovery sources and retry them after a while. 2011-09-05 17:09:30 +00:00
Mike Hearn
6a049b633e Don't log stack traces for expected network problems. Clean up the logging a bit. Resolves issue 69. 2011-09-05 13:20:48 +00:00
Mike Hearn
9d5af32a9c When confirming a transaction as sent, move connected newly spent transactions from unspent->spent. Introduce a method to do this, so as to avoid duplication with updateForSpends(). Add a getPoolSize() method and use it in unit tests to verify the pools at various points. Resolves issue 72. 2011-09-05 13:06:33 +00:00
Mike Hearn
91fe7cdefb Use "d" mode not "s" mode, to avoid needlessly updating file metadata (we don't use it). 2011-09-05 12:24:14 +00:00
Mike Hearn
c808ba89d2 Open files in sync mode. This forces use of fsync() at the right times, and may help resolve corruption issues observed on Android devices. Updates issue 66. 2011-09-05 12:22:42 +00:00
Mike Hearn
f4e54046f0 Make some fields static/final as a memory optimization. Thanks to Andreas for his suggestions.
Fix a bug that affected Windows machines by always closing files on the exception propagation path.
2011-09-05 12:17:54 +00:00
Miron Cuperman (devrandom)
098671ffba Fix key array handling in importing/exporting private keys. Resolves issue 48. 2011-08-30 21:09:51 +00:00
Miron Cuperman (devrandom)
23b1325de7 Dependency copy mvn target for Eclipse users 2011-08-30 20:31:20 +00:00
Mike Hearn
f91978cc28 Support for importing/exporting private keys in sipa format. Resolves issue 48. 2011-08-18 11:49:42 +00:00
Miron Cuperman (devrandom)
c89d2aa124 Yet more PeerTest cleanup 2011-08-12 22:06:44 +00:00