aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-15 21:05:16 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-08-15 21:05:16 +0000
commit4bd188c4383d6e614e18f79dc337fbabe8464c82 (patch)
tree4a557aef24b72923d52721c93d7a25b6f64f0d80 /main.cpp
parent01cd2fdaf3ac6071304ceb80fb7436ac02b1059e (diff)
downloadbitcoin-4bd188c4383d6e614e18f79dc337fbabe8464c82.tar.xz
misc changes
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@131 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp72
1 files changed, 51 insertions, 21 deletions
diff --git a/main.cpp b/main.cpp
index 4b7146577c..3e7d2b9ecc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -538,7 +538,7 @@ bool CTransaction::AcceptTransaction(CTxDB& txdb, bool fCheckInputs, bool* pfMis
// Check against previous transactions
map<uint256, CTxIndex> mapUnused;
int64 nFees = 0;
- if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), 0, nFees, false, false))
+ if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false))
{
if (pfMissingInputs)
*pfMissingInputs = true;
@@ -744,7 +744,7 @@ void ResendWalletTransactions()
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
- nNextTime = GetTime() + GetRand(120 * 60);
+ nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;
@@ -760,7 +760,7 @@ void ResendWalletTransactions()
CWalletTx& wtx = item.second;
// Don't rebroadcast until it's had plenty of time that
// it should have gotten in already by now.
- if (nTimeBestReceived - wtx.nTimeReceived > 60 * 60)
+ if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60)
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
foreach(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
@@ -931,7 +931,8 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
}
-bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, int nHeight, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)
+bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,
+ CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)
{
// Take over previous transactions' spent pointers
if (!IsCoinBase())
@@ -983,9 +984,9 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
// If prev is coinbase, check that it's matured
if (txPrev.IsCoinBase())
- for (CBlockIndex* pindex = pindexBest; pindex && nBestHeight - pindex->nHeight < COINBASE_MATURITY-1; pindex = pindex->pprev)
+ for (CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev)
if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)
- return error("ConnectInputs() : tried to spend coinbase at depth %d", nBestHeight - pindex->nHeight);
+ return error("ConnectInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - pindex->nHeight);
// Verify signature
if (!VerifySignature(txPrev, *this, i))
@@ -1019,7 +1020,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
if (fBlock)
{
// Add transaction to disk index
- if (!txdb.AddTxIndex(*this, posThisTx, nHeight))
+ if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight))
return error("ConnectInputs() : AddTxPos failed");
}
else if (fMiner)
@@ -1108,7 +1109,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);
nTxPos += ::GetSerializeSize(tx, SER_DISK);
- if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex->nHeight, nFees, true, false))
+ if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false))
return false;
}
@@ -1379,14 +1380,12 @@ bool CBlock::AcceptBlock()
return error("AcceptBlock() : incorrect proof of work");
// Check that the block chain matches the known block chain up to a checkpoint
- if (pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
- return error("AcceptBlock() : rejected by checkpoint lockin at 11111");
- if (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
- return error("AcceptBlock() : rejected by checkpoint lockin at 33333");
- if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))
- return error("AcceptBlock() : rejected by checkpoint lockin at 68555");
- if (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))
- return error("AcceptBlock() : rejected by checkpoint lockin at 70567");
+ if ((pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||
+ (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||
+ (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
+ (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
+ (pindexPrev->nHeight+1 == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")))
+ return error("AcceptBlock() : rejected by checkpoint lockin");
// Write block to history file
if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))
@@ -2577,6 +2576,8 @@ inline void SHA256Transform(void* pstate, void* pinput, const void* pinit)
CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput);
}
+static const int NPAR = 32;
+extern void Double_BlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);
@@ -2658,7 +2659,7 @@ void BitcoinMiner()
int64 nMinFee = tx.GetMinFee(nBlockSize);
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
- if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), 0, nFees, false, true, nMinFee))
+ if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee))
continue;
swap(mapTestPool, mapTestPoolTmp);
@@ -2719,14 +2720,40 @@ void BitcoinMiner()
//
// Search
//
+ bool f4WaySSE2 = mapArgs.count("-4way");
int64 nStart = GetTime();
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
uint256 hashbuf[2];
uint256& hash = *alignup<16>(hashbuf);
loop
{
- SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);
- SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);
+#ifdef FOURWAYSSE2
+ if (f4WaySSE2)
+ {
+ // tcatm's 4-way SSE2 SHA-256
+ tmp.block.nNonce += NPAR;
+ unsigned int thashbuf[9][NPAR];
+ unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf);
+ Double_BlockSHA256((char*)&tmp.block + 64, &tmp.hash1, &midstate, thash, pSHA256InitState);
+ ((unsigned short*)&hash)[14] = 0xffff;
+ for (int j = 0; j < NPAR; j++)
+ {
+ if (thash[7][j] == 0)
+ {
+ for (int i = 0; i < sizeof(hash)/4; i++)
+ ((unsigned int*)&hash)[i] = thash[i][j];
+ pblock->nNonce = ByteReverse(tmp.block.nNonce + j);
+ }
+ }
+ }
+ else
+#endif
+ {
+ // Crypto++ SHA-256
+ tmp.block.nNonce++;
+ SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);
+ SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);
+ }
if (((unsigned short*)&hash)[14] == 0)
{
@@ -2736,7 +2763,10 @@ void BitcoinMiner()
if (hash <= hashTarget)
{
- pblock->nNonce = ByteReverse(tmp.block.nNonce);
+#ifdef FOURWAYSSE2
+ if (!f4WaySSE2)
+#endif
+ pblock->nNonce = ByteReverse(tmp.block.nNonce);
assert(hash == pblock->GetHash());
//// debug print
@@ -2775,7 +2805,7 @@ void BitcoinMiner()
// Update nTime every few seconds
const unsigned int nMask = 0xffff;
const int nHashesPerCycle = (nMask+1);
- if ((++tmp.block.nNonce & nMask) == 0)
+ if ((tmp.block.nNonce & nMask) == 0)
{
// Meter hashes/sec
static int nCycleCounter;