3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 18:25:51 +00:00

Don't mark transactions that have just been completed as pending, and then fix a stupid efficiency bug in AbstractBlockChain that was revealed by the change.

This commit is contained in:
Mike Hearn 2013-06-20 15:04:18 +02:00
parent 6b7d653614
commit a28cb5c59a
3 changed files with 2 additions and 5 deletions

View File

@ -478,7 +478,7 @@ public abstract class AbstractBlockChain {
// is relevant to both of them, they don't end up accidentally sharing the same object (which can // is relevant to both of them, they don't end up accidentally sharing the same object (which can
// result in temporary in-memory corruption during re-orgs). See bug 257. We only duplicate in // result in temporary in-memory corruption during re-orgs). See bug 257. We only duplicate in
// the case of multiple wallets to avoid an unnecessary efficiency hit in the common case. // the case of multiple wallets to avoid an unnecessary efficiency hit in the common case.
sendTransactionsToListener(newBlock, NewBlockType.SIDE_CHAIN, listener, txnToNotify, first); sendTransactionsToListener(newBlock, NewBlockType.SIDE_CHAIN, listener, txnToNotify, !first);
if (filteredTxHashList != null) { if (filteredTxHashList != null) {
for (Sha256Hash hash : filteredTxHashList) { for (Sha256Hash hash : filteredTxHashList) {
listener.notifyTransactionIsInBlock(hash, newBlock, NewBlockType.SIDE_CHAIN); listener.notifyTransactionIsInBlock(hash, newBlock, NewBlockType.SIDE_CHAIN);

View File

@ -2036,8 +2036,6 @@ public class Wallet implements Serializable, BlockChainListener {
// the transaction is confirmed. We deliberately won't bother notifying listeners here as there's not much // the transaction is confirmed. We deliberately won't bother notifying listeners here as there's not much
// point - the user isn't interested in a confidence transition they made themselves. // point - the user isn't interested in a confidence transition they made themselves.
req.tx.getConfidence().setSource(TransactionConfidence.Source.SELF); req.tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
// TODO: Remove this - a newly completed tx isn't really pending, nothing was done with it yet.
req.tx.getConfidence().setConfidenceType(ConfidenceType.PENDING);
req.completed = true; req.completed = true;
req.fee = calculatedFee; req.fee = calculatedFee;
log.info(" completed {} with {} inputs", req.tx.getHashAsString(), req.tx.getInputs().size()); log.info(" completed {} with {} inputs", req.tx.getHashAsString(), req.tx.getInputs().size());

View File

@ -206,7 +206,6 @@ public class WalletTest extends TestWithWallet {
private void basicSanityChecks(Wallet wallet, Transaction t, Address fromAddress, Address destination) throws VerificationException { private void basicSanityChecks(Wallet wallet, Transaction t, Address fromAddress, Address destination) throws VerificationException {
assertEquals("Wrong number of tx inputs", 1, t.getInputs().size()); assertEquals("Wrong number of tx inputs", 1, t.getInputs().size());
assertEquals(fromAddress, t.getInputs().get(0).getScriptSig().getFromAddress(params)); assertEquals(fromAddress, t.getInputs().get(0).getScriptSig().getFromAddress(params));
assertEquals(TransactionConfidence.ConfidenceType.PENDING, t.getConfidence().getConfidenceType());
assertEquals("Wrong number of tx outputs",2, t.getOutputs().size()); assertEquals("Wrong number of tx outputs",2, t.getOutputs().size());
assertEquals(destination, t.getOutputs().get(0).getScriptPubKey().getToAddress(params)); assertEquals(destination, t.getOutputs().get(0).getScriptPubKey().getToAddress(params));
assertEquals(wallet.getChangeAddress(), t.getOutputs().get(1).getScriptPubKey().getToAddress(params)); assertEquals(wallet.getChangeAddress(), t.getOutputs().get(1).getScriptPubKey().getToAddress(params));
@ -283,7 +282,7 @@ public class WalletTest extends TestWithWallet {
assertTrue(complete); assertTrue(complete);
assertEquals(1, t2.getInputs().size()); assertEquals(1, t2.getInputs().size());
assertEquals(myAddress, t2.getInputs().get(0).getScriptSig().getFromAddress(params)); assertEquals(myAddress, t2.getInputs().get(0).getScriptSig().getFromAddress(params));
assertEquals(TransactionConfidence.ConfidenceType.PENDING, t2.getConfidence().getConfidenceType()); assertEquals(TransactionConfidence.ConfidenceType.UNKNOWN, t2.getConfidence().getConfidenceType());
// We have NOT proven that the signature is correct! // We have NOT proven that the signature is correct!
wallet.commitTx(t2); wallet.commitTx(t2);