diff --git a/core/src/main/java/com/google/bitcoin/store/FullPrunedBlockStore.java b/core/src/main/java/com/google/bitcoin/store/FullPrunedBlockStore.java index a60a2e34..c613b6af 100644 --- a/core/src/main/java/com/google/bitcoin/store/FullPrunedBlockStore.java +++ b/core/src/main/java/com/google/bitcoin/store/FullPrunedBlockStore.java @@ -67,6 +67,7 @@ public interface FullPrunedBlockStore extends BlockStore { /** * Removes a {@link StoredTransactionOutput} from the list of unspent TransactionOutputs + * Note that the coinbase of the genesis block should NEVER be spendable and thus never in the list. * @throws BlockStoreException if there is an underlying storage issue, or out was not in the list. */ void removeUnspentTransactionOutput(StoredTransactionOutput out) throws BlockStoreException; diff --git a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java index 79a8ef80..21396bfa 100644 --- a/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java +++ b/core/src/main/java/com/google/bitcoin/store/H2FullPrunedBlockStore.java @@ -17,6 +17,7 @@ package com.google.bitcoin.store; import com.google.bitcoin.core.*; +import com.google.common.collect.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -196,12 +197,10 @@ public class H2FullPrunedBlockStore implements FullPrunedBlockStore { // Set up the genesis block. When we start out fresh, it is by // definition the top of the chain. StoredBlock storedGenesisHeader = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0); - - LinkedList genesisTransactions = new LinkedList(); - for (Transaction tx : params.genesisBlock.getTransactions()) - genesisTransactions.add(new StoredTransaction(tx, 0)); + // The coinbase in the genesis block is not spendable. This is because of how the reference client inits + // its database - the genesis transaction isn't actually in the db so its spent flags can never be updated. + List genesisTransactions = Lists.newLinkedList(); StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.genesisBlock.getHash(), genesisTransactions); - put(storedGenesisHeader, storedGenesis); setChainHead(storedGenesisHeader); } catch (VerificationException e) { diff --git a/core/src/main/java/com/google/bitcoin/store/MemoryFullPrunedBlockStore.java b/core/src/main/java/com/google/bitcoin/store/MemoryFullPrunedBlockStore.java index e3a3165c..c2d1014b 100644 --- a/core/src/main/java/com/google/bitcoin/store/MemoryFullPrunedBlockStore.java +++ b/core/src/main/java/com/google/bitcoin/store/MemoryFullPrunedBlockStore.java @@ -19,6 +19,7 @@ package com.google.bitcoin.store; import com.google.bitcoin.core.*; import com.google.common.base.Objects; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import java.io.Serializable; import java.util.*; @@ -238,12 +239,9 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore { // Insert the genesis block. try { StoredBlock storedGenesisHeader = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0); - - LinkedList genesisTransactions = new LinkedList(); - for (Transaction tx : params.genesisBlock.getTransactions()) - genesisTransactions.add(new StoredTransaction(tx, 0)); + // The coinbase in the genesis block is not spendable + List genesisTransactions = Lists.newLinkedList(); StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.genesisBlock.getHash(), genesisTransactions); - put(storedGenesisHeader, storedGenesis); setChainHead(storedGenesisHeader); } catch (BlockStoreException e) {