When using BitcoinJ to listen to the blockchain I get an error on the testnet:
[NioClientManager] INFO org.bitcoinj.core.MemoryPool - [192.241.225.155]:18333:
Peer announced new transaction [1] 73e8f6fcc45922fe1ac7db57ed164a0b291ce1cd8b2e2
ee1451d4bdba52896b5
[NioClientManager] ERROR org.bitcoinj.core.AbstractBlockChain - Failed to verify
block:
org.bitcoinj.core.VerificationException: Block too far in future: 1423230446 vs
1423230444
at org.bitcoinj.core.Block.checkTimestamp(Block.java:672)
at org.bitcoinj.core.Block.verifyHeader(Block.java:781)
at org.bitcoinj.core.AbstractBlockChain.add(AbstractBlockChain.java:397)
I had a look at it, and I came across a difference between how Java does timestamping versus Bitcoin Core.
In Core, I think that it defaults to using whole seconds, while in Java the default is milliseconds.
The problem arises on line 53 here:
https://code.google.com/p/bitcoinj/source/browse/core/src/main/java/com/google/bitcoin/core/Block.java?r=0208b426f5ec537cd019378d4261868af9cb9b1e static final long ALLOWED_TIME_DRIFT = 2 * 60 * 60; // Same value as official client.
My suggestion is that that line should be:
static final long ALLOWED_TIME_DRIFT = 2 * 60 * 60 * 1000; // Same value as official client, converted to milliseconds
It's a problem because the timestamp allowed is different by a factor of three magnitudes compared to official client, and it's throwing exceptions about 50% of the time.