Skip to content

Commit

Permalink
Merge tag 'v0.15.5' of https://github.com/bitcoinj/bitcoinj into upda…
Browse files Browse the repository at this point in the history
…te-0.15.5

Update groestlcoinj to 0.15.5 release

# gpg: Signature made 10/01/19 14:32:12 Pacific Daylight Time
# gpg:                using DSA key E944AE667CF960B1004BC32FCA662BE18B877A60
# gpg:                issuer "[email protected]"
# gpg: Can't check signature: No public key

# Conflicts:
#	core/build.gradle
  • Loading branch information
HashEngineering committed Oct 16, 2019
2 parents 8e3b9f4 + 9523fe0 commit 7b86cff
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 83 deletions.
14 changes: 7 additions & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ apply plugin: 'com.google.protobuf'
apply plugin: 'maven'
apply plugin: 'eclipse'

version = '0.15.2'
version = '0.15.5'
archivesBaseName = 'groestlcoinj-core'
eclipse.project.name = 'groestlcoinj-core'

dependencies {
compile 'org.bouncycastle:bcprov-jdk15on:1.60'
implementation 'com.lambdaworks:scrypt:1.4.0'
implementation 'com.google.guava:guava:27.0.1-android'
compile 'org.bouncycastle:bcprov-jdk15to18:1.63'
implementation 'com.google.guava:guava:27.1-android'
compile 'com.google.protobuf:protobuf-java:3.6.1'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'org.slf4j:slf4j-api:1.7.25'
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
implementation 'org.slf4j:slf4j-api:1.7.28'
implementation 'net.jcip:jcip-annotations:1.0'
compileOnly 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
testImplementation 'junit:junit:4.12'
testImplementation 'org.easymock:easymock:3.2'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.2'
testImplementation 'org.slf4j:slf4j-jdk14:1.7.25'
testImplementation 'org.slf4j:slf4j-jdk14:1.7.28'
testImplementation 'com.h2database:h2:1.3.167'
testImplementation 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
}

sourceCompatibility = 1.7
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
javadoc.options.encoding = 'UTF-8'

