Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Commit b22d896

Browse files
committed
Update: Overhauled Velocity Security System to v4
1 parent a85d05f commit b22d896

File tree

11 files changed

+99
-221
lines changed

11 files changed

+99
-221
lines changed

DigitalNote.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TEMPLATE = app
22
TARGET = DigitalNote-qt
3-
VERSION = 1.0.4.1
3+
VERSION = 1.0.4.2
44
INCLUDEPATH += src src/json src/qt src/qt/plugins/mrichtexteditor
55
QT += core gui widgets network printsupport
66
DEFINES += ENABLE_WALLET

src/clientversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define CLIENT_VERSION_MAJOR 1
1010
#define CLIENT_VERSION_MINOR 0
1111
#define CLIENT_VERSION_REVISION 4
12-
#define CLIENT_VERSION_BUILD 1
12+
#define CLIENT_VERSION_BUILD 2
1313

1414
// Set to true for release, false for prerelease or test build
1515
#define CLIENT_VERSION_IS_RELEASE true

src/main.cpp

Lines changed: 34 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ bool AreInputsStandard(const CTransaction& tx, const MapPrevTx& mapInputs)
584584

585585
for (unsigned int i = 0; i < tx.vin.size(); i++)
586586
{
587-
const CTxOut& prev = tx.GetOutputFor(tx.vin[i], mapInputs, false);
587+
const CTxOut& prev = tx.GetOutputFor(tx.vin[i], mapInputs);
588588

589589
vector<vector<unsigned char> > vSolutions;
590590
txnouttype whichType;
@@ -662,7 +662,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const MapPrevTx& inputs)
662662
unsigned int nSigOps = 0;
663663
for (unsigned int i = 0; i < tx.vin.size(); i++)
664664
{
665-
const CTxOut& prevout = tx.GetOutputFor(tx.vin[i], inputs, false);
665+
const CTxOut& prevout = tx.GetOutputFor(tx.vin[i], inputs);
666666
if (prevout.scriptPubKey.IsPayToScriptHash())
667667
nSigOps += prevout.scriptPubKey.GetSigOpCount(tx.vin[i].scriptSig);
668668
}
@@ -735,24 +735,6 @@ double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSiz
735735
return dPriorityInputs / nTxSize;
736736
}
737737

738-
void CTransaction::GetMapTxInputs(MapPrevTx& mapInputs, bool fAcceptBlock) const
739-
{
740-
// Load TX inputs
741-
CTxDB txdb("r");
742-
map<uint256, CTxIndex> mapUnused;
743-
bool fInvalid = false;
744-
745-
// Ensure we can fetch inputs
746-
if (!this->FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid, fAcceptBlock))
747-
{
748-
if (fInvalid)
749-
{
750-
LogPrintf("Invalid TX attempted to set in GetMapTXInputs\n");
751-
return;
752-
}
753-
}
754-
}
755-
756738
bool CTransaction::CheckTransaction() const
757739
{
758740
// Basic checks that don't depend on any context
@@ -912,7 +894,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree,
912894
MapPrevTx mapInputs;
913895
map<uint256, CTxIndex> mapUnused;
914896
bool fInvalid = false;
915-
if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid, false))
897+
if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
916898
{
917899
if (fInvalid)
918900
return error("AcceptToMemoryPool : FetchInputs found invalid tx %s", hash.ToString());
@@ -935,8 +917,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CTransaction &tx, bool fLimitFree,
935917
error("AcceptToMemoryPool : too many sigops %s, %d > %d",
936918
hash.ToString(), nSigOps, MAX_TX_SIGOPS));
937919

