From 055240b2a910adc29b805f8cd3f90bda36aefbeb Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 13 Jan 2014 09:16:04 -0200 Subject: [PATCH] fix "CreateNewBlock() : ConnectBlock failed" due to "duplicate username". improve transaction collect in CreateNewBlock --- src/main.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6631def4..e5e56a79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3713,21 +3713,33 @@ CBlockTemplate* CreateNewBlock(std::vector &salt) uint64 nBlockSize = 1000; uint64 nBlockTx = 0; + // Avoid duplicate usernames within the same block + set uniqueUsers; + for (map::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi) { CTransaction& tx = (*mi).second; if (tx.IsSpamMessage()) continue; - // This should never happen; all transactions in the memory are new - uint256 txid = SerializeHash(make_pair(tx.GetUsername(),-1)); - if( pblocktree->HaveTxIndex(txid) ) { + // This should never happen (unless replacement); all transactions in the memory are new + CTransaction txOld; + uint256 hashBlock = 0; + if( GetTransaction(tx.GetUsername(), txOld, hashBlock) ) { if( !verifyDuplicateOrReplacementTx(tx, false, true) ) { - printf("ERROR: mempool transaction already exists\n"); - if (fDebug) assert("mempool transaction already exists" == 0); + printf("CreateNewBlock: mempool transaction already exists (%s)\n", + tx.GetUsername().c_str()); + continue; } } + if( uniqueUsers.count(tx.GetUsernameHash()) ) { + printf("CreateNewBlock() : duplicate username (%s)\n", + tx.GetUsername().c_str()); + continue; + } + uniqueUsers.insert(tx.GetUsernameHash()); + // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize)