Skip to content

Commit

Permalink
Merge branch 'release-0.15' of https://github.com/bitcoinj/bitcoinj i…
Browse files Browse the repository at this point in the history
…nto release-0.15.10
  • Loading branch information
HashEngineering committed Jul 3, 2021
2 parents 753481c + 75ce78b commit 5ce82ab
Show file tree
Hide file tree
Showing 62 changed files with 728 additions and 474 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
repositories {
jcenter()
mavenCentral()
}

dependencies {
Expand All @@ -10,7 +10,7 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
}

group = 'org.groestlcoinj'
Expand Down
23 changes: 16 additions & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ apply plugin: 'com.google.protobuf'
apply plugin: 'maven'
apply plugin: 'eclipse'

version = '0.15.5.1'
version = '0.15.10'
archivesBaseName = 'groestlcoinj-core'
eclipse.project.name = 'groestlcoinj-core'

dependencies {
compile 'org.bouncycastle:bcprov-jdk15to18:1.63'
implementation 'com.google.guava:guava:27.1-android'
compile 'org.bouncycastle:bcprov-jdk15to18:1.68'
implementation 'com.google.guava:guava:28.2-android'
compile 'com.google.protobuf:protobuf-java:3.6.1'
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
implementation 'org.slf4j:slf4j-api:1.7.28'
implementation 'com.squareup.okhttp3:okhttp:3.12.8'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'net.jcip:jcip-annotations:1.0'
compileOnly 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.easymock:easymock:3.2'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.5.2'
testImplementation 'org.slf4j:slf4j-jdk14:1.7.28'
testImplementation 'org.slf4j:slf4j-jdk14:1.7.30'
testImplementation 'com.h2database:h2:1.3.167'
testImplementation 'org.fusesource.leveldbjni:leveldbjni-all:1.8'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
}

sourceCompatibility = 1.7
Expand Down Expand Up @@ -60,3 +61,11 @@ artifacts {
archives sourcesJar
archives javadocJar
}


