|
|
@ -598,6 +598,8 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi |
|
|
|
if (i != 0) |
|
|
|
if (i != 0) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
ptxOld = mapNextTx[outpoint].ptx; |
|
|
|
ptxOld = mapNextTx[outpoint].ptx; |
|
|
|
|
|
|
|
if (ptxOld->IsFinal()) |
|
|
|
|
|
|
|
return false; |
|
|
|
if (!IsNewerThan(*ptxOld)) |
|
|
|
if (!IsNewerThan(*ptxOld)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
for (int i = 0; i < vin.size(); i++) |
|
|
|
for (int i = 0; i < vin.size(); i++) |
|
|
@ -3031,6 +3033,28 @@ extern unsigned int ScanHash_4WaySSE2(char* pmidstate, char* pblock, char* phash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class COrphan |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
CTransaction* ptx; |
|
|
|
|
|
|
|
set<uint256> setDependsOn; |
|
|
|
|
|
|
|
double dPriority; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COrphan(CTransaction* ptxIn) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ptx = ptxIn; |
|
|
|
|
|
|
|
dPriority = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print() const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
printf("COrphan(hash=%s, dPriority=%.1f)\n", ptx->GetHash().ToString().substr(0,10).c_str(), dPriority); |
|
|
|
|
|
|
|
foreach(uint256 hash, setDependsOn) |
|
|
|
|
|
|
|
printf(" setDependsOn %s\n", hash.ToString().substr(0,10).c_str()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BitcoinMiner() |
|
|
|
void BitcoinMiner() |
|
|
|
{ |
|
|
|
{ |
|
|
@ -3098,6 +3122,8 @@ void BitcoinMiner() |
|
|
|
CTxDB txdb("r"); |
|
|
|
CTxDB txdb("r"); |
|
|
|
|
|
|
|
|
|
|
|
// Priority order to process transactions
|
|
|
|
// Priority order to process transactions
|
|
|
|
|
|
|
|
list<COrphan> vOrphan; // list memory doesn't move
|
|
|
|
|
|
|
|
map<uint256, vector<COrphan*> > mapDependers; |
|
|
|
multimap<double, CTransaction*> mapPriority; |
|
|
|
multimap<double, CTransaction*> mapPriority; |
|
|
|
for (map<uint256, CTransaction>::iterator mi = mapTransactions.begin(); mi != mapTransactions.end(); ++mi) |
|
|
|
for (map<uint256, CTransaction>::iterator mi = mapTransactions.begin(); mi != mapTransactions.end(); ++mi) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -3105,6 +3131,7 @@ void BitcoinMiner() |
|
|
|
if (tx.IsCoinBase() || !tx.IsFinal()) |
|
|
|
if (tx.IsCoinBase() || !tx.IsFinal()) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COrphan* porphan = NULL; |
|
|
|
double dPriority = 0; |
|
|
|
double dPriority = 0; |
|
|
|
foreach(const CTxIn& txin, tx.vin) |
|
|
|
foreach(const CTxIn& txin, tx.vin) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -3112,7 +3139,18 @@ void BitcoinMiner() |
|
|
|
CTransaction txPrev; |
|
|
|
CTransaction txPrev; |
|
|
|
CTxIndex txindex; |
|
|
|
CTxIndex txindex; |
|
|
|
if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) |
|
|
|
if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Has to wait for dependencies
|
|
|
|
|
|
|
|
if (!porphan) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Use list for automatic deletion
|
|
|
|
|
|
|
|
vOrphan.push_back(COrphan(&tx)); |
|
|
|
|
|
|
|
porphan = &vOrphan.back(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mapDependers[txin.prevout.hash].push_back(porphan); |
|
|
|
|
|
|
|
porphan->setDependsOn.insert(txin.prevout.hash); |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; |
|
|
|
int64 nValueIn = txPrev.vout[txin.prevout.n].nValue; |
|
|
|
|
|
|
|
|
|
|
|
// Read block header
|
|
|
|
// Read block header
|
|
|
@ -3138,55 +3176,66 @@ void BitcoinMiner() |
|
|
|
// Priority is sum(valuein * age) / txsize
|
|
|
|
// Priority is sum(valuein * age) / txsize
|
|
|
|
dPriority /= ::GetSerializeSize(tx, SER_NETWORK); |
|
|
|
dPriority /= ::GetSerializeSize(tx, SER_NETWORK); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (porphan) |
|
|
|
|
|
|
|
porphan->dPriority = dPriority; |
|
|
|
|
|
|
|
else |
|
|
|
mapPriority.insert(make_pair(-dPriority, &(*mi).second)); |
|
|
|
mapPriority.insert(make_pair(-dPriority, &(*mi).second)); |
|
|
|
|
|
|
|
|
|
|
|
if (fDebug && mapArgs.count("-printpriority")) |
|
|
|
if (fDebug && mapArgs.count("-printpriority")) |
|
|
|
printf("priority %-20.1f %s\n%s\n", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str()); |
|
|
|
{ |
|
|
|
|
|
|
|
printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str()); |
|
|
|
|
|
|
|
if (porphan) |
|
|
|
|
|
|
|
porphan->print(); |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Collect transactions into block
|
|
|
|
// Collect transactions into block
|
|
|
|
map<uint256, CTxIndex> mapTestPool; |
|
|
|
map<uint256, CTxIndex> mapTestPool; |
|
|
|
uint64 nBlockSize = 1000; |
|
|
|
uint64 nBlockSize = 1000; |
|
|
|
int nBlockSigOps = 100; |
|
|
|
int nBlockSigOps = 100; |
|
|
|
bool fFoundSomething = true; |
|
|
|
while (!mapPriority.empty()) |
|
|
|
while (fFoundSomething) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
fFoundSomething = false; |
|
|
|
// Take highest priority transaction off priority queue
|
|
|
|
for (multimap<double, CTransaction*>::iterator mi = mapPriority.begin(); mi != mapPriority.end();) |
|
|
|
CTransaction& tx = *(*mapPriority.begin()).second; |
|
|
|
{ |
|
|
|
mapPriority.erase(mapPriority.begin()); |
|
|
|
CTransaction& tx = *(*mi).second; |
|
|
|
|
|
|
|
|
|
|
|
// Size limits
|
|
|
|
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK); |
|
|
|
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK); |
|
|
|
if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN) |
|
|
|
if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN) |
|
|
|
{ |
|
|
|
|
|
|
|
mapPriority.erase(mi++); |
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
int nTxSigOps = tx.GetSigOpCount(); |
|
|
|
int nTxSigOps = tx.GetSigOpCount(); |
|
|
|
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) |
|
|
|
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) |
|
|
|
{ |
|
|
|
|
|
|
|
mapPriority.erase(mi++); |
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transaction fee based on block size
|
|
|
|
// Transaction fee based on block size
|
|
|
|
int64 nMinFee = tx.GetMinFee(nBlockSize); |
|
|
|
int64 nMinFee = tx.GetMinFee(nBlockSize); |
|
|
|
|
|
|
|
|
|
|
|
// Connecting can fail due to dependency on other memory pool transactions
|
|
|
|
// Connecting shouldn't fail due to dependency on other memory pool transactions
|
|
|
|
// that aren't in the block yet, so keep trying in later passes
|
|
|
|
// because we're already processing them in order of dependency
|
|
|
|
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool); |
|
|
|
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool); |
|
|
|
if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee)) |
|
|
|
if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee)) |
|
|
|
{ |
|
|
|
|
|
|
|
mi++; |
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
swap(mapTestPool, mapTestPoolTmp); |
|
|
|
swap(mapTestPool, mapTestPoolTmp); |
|
|
|
|
|
|
|
|
|
|
|
// Added
|
|
|
|
// Added
|
|
|
|
pblock->vtx.push_back(tx); |
|
|
|
pblock->vtx.push_back(tx); |
|
|
|
nBlockSize += nTxSize; |
|
|
|
nBlockSize += nTxSize; |
|
|
|
nBlockSigOps += nTxSigOps; |
|
|
|
nBlockSigOps += nTxSigOps; |
|
|
|
fFoundSomething = true; |
|
|
|
|
|
|
|
mapPriority.erase(mi++); |
|
|
|
// Add transactions that depend on this one to the priority queue
|
|
|
|
|
|
|
|
uint256 hash = tx.GetHash(); |
|
|
|
|
|
|
|
if (mapDependers.count(hash)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach(COrphan* porphan, mapDependers[hash]) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!porphan->setDependsOn.empty()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
porphan->setDependsOn.erase(hash); |
|
|
|
|
|
|
|
if (porphan->setDependsOn.empty()) |
|
|
|
|
|
|
|
mapPriority.insert(make_pair(-porphan->dPriority, porphan->ptx)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|