938-
int64_t nFees = tx.GetValueMapIn(mapInputs, false)-tx.GetValueOut();
939-
if (tx.GetValueMapIn(mapInputs, false) < tx.GetValueOut()) {
920+
int64_t nFees = tx.GetValueMapIn(mapInputs)-tx.GetValueOut();
921+
if (tx.GetValueMapIn(mapInputs) < tx.GetValueOut()) {
940922
LogPrintf("AcceptToMemoryPool : tx input is less that output\n");
941923
return tx.DoS(100, error("AcceptToMemoryPool : tx input is less that output"));
942924
}
@@ -1078,7 +1060,7 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
10781060
MapPrevTx mapInputs;
10791061
map<uint256, CTxIndex> mapUnused;
10801062
bool fInvalid = false;
1081-
if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid, false))
1063+
if (!tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
10821064
{
10831065
if (fInvalid)
10841066
return error("AcceptableInputs : FetchInputs found invalid tx %s", hash.ToString());
@@ -1101,8 +1083,8 @@ bool AcceptableInputs(CTxMemPool& pool, const CTransaction &txo, bool fLimitFree
11011083
error("AcceptableInputs : too many sigops %s, %d > %d",
11021084
hash.ToString(), nSigOps, MAX_TX_SIGOPS));
11031085

1104-
int64_t nFees = tx.GetValueMapIn(mapInputs, false)-tx.GetValueOut();
1105-
if (tx.GetValueMapIn(mapInputs, false) < tx.GetValueOut()) {
1086+
int64_t nFees = tx.GetValueMapIn(mapInputs)-tx.GetValueOut();
1087+
if (tx.GetValueMapIn(mapInputs) < tx.GetValueOut()) {
11061088
LogPrintf("AcceptableInputs : tx input is less that output\n");
11071089
return error("AcceptableInputs : tx input is less than output");
11081090
}
@@ -1594,7 +1576,7 @@ bool CTransaction::DisconnectInputs(CTxDB& txdb)
15941576

15951577

15961578
bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTestPool,
1597-
bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid, bool fAcceptBlock) const
1579+
bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid) const
15981580
{
15991581
// FetchInputs can return false either because we just haven't seen some inputs
16001582
// (in which case the transaction should be stored as an orphan)
@@ -1632,54 +1614,39 @@ bool CTransaction::FetchInputs(CTxDB& txdb, const map<uint256, CTxIndex>& mapTes
16321614
if (!fFound || txindex.pos == CDiskTxPos(1,1,1))
16331615
{
16341616
// Get prev tx from single transactions in memory
1635-
if (!mempool.lookup(prevout.hash, txPrev)) {
1636-
if (!fAcceptBlock) {
1637-
return error("FetchInputs() : %s mempool Tx prev not found %s", GetHash().ToString(), prevout.hash.ToString());
1638-
} else {
1639-
LogPrintf("FetchInputs() : fAcceptBlock toggled, Skipping mempool Tx prev not found error \n");
1640-
}
1641-
}
1642-
if (!fFound) {
1617+
if (!mempool.lookup(prevout.hash, txPrev))
1618+
return error("FetchInputs() : %s mempool Tx prev not found %s", GetHash().ToString(), prevout.hash.ToString());
1619+
if (!fFound)
16431620
txindex.vSpent.resize(txPrev.vout.size());
1644-
}
16451621
}
16461622
else
16471623
{
16481624
// Get prev tx from disk
1649-
if (!txPrev.ReadFromDisk(txindex.pos)) {
1650-
if (!fAcceptBlock) {
1651-
return error("FetchInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString(), prevout.hash.ToString());
1652-
} else {
1653-
LogPrintf("FetchInputs() : fAcceptBlock toggled, Skipping ReadFromDisk Tx prev not found error \n");
1654-
}
1655-
}
1625+
if (!txPrev.ReadFromDisk(txindex.pos))
1626+
return error("FetchInputs() : %s ReadFromDisk prev tx %s failed", GetHash().ToString(), prevout.hash.ToString());
16561627
}
16571628
}
16581629

1659-
if (!fAcceptBlock) {
1660-
// Make sure all prevout.n indexes are valid:
1661-
for (unsigned int i = 0; i < vin.size(); i++)
1630+
// Make sure all prevout.n indexes are valid:
1631+
for (unsigned int i = 0; i < vin.size(); i++)
1632+
{
1633+
const COutPoint prevout = vin[i].prevout;
1634+
assert(inputsRet.count(prevout.hash) != 0);
1635+
const CTxIndex& txindex = inputsRet[prevout.hash].first;
1636+
const CTransaction& txPrev = inputsRet[prevout.hash].second;
1637+
if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
16621638
{
1663-
const COutPoint prevout = vin[i].prevout;
1664-
assert(inputsRet.count(prevout.hash) != 0);
1665-
const CTxIndex& txindex = inputsRet[prevout.hash].first;
1666-
const CTransaction& txPrev = inputsRet[prevout.hash].second;
1667-
if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
1668-
{
1669-
// Revisit this if/when transaction replacement is implemented and allows
1670-
// adding inputs:
1671-
fInvalid = true;
1672-
return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %u %u prev tx %s\n%s", GetHash().ToString(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString(), txPrev.ToString()));
1673-
}
1639+
// Revisit this if/when transaction replacement is implemented and allows
1640+
// adding inputs:
1641+
fInvalid = true;
1642+
return DoS(100, error("FetchInputs() : %s prevout.n out of range %d %u %u prev tx %s\n%s", GetHash().ToString(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString(), txPrev.ToString()));
16741643
}
1675-
} else {
1676-
LogPrintf("FetchInputs() : fAcceptBlock toggled, Skipping prevout.n validation \n");
16771644
}
16781645

16791646
return true;
16801647
}
16811648

1682-
const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& inputs, bool fAcceptBlock) const
1649+
const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const
16831650
{
16841651
MapPrevTx::const_iterator mi = inputs.find(input.prevout.hash);
16851652
if (mi == inputs.end()) {
@@ -1689,26 +1656,22 @@ const CTxOut& CTransaction::GetOutputFor(const CTxIn& input, const MapPrevTx& in
16891656
const CTransaction& txPrev = (mi->second).second;
16901657
// Don't allow oversized outputs
16911658
if (input.prevout.n >= txPrev.vout.size()) {
1692-
// Skip if queried by AcceptBlock()
1693-
if (!fAcceptBlock) {
1694-
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.n out of range");
1695-
}
1659+
throw std::runtime_error("CTransaction::GetOutputFor() : prevout.n out of range");
16961660
}
16971661

16981662
return txPrev.vout[input.prevout.n];
16991663
}
17001664

1701-
int64_t CTransaction::GetValueMapIn(const MapPrevTx& inputs, bool fAcceptBlock) const
1665+
int64_t CTransaction::GetValueMapIn(const MapPrevTx& inputs) const
17021666
{
17031667
if (IsCoinBase())
17041668
return 0;
17051669

17061670
int64_t nResult = 0;
17071671
for (unsigned int i = 0; i < vin.size(); i++)
17081672
{
1709-
nResult += GetOutputFor(vin[i], inputs, fAcceptBlock).nValue;
1673+
nResult += GetOutputFor(vin[i], inputs).nValue;
17101674
}
1711-
17121675
return nResult;
17131676

17141677
}
@@ -1927,7 +1890,7 @@ void CBlock::RebuildAddressIndex(CTxDB& txdb)
19271890
MapPrevTx mapInputs;
19281891
map<uint256, CTxIndex> mapQueuedChangesT;
19291892
bool fInvalid;
1930-
if (!tx.FetchInputs(txdb, mapQueuedChangesT, true, false, mapInputs, fInvalid, false))
1893+
if (!tx.FetchInputs(txdb, mapQueuedChangesT, true, false, mapInputs, fInvalid))
19311894
return;
19321895

19331896
MapPrevTx::const_iterator mi;
@@ -2010,7 +1973,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20101973
else
20111974
{
20121975
bool fInvalid;
2013-
if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs, fInvalid, false))
1976+
if (!tx.FetchInputs(txdb, mapQueuedChanges, true, false, mapInputs, fInvalid))
20141977
return false;
20151978

20161979
// Add in sigops done by pay-to-script-hash inputs;
@@ -2020,7 +1983,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20201983
if (nSigOps > MAX_BLOCK_SIGOPS)
20211984
return DoS(100, error("ConnectBlock() : too many sigops"));
20221985

2023-
int64_t nTxValueIn = tx.GetValueMapIn(mapInputs, false);
1986+
int64_t nTxValueIn = tx.GetValueMapIn(mapInputs);
20241987
int64_t nTxValueOut = tx.GetValueOut();
20251988
nValueIn += nTxValueIn;
20261989
nValueOut += nTxValueOut;
@@ -2092,7 +2055,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
20922055
MapPrevTx mapInputs;
20932056
map<uint256, CTxIndex> mapQueuedChangesT;
20942057
bool fInvalid;
2095-
if (!tx.FetchInputs(txdb, mapQueuedChangesT, true, false, mapInputs, fInvalid, false))
2058+
if (!tx.FetchInputs(txdb, mapQueuedChangesT, true, false, mapInputs, fInvalid))
20962059
return false;
20972060

20982061
MapPrevTx::const_iterator mi;
@@ -2965,42 +2928,12 @@ bool CBlock::AcceptBlock()
29652928
if (GetBlockTime() <= pindexPrev->GetPastTimeLimit() || FutureDrift(GetBlockTime()) < pindexPrev->GetBlockTime())
29662929
return error("AcceptBlock() : block's timestamp is too early");
29672930

2968-
// Set logged values
2969-
CAmount tx_inputs_values = 0;
2970-
CAmount tx_outputs_values = 0;
2971-
CAmount tx_MapIn_values = 0;
2972-
CAmount tx_threshold = (300 * COIN);
29732931
// Check that all transactions are finalized
29742932
BOOST_FOREACH(const CTransaction& tx, vtx)
29752933
{
29762934
if (!IsFinalTx(tx, nHeight, GetBlockTime())) {
29772935
return DoS(10, error("AcceptBlock() : contains a non-final transaction"));
29782936
}
2979-
// Log inputs/output values
2980-
MapPrevTx mapInputs;
2981-
tx.GetMapTxInputs(mapInputs, true);
2982-
tx_MapIn_values = tx.GetValueMapIn(mapInputs, true);
2983-
// Log inputs/output values
2984-
if((tx_inputs_values + tx_MapIn_values) >= 0)
2985-
{
2986-
tx_inputs_values += tx_MapIn_values;
2987-
} else {
2988-
return DoS(10, error("AcceptBlock() : overflow detected tx_inputs_values + tx.GetValueMapIn(mapInputs)"));
2989-
}
2990-
if(tx_outputs_values + tx.GetValueOut() >= 0)
2991-
{
2992-
tx_outputs_values += tx.GetValueOut();
2993-
} else {
2994-
return DoS(10, error("AcceptBlock() : overflow detected tx_outputs_values + tx.GetValueOut()"));
2995-
}
2996-
}
2997-
2998-
// Ensure input/output sanity of transactions in the block
2999-
if((tx_inputs_values + tx_threshold) < tx_outputs_values)
3000-
{
3001-
if(nHeight > 175) {
3002-
return DoS(100, error("AcceptBlock() : block contains a tx input that is less that output"));
3003-
}
30042937
}
30052938

30062939
// Check that the block chain matches the known block chain up to a checkpoint

src/main.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static const int64_t MIN_RELAY_TX_FEE = MIN_TX_FEE;
6060
/** Minimum TX count (for relaying) */
6161
static const int64_t MIN_TX_COUNT = 0;
6262
/** Minimum TX value (for relaying) */
63-
static const int64_t MIN_TX_VALUE = 0.01 * COIN;
63+
static const int64_t MIN_TX_VALUE = 1 * COIN;
6464
/** No amount larger than this (in satoshi) is valid */
6565
static const int64_t MAX_SINGLE_TX = 10000000000 * COIN; // 10 Billion DigitalNote coins
6666
/** Moneyrange params */
@@ -79,6 +79,8 @@ static const int64_t nDrift = 5 * 60;
7979
inline int64_t FutureDrift(int64_t nTime) { return nTime + nDrift; }
8080
/** "reject" message codes **/
8181
static const unsigned char REJECT_INVALID = 0x10;
82+
/** Velocity Factor handling toggle */
83+
inline bool FACTOR_TOGGLE(int nHeight) { return TestNet() || nHeight > 394623; }
8284

8385
extern CScript COINBASE_FLAGS;
8486
extern CCriticalSection cs_main;
@@ -328,8 +330,6 @@ class CTransaction
328330
}
329331
return nValueOut;
330332
}
331-
// Map TX inputs for scanning
332-
void GetMapTxInputs(MapPrevTx &mapInputs, bool fAcceptBlock) const;
333333

334334
/** Amount of bitcoins coming in to this transaction
335335
Note that lightweight clients may not know anything besides the hash of previous transactions,
@@ -339,7 +339,7 @@ class CTransaction
339339
@return Sum of value of all inputs (scriptSigs)
340340
@see CTransaction::FetchInputs
341341
*/
342-
int64_t GetValueMapIn(const MapPrevTx& mapInputs, bool fAcceptBlock) const;
342+
int64_t GetValueMapIn(const MapPrevTx& mapInputs) const;
343343

344344
bool ReadFromDisk(CDiskTxPos pos, FILE** pfileRet=NULL)
345345
{
@@ -418,7 +418,7 @@ class CTransaction
418418
@return Returns true if all inputs are in txdb or mapTestPool
419419
*/
420420
bool FetchInputs(CTxDB& txdb, const std::map<uint256, CTxIndex>& mapTestPool,
421-
bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid, bool fAcceptBlock) const;
421+
bool fBlock, bool fMiner, MapPrevTx& inputsRet, bool& fInvalid) const;
422422

423423
/** Sanity check previous transactions, then, if all checks succeed,
424424
mark them as spent by this transaction.
@@ -437,7 +437,7 @@ class CTransaction
437437
bool CheckTransaction() const;
438438
bool GetCoinAge(CTxDB& txdb, const CBlockIndex* pindexPrev, uint64_t& nCoinAge) const;
439439

440-
const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs, bool fAcceptBlock) const;
440+
const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
441441
};
442442

443443

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ CBlock* CreateNewBlock(CReserveKey& reservekey, bool fProofOfStake, int64_t* pFe
313313
map<uint256, CTxIndex> mapTestPoolTmp(mapTestPool);
314314
MapPrevTx mapInputs;
315315
bool fInvalid;
316-
if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid, false))
316+
if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid))
317317
continue;
318318

319-
int64_t nTxFees = tx.GetValueMapIn(mapInputs, false)-tx.GetValueOut();
319+
int64_t nTxFees = tx.GetValueMapIn(mapInputs)-tx.GetValueOut();
320320

321321
nTxSigOps += GetP2SHSigOpCount(tx, mapInputs);
322322
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)

src/rpcmining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,9 @@ Value getblocktemplate(const Array& params, bool fHelp)
621621
MapPrevTx mapInputs;
622622
map<uint256, CTxIndex> mapUnused;
623623
bool fInvalid = false;
624-
if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid, false))
624+
if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid))
625625
{
626-
entry.push_back(Pair("fee", (int64_t)(tx.GetValueMapIn(mapInputs, false) - tx.GetValueOut())));
626+
entry.push_back(Pair("fee", (int64_t)(tx.GetValueMapIn(mapInputs) - tx.GetValueOut())));
627627

628628
Array deps;
629629
BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs)

src/rpcrawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
399399

400400
// FetchInputs aborts on failure, so we go one at a time.
401401
tempTx.vin.push_back(mergedTx.vin[i]);
402-
tempTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid, false);
402+
tempTx.FetchInputs(txdb, unused, false, false, mapPrevTx, fInvalid);
403403

404404
// Copy results into mapPrevOut:
405405
BOOST_FOREACH(const CTxIn& txin, tempTx.vin)

src/rpcvelocity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ json_spirit::Value getvelocityinfo(const Array& params, bool fHelp) {
3939
obj.push_back(json_spirit::Pair("min-value", (int)VELOCITY_MIN_VALUE[i]));
4040
if( VELOCITY_MIN_FEE[i] > 0 )
4141
obj.push_back(json_spirit::Pair("min-fee", (int)VELOCITY_MIN_FEE[i]));
42-
obj.push_back(json_spirit::Pair("factor", VELOCITY_FACTOR[i]));
42+
obj.push_back(json_spirit::Pair("factor", VELOCITY_FACTOR));
4343
obj.push_back(json_spirit::Pair("explicit", VELOCITY_EXPLICIT[i]));
4444
return obj;
4545
}

0 commit comments

Comments
 (0)