tasks.withType(Javadoc) {
failOnError false
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
5 changes: 1 addition & 4 deletions core/src/main/java/org/bitcoin/Secp256k1Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public class Secp256k1Context {
try {
System.loadLibrary("secp256k1");
contextRef = secp256k1_init_context();
} catch (UnsatisfiedLinkError e) {
log.info(e.toString());
isEnabled = false;
} catch (AccessControlException e) {
} catch (UnsatisfiedLinkError | AccessControlException e) {
log.debug(e.toString());
isEnabled = false;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/bitcoinj/core/AbstractBlockChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ public final void addWallet(Wallet wallet) {
addTransactionReceivedListener(Threading.SAME_THREAD, wallet);
int walletHeight = wallet.getLastBlockSeenHeight();
int chainHeight = getBestChainHeight();
if (walletHeight != chainHeight) {
if (walletHeight != chainHeight && walletHeight > 0) {
log.warn("Wallet/chain height mismatch: {} vs {}", walletHeight, chainHeight);
log.warn("Hashes: {} vs {}", wallet.getLastBlockSeenHash(), getChainHead().getHeader().getHash());

// This special case happens when the VM crashes because of a transaction received. It causes the updated
// block store to persist, but not the wallet. In order to fix the issue, we roll back the block store to
// the wallet height to make it look like as if the block has never been received.
if (walletHeight < chainHeight && walletHeight > 0) {
if (walletHeight < chainHeight) {
try {
rollbackBlockStore(walletHeight);
log.info("Rolled back block store to height {}.", walletHeight);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public enum VerifyFlag {
// Set up a few basic things. We are not complete after this though.
version = setVersion;
difficultyTarget = 0x1d07fff8L;
time = System.currentTimeMillis() / 1000;
time = Utils.currentTimeSeconds();
prevBlockHash = Sha256Hash.ZERO_HASH;

length = HEADER_SIZE;
Expand Down
29 changes: 16 additions & 13 deletions core/src/main/java/org/bitcoinj/core/CheckpointManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class CheckpointManager {
private static final String TEXTUAL_MAGIC = "TXT CHECKPOINTS 1";
private static final int MAX_SIGNATURES = 256;

// Map of block header time to data.
// Map of block header time (in seconds) to data.
protected final TreeMap<Long, StoredBlock> checkpoints = new TreeMap<>();

protected final NetworkParameters params;
Expand Down Expand Up @@ -121,7 +121,7 @@ private Sha256Hash readBinary(InputStream inputStream) throws IOException {
digestInputStream.on(false);
byte[] header = new byte[BINARY_MAGIC.length()];
dis.readFully(header);
if (!Arrays.equals(header, BINARY_MAGIC.getBytes("US-ASCII")))
if (!Arrays.equals(header, BINARY_MAGIC.getBytes(StandardCharsets.US_ASCII)))
throw new IOException("Header bytes did not match expected version");
int numSignatures = checkPositionIndex(dis.readInt(), MAX_SIGNATURES, "Num signatures out of range");
for (int i = 0; i < numSignatures; i++) {
Expand All @@ -142,7 +142,8 @@ private Sha256Hash readBinary(InputStream inputStream) throws IOException {
checkpoints.put(block.getHeader().getTimeSeconds(), block);
}
Sha256Hash dataHash = Sha256Hash.wrap(digest.digest());
log.info("Read {} checkpoints, hash is {}", checkpoints.size(), dataHash);
log.info("Read {} checkpoints up to time {}, hash is {}", checkpoints.size(),
Utils.dateTimeFormat(checkpoints.lastEntry().getKey() * 1000), dataHash);
return dataHash;
} catch (ProtocolException e) {
throw new IOException(e);
Expand Down Expand Up @@ -179,7 +180,8 @@ private Sha256Hash readTextual(InputStream inputStream) throws IOException {
checkpoints.put(block.getHeader().getTimeSeconds(), block);
}
HashCode hash = hasher.hash();
log.info("Read {} checkpoints, hash is {}", checkpoints.size(), hash);
log.info("Read {} checkpoints up to time {}, hash is {}", checkpoints.size(),
Utils.dateTimeFormat(checkpoints.lastEntry().getKey() * 1000), hash);
return Sha256Hash.wrap(hash.asBytes());
} finally {
if (reader != null) reader.close();
Expand All @@ -190,11 +192,11 @@ private Sha256Hash readTextual(InputStream inputStream) throws IOException {
* Returns a {@link StoredBlock} representing the last checkpoint before the given time, for example, normally
* you would want to know the checkpoint before the earliest wallet birthday.
*/
public StoredBlock getCheckpointBefore(long time) {
public StoredBlock getCheckpointBefore(long timeSecs) {
try {
checkArgument(time > params.getGenesisBlock().getTimeSeconds());
checkArgument(timeSecs > params.getGenesisBlock().getTimeSeconds());
// This is thread safe because the map never changes after creation.
Map.Entry<Long, StoredBlock> entry = checkpoints.floorEntry(time);
Map.Entry<Long, StoredBlock> entry = checkpoints.floorEntry(timeSecs);
if (entry != null) return entry.getValue();
Block genesis = params.getGenesisBlock().cloneAsHeader();
return new StoredBlock(genesis, genesis.getWork(), 0);
Expand All @@ -218,9 +220,9 @@ public Sha256Hash getDataHash() {
* time, then inserts it into the store and sets that to be the chain head. Useful when you have just created
* a new store from scratch and want to use configure it all in one go.</p>
*
* <p>Note that time is adjusted backwards by a week to account for possible clock drift in the block headers.</p>
* <p>Note that timeSecs is adjusted backwards by a week to account for possible clock drift in the block headers.</p>
*/
public static void checkpoint(NetworkParameters params, InputStream checkpoints, BlockStore store, long time)
public static void checkpoint(NetworkParameters params, InputStream checkpoints, BlockStore store, long timeSecs)
throws IOException, BlockStoreException {

if(!CoinDefinition.checkpointFileSupport)
Expand All @@ -230,14 +232,15 @@ public static void checkpoint(NetworkParameters params, InputStream checkpoints,
checkNotNull(store);
checkArgument(!(store instanceof FullPrunedBlockStore), "You cannot use checkpointing with a full store.");

time -= 86400 * 7;
timeSecs -= 60 * 60 * 24 * 7; // one week in seconds

checkArgument(time > 0);
log.info("Attempting to initialize a new block store with a checkpoint for time {} ({})", time, Utils.dateTimeFormat(time * 1000));
checkArgument(timeSecs > 0);
log.info("Attempting to initialize a new block store with a checkpoint for time {} ({})", timeSecs,
Utils.dateTimeFormat(timeSecs * 1000));

BufferedInputStream stream = new BufferedInputStream(checkpoints);
CheckpointManager manager = new CheckpointManager(params, stream);
StoredBlock checkpoint = manager.getCheckpointBefore(time);
StoredBlock checkpoint = manager.getCheckpointBefore(timeSecs);
store.put(checkpoint);
store.setChainHead(checkpoint);
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/bitcoinj/core/ChildMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public ChildMessage(NetworkParameters params, byte[] payload, int offset, int pr
super(params, payload, offset, protocolVersion);
}

public ChildMessage(NetworkParameters params, byte[] payload, int offset, int protocolVersion, Message parent, MessageSerializer setSerializer, int length) throws ProtocolException {
public ChildMessage(NetworkParameters params, byte[] payload, int offset, int protocolVersion,
@Nullable Message parent, MessageSerializer setSerializer, int length) throws ProtocolException {
super(params, payload, offset, protocolVersion, setSerializer, length);
this.parent = parent;
}
Expand Down
22 changes: 14 additions & 8 deletions core/src/main/java/org/bitcoinj/core/Coin.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public long getValue() {

/**
* Convert an amount expressed in the way humans are used to into satoshis.
*
* @param coins Number of bitcoins
* @param cents Number of bitcents (0.01 bitcoin)
* @return {@code Coin} object containing value in satoshis
*/
public static Coin valueOf(final int coins, final int cents) {
checkArgument(cents < 100);
Expand All @@ -116,10 +120,11 @@ public static Coin valueOf(final int coins, final int cents) {
}

/**
* <p>Parses an amount expressed in the way humans are used to.</p>
* <p>This takes string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* "1.23E3", "1234.5E-5".</p>
*
* Parses an amount expressed in the way humans are used to.
*
* @param str string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* * "1.23E3", "1234.5E-5".
* @return {@code Coin} object containing value in satoshis
* @throws IllegalArgumentException
* if you try to specify fractional satoshis, or a value out of range.
*/
Expand All @@ -133,10 +138,11 @@ public static Coin parseCoin(final String str) {
}

/**
* <p>Parses an amount expressed in the way humans are used to. The amount is cut to satoshi precision.</p>
* <p>This takes string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* "1.23E3", "1234.5E-5".</p>
*
* Parses an amount expressed in the way humans are used to. The amount is cut to satoshi precision.
*
* @param str string in a format understood by {@link BigDecimal#BigDecimal(String)}, for example "0", "1", "0.10",
* * "1.23E3", "1234.5E-5".
* @return {@code Coin} object containing value in satoshis
* @throws IllegalArgumentException
* if you try to specify a value out of range.
*/
Expand Down
Loading

0 comments on commit 5ce82ab

Please sign in to comment.