Make genesis coinbase unspendable.

This commit is contained in:
Matt Corallo 2012-10-18 17:58:07 -04:00 committed by Mike Hearn
parent 282b58c5ea
commit 49d26f6e28
3 changed files with 8 additions and 10 deletions

View File

@ -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;

View File

@ -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<StoredTransaction> genesisTransactions = new LinkedList<StoredTransaction>();
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<StoredTransaction> genesisTransactions = Lists.newLinkedList();
StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.genesisBlock.getHash(), genesisTransactions);
put(storedGenesisHeader, storedGenesis);
setChainHead(storedGenesisHeader);
} catch (VerificationException e) {

View File

@ -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<StoredTransaction> genesisTransactions = new LinkedList<StoredTransaction>();
for (Transaction tx : params.genesisBlock.getTransactions())
genesisTransactions.add(new StoredTransaction(tx, 0));
// The coinbase in the genesis block is not spendable
List<StoredTransaction> genesisTransactions = Lists.newLinkedList();
StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.genesisBlock.getHash(), genesisTransactions);
put(storedGenesisHeader, storedGenesis);
setChainHead(storedGenesisHeader);
} catch (BlockStoreException e) {