mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-12 07:39:41 +02:00
Merge branch '0.4.x' into 0.5.0.x
This commit is contained in:
@@ -314,7 +314,7 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
obj.push_back(Pair("keypoolsize", pwalletMain->GetKeyPoolSize()));
|
||||||
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
|
||||||
if (pwalletMain->IsCrypted())
|
if (pwalletMain->IsCrypted())
|
||||||
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
|
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime / 1000));
|
||||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@@ -1403,7 +1403,7 @@ void ThreadTopUpKeyPool(void* parg)
|
|||||||
|
|
||||||
void ThreadCleanWalletPassphrase(void* parg)
|
void ThreadCleanWalletPassphrase(void* parg)
|
||||||
{
|
{
|
||||||
int64 nMyWakeTime = GetTime() + *((int*)parg);
|
int64 nMyWakeTime = GetTimeMillis() + *((int*)parg) * 1000;
|
||||||
|
|
||||||
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
|
|
||||||
@@ -1411,17 +1411,25 @@ void ThreadCleanWalletPassphrase(void* parg)
|
|||||||
{
|
{
|
||||||
nWalletUnlockTime = nMyWakeTime;
|
nWalletUnlockTime = nMyWakeTime;
|
||||||
|
|
||||||
while (GetTime() < nWalletUnlockTime)
|
do
|
||||||
{
|
{
|
||||||
int64 nToSleep = GetTime() - nWalletUnlockTime;
|
if (nWalletUnlockTime==0)
|
||||||
|
break;
|
||||||
|
int64 nToSleep = nWalletUnlockTime - GetTimeMillis();
|
||||||
|
if (nToSleep <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
LEAVE_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
Sleep(nToSleep);
|
Sleep(nToSleep);
|
||||||
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
ENTER_CRITICAL_SECTION(cs_nWalletUnlockTime);
|
||||||
}
|
|
||||||
|
|
||||||
nWalletUnlockTime = 0;
|
} while(1);
|
||||||
pwalletMain->Lock();
|
|
||||||
|
if (nWalletUnlockTime)
|
||||||
|
{
|
||||||
|
nWalletUnlockTime = 0;
|
||||||
|
pwalletMain->Lock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1519,9 +1527,9 @@ Value walletlock(const Array& params, bool fHelp)
|
|||||||
if (!pwalletMain->IsCrypted())
|
if (!pwalletMain->IsCrypted())
|
||||||
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
throw JSONRPCError(-15, "Error: running with an unencrypted wallet, but walletlock was called.");
|
||||||
|
|
||||||
pwalletMain->Lock();
|
|
||||||
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
CRITICAL_BLOCK(cs_nWalletUnlockTime)
|
||||||
{
|
{
|
||||||
|
pwalletMain->Lock();
|
||||||
nWalletUnlockTime = 0;
|
nWalletUnlockTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Checkpoints
|
|||||||
(118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"))
|
(118000, uint256("0x000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"))
|
||||||
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
|
(134444, uint256("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"))
|
||||||
(140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd"))
|
(140700, uint256("0x000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd"))
|
||||||
|
(168000, uint256("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763"))
|
||||||
;
|
;
|
||||||
|
|
||||||
bool CheckBlock(int nHeight, const uint256& hash)
|
bool CheckBlock(int nHeight, const uint256& hash)
|
||||||
|
|||||||
@@ -110,14 +110,14 @@ bool RecvLine(SOCKET hSocket, string& strLine)
|
|||||||
if (nBytes == 0)
|
if (nBytes == 0)
|
||||||
{
|
{
|
||||||
// socket closed
|
// socket closed
|
||||||
printf("IRC socket closed\n");
|
printf("socket closed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// socket error
|
// socket error
|
||||||
int nErr = WSAGetLastError();
|
int nErr = WSAGetLastError();
|
||||||
printf("IRC recv failed: %d\n", nErr);
|
printf("recv failed: %d\n", nErr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,10 +229,13 @@ public:
|
|||||||
if (vchSecret.size() != 32)
|
if (vchSecret.size() != 32)
|
||||||
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
|
throw key_error("CKey::SetSecret() : secret must be 32 bytes");
|
||||||
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
|
BIGNUM *bn = BN_bin2bn(&vchSecret[0],32,BN_new());
|
||||||
if (bn == NULL)
|
if (bn == NULL)
|
||||||
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
|
throw key_error("CKey::SetSecret() : BN_bin2bn failed");
|
||||||
if (!EC_KEY_regenerate_key(pkey,bn))
|
if (!EC_KEY_regenerate_key(pkey,bn))
|
||||||
|
{
|
||||||
|
BN_clear_free(bn);
|
||||||
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
|
throw key_error("CKey::SetSecret() : EC_KEY_regenerate_key failed");
|
||||||
|
}
|
||||||
BN_clear_free(bn);
|
BN_clear_free(bn);
|
||||||
fSet = true;
|
fSet = true;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
51
src/main.cpp
51
src/main.cpp
@@ -166,13 +166,14 @@ void static ResendWalletTransactions()
|
|||||||
// mapOrphanTransactions
|
// mapOrphanTransactions
|
||||||
//
|
//
|
||||||
|
|
||||||
void static AddOrphanTx(const CDataStream& vMsg)
|
void AddOrphanTx(const CDataStream& vMsg)
|
||||||
{
|
{
|
||||||
CTransaction tx;
|
CTransaction tx;
|
||||||
CDataStream(vMsg) >> tx;
|
CDataStream(vMsg) >> tx;
|
||||||
uint256 hash = tx.GetHash();
|
uint256 hash = tx.GetHash();
|
||||||
if (mapOrphanTransactions.count(hash))
|
if (mapOrphanTransactions.count(hash))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg);
|
CDataStream* pvMsg = mapOrphanTransactions[hash] = new CDataStream(vMsg);
|
||||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||||
mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg));
|
mapOrphanTransactionsByPrev.insert(make_pair(txin.prevout.hash, pvMsg));
|
||||||
@@ -200,6 +201,23 @@ void static EraseOrphanTx(uint256 hash)
|
|||||||
mapOrphanTransactions.erase(hash);
|
mapOrphanTransactions.erase(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LimitOrphanTxSize(int nMaxOrphans)
|
||||||
|
{
|
||||||
|
int nEvicted = 0;
|
||||||
|
while (mapOrphanTransactions.size() > nMaxOrphans)
|
||||||
|
{
|
||||||
|
// Evict a random orphan:
|
||||||
|
std::vector<unsigned char> randbytes(32);
|
||||||
|
RAND_bytes(&randbytes[0], 32);
|
||||||
|
uint256 randomhash(randbytes);
|
||||||
|
map<uint256, CDataStream*>::iterator it = mapOrphanTransactions.lower_bound(randomhash);
|
||||||
|
if (it == mapOrphanTransactions.end())
|
||||||
|
it = mapOrphanTransactions.begin();
|
||||||
|
EraseOrphanTx(it->first);
|
||||||
|
++nEvicted;
|
||||||
|
}
|
||||||
|
return nEvicted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -839,8 +857,10 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove transaction from index
|
// Remove transaction from index
|
||||||
if (!txdb.EraseTxIndex(*this))
|
// This can fail if a duplicate of this transaction was in a chain that got
|
||||||
return error("DisconnectInputs() : EraseTxPos failed");
|
// reorganized away. This is only possible if this transaction was completely
|
||||||
|
// spent, so erasing it would be a no-op anway.
|
||||||
|
txdb.EraseTxIndex(*this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1050,6 +1070,26 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex)
|
|||||||
if (!CheckBlock())
|
if (!CheckBlock())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
|
||||||
|
// unless those are already completely spent.
|
||||||
|
// If such overwrites are allowed, coinbases and transactions depending upon those
|
||||||
|
// can be duplicated to remove the ability to spend the first instance -- even after
|
||||||
|
// being sent to another address.
|
||||||
|
// See BIP30 and http://r6.ca/blog/20120206T005236Z.html for more information.
|
||||||
|
// This logic is not necessary for memory pool transactions, as AcceptToMemoryPool
|
||||||
|
// already refuses previously-known transaction id's entirely.
|
||||||
|
// This rule applies to all blocks whose timestamp is after March 15, 2012, 0:00 UTC.
|
||||||
|
// On testnet it is enabled as of februari 20, 2012, 0:00 UTC.
|
||||||
|
if (pindex->nTime > 1331769600 || (fTestNet && pindex->nTime > 1329696000))
|
||||||
|
BOOST_FOREACH(CTransaction& tx, vtx)
|
||||||
|
{
|
||||||
|
CTxIndex txindexOld;
|
||||||
|
if (txdb.ReadTxIndex(tx.GetHash(), txindexOld))
|
||||||
|
BOOST_FOREACH(CDiskTxPos &pos, txindexOld.vSpent)
|
||||||
|
if (pos.IsNull())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//// issue here: it doesn't know the version
|
//// issue here: it doesn't know the version
|
||||||
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
|
unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
|
||||||
|
|
||||||
@@ -2224,6 +2264,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
|
|||||||
{
|
{
|
||||||
printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
|
printf("storing orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
|
||||||
AddOrphanTx(vMsg);
|
AddOrphanTx(vMsg);
|
||||||
|
|
||||||
|
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
|
||||||
|
int nEvicted = LimitOrphanTxSize(MAX_ORPHAN_TRANSACTIONS);
|
||||||
|
if (nEvicted > 0)
|
||||||
|
printf("mapOrphan overflow, removed %d tx\n", nEvicted);
|
||||||
}
|
}
|
||||||
if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
|
if (tx.nDoS) pfrom->Misbehaving(tx.nDoS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class CBlockIndex;
|
|||||||
static const unsigned int MAX_BLOCK_SIZE = 1000000;
|
static const unsigned int MAX_BLOCK_SIZE = 1000000;
|
||||||
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
|
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
|
||||||
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
|
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
|
||||||
|
static const int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
|
||||||
static const int64 COIN = 100000000;
|
static const int64 COIN = 100000000;
|
||||||
static const int64 CENT = 1000000;
|
static const int64 CENT = 1000000;
|
||||||
static const int64 MIN_TX_FEE = 50000;
|
static const int64 MIN_TX_FEE = 50000;
|
||||||
|
|||||||
@@ -100,13 +100,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
base_uint& operator&=(uint64 b)
|
|
||||||
{
|
|
||||||
pn[0] &= (unsigned int)b;
|
|
||||||
pn[1] &= (unsigned int)(b >> 32);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
base_uint& operator|=(uint64 b)
|
base_uint& operator|=(uint64 b)
|
||||||
{
|
{
|
||||||
pn[0] |= (unsigned int)b;
|
pn[0] |= (unsigned int)b;
|
||||||
|
|||||||
19
src/util.cpp
19
src/util.cpp
@@ -737,26 +737,35 @@ string MyGetSpecialFolderPath(int nFolder, bool fCreate)
|
|||||||
{
|
{
|
||||||
PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
|
PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =
|
||||||
(PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
|
(PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");
|
||||||
|
bool fSuccess = false;
|
||||||
if (pSHGetSpecialFolderPath)
|
if (pSHGetSpecialFolderPath)
|
||||||
|
fSuccess =
|
||||||
(*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
|
(*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);
|
||||||
FreeModule(hShell32);
|
FreeModule(hShell32);
|
||||||
|
if (fSuccess)
|
||||||
|
return pszPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backup option
|
// Backup option
|
||||||
if (pszPath[0] == '\0')
|
std::string strPath;
|
||||||
{
|
{
|
||||||
|
const char *pszEnv;
|
||||||
if (nFolder == CSIDL_STARTUP)
|
if (nFolder == CSIDL_STARTUP)
|
||||||
{
|
{
|
||||||
strcpy(pszPath, getenv("USERPROFILE"));
|
pszEnv = getenv("USERPROFILE");
|
||||||
strcat(pszPath, "\\Start Menu\\Programs\\Startup");
|
if (pszEnv)
|
||||||
|
strPath = pszEnv;
|
||||||
|
strPath += "\\Start Menu\\Programs\\Startup";
|
||||||
}
|
}
|
||||||
else if (nFolder == CSIDL_APPDATA)
|
else if (nFolder == CSIDL_APPDATA)
|
||||||
{
|
{
|
||||||
strcpy(pszPath, getenv("APPDATA"));
|
pszEnv = getenv("APPDATA");
|
||||||
|
if (pszEnv)
|
||||||
|
strPath = pszEnv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pszPath;
|
return strPath;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
|||||||
if (!pwalletdbEncryption->TxnCommit())
|
if (!pwalletdbEncryption->TxnCommit())
|
||||||
exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet.
|
exit(1); //We now have keys encrypted in memory, but no on disk...die to avoid confusion and let the user reload their unencrypted wallet.
|
||||||
|
|
||||||
pwalletdbEncryption->Close();
|
delete pwalletdbEncryption;
|
||||||
pwalletdbEncryption = NULL;
|
pwalletdbEncryption = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user