Skip to content

Commit 4bd188c

Browse files
misc changes
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@131 1a98c847-1fd6-4fd8-948a-caf3550aa51b
1 parent 01cd2fd commit 4bd188c

8 files changed

Lines changed: 538 additions & 52 deletions

File tree

init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ bool AppInit2(int argc, char* argv[])
373373
wxMessageBox(_("Invalid amount for -paytxfee=<amount>"), "Bitcoin");
374374
return false;
375375
}
376+
if (nTransactionFee > 1 * COIN)
377+
wxMessageBox(_("Warning: -paytxfee is set very high. This is the transaction fee you will pay if you send a transaction."), "Bitcoin");
376378
}
377379

378380
//

main.cpp

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ bool CTransaction::AcceptTransaction(CTxDB& txdb, bool fCheckInputs, bool* pfMis
538538
// Check against previous transactions
539539
map<uint256, CTxIndex> mapUnused;
540540
int64 nFees = 0;
541-
if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), 0, nFees, false, false))
541+
if (fCheckInputs && !ConnectInputs(txdb, mapUnused, CDiskTxPos(1,1,1), pindexBest, nFees, false, false))
542542
{
543543
if (pfMissingInputs)
544544
*pfMissingInputs = true;
@@ -744,7 +744,7 @@ void ResendWalletTransactions()
744744
if (GetTime() < nNextTime)
745745
return;
746746
bool fFirst = (nNextTime == 0);
747-
nNextTime = GetTime() + GetRand(120 * 60);
747+
nNextTime = GetTime() + GetRand(30 * 60);
748748
if (fFirst)
749749
return;
750750

@@ -760,7 +760,7 @@ void ResendWalletTransactions()
760760
CWalletTx& wtx = item.second;
761761
// Don't rebroadcast until it's had plenty of time that
762762
// it should have gotten in already by now.
763-
if (nTimeBestReceived - wtx.nTimeReceived > 60 * 60)
763+
if (nTimeBestReceived - (int64)wtx.nTimeReceived > 5 * 60)
764764
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
765765
}
766766
foreach(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
@@ -931,7 +931,8 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
931931
}
932932

933933

934-
bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, int nHeight, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)
934+
bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,
935+
CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee)
935936
{
936937
// Take over previous transactions' spent pointers
937938
if (!IsCoinBase())
@@ -983,9 +984,9 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
983984

984985
// If prev is coinbase, check that it's matured
985986
if (txPrev.IsCoinBase())
986-
for (CBlockIndex* pindex = pindexBest; pindex && nBestHeight - pindex->nHeight < COINBASE_MATURITY-1; pindex = pindex->pprev)
987+
for (CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < COINBASE_MATURITY; pindex = pindex->pprev)
987988
if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)
988-
return error("ConnectInputs() : tried to spend coinbase at depth %d", nBestHeight - pindex->nHeight);
989+
return error("ConnectInputs() : tried to spend coinbase at depth %d", pindexBlock->nHeight - pindex->nHeight);
989990

990991
// Verify signature
991992
if (!VerifySignature(txPrev, *this, i))
@@ -1019,7 +1020,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
10191020
if (fBlock)
10201021
{
10211022
// Add transaction to disk index
1022-
if (!txdb.AddTxIndex(*this, posThisTx, nHeight))
1023+
if (!txdb.AddTxIndex(*this, posThisTx, pindexBlock->nHeight))
10231024
return error("ConnectInputs() : AddTxPos failed");
10241025
}
10251026
else if (fMiner)
@@ -1108,7 +1109,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
11081109
CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos);
11091110
nTxPos += ::GetSerializeSize(tx, SER_DISK);
11101111

1111-
if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex->nHeight, nFees, true, false))
1112+
if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false))
11121113
return false;
11131114
}
11141115

@@ -1379,14 +1380,12 @@ bool CBlock::AcceptBlock()
13791380
return error("AcceptBlock() : incorrect proof of work");
13801381

