mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 06:44:16 +00:00
Block tester: Bring back UTXO rules when the local node supports them
This commit is contained in:
parent
aed7c438ea
commit
9025a65334
@ -69,7 +69,7 @@ public class BitcoindComparisonTool {
|
||||
blockFile.deleteOnExit();
|
||||
|
||||
FullBlockTestGenerator generator = new FullBlockTestGenerator(params);
|
||||
final RuleList blockList = generator.getBlocksToTest(true, runExpensiveTests, blockFile);
|
||||
final RuleList blockList = generator.getBlocksToTest(false, runExpensiveTests, blockFile);
|
||||
final Map<Sha256Hash, Block> preloadedBlocks = new HashMap<Sha256Hash, Block>();
|
||||
final Iterator<Block> blocks = new BlockFileLoader(params, Arrays.asList(blockFile));
|
||||
|
||||
@ -210,7 +210,7 @@ public class BitcoindComparisonTool {
|
||||
bitcoindChainHead = params.getGenesisBlock().getHash();
|
||||
|
||||
// bitcoind MUST be on localhost or we will get banned as a DoSer
|
||||
new NioClient(new InetSocketAddress(InetAddress.getLocalHost(), args.length > 2 ? Integer.parseInt(args[2]) : params.getPort()), bitcoind, 1000);
|
||||
new NioClient(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), args.length > 2 ? Integer.parseInt(args[2]) : params.getPort()), bitcoind, 1000);
|
||||
|
||||
connectedFuture.get();
|
||||
|
||||
@ -342,6 +342,19 @@ public class BitcoindComparisonTool {
|
||||
rulesSinceFirstFail++;
|
||||
}
|
||||
mostRecentInv = null;
|
||||
} else if (rule instanceof UTXORule) {
|
||||
if (bitcoind.getPeerVersionMessage().isGetUTXOsSupported()) {
|
||||
UTXORule r = (UTXORule) rule;
|
||||
UTXOsMessage result = bitcoind.getUTXOs(r.query).get();
|
||||
if (!result.equals(r.result)) {
|
||||
log.error("utxo result was not what we expected.");
|
||||
log.error("Wanted {}", r.result);
|
||||
log.error("but got {}", result);
|
||||
rulesSinceFirstFail++;
|
||||
} else {
|
||||
log.info("Successful utxo query {}: {}", r.ruleName, result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Unknown rule");
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.core.Transaction.SigHash;
|
||||
import org.bitcoinj.crypto.TransactionSignature;
|
||||
import org.bitcoinj.script.Script;
|
||||
@ -94,6 +96,23 @@ class MemoryPoolState extends Rule {
|
||||
}
|
||||
}
|
||||
|
||||
class UTXORule extends Rule {
|
||||
List<TransactionOutPoint> query;
|
||||
UTXOsMessage result;
|
||||
|
||||
public UTXORule(String ruleName, TransactionOutPoint query, UTXOsMessage result) {
|
||||
super(ruleName);
|
||||
this.query = Collections.singletonList(query);
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public UTXORule(String ruleName, List<TransactionOutPoint> query, UTXOsMessage result) {
|
||||
super(ruleName);
|
||||
this.query = query;
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
class RuleList {
|
||||
public List<Rule> list;
|
||||
public int maximumReorgBlockCount;
|
||||
@ -197,6 +216,17 @@ public class FullBlockTestGenerator {
|
||||
// Make sure nothing breaks if we add b3 twice
|
||||
blocks.add(new BlockAndValidity(b3, true, false, b2.getHash(), chainHeadHeight + 2, "b3"));
|
||||
|
||||
// Do a simple UTXO query.
|
||||
UTXORule utxo1;
|
||||
{
|
||||
Transaction coinbase = b2.block.getTransactions().get(0);
|
||||
TransactionOutPoint outpoint = new TransactionOutPoint(params, 0, coinbase.getHash());
|
||||
long[] heights = new long[] {chainHeadHeight + 2};
|
||||
UTXOsMessage result = new UTXOsMessage(params, ImmutableList.of(coinbase.getOutput(0)), heights, b2.getHash(), chainHeadHeight + 2);
|
||||
utxo1 = new UTXORule("utxo1", outpoint, result);
|
||||
blocks.add(utxo1);
|
||||
}
|
||||
|
||||
// Now we add another block to make the alternative chain longer.
|
||||
//
|
||||
// genesis -> b1 (0) -> b2 (1)
|
||||
@ -206,6 +236,18 @@ public class FullBlockTestGenerator {
|
||||
NewBlock b4 = createNextBlock(b3, chainHeadHeight + 3, out2, null);
|
||||
blocks.add(new BlockAndValidity(b4, true, false, b4.getHash(), chainHeadHeight + 3, "b4"));
|
||||
|
||||
// Check that the old coinbase is no longer in the UTXO set and the new one is.
|
||||
{
|
||||
Transaction coinbase = b4.block.getTransactions().get(0);
|
||||
TransactionOutPoint outpoint = new TransactionOutPoint(params, 0, coinbase.getHash());
|
||||
List<TransactionOutPoint> queries = ImmutableList.of(utxo1.query.get(0), outpoint);
|
||||
List<TransactionOutput> results = Lists.asList(null, coinbase.getOutput(0), new TransactionOutput[]{});
|
||||
long[] heights = new long[] {chainHeadHeight + 3};
|
||||
UTXOsMessage result = new UTXOsMessage(params, results, heights, b4.getHash(), chainHeadHeight + 3);
|
||||
UTXORule utxo2 = new UTXORule("utxo2", queries, result);
|
||||
blocks.add(utxo2);
|
||||
}
|
||||
|
||||
// ... and back to the first chain.
|
||||
NewBlock b5 = createNextBlock(b2, chainHeadHeight + 3, out2, null);
|
||||
blocks.add(new BlockAndValidity(b5, true, false, b4.getHash(), chainHeadHeight + 3, "b5"));
|
||||
@ -1457,6 +1499,15 @@ public class FullBlockTestGenerator {
|
||||
post82Mempool.add(new InventoryItem(InventoryItem.Type.Transaction, b79tx.getHash()));
|
||||
blocks.add(new MemoryPoolState(post82Mempool, "post-b82 tx resurrection"));
|
||||
|
||||
// Check the UTXO query takes mempool into account.
|
||||
{
|
||||
TransactionOutPoint outpoint = new TransactionOutPoint(params, 0, b79tx.getHash());
|
||||
long[] heights = new long[] { UTXOsMessage.MEMPOOL_HEIGHT };
|
||||
UTXOsMessage result = new UTXOsMessage(params, ImmutableList.of(b79tx.getOutput(0)), heights, b82.getHash(), chainHeadHeight + 28);
|
||||
UTXORule utxo3 = new UTXORule("utxo3", outpoint, result);
|
||||
blocks.add(utxo3);
|
||||
}
|
||||
|
||||
// Test invalid opcodes in dead execution paths.
|
||||
// -> b81 (26) -> b82 (27) -> b83 (28)
|
||||
// b83 creates a tx which contains a transaction script with an invalid opcode in a dead execution path:
|
||||
|
Loading…
Reference in New Issue
Block a user