protobuf {
protoc {
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/org/bitcoinj/core/AbstractBlockChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
* we say it is an orphan chain. Orphan chains can occur when blocks are solved and received during the initial block
* chain download, or if we connect to a peer that doesn't send us blocks in order.</p>
*
* <p>A reorganize occurs when the blocks that make up the best known chain changes. Note that simply adding a
* new block to the top of the best chain isn't as reorganize, but that a reorganize is always triggered by adding
* <p>A reorganize occurs when the blocks that make up the best known chain change. Note that simply adding a
* new block to the top of the best chain isn't a reorganize, but that a reorganize is always triggered by adding
* a new block that connects to some other (non best head) block. By "best" we mean the chain representing the largest
* amount of work done.</p>
*
Expand Down Expand Up @@ -543,7 +543,8 @@ private void connectBlock(final Block block, StoredBlock storedPrev, boolean exp
block.transactions == null ? block : block.cloneAsHeader(), txOutChanges);
versionTally.add(block.getVersion());
setChainHead(newStoredBlock);
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());
if (log.isDebugEnabled())
log.debug("Chain is now {} blocks high, running listeners", newStoredBlock.getHeight());
informListenersForNewBlock(block, NewBlockType.BEST_CHAIN, filteredTxHashList, filteredTxn, newStoredBlock);
} else {
// This block connects to somewhere other than the top of the best known chain. We treat these differently.
Expand Down Expand Up @@ -898,7 +899,8 @@ private void tryConnectingOrphans() throws VerificationException, BlockStoreExce
StoredBlock prev = getStoredBlockInCurrentScope(orphanBlock.block.getPrevBlockHash());
if (prev == null) {
// This is still an unconnected/orphan block.
log.debug("Orphan block {} is not connectable right now", orphanBlock.block.getHash());
if (log.isDebugEnabled())
log.debug("Orphan block {} is not connectable right now", orphanBlock.block.getHash());
continue;
}
// Otherwise we can connect it now.
Expand Down Expand Up @@ -1042,7 +1044,7 @@ void trackFalsePositives(int count) {
// Track false positives in batch by adding alpha to the false positive estimate once per count.
// Each false positive counts as 1.0 towards the estimate.
falsePositiveRate += FP_ESTIMATOR_ALPHA * count;
if (count > 0)
if (count > 0 && log.isDebugEnabled())
log.debug("{} false positives, current rate = {} trend = {}", count, falsePositiveRate, falsePositiveTrend);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public int compare(ECKey k1, ECKey k2) {

// The two parts of the key. If "priv" is set, "pub" can always be calculated. If "pub" is set but not "priv", we
// can only verify signatures not make them.
protected final BigInteger priv; // A field element.
@Nullable protected final BigInteger priv; // A field element.
protected final LazyECPoint pub;

// Creation time of the key in seconds since the epoch, or zero if the key was deserialized from a version that did
Expand Down Expand Up @@ -992,7 +992,7 @@ public static ECKey recoverFromSignature(int recId, ECDSASignature sig, Sha256Ha
// 1.2. Convert the integer x to an octet string X of length mlen using the conversion routine
// specified in Section 2.3.7, where mlen = ⌈(log2 p)/8⌉ or mlen = ⌈m/8⌉.
// 1.3. Convert the octet string (16 set binary digits)||X to an elliptic curve point R using the
// conversion routine specified in Section 2.3.4. If this conversion routine outputs invalid, then
// conversion routine specified in Section 2.3.4. If this conversion routine outputs "invalid", then
// do another iteration of Step 1.
//
// More concisely, what these points mean is to use X as a compressed public key.
Expand Down
44 changes: 27 additions & 17 deletions core/src/main/java/org/bitcoinj/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ private void processVersionMessage(VersionMessage m) throws ProtocolException {
// Now it's our turn ...
// Send an ACK message stating we accept the peers protocol version.
sendMessage(new VersionAck());
log.debug("{}: Incoming version handshake complete.", this);
if (log.isDebugEnabled())
log.debug("{}: Incoming version handshake complete.", this);
incomingVersionHandshakeFuture.set(this);
}

Expand All @@ -586,12 +587,14 @@ private void processVersionAck(VersionAck m) throws ProtocolException {
if (outgoingVersionHandshakeFuture.isDone()) {
throw new ProtocolException("got more than one version ack");
}
log.debug("{}: Outgoing version handshake complete.", this);
if (log.isDebugEnabled())
log.debug("{}: Outgoing version handshake complete.", this);
outgoingVersionHandshakeFuture.set(this);
}

private void versionHandshakeComplete() {
log.debug("{}: Handshake complete.", this);
if (log.isDebugEnabled())
log.debug("{}: Handshake complete.", this);
setTimeoutEnabled(false);
for (final ListenerRegistration<PeerConnectedEventListener> registration : connectedEventListeners) {
registration.executor.execute(new Runnable() {
Expand Down Expand Up @@ -640,10 +643,11 @@ protected void processNotFoundMessage(NotFoundMessage m) {

protected void processAlert(AlertMessage m) {
try {
if (m.isSignatureValid()) {
log.debug("Received alert from peer {}: {}", this, m.getStatusBar());
} else {
log.debug("Received alert with invalid signature from peer {}: {}", this, m.getStatusBar());
if (log.isDebugEnabled()) {
if (m.isSignatureValid())
log.debug("Received alert from peer {}: {}", this, m.getStatusBar());
else
log.debug("Received alert with invalid signature from peer {}: {}", this, m.getStatusBar());
}
} catch (Throwable t) {
// Signature checking can FAIL on Android platforms before Gingerbread apparently due to bugs in their
Expand Down Expand Up @@ -758,7 +762,8 @@ protected void processTransaction(final Transaction tx) throws VerificationExcep
tx.verify();
lock.lock();
try {
log.debug("{}: Received tx {}", getAddress(), tx.getTxId());
if (log.isDebugEnabled())
log.debug("{}: Received tx {}", getAddress(), tx.getTxId());
// Label the transaction as coming in from the P2P network (as opposed to being created by us, direct import,
// etc). This helps the wallet decide how to risk analyze it later.
//
Expand Down Expand Up @@ -967,18 +972,19 @@ public void onFailure(Throwable throwable) {
}

protected void processBlock(Block m) {
if (log.isDebugEnabled()) {
if (log.isDebugEnabled())
log.debug("{}: Received broadcast block {}", getAddress(), m.getHashAsString());
}
// Was this block requested by getBlock()?
if (maybeHandleRequestedData(m)) return;
if (blockChain == null) {
log.debug("Received block but was not configured with an AbstractBlockChain");
if (log.isDebugEnabled())
log.debug("Received block but was not configured with an AbstractBlockChain");
return;
}
// Did we lose download peer status after requesting block data?
if (!vDownloadData) {
log.debug("{}: Received block we did not ask for: {}", getAddress(), m.getHashAsString());
if (log.isDebugEnabled())
log.debug("{}: Received block we did not ask for: {}", getAddress(), m.getHashAsString());
return;
}
pendingBlockDownloads.remove(m.getHash());
Expand Down Expand Up @@ -1032,11 +1038,13 @@ protected void endFilteredBlock(FilteredBlock m) {
if (log.isDebugEnabled())
log.debug("{}: Received broadcast filtered block {}", getAddress(), m.getHash().toString());
if (!vDownloadData) {
log.debug("{}: Received block we did not ask for: {}", getAddress(), m.getHash().toString());
if (log.isDebugEnabled())
log.debug("{}: Received block we did not ask for: {}", getAddress(), m.getHash().toString());
return;
}
if (blockChain == null) {
log.debug("Received filtered block but was not configured with an AbstractBlockChain");
if (log.isDebugEnabled())
log.debug("Received filtered block but was not configured with an AbstractBlockChain");
return;
}
// Note that we currently do nothing about peers which maliciously do not include transactions which
Expand Down Expand Up @@ -1220,7 +1228,8 @@ protected void processInv(InventoryMessage inv) {
// We created this transaction ourselves, so don't download.
it.remove();
} else {
log.debug("{}: getdata on tx {}", getAddress(), item.hash);
if (log.isDebugEnabled())
log.debug("{}: getdata on tx {}", getAddress(), item.hash);
getdata.addTransaction(item.hash, vPeerVersionMessage.isWitnessSupported());
// Register with the garbage collector that we care about the confidence data for a while.
pendingTxDownloads.add(conf);
Expand Down Expand Up @@ -1521,7 +1530,8 @@ public void complete() {
if (!future.isDone()) {
long elapsed = Utils.currentTimeMillis() - startTimeMsec;
Peer.this.addPingTimeData(elapsed);
log.debug("{}: ping time is {} ms", Peer.this.toString(), elapsed);
if (log.isDebugEnabled())
log.debug("{}: ping time is {} ms", Peer.this.toString(), elapsed);
future.set(elapsed);
}
}
Expand Down Expand Up @@ -1725,7 +1735,7 @@ public void setBloomFilter(BloomFilter filter, boolean andQueryMemPool) {
if (ver == null || !ver.isBloomFilteringSupported())
return;
vBloomFilter = filter;
log.debug("{}: Sending Bloom filter{}", this, andQueryMemPool ? " and querying mempool" : "");
log.info("{}: Sending Bloom filter{}", this, andQueryMemPool ? " and querying mempool" : "");
sendMessage(filter);
if (andQueryMemPool)
sendMessage(new MemoryPoolMessage());
Expand Down
27 changes: 15 additions & 12 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,37 @@ public class PeerGroup implements TransactionBroadcaster {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
// We received a relevant transaction. We MAY need to recalculate and resend the Bloom filter, but only
// if we have received a transaction that includes a relevant P2PK output.
// if we have received a transaction that includes a relevant P2PK or P2WPKH output.
//
// The reason is that P2PK outputs, when spent, will not repeat any data we can predict in their
// The reason is that P2PK and P2WPKH outputs, when spent, will not repeat any data we can predict in their
// inputs. So a remote peer will update the Bloom filter for us when such an output is seen matching the
// existing filter, so that it includes the tx hash in which the P2PK output was observed. Thus
// existing filter, so that it includes the tx hash in which the P2PK/P2WPKH output was observed. Thus
// the spending transaction will always match (due to the outpoint structure).
//
// Unfortunately, whilst this is required for correct sync of the chain in blocks, there are two edge cases.
//
// (1) If a wallet receives a relevant, confirmed p2pubkey output that was not broadcast across the network,
// (1) If a wallet receives a relevant, confirmed P2PK/P2WPKH output that was not broadcast across the network,
// for example in a coinbase transaction, then the node that's serving us the chain will update its filter
// but the rest will not. If another transaction then spends it, the other nodes won't match/relay it.
//
// (2) If we receive a p2pubkey output broadcast across the network, all currently connected nodes will see
// (2) If we receive a P2PK/P2WPKH output broadcast across the network, all currently connected nodes will see
// it and update their filter themselves, but any newly connected nodes will receive the last filter we
// calculated, which would not include this transaction.
//
// For this reason we check if the transaction contained any relevant pay to pubkeys and force a recalc
// For this reason we check if the transaction contained any relevant P2PKs or P2WPKHs and force a recalc
// and possibly retransmit if so. The recalculation process will end up including the tx hash into the
// filter. In case (1), we need to retransmit the filter to the connected peers. In case (2), we don't
// and shouldn't, we should just recalculate and cache the new filter for next time.
for (TransactionOutput output : tx.getOutputs()) {
if (ScriptPattern.isP2PK(output.getScriptPubKey()) && output.isMine(wallet)) {
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
else
recalculateFastCatchupAndFilter(FilterRecalculateMode.DONT_SEND);
return;
Script scriptPubKey = output.getScriptPubKey();
if (ScriptPattern.isP2PK(scriptPubKey) || ScriptPattern.isP2WPKH(scriptPubKey)) {
if (output.isMine(wallet)) {
if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING)
recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
else
recalculateFastCatchupAndFilter(FilterRecalculateMode.DONT_SEND);
return;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/SegwitAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private SegwitAddress(NetworkParameters params, int witnessVersion, byte[] witne
private static byte[] encode(int witnessVersion, byte[] witnessProgram) throws AddressFormatException {
byte[] convertedProgram = convertBits(witnessProgram, 0, witnessProgram.length, 8, 5, true);
byte[] bytes = new byte[1 + convertedProgram.length];
bytes[0] = (byte) (Script.encodeToOpN(witnessVersion) & 0xff);
bytes[0] = (byte) (witnessVersion & 0xff);
System.arraycopy(convertedProgram, 0, bytes, 1, convertedProgram.length);
return bytes;
}
Expand Down
Loading

0 comments on commit 7b86cff

Please sign in to comment.