13811382
// Check that the block chain matches the known block chain up to a checkpoint
1382-
if (pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"))
1383-
return error("AcceptBlock() : rejected by checkpoint lockin at 11111");
1384-
if (pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"))
1385-
return error("AcceptBlock() : rejected by checkpoint lockin at 33333");
1386-
if (pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"))
1387-
return error("AcceptBlock() : rejected by checkpoint lockin at 68555");
1388-
if (pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"))
1389-
return error("AcceptBlock() : rejected by checkpoint lockin at 70567");
1383+
if ((pindexPrev->nHeight+1 == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||
1384+
(pindexPrev->nHeight+1 == 33333 && hash != uint256("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")) ||
1385+
(pindexPrev->nHeight+1 == 68555 && hash != uint256("0x00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a")) ||
1386+
(pindexPrev->nHeight+1 == 70567 && hash != uint256("0x00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a")) ||
1387+
(pindexPrev->nHeight+1 == 74000 && hash != uint256("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")))
1388+
return error("AcceptBlock() : rejected by checkpoint lockin");
13901389

13911390
// Write block to history file
13921391
if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))
@@ -2577,6 +2576,8 @@ inline void SHA256Transform(void* pstate, void* pinput, const void* pinit)
25772576
CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput);
25782577
}
25792578

2579+
static const int NPAR = 32;
2580+
extern void Double_BlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);
25802581

25812582

25822583

@@ -2658,7 +2659,7 @@ void BitcoinMiner()
26582659
int64 nMinFee = tx.GetMinFee(nBlockSize);
26592660

26602661
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
2661-
if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), 0, nFees, false, true, nMinFee))
2662+
if (!tx.ConnectInputs(txdb, mapTestPoolTmp, CDiskTxPos(1,1,1), pindexPrev, nFees, false, true, nMinFee))
26622663
continue;
26632664
swap(mapTestPool, mapTestPoolTmp);
26642665

@@ -2719,14 +2720,40 @@ void BitcoinMiner()
27192720
//
27202721
// Search
27212722
//
2723+
bool f4WaySSE2 = mapArgs.count("-4way");
27222724
int64 nStart = GetTime();
27232725
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
27242726
uint256 hashbuf[2];
27252727
uint256& hash = *alignup<16>(hashbuf);
27262728
loop
27272729
{
2728-
SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);
2729-
SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);
2730+
#ifdef FOURWAYSSE2
2731+
if (f4WaySSE2)
2732+
{
2733+
// tcatm's 4-way SSE2 SHA-256
2734+
tmp.block.nNonce += NPAR;
2735+
unsigned int thashbuf[9][NPAR];
2736+
unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf);
2737+
Double_BlockSHA256((char*)&tmp.block + 64, &tmp.hash1, &midstate, thash, pSHA256InitState);
2738+
((unsigned short*)&hash)[14] = 0xffff;
2739+
for (int j = 0; j < NPAR; j++)
2740+
{
2741+
if (thash[7][j] == 0)
2742+
{
2743+
for (int i = 0; i < sizeof(hash)/4; i++)
2744+
((unsigned int*)&hash)[i] = thash[i][j];
2745+
pblock->nNonce = ByteReverse(tmp.block.nNonce + j);
2746+
}
2747+
}
2748+
}
2749+
else
2750+
#endif
2751+
{
2752+
// Crypto++ SHA-256
2753+
tmp.block.nNonce++;
2754+
SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);
2755+
SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);
2756+
}
27302757

