diff --git a/src/com/google/bitcoin/core/BlockChain.java b/src/com/google/bitcoin/core/BlockChain.java index e719758f..34b0fcb0 100644 --- a/src/com/google/bitcoin/core/BlockChain.java +++ b/src/com/google/bitcoin/core/BlockChain.java @@ -145,7 +145,7 @@ public class BlockChain { // Store it. blockStore.put(newStoredBlock); // TODO: Break the assumption of object equality here. - if (storedPrev == chainHead) { + if (storedPrev.equals(chainHead)) { // This block connects to the best known block, it is a normal continuation of the system. chainHead = newStoredBlock; LOG("Received new block, chain is now " + chainHead.height + " blocks high"); diff --git a/src/com/google/bitcoin/core/StoredBlock.java b/src/com/google/bitcoin/core/StoredBlock.java index b4f3dfd3..f74a6ea4 100644 --- a/src/com/google/bitcoin/core/StoredBlock.java +++ b/src/com/google/bitcoin/core/StoredBlock.java @@ -56,4 +56,11 @@ class StoredBlock { boolean moreWorkThan(StoredBlock other) { return chainWork.compareTo(other.chainWork) > 0; } + + @Override + public boolean equals(Object other) { + if (!(other instanceof StoredBlock)) return false; + StoredBlock o = (StoredBlock) other; + return o.header.equals(header) && o.chainWork.equals(chainWork) && o.height == height; + } }