Rename CClaimTrieCache to CClaimTrieUpdateBuffer #156
2 changed files with 432 additions and 72 deletions
|
@ -77,7 +77,6 @@ bool CClaimTrieNode::removeValue(uint256& txhash, uint32_t nOut, CNodeValue& val
|
|||
{
|
||||
LogPrintf("\ttxid: %s, nOut: %d\n", values[i].txhash.ToString(), values[i].nOut);
|
||||
}
|
||||
std::cout << "couldnt find the thing" << std::endl;
|
||||
return false;
|
||||
}
|
||||
//if (!values.empty())
|
||||
|
@ -1296,7 +1295,7 @@ bool CClaimTrieCache::reorderTrieNode(const std::string name) const
|
|||
{
|
||||
assert(base);
|
||||
nodeCacheType::iterator cachedNode;
|
||||
cachedNode = cache.find("name");
|
||||
cachedNode = cache.find(name);
|
||||
if (cachedNode == cache.end())
|
||||
{
|
||||
CClaimTrieNode* currentNode = &(base->root);
|
||||
|
@ -1405,15 +1404,25 @@ bool CClaimTrieCache::removeSupportFromMap(const std::string name, uint256 txhas
|
|||
assert(ret.second);
|
||||
cachedNode = ret.first;
|
||||
}
|
||||
for (supportMapNodeType::iterator itSupport = cachedNode->second.begin(); itSupport != cachedNode->second.end(); ++itSupport)
|
||||
supportMapNodeType::iterator itSupport;
|
||||
for (itSupport = cachedNode->second.begin(); itSupport != cachedNode->second.end(); ++itSupport)
|
||||
{
|
||||
if (itSupport->txhash == txhash && itSupport->nOut == nOut && itSupport->supportTxhash == supportedTxhash && itSupport->supportnOut == supportednOut && itSupport->nHeight == nHeight)
|
||||
{
|
||||
nValidAtHeight = itSupport->nValidAtHeight;
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (itSupport != cachedNode->second.end())
|
||||
{
|
||||
cachedNode->second.erase(itSupport);
|
||||
return reorderTrieNode(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrintf("CClaimTrieCache::%s() : asked to remove a support that doesn't exist\n", __func__);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
supportValueQueueType::iterator CClaimTrieCache::getSupportQueueCacheRow(int nHeight, bool createIfNotExists) const
|
||||
|
@ -1488,7 +1497,7 @@ bool CClaimTrieCache::addSupport(const std::string name, uint256 txhash, uint32_
|
|||
|
||||
bool CClaimTrieCache::undoSpendSupport(const std::string name, uint256 txhash, uint32_t nOut, CAmount nAmount, uint256 supportedTxhash, int supportednOut, int nHeight, int nValidAtHeight) const
|
||||
{
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight);
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, nAmount: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, nAmount, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
|
||||
if (nValidAtHeight < nCurrentHeight)
|
||||
{
|
||||
CSupportNodeValue val(txhash, nOut, supportedTxhash, supportednOut, nAmount, nHeight, nValidAtHeight);
|
||||
|
@ -1518,14 +1527,14 @@ bool CClaimTrieCache::removeSupport(const std::string name, uint256 txhash, uint
|
|||
|
||||
bool CClaimTrieCache::undoAddSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight) const
|
||||
{
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight);
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
|
||||
int throwaway;
|
||||
return removeSupport(name, txhash, nOut, supportedTxhash, supportednOut, nHeight, throwaway);
|
||||
}
|
||||
|
||||
bool CClaimTrieCache::spendSupport(const std::string name, uint256 txhash, uint32_t nOut, uint256 supportedTxhash, int supportednOut, int nHeight, int& nValidAtHeight) const
|
||||
{
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight);
|
||||
LogPrintf("%s: name: %s, txhash: %s, nOut: %d, supportedTxhash: %s, supportednOut: %d, nHeight: %d, nCurrentHeight: %d\n", __func__, name, txhash.GetHex(), nOut, supportedTxhash.GetHex(), supportednOut, nHeight, nCurrentHeight);
|
||||
return removeSupport(name, txhash, nOut, supportedTxhash, supportednOut, nHeight, nValidAtHeight);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,67 +82,78 @@ const unsigned int insert_nonces[] = {
|
|||
28808, 57914, 67186, 8294, 142255, 26350, 94732, 1635, 2272, 113460,
|
||||
126065, 32864, 69844, 137209, 12286, 45293, 46530, 3738, 9976, 11934,
|
||||
21574, 674, 8540, 63574, 68149, 40583, 148497, 125165, 6685, 8401,
|
||||
154662, 37101, 39016, 32108, 11193, 167425, 41041,
|
||||
154662, 37101, 39016, 32108, 11193, 167425, 41041, 18322, 52212, 51840,
|
||||
42878, 91589, 61917, 124810, 27102, 2216, 21835, 126406, 39437, 17288,
|
||||
34800, 111796, 707, 36455, 153492, 159933, 12398, 67544, 37082, 30098,
|
||||
229205, 47964, 5544, 3483, 85833, 98896, 114927, 4548, 5466, 339131,
|
||||
53091, 12742, 120717, 16555, 66390, 60497, 146946, 179155, 101302, 25237,
|
||||
7373, 29939, 192727, 139469, 100098, 7412, 10109, 108590, 85040, 57723,
|
||||
205366, 14108, 1675, 104092, 4531, 6625, 194140, 108134, 51179, 286475,
|
||||
57364, 35435, 101339, 49842, 170756, 74109, 167787, 74888, 13734, 2200,
|
||||
51025, 20673, 114840, 226387, 45924, 81994, 15964, 72198, 137478, 189006,
|
||||
5563, 76228, 112664, 6093, 22526, 218231, 28274, 62240, 834, 3040,
|
||||
11374, 44162, 32366, 28706, 27518, 73387, 74858, 13841,
|
||||
};
|
||||
|
||||
const unsigned int expire_nonces[] = {
|
||||
6685, 83337, 74116, 50981, 51352, 158110, 132142, 161310, 95702, 32959,
|
||||
5785, 229298, 59738, 71206, 24625, 6, 141161, 43901, 35697, 98865,
|
||||
41764, 104919, 89611, 813, 54564, 13614, 24774, 39079, 67709, 94367,
|
||||
24006, 137451, 87265, 4096, 17540, 93657, 64419, 178853, 45385, 18571,
|
||||
49357, 67111, 92635, 73880, 7810, 15338, 56201, 1419, 92096, 121328,
|
||||
60987, 32796, 63605, 2178, 25415, 19115, 62190, 76200, 155888, 208604,
|
||||
43921, 623, 63809, 129207, 59080, 111270, 58799, 47014, 26935, 140745,
|
||||
15982, 22417, 54877, 64708, 3508, 63688, 117163, 93037, 27595, 49051,
|
||||
109801, 54794, 38790, 192113, 14920, 2056, 419624, 20495, 86719, 27455,
|
||||
94870, 5539, 12871, 24142, 103201, 12358, 60226, 11163, 57429, 49086,
|
||||
115051, 39940, 68936, 392, 23999, 23185, 37265, 793, 196124, 133047,
|
||||
95771, 4927, 2410, 191047, 8416, 36182, 126426, 101492, 268543, 66462,
|
||||
132688, 9709, 25766, 10781, 56169, 17484, 191643, 46857, 180718, 129600,
|
||||
76319, 275342, 113429, 52200, 8584, 205931, 60264, 99367, 71513, 10931,
|
||||
2470, 146435, 35660, 30357, 53621, 126053, 198310, 7340, 23329, 56232,
|
||||
43152, 1290, 178803, 58294, 28730, 135307, 26024, 33903, 23202, 69984,
|
||||
91861, 4406, 21564, 12088, 5307, 17517, 177507, 3629, 81666, 196118,
|
||||
37329, 42816, 1766, 5227, 98516, 62284, 1449, 10331, 4915, 1086,
|
||||
257130, 125081, 63069, 34059, 51482, 15396, 25319, 208595, 45717, 145038,
|
||||
51317, 34896, 60597, 8930, 150489, 15827, 94634, 19809, 90784, 102628,
|
||||
26279, 36205, 239377, 98432, 1949, 167692, 123222, 36572, 5435, 239413,
|
||||
85529, 124924, 17443, 10391, 21356, 109441, 711, 27883, 15410, 172902,
|
||||
9155, 6372, 93226, 31199, 47383, 77311, 107243, 1248, 3968, 88072,
|
||||
50741, 175826, 9475, 19473, 78911, 59587, 172626, 54698, 127135, 4356,
|
||||
70568, 9206, 41708, 162673, 82436, 8787, 12851, 17524, 27151, 34992,
|
||||
19003, 17118, 1353, 173957, 62721, 10956, 28301, 38722, 35000, 51572,
|
||||
122622, 26131, 219537, 24299, 8306, 22556, 117394, 5874, 1658, 4299,
|
||||
85895, 59207, 17620, 65379, 53730, 66114, 31973, 80054, 39898, 88576,
|
||||
35918, 54740, 43218, 310351, 18849, 65424, 18941, 49216, 21837, 1044,
|
||||
36089, 89042, 1064, 57622, 18277, 30812, 392721, 68449, 21958, 59353,
|
||||
230626, 192876, 152661, 83303, 12403, 48000, 322, 36098, 216060, 261073,
|
||||
10127, 40078, 13820, 37595, 2465, 67578, 8074, 17069, 23001, 75590,
|
||||
59540, 38500, 81671, 83017, 21630, 42072, 87988, 34685, 54463, 73723,
|
||||
64583, 11708, 27819, 60914, 44671, 73532, 481251, 50437, 51482, 140164,
|
||||
17802, 52420, 18605, 39313, 5815, 130397, 47241, 41700, 73784, 38254,
|
||||
31816, 81033, 63873, 61180, 73597, 31012, 46596, 34360, 16076, 3553,
|
||||
19667, 70678, 76463, 14007, 6695, 34346, 177277, 82740, 10695, 195656,
|
||||
199473, 19061, 12235, 118857, 5890, 158834, 14991, 9908, 40669, 76476,
|
||||
5798, 56010, 12434, 136848, 44171, 33686, 38022, 85052, 88529, 96055,
|
||||
77808, 14052, 26881, 183273, 110552, 14780, 62505, 29327, 16832, 146503,
|
||||
4492, 3210, 60633, 117771, 14125, 30949, 20800, 35101, 72610, 3023,
|
||||
39933, 7829, 21639, 14090, 59951, 46100, 26005, 57832, 3410, 58340,
|
||||
83407, 189530, 1991, 46036, 39758, 26344, 36726, 13556, 54091, 52219,
|
||||
10445, 23350, 62863, 41887, 39607, 47051, 170358, 62714, 54450, 44956,
|
||||
90394, 89040, 82532, 10732, 30853, 69521, 27096, 129159, 25700, 56643,
|
||||
4510, 61375, 45066, 84264, 47513, 27524, 25215, 95656, 73959, 20581,
|
||||
101988, 14797, 76360, 120161, 17567, 3903, 126413, 64154, 317038, 33995,
|
||||
25108, 8165, 132499, 174571, 4312, 63941, 109366, 12461, 81720, 36019,
|
||||
57768, 30058, 64038, 60147, 5536, 87586, 10954, 84112, 42404, 109189,
|
||||
13869, 50548, 11654, 10051, 76725, 20594, 51481, 2668, 262831, 23754,
|
||||
66190, 133133, 119290, 52240, 72002, 103103, 9144, 72562, 54350, 22676,
|
||||
126558, 532, 23582, 20393, 25177, 4026, 55663, 24424, 175796, 14987,
|
||||
58251, 124293, 4159, 220204, 2488, 36895, 10692, 1368, 80599, 203043,
|
||||
3851, 11006, 24724, 40853, 19234, 36755, 43655, 12807, 40882, 43029,
|
||||
4359, 35786, 24830, 102413, 17399, 48845, 22866, 8417, 24049, 50162,
|
||||
36921, 162891, 38509, 121018, 54548, 158171, 54355, 12742, 6174,
|
||||
53643, 193025, 37619, 252203, 58420, 37206, 120531, 38736, 98682, 46851,
|
||||
5408, 42419, 79305, 42088, 27227, 38681, 10473, 68404, 13386, 148340,
|
||||
27265, 14930, 23512, 259139, 52524, 139580, 15274, 107872, 13512, 39058,
|
||||
6528, 171375, 100432, 20647, 38238, 41994, 32188, 20306, 37666, 102447,
|
||||
122325, 24994, 13778, 12889, 14487, 5961, 212456, 5949, 14945, 72000,
|
||||
34139, 52284, 72275, 39792, 3626, 47870, 26350, 2030, 21205, 242795,
|
||||
6922, 42897, 49239, 36965, 29472, 47434, 39801, 7848, 107087, 56181,
|
||||
11574, 218603, 921, 62918, 87550, 5039, 199191, 11595, 151114, 69613,
|
||||
200746, 93161, 24752, 54040, 30086, 243689, 4355, 148401, 23334, 22731,
|
||||
67536, 4909, 129386, 17413, 48047, 59554, 80856, 112253, 116605, 49616,
|
||||
28509, 124700, 81689, 20237, 45435, 65531, 88501, 69505, 1910, 2339,
|
||||
105547, 3571, 92337, 40606, 19594, 65255, 171478, 180842, 42044, 165883,
|
||||
13358, 31680, 36101, 172555, 96773, 72536, 155350, 2098, 11005, 150888,
|
||||
23162, 238079, 8065, 88390, 59240, 159426, 18883, 100712, 50303, 12778,
|
||||
4122, 39015, 87028, 21859, 204734, 125392, 7046, 101177, 30313, 38983,
|
||||
33926, 12411, 89317, 13614, 32803, 20403, 9974, 155161, 126861, 138228,
|
||||
96019, 41401, 7382, 276438, 241196, 87614, 19478, 50243, 29382, 27322,
|
||||
50149, 12226, 72311, 261323, 148422, 33798, 19257, 159967, 35923, 1871,
|
||||
35370, 1934, 20297, 67350, 39297, 37949, 27448, 11718, 99752, 78981,
|
||||
6827, 9146, 54521, 11337, 32495, 131559, 74671, 18399, 9176, 23039,
|
||||
68035, 35216, 10352, 48005, 57711, 4111, 10910, 3728, 42934, 148284,
|
||||
17258, 25026, 21188, 74496, 85191, 42063, 88363, 50770, 6496, 96991,
|
||||
18379, 166816, 51923, 11159, 46012, 40566, 191245, 77859, 10582, 39886,
|
||||
14617, 87189, 10621, 1924, 82382, 17764, 6480, 57891, 34821, 2814,
|
||||
54541, 73597, 97789, 127407, 32318, 12967, 29903, 11871, 96127, 29539,
|
||||
43608, 8382, 9974, 13281, 201100, 8637, 310817, 49145, 46113, 6755,
|
||||
140141, 237272, 101425, 275710, 35425, 107336, 21626, 24303, 67533, 97938,
|
||||
38556, 315214, 12328, 322, 51291, 15382, 7078, 111, 11374, 13528,
|
||||
23632, 114220, 5723, 34296, 86986, 16045, 522, 22529, 5611, 73259,
|
||||
48757, 39981, 58614, 69598, 172362, 61830, 38832, 77165, 17464, 229210,
|
||||
146635, 100205, 72180, 115848, 65228, 47877, 27028, 136614, 37698, 6976,
|
||||
16142, 114525, 149787, 14563, 26711, 75974, 1473, 80188, 115058, 144729,
|
||||
39907, 40755, 30276, 46183, 119711, 206462, 17425, 103303, 2199, 57205,
|
||||
226714, 57224, 110498, 60932, 93610, 129, 130557, 59604, 22063, 43375,
|
||||
11610, 28350, 7582, 79781, 10865, 43149, 96470, 36001, 192437, 179354,
|
||||
10228, 89266, 7910, 156039, 267310, 13344, 93112, 27293, 42582, 55182,
|
||||
27195, 17225, 93669, 102846, 64936, 1136, 140, 73174, 8659, 112737,
|
||||
131488, 53985, 80662, 176405, 87433, 170967, 10978, 185759, 199916, 34024,
|
||||
7838, 5129, 3591, 8126, 19177, 33500, 143216, 39321, 16370, 143905,
|
||||
2679, 51503, 92834, 19531, 33340, 5086, 70009, 4983, 74213, 68851,
|
||||
26319, 10016, 55917, 137039, 20227, 9087, 6602, 207466, 1920, 14902,
|
||||
8778, 112930, 6476, 39473, 47094, 4146, 46644, 230231, 59400, 8385,
|
||||
80074, 92678, 13163, 440, 61457, 65142, 1264, 47993, 28298, 22303,
|
||||
102585, 84609, 62724, 32058, 4264, 12953, 66000, 20420, 5845, 9863,
|
||||
38763, 33772, 92168, 68659, 121676, 16753, 56006, 94837, 72432, 42723,
|
||||
10070, 18181, 27435, 55469, 5014, 6212, 32777, 13640, 155058, 4801,
|
||||
2172, 22607, 22045, 337783, 15163, 14092, 70761, 45246, 57947, 8256,
|
||||
21857, 57639, 69802, 37692, 75350, 108166, 110128, 10297, 202304, 277189,
|
||||
100368, 258936, 31115, 6587, 41871, 122116, 49827, 78331, 38975, 159839,
|
||||
16620, 8790, 25848, 32898, 21040, 381409, 33867, 198668, 25577, 50833,
|
||||
1563, 66657, 46516, 42621, 22630, 33949, 46949, 17531, 7166, 61699,
|
||||
32573, 14976, 62930, 117242, 16964, 87579, 33119, 235295, 54355, 60343,
|
||||
22289, 58048, 1946, 36960, 25046, 5308, 205643, 220624, 64664, 68716,
|
||||
97214, 40261, 141321, 99397, 132590, 14605, 58838, 62340, 44877, 91900,
|
||||
3790, 25997, 1795, 11827, 97922, 93, 179423, 350, 10327, 40879,
|
||||
22343, 31416, 138676, 3672, 41575, 77002, 199599, 59124, 4381,
|
||||
};
|
||||
|
||||
const unsigned int support_nonces[] = {
|
||||
6685, 83337, 74116, 50981, 51352, 158110, 132142, 161310, 95702, 32959,
|
||||
5785, 229298, 59738, 71206, 24625, 6, 141161, 43901, 35697, 98865,
|
||||
|
@ -174,6 +185,26 @@ const unsigned int support_nonces[] = {
|
|||
85895, 59207, 17620, 65379, 53730, 66114, 31973, 80054, 39898, 88576,
|
||||
35918, 54740, 43218, 310351, 18849, 65424, 18941, 49216, 21837, 1044,
|
||||
36089, 89042, 1064, 57622, 18277, 30812, 392721, 68449, 21958, 59353,
|
||||
36089, 89042, 1064, 57622, 18277, 30812, 392721, 68449, 21958, 59353,
|
||||
36089, 89042, 1064, 57622, 18277, 30812, 392721, 68449, 21958, 59353,
|
||||
230626, 192876, 152661, 83303, 12403, 48000, 322, 36098, 216060, 261073,
|
||||
10127, 40078, 13820, 37595, 2465, 67578, 8074, 17069, 23001, 75590,
|
||||
59540, 38500, 81671, 83017, 21630, 42072, 87988, 34685, 54463, 73723,
|
||||
64583, 11708, 27819, 60914, 44671, 73532, 481251, 50437, 51482, 140164,
|
||||
17802, 52420, 18605, 39313, 5815, 130397, 47241, 41700, 73784, 38254,
|
||||
31816, 81033, 63873, 61180, 73597, 31012, 46596, 34360, 16076, 3553,
|
||||
19667, 70678, 76463, 14007, 6695, 34346, 177277, 82740, 10695, 195656,
|
||||
199473, 19061, 12235, 118857, 5890, 158834, 14991, 9908, 40669, 76476,
|
||||
5798, 56010, 12434, 136848, 44171, 33686, 38022, 85052, 88529, 96055,
|
||||
230626, 192876, 152661, 83303, 12403, 48000, 322, 36098, 216060, 261073,
|
||||
10127, 40078, 13820, 37595, 2465, 67578, 8074, 17069, 23001, 75590,
|
||||
59540, 38500, 81671, 83017, 21630, 42072, 87988, 34685, 54463, 73723,
|
||||
64583, 11708, 27819, 60914, 44671, 73532, 481251, 50437, 51482, 140164,
|
||||
17802, 52420, 18605, 39313, 5815, 130397, 47241, 41700, 73784, 38254,
|
||||
31816, 81033, 63873, 61180, 73597, 31012, 46596, 34360, 16076, 3553,
|
||||
19667, 70678, 76463, 14007, 6695, 34346, 177277, 82740, 10695, 195656,
|
||||
199473, 19061, 12235, 118857, 5890, 158834, 14991, 9908, 40669, 76476,
|
||||
5798, 56010, 12434, 136848, 44171, 33686, 38022, 85052, 88529, 96055,
|
||||
230626, 192876, 152661, 83303, 12403, 48000, 322, 36098, 216060, 261073,
|
||||
10127, 40078, 13820, 37595, 2465, 67578, 8074, 17069, 23001, 75590,
|
||||
59540, 38500, 81671, 83017, 21630, 42072, 87988, 34685, 54463, 73723,
|
||||
|
@ -214,26 +245,35 @@ CMutableTransaction BuildTransaction(const uint256& prevhash)
|
|||
return tx;
|
||||
}
|
||||
|
||||
CMutableTransaction BuildTransaction(const CMutableTransaction& prev)
|
||||
CMutableTransaction BuildTransaction(const CMutableTransaction& prev, uint32_t prevout=0, unsigned int numOutputs=1)
|
||||
{
|
||||
CMutableTransaction tx;
|
||||
tx.nVersion = 1;
|
||||
tx.nLockTime = 0;
|
||||
tx.vin.resize(1);
|
||||
tx.vout.resize(1);
|
||||
tx.vout.resize(numOutputs);
|
||||
tx.vin[0].prevout.hash = prev.GetHash();
|
||||
tx.vin[0].prevout.n = 0;
|
||||
tx.vin[0].prevout.n = prevout;
|
||||
tx.vin[0].scriptSig = CScript();
|
||||
tx.vin[0].nSequence = std::numeric_limits<unsigned int>::max();
|
||||
tx.vout[0].scriptPubKey = CScript();
|
||||
tx.vout[0].nValue = prev.vout[0].nValue;
|
||||
CAmount valuePerOutput = prev.vout[prevout].nValue;
|
||||
unsigned int numOutputsCopy = numOutputs;
|
||||
while ((numOutputsCopy = numOutputsCopy >> 1) > 0)
|
||||
{
|
||||
valuePerOutput = valuePerOutput >> 1;
|
||||
}
|
||||
for (unsigned int i = 0; i < numOutputs; ++i)
|
||||
{
|
||||
tx.vout[i].scriptPubKey = CScript();
|
||||
tx.vout[i].nValue = valuePerOutput;
|
||||
}
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
CMutableTransaction BuildTransaction(const CTransaction& prev)
|
||||
CMutableTransaction BuildTransaction(const CTransaction& prev, uint32_t prevout=0, unsigned int numOutputs=1)
|
||||
{
|
||||
return BuildTransaction(CMutableTransaction(prev));
|
||||
return BuildTransaction(CMutableTransaction(prev), prevout, numOutputs);
|
||||
}
|
||||
|
||||
void AddToMempool(CMutableTransaction& tx)
|
||||
|
@ -482,6 +522,10 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
|
|||
CMutableTransaction tx7 = BuildTransaction(coinbases[3]);
|
||||
tx7.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||
tx7.vout[0].nValue = tx1.vout[0].nValue - 1;
|
||||
CMutableTransaction tx8 = BuildTransaction(tx3, 0, 2);
|
||||
tx8.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
|
||||
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
|
||||
CNodeValue val;
|
||||
|
||||
std::vector<uint256> blocks_to_invalidate;
|
||||
|
@ -928,6 +972,58 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
|
|||
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
|
||||
BOOST_CHECK(val.txhash == tx3.GetHash());
|
||||
|
||||
// Test having two updates to a claim in the same transaction
|
||||
|
||||
// Add both txouts (tx8 spends tx3)
|
||||
|
||||
AddToMempool(tx8);
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
// ensure txout 0 made it into the trie and txout 1 did not
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
|
||||
BOOST_CHECK(val.txhash == tx8.GetHash() && val.nOut == 0);
|
||||
|
||||
// roll forward until tx8 output 1 gets into the trie
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 1; i < 100; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, insert_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
// ensure txout 1 made it into the trie and is now in control
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName1, val));
|
||||
BOOST_CHECK(val.txhash == tx8.GetHash() && val.nOut == 1);
|
||||
|
||||
// roll back to before tx8
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// roll all the way back
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
|
@ -1308,6 +1404,15 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
|||
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1Hash << CScriptNum(0) << OP_2DROP << OP_2DROP << OP_TRUE;
|
||||
tx3.vout[0].nValue = 500000000;
|
||||
|
||||
CMutableTransaction tx4 = BuildTransaction(tx1);
|
||||
tx4.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
||||
|
||||
CMutableTransaction tx5 = BuildTransaction(tx2);
|
||||
tx5.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
||||
|
||||
CMutableTransaction tx6 = BuildTransaction(tx3);
|
||||
tx6.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
||||
|
||||
CNodeValue val;
|
||||
std::vector<uint256> blocks_to_invalidate;
|
||||
|
||||
|
@ -1332,6 +1437,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
|||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(pcoinsTip->HaveCoins(tx1.GetHash()));
|
||||
|
@ -1429,6 +1535,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
|||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->supportEmpty());
|
||||
|
@ -1457,6 +1564,249 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
|||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx1.GetHash());
|
||||
|
||||
// spend tx3
|
||||
|
||||
AddToMempool(tx6);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
// verify tx2 gains control
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx2.GetHash());
|
||||
|
||||
// roll back to before tx3 is valid
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// advance until tx3 is valid
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(!pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx1.GetHash());
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
|
||||
// advance until tx2 is valid
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 121; i < 140; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx1.GetHash());
|
||||
|
||||
// spend tx3
|
||||
AddToMempool(tx6);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock);
|
||||
delete pblocktemplate;
|
||||
|
||||
// verify tx2 gains control
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx2.GetHash());
|
||||
|
||||
// undo spending tx3
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// verify tx1 has control again
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(!pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx1.GetHash());
|
||||
|
||||
// roll back to before tx2 is valid
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// spend tx3
|
||||
|
||||
AddToMempool(tx6);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
// Verify tx2 gains control
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx2.GetHash());
|
||||
|
||||
// roll back to before tx3 is valid
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// spend tx3
|
||||
|
||||
AddToMempool(tx6);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
|
||||
// advance until tx2 is valid
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 121; i < 140; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 1);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx2.GetHash());
|
||||
|
||||
// roll back to before tx3 is inserted
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// advance 20 blocks
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 20; i < 40; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
// Put tx2 into the blockchain
|
||||
|
||||
AddToMempool(tx2);
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate->block.vtx.size() == 2);
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(pcoinsTip->HaveCoins(tx2.GetHash()));
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
// advance until tx1 is valid
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 41; i < 100; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportEmpty());
|
||||
BOOST_CHECK(pclaimTrie->supportQueueEmpty());
|
||||
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx1.GetHash());
|
||||
|
||||
// advance until tx2 is valid
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
for (unsigned int i = 101; i < 140; ++i)
|
||||
{
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
}
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(!pclaimTrie->queueEmpty());
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
|
||||
pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash();
|
||||
BOOST_CHECK(CreateBlock(pblocktemplate, pnp, support_nonces[block_counter++]));
|
||||
delete pblocktemplate;
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK(pclaimTrie->queueEmpty());
|
||||
BOOST_CHECK(pclaimTrie->getInfoForName(sName, val));
|
||||
BOOST_CHECK(val.txhash == tx2.GetHash());
|
||||
|
||||
// roll all the way back
|
||||
|
||||
BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back()));
|
||||
blocks_to_invalidate.pop_back();
|
||||
|
||||
// Test 2: create 1 LBC claim (tx1), create 5 LBC claim (tx2), create 5 LBC support (tx3)
|
||||
// Verify that tx1 loses control when tx2 becomes valid, and then tx1 gains control when tx3 becomes valid
|
||||
|
||||
|
@ -1477,6 +1827,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
|
|||
|
||||
// Test 8: create 1 LBC claim (tx1), create 5 LBC support (tx3), wait till tx1 valid, spend tx1, wait till tx3 valid
|
||||
// Verify name trie is empty
|
||||
//noncePrinter.printNonces();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(claimtrienode_serialize_unserialize)
|
||||
|
|
Loading…
Reference in a new issue