27312758
if (((unsigned short*)&hash)[14] == 0)
27322759
{
@@ -2736,7 +2763,10 @@ void BitcoinMiner()
27362763

27372764
if (hash <= hashTarget)
27382765
{
2739-
pblock->nNonce = ByteReverse(tmp.block.nNonce);
2766+
#ifdef FOURWAYSSE2
2767+
if (!f4WaySSE2)
2768+
#endif
2769+
pblock->nNonce = ByteReverse(tmp.block.nNonce);
27402770
assert(hash == pblock->GetHash());
27412771

27422772
//// debug print
@@ -2775,7 +2805,7 @@ void BitcoinMiner()
27752805
// Update nTime every few seconds
27762806
const unsigned int nMask = 0xffff;
27772807
const int nHashesPerCycle = (nMask+1);
2778-
if ((++tmp.block.nNonce & nMask) == 0)
2808+
if ((tmp.block.nNonce & nMask) == 0)
27792809
{
27802810
// Meter hashes/sec
27812811
static int nCycleCounter;

main.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ class CTransaction
613613

614614

615615
bool DisconnectInputs(CTxDB& txdb);
616-
bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx, int nHeight, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);
616+
bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,
617+
CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);
617618
bool ClientConnectInputs();
618619

619620
bool AcceptTransaction(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);

script.cpp

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,30 @@ static const CBigNum bnZero(0);
1616
static const CBigNum bnOne(1);
1717
static const CBigNum bnFalse(0);
1818
static const CBigNum bnTrue(1);
19-
static const size_t nMaxNumSize = 258;
19+
static const size_t nMaxNumSize = 4;
2020

2121

22+
CBigNum CastToBigNum(const valtype& vch)
23+
{
24+
if (vch.size() > nMaxNumSize)
25+
throw runtime_error("CastToBigNum() : overflow");
26+
// Get rid of extra leading zeros
27+
return CBigNum(CBigNum(vch).getvch());
28+
}
29+
2230
bool CastToBool(const valtype& vch)
2331
{
24-
return (CBigNum(vch) != bnZero);
32+
for (int i = 0; i < vch.size(); i++)
33+
{
34+
if (vch[i] != 0)
35+
{
36+
// Can be negative zero
37+
if (i == vch.size()-1 && vch[i] == 0x80)
38+
return false;
39+
return true;
40+
}
41+
}
42+
return false;
2543
}
2644

2745
void MakeSameSize(valtype& vch1, valtype& vch2)
@@ -68,11 +86,28 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
6886
valtype vchPushValue;
6987
if (!script.GetOp(pc, opcode, vchPushValue))
7088
return false;
71-
if (vchPushValue.size() > 5000)
89+
if (vchPushValue.size() > 520)
7290
return false;
7391
if (opcode > OP_16 && nOpCount++ > 200)
7492
return false;
7593

94+
if (opcode == OP_CAT ||
95+
opcode == OP_SUBSTR ||
96+
opcode == OP_LEFT ||
97+
opcode == OP_RIGHT ||
98+
opcode == OP_INVERT ||
99+
opcode == OP_AND ||
100+
opcode == OP_OR ||
101+
opcode == OP_XOR ||
102+
opcode == OP_2MUL ||
103+
opcode == OP_2DIV ||
104+
opcode == OP_MUL ||
105+
opcode == OP_DIV ||
106+
opcode == OP_MOD ||
107+
opcode == OP_LSHIFT ||
108+
opcode == OP_RSHIFT)
109+
return false;
110+
76111
if (fExec && opcode <= OP_PUSHDATA4)
77112
stack.push_back(vchPushValue);
78113
else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF))
@@ -332,7 +367,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
332367
// (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)
333368
if (stack.size() < 2)
334369
return false;
335-
int n = CBigNum(stacktop(-1)).getint();
370+
int n = CastToBigNum(stacktop(-1)).getint();
336371
stack.pop_back();
337372
if (n < 0 || n >= stack.size())
338373
return false;
@@ -387,7 +422,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
387422
valtype& vch2 = stacktop(-1);
388423
vch1.insert(vch1.end(), vch2.begin(), vch2.end());
389424
stack.pop_back();
390-
if (stacktop(-1).size() > 5000)
425+
if (stacktop(-1).size() > 520)
391426
return false;
392427
}
393428
break;
@@ -398,8 +433,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
398433
if (stack.size() < 3)
399434
return false;
400435
valtype& vch = stacktop(-3);
401-
int nBegin = CBigNum(stacktop(-2)).getint();
402-
int nEnd = nBegin + CBigNum(stacktop(-1)).getint();
436+
int nBegin = CastToBigNum(stacktop(-2)).getint();
437+
int nEnd = nBegin + CastToBigNum(stacktop(-1)).getint();
403438
if (nBegin < 0 || nEnd < nBegin)
404439
return false;
405440
if (nBegin > vch.size())
@@ -420,7 +455,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
420455
if (stack.size() < 2)
421456
return false;
422457
valtype& vch = stacktop(-2);
423-
int nSize = CBigNum(stacktop(-1)).getint();
458+
int nSize = CastToBigNum(stacktop(-1)).getint();
424459
if (nSize < 0)
425460
return false;
426461
if (nSize > vch.size())
@@ -531,9 +566,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
531566
// (in -- out)
532567
if (stack.size() < 1)
533568
return false;
534-
if (stacktop(-1).size() > nMaxNumSize)
535-
return false;
536-
CBigNum bn(stacktop(-1));
569+
CBigNum bn = CastToBigNum(stacktop(-1));
537570
switch (opcode)
538571
{
539572
case OP_1ADD: bn += bnOne; break;
@@ -572,11 +605,8 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
572605
// (x1 x2 -- out)
573606
if (stack.size() < 2)
574607
return false;
575-
if (stacktop(-2).size() > nMaxNumSize ||
576-
stacktop(-1).size() > nMaxNumSize)
577-
return false;
578-
CBigNum bn1(stacktop(-2));
579-
CBigNum bn2(stacktop(-1));
608+
CBigNum bn1 = CastToBigNum(stacktop(-2));
609+
CBigNum bn2 = CastToBigNum(stacktop(-1));
580610
CBigNum bn;
581611
switch (opcode)
582612
{
@@ -646,13 +676,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
646676
// (x min max -- out)
647677
if (stack.size() < 3)
648678
return false;
649-
if (stacktop(-3).size() > nMaxNumSize ||
650-
stacktop(-2).size() > nMaxNumSize ||
651-
stacktop(-1).size() > nMaxNumSize)
652-
return false;
653-
CBigNum bn1(stacktop(-3));
654-
CBigNum bn2(stacktop(-2));
655-
CBigNum bn3(stacktop(-1));
679+
CBigNum bn1 = CastToBigNum(stacktop(-3));
680+
CBigNum bn2 = CastToBigNum(stacktop(-2));
681+
CBigNum bn3 = CastToBigNum(stacktop(-1));
656682
bool fValue = (bn2 <= bn1 && bn1 < bn3);
657683
stack.pop_back();
658684
stack.pop_back();
@@ -748,15 +774,15 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
748774
if (stack.size() < i)
749775
return false;
750776

751-
int nKeysCount = CBigNum(stacktop(-i)).getint();
777+
int nKeysCount = CastToBigNum(stacktop(-i)).getint();
752778
if (nKeysCount < 0)
753779
return false;
754780
int ikey = ++i;
755781
i += nKeysCount;
756782
if (stack.size() < i)
757783
return false;
758784

759-
int nSigsCount = CBigNum(stacktop(-i)).getint();
785+
int nSigsCount = CastToBigNum(stacktop(-i)).getint();
760786
if (nSigsCount < 0 || nSigsCount > nKeysCount)
761787
return false;
762788
int isig = ++i;

serialize.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class CScript;
1919
class CDataStream;
2020
class CAutoFile;
2121

22-
static const int VERSION = 308;
23-
static const char* pszSubVer = ".4";
22+
static const int VERSION = 309;
23+
static const char* pszSubVer = ".0";
2424

2525

2626

setup.nsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RequestExecutionLevel highest
77

88
# General Symbol Definitions
99
!define REGKEY "SOFTWARE\$(^Name)"
10-
!define VERSION 0.3.8
10+
!define VERSION 0.3.9
1111
!define COMPANY "Bitcoin project"
1212
!define URL http://www.bitcoin.org/
1313

@@ -42,12 +42,12 @@ Var StartMenuGroup
4242
!insertmacro MUI_LANGUAGE English
4343

4444
# Installer attributes
45-
OutFile bitcoin-0.3.8-win32-setup.exe
45+
OutFile bitcoin-0.3.9-win32-setup.exe
4646
InstallDir $PROGRAMFILES\Bitcoin
4747
CRCCheck on
4848
XPStyle on
4949
ShowInstDetails show
50-
VIProductVersion 0.3.8.0
50+
VIProductVersion 0.3.9.0
5151
VIAddVersionKey ProductName Bitcoin
5252
VIAddVersionKey ProductVersion "${VERSION}"
5353
VIAddVersionKey CompanyName "${COMPANY}"

0 commit comments

Comments
 (0)