mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-09 14:28:22 +00:00
fix "CreateNewBlock() : ConnectBlock failed" due to "duplicate username".
improve transaction collect in CreateNewBlock
This commit is contained in:
parent
bf3ec900d0
commit
055240b2a9
22
src/main.cpp
22
src/main.cpp
@ -3713,21 +3713,33 @@ CBlockTemplate* CreateNewBlock(std::vector<unsigned char> &salt)
|
|||||||
uint64 nBlockSize = 1000;
|
uint64 nBlockSize = 1000;
|
||||||
uint64 nBlockTx = 0;
|
uint64 nBlockTx = 0;
|
||||||
|
|
||||||
|
// Avoid duplicate usernames within the same block
|
||||||
|
set<uint256> uniqueUsers;
|
||||||
|
|
||||||
for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
|
for (map<uint256, CTransaction>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi)
|
||||||
{
|
{
|
||||||
CTransaction& tx = (*mi).second;
|
CTransaction& tx = (*mi).second;
|
||||||
if (tx.IsSpamMessage())
|
if (tx.IsSpamMessage())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// This should never happen; all transactions in the memory are new
|
// This should never happen (unless replacement); all transactions in the memory are new
|
||||||
uint256 txid = SerializeHash(make_pair(tx.GetUsername(),-1));
|
CTransaction txOld;
|
||||||
if( pblocktree->HaveTxIndex(txid) ) {
|
uint256 hashBlock = 0;
|
||||||
|
if( GetTransaction(tx.GetUsername(), txOld, hashBlock) ) {
|
||||||
if( !verifyDuplicateOrReplacementTx(tx, false, true) ) {
|
if( !verifyDuplicateOrReplacementTx(tx, false, true) ) {
|
||||||
printf("ERROR: mempool transaction already exists\n");
|
printf("CreateNewBlock: mempool transaction already exists (%s)\n",
|
||||||
if (fDebug) assert("mempool transaction already exists" == 0);
|
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
|
// Size limits
|
||||||
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
|
||||||
if (nBlockSize + nTxSize >= nBlockMaxSize)
|
if (nBlockSize + nTxSize >= nBlockMaxSize)
|
||||||
|
Loading…
Reference in New Issue
Block a user