diff options
author | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-03 22:07:58 +0000 |
---|---|---|
committer | Antonio Juarez <antonio.maria.juarez@live.com> | 2014-03-03 22:07:58 +0000 |
commit | 296ae46ed8f8f6e5f986f978febad302e3df231a (patch) | |
tree | 1629164454a239308f33c9e12afb22e7f3cd8eeb /tests/difficulty | |
parent | changed name (diff) | |
download | monero-296ae46ed8f8f6e5f986f978febad302e3df231a.tar.xz |
moved all stuff to github
Diffstat (limited to 'tests/difficulty')
-rw-r--r-- | tests/difficulty/data.txt | 1000 | ||||
-rw-r--r-- | tests/difficulty/difficulty.cpp | 55 | ||||
-rwxr-xr-x | tests/difficulty/generate-data | 52 |
3 files changed, 1107 insertions, 0 deletions
diff --git a/tests/difficulty/data.txt b/tests/difficulty/data.txt new file mode 100644 index 000000000..17c48025e --- /dev/null +++ b/tests/difficulty/data.txt @@ -0,0 +1,1000 @@ +996 1 +985 1 +978 11 +1001 80 +1040 480 +1196 1108 +1109 925 +1241 1434 +1243 1843 +986 2664 +920 3870 +2213 4613 +2472 1581 +2592 1439 +2712 1439 +3056 1439 +3392 1289 +3723 1176 +3937 1088 +4219 1054 +4447 1002 +4681 971 +4702 942 +4683 967 +4942 997 +4958 968 +5126 993 +5188 981 +5322 995 +5545 991 +5531 969 +5792 994 +5831 969 +6020 985 +5943 971 +6179 994 +6409 987 +6587 967 +6736 957 +7027 952 +7293 926 +7494 905 +7747 893 +7805 876 +7911 884 +7923 886 +7996 899 +8149 905 +8101 901 +8258 916 +8395 918 +8295 915 +8430 930 +8719 941 +8698 920 +8819 934 +8788 937 +8804 951 +8797 966 +8857 980 +8848 990 +8981 1005 +8896 1005 +9012 1020 +9104 1031 +9295 1035 +9312 1026 +9432 1038 +9731 1038 +9991 1017 +10291 1002 +10510 982 +10607 972 +10563 975 +10669 987 +10567 993 +10813 1005 +11075 1002 +11045 988 +11253 1000 +11321 994 +11492 999 +11721 995 +11839 984 +11855 985 +12017 994 +12104 990 +12062 993 +12162 1004 +12075 1009 +12211 1020 +12345 1027 +12257 1025 +12155 1036 +12326 1047 +12620 1058 +12772 1044 +12993 1041 +13173 1032 +13081 1027 +13079 1037 +13082 1048 +13072 1058 +13078 1068 +13069 1079 +13060 1089 +13056 1100 +13057 1111 +13062 1122 +13056 1133 +13060 1144 +13052 1155 +13057 1166 +13049 1178 +13041 1189 +13042 1201 +13036 1213 +13041 1224 +13036 1236 +13034 1249 +13031 1261 +13029 1273 +13025 1286 +13030 1298 +13020 1311 +13026 1324 +13021 1337 +13028 1350 +13038 1363 +13037 1376 +13026 1390 +13024 1403 +13014 1417 +13011 1431 +13011 1445 +13004 1459 +13000 1474 +12992 1488 +13000 1503 +13003 1517 +13004 1532 +12995 1547 +12987 1562 +12983 1578 +12992 1593 +12993 1609 +12983 1624 +12973 1640 +12967 1656 +12961 1673 +12960 1689 +12963 1705 +12971 1722 +12968 1739 +12973 1756 +12968 1773 +12965 1791 +12966 1808 +12958 1826 +12949 1844 +12957 1862 +12947 1880 +12957 1898 +12958 1917 +12967 1936 +12975 1955 +12973 1974 +12965 1993 +12974 2013 +12975 2033 +12979 2052 +12978 2073 +12968 2093 +12965 2113 +12975 2134 +12966 2155 +12962 2176 +12955 2197 +12960 2219 +12969 2241 +12965 2263 +12973 2285 +12962 2307 +12956 2330 +12947 2352 +12948 2376 +12944 2399 +12950 2422 +12949 2446 +12942 2470 +12942 2494 +12945 2519 +12934 2543 +12932 2568 +12932 2593 +12939 2619 +12940 2644 +12931 2670 +12930 2696 +12922 2723 +12920 2749 +12925 2776 +12916 2804 +12922 2831 +12923 2859 +12922 2887 +12924 2915 +12927 2944 +12932 2972 +12925 3001 +12924 3031 +12933 3061 +12942 3091 +12934 3121 +12925 3151 +12930 3182 +12927 3213 +12935 3245 +12931 3277 +12938 3309 +12931 3341 +12933 3374 +12940 3407 +12935 3440 +12944 3474 +12943 3508 +12954 3542 +12952 3577 +12956 3612 +12959 3647 +12968 3683 +12975 3719 +12976 3756 +12979 3792 +12988 3830 +12993 3867 +12986 3905 +12979 3943 +12980 3982 +12974 4021 +12972 4060 +12978 4100 +12980 4140 +12989 4181 +12997 4222 +12988 4263 +12996 4305 +13001 4347 +12998 4389 +12996 4432 +13001 4476 +12995 4520 +12991 4564 +12984 4609 +12993 4654 +12991 4699 +12983 4745 +12987 4792 +12978 4839 +12982 4886 +12973 4934 +12964 4982 +12961 5031 +12970 5080 +12981 5130 +12974 5180 +12972 5231 +12962 5282 +12970 5334 +12969 5386 +12973 5439 +12971 5492 +12964 5546 +12975 5600 +12985 5655 +12977 5711 +12971 5767 +12964 5823 +12974 5880 +12982 5938 +12991 5996 +12993 6055 +13002 6114 +12991 6174 +12988 6234 +12987 6295 +12995 6357 +12986 6419 +12993 6482 +13000 6545 +13005 6610 +13002 6674 +12997 6740 +12998 6806 +12999 6872 +13009 6940 +13004 7008 +13006 7076 +12996 7146 +13002 7216 +13014 7286 +13026 7358 +13024 7430 +13029 7502 +13033 7576 +13037 7650 +13045 7725 +13047 7801 +13058 7877 +13058 7954 +13062 8032 +13052 8111 +13049 8190 +13056 8270 +13057 8351 +13047 8433 +13039 8516 +13031 8599 +13038 8683 +13029 8768 +13019 8854 +13010 8941 +13005 9029 +12995 9117 +12988 9206 +12999 9296 +12998 9387 +12991 9479 +12997 9572 +13002 9666 +12993 9761 +13004 9856 +13005 9953 +13013 10050 +13006 10149 +13000 10248 +12995 10348 +12996 10450 +12996 10552 +12995 10655 +12998 10760 +12993 10865 +12998 10972 +12989 11079 +12998 11188 +12991 11297 +13003 11408 +13008 11519 +12997 11632 +13005 11746 +13009 11861 +13009 11977 +13005 12095 +13000 12213 +12998 12333 +12993 12454 +12986 12575 +12994 12699 +12996 12823 +13004 12949 +13008 13075 +13008 13203 +13007 13333 +13002 13463 +13013 13595 +13013 13728 +13009 13863 +13023 13999 +13027 14136 +13027 14274 +13028 14414 +13025 14555 +13015 14698 +13020 14842 +13020 14987 +13023 15134 +13013 15282 +13023 15432 +13023 15583 +13037 15735 +13048 15889 +13061 16045 +13050 16202 +13063 16361 +13061 16521 +13049 16683 +13059 16846 +13059 17011 +13060 17178 +13075 17346 +13071 17516 +13073 17687 +13082 17861 +13091 18036 +13083 18212 +13090 18391 +13078 18571 +13084 18753 +13092 18936 +13085 19122 +13077 19309 +13067 19498 +13078 19689 +13093 19882 +13090 20077 +13094 20273 +13098 20472 +13114 20672 +13108 20875 +13117 21079 +13112 21286 +13102 21494 +13109 21705 +13122 21917 +13121 22132 +13129 22348 +13122 22567 +13115 22788 +13113 23012 +13121 23237 +13114 23464 +13103 23694 +13093 23926 +13098 24161 +13099 24397 +13092 24636 +13102 24877 +13104 25121 +13092 25367 +13103 25616 +13099 25866 +13089 26120 +13093 26376 +13101 26634 +13113 26895 +13121 27158 +13128 27424 +13138 27693 +13140 27964 +13157 28238 +13157 28514 +13144 28794 +13155 29076 +13156 29360 +13173 29648 +13163 29938 +13180 30231 +13188 30510 +13191 30789 +13177 31082 +13174 31386 +13164 31693 +13168 32003 +13173 32316 +13167 32632 +13177 32951 +13188 33273 +13201 33599 +13209 33900 +13220 34209 +13211 34512 +13208 34848 +13194 35188 +13181 35532 +13198 35878 +13192 36228 +13201 36582 +13208 36939 +13197 37299 +13197 37663 +13196 38030 +13208 38401 +13215 38776 +13226 39154 +13215 39517 +13231 39902 +13244 40275 +13254 40625 +13253 40987 +13241 41386 +13241 41789 +13235 42195 +13237 42606 +13239 43020 +13243 43439 +13233 43861 +13241 44288 +13231 44719 +13252 45154 +13263 45593 +13251 46003 +13261 46451 +13277 46902 +13290 47305 +13280 47714 +13291 48177 +13293 48640 +13284 49104 +13278 49580 +13281 50061 +13277 50547 +13284 51037 +13294 51532 +13286 52027 +13285 52532 +13292 53041 +13283 53556 +13291 54075 +13281 54600 +13278 55129 +13267 55664 +13269 56203 +13279 56749 +13269 57299 +13270 57855 +13278 58416 +13283 58982 +13282 59554 +13278 60132 +13272 60715 +13275 61304 +13278 61898 +13286 62498 +13285 63104 +13291 63716 +13295 64334 +13305 64953 +13311 65530 +13310 66133 +13314 66773 +13323 67404 +13316 68007 +13324 68665 +13322 69323 +13330 69994 +13322 70637 +13315 71320 +13322 72010 +13332 72706 +13333 73397 +13337 74101 +13337 74793 +13339 75516 +13340 76234 +13347 76964 +13351 77664 +13353 78389 +13349 79132 +13357 79896 +13347 80641 +13347 81420 +13336 82205 +13330 82998 +13325 83799 +13324 84608 +13315 85424 +13316 86248 +13325 87080 +13321 87921 +13327 88769 +13320 89625 +13313 90490 +13322 91363 +13327 92245 +13318 93135 +13313 94033 +13304 94941 +13298 95857 +13301 96782 +13294 97716 +13284 98658 +13291 99610 +13287 100571 +13296 101542 +13296 102521 +13299 103511 +13303 104509 +13312 105518 +13313 106536 +13315 107564 +13307 108602 +13299 109649 +13289 110707 +13297 111776 +13289 112854 +13295 113943 +13304 115042 +13296 116152 +13296 117273 +13301 118405 +13292 119547 +13301 120701 +13305 121865 +13294 123041 +13301 124228 +13308 125427 +13315 126637 +13309 127859 +13316 129092 +13322 130338 +13324 131596 +13330 133488 +13328 133531 +13328 134902 +13335 134923 +13334 136229 +13328 136252 +13328 137668 +13330 137690 +13336 139046 +13328 139046 +13317 140806 +13324 140806 +13316 142922 +13317 143004 +13326 145371 +13330 145383 +13332 147263 +13332 147287 +13327 148653 +13324 148653 +13323 163065 +13314 163080 +13323 168505 +13322 168505 +13327 171944 +13331 171960 +13336 175501 +13343 175501 +13336 183009 +13341 183009 +13334 190931 +13338 190931 +13337 199306 +13329 199306 +13333 205710 +13338 205710 +13335 213997 +13330 213997 +13329 221480 +13322 221505 +13326 229542 +13325 229542 +13324 231843 +13331 231870 +13329 234634 +13326 234634 +13332 243740 +13339 243769 +13328 246606 +13332 246635 +13325 254183 +13332 254183 +13335 258637 +13325 258637 +13330 265577 +13321 265611 +13315 275411 +13319 275411 +13309 278711 +13303 278711 +13313 290738 +13310 290738 +13305 295289 +13294 295289 +13293 302850 +13288 302850 +13285 309294 +13280 309336 +13288 319541 +13295 319541 +13304 333707 +13309 333755 +13301 346209 +13293 346209 +13301 357909 +13304 357909 +13310 378490 +13309 378490 +13310 399550 +13302 399550 +13313 417848 +13313 417848 +13324 441697 +13315 441697 +13319 451301 +13311 451382 +13317 465329 +13314 465329 +13318 471489 +13322 471489 +13313 483202 +13311 483293 +13300 498367 +13302 498367 +13296 508613 +13290 508613 +13280 525295 +13278 525295 +13280 535015 +13288 535015 +13288 551838 +13285 551838 +13292 561986 +13303 562101 +13300 601209 +13290 601209 +13293 610660 +13292 610660 +13296 626756 +13297 626756 +13294 635012 +13305 635152 +13299 643158 +13299 643158 +13300 652606 +13304 652606 +13296 664186 +13287 664335 +13296 673132 +13301 673132 +13301 673132 +13310 673132 +13307 673132 +13303 673132 +13302 673132 +13296 673132 +13293 673132 +13305 673132 +13294 673132 +13297 673132 +13288 673132 +13294 673132 +13296 673132 +13304 673132 +13297 673132 +13306 686583 +13296 708022 +13302 721171 +13301 745255 +13293 789338 +13288 801708 +13294 835723 +13295 915543 +13291 998038 +13298 1109322 +13302 1209204 +13312 1246864 +13314 1263152 +13320 1296983 +13325 1342856 +13324 1436884 +13320 1601878 +13325 1643370 +13324 1806409 +13334 1891570 +13330 2094126 +13319 2424286 +13319 2650457 +13325 2715282 +13311 3092010 +13318 3244961 +13306 3321946 +13321 3446480 +13328 3644333 +13334 3714812 +13328 3928889 +13313 4152287 +13324 4497011 +13324 4645094 +13325 6541658 +13339 8449869 +13337 11545575 +13316 11814280 +13302 12028489 +13324 12187097 +13349 12345701 +13354 12540339 +13396 12735943 +13396 12903378 +13425 13103440 +13461 13283023 +13509 13429115 +13499 13679122 +13521 13861980 +13523 14155832 +13530 14344931 +13518 14573230 +13511 14765343 +13547 14959879 +13528 15192777 +13579 15390669 +13611 15588557 +13644 15789960 +13676 15991403 +13708 16236622 +13753 16441249 +13812 16688228 +13787 16893368 +13812 17230031 +13793 17481566 +13811 17688803 +13792 17896037 +13830 18196823 +13819 18357684 +13834 18565439 +13870 18821700 +13859 19079284 +13897 19288103 +13883 19547559 +13908 19860081 +13963 20070522 +14012 20285173 +14080 20560219 +14140 20732016 +14148 21019918 +14162 21379326 +14150 21746458 +14130 22069652 +14183 22420034 +14219 22677730 +14213 23091563 +14260 23414683 +14276 23874363 +14274 24276963 +14318 24756195 +14390 25185364 +14462 25644616 +14544 26226598 +14557 26681976 +14554 27332346 +14521 27938692 +14602 28610024 +14588 29308918 +14613 30156474 +14580 31024769 +14543 32013610 +14577 32963488 +14676 34023072 +14675 35029231 +14691 36188609 +14767 37370414 +14885 38518184 +14878 39730624 +14974 40937806 +15008 41959660 +15009 43997972 +15039 46631045 +15039 49969426 +15147 53632107 +15180 57066286 +15368 60514005 +15379 64138256 +15356 67460179 +15403 64918929 +15560 68486057 +15590 67591981 +15580 65909365 +15514 64245787 +15641 66071664 +15587 68860387 +15537 71048137 +15710 73745734 +15627 76599571 +15618 79052834 +15739 81934490 +15985 82669438 +15981 81374711 +16103 80244245 +16349 79139295 +16328 78279627 +16544 77533151 +16615 75616132 +16616 74926817 +16593 76917472 +16584 79312606 +16665 80101567 +16634 82504177 +16867 85030276 +16971 86883326 +16895 88319800 +16965 90469139 +16950 90465262 +16877 91890415 +17117 93106091 +17238 94321256 +17441 95846287 +17491 92979967 +17446 90954994 +17394 87623370 +17542 85999264 +17681 87412539 +17819 88988409 +17725 91038329 +17943 92336744 +17991 93029082 +18031 92973033 +17970 94737578 +18141 93980118 +18320 95237016 +18545 97391127 +18712 96561416 +18849 93797276 +19074 91336444 +19161 89892725 +19148 90669712 +19232 92693040 +19181 94222209 +19254 96265222 +19423 97254840 +19535 99319736 +19760 101190729 +19980 102676323 +20185 104459744 +20111 103054687 +20358 105521248 +20374 107126438 +20374 105088747 +20372 101446709 +20283 103568593 +20594 101467587 +20811 102246714 +20967 104790689 +21208 106029191 +21371 108934133 +21676 106529418 +21593 108090230 +21829 103189197 +22124 105891192 +22244 108822755 +22548 110958877 +22829 109385192 +23059 111573148 +23240 113687895 +23411 115823707 +23340 118555853 +23628 121634310 +23764 123624077 +24150 126599053 +24048 129441066 +23992 129644548 +24056 131850076 +23959 124550087 +24027 127640855 +24241 125937704 +24583 120297009 +24504 122340050 +24487 118247531 +24522 119488591 +24540 121684801 +24460 123559998 +24412 126151243 +24638 128166276 +24577 129779407 +24541 125648210 +24616 128007653 +24872 130198716 +24743 131132412 +24629 133370101 +24483 135940710 +24513 133837081 +24476 132688318 +24687 130598203 +25045 131756130 +25247 134089716 +25356 135086151 +25531 135840432 +25757 134049326 +25820 135059817 +25838 134720446 +25847 133583240 +25722 135102319 +25599 136767738 +25942 137938928 +25959 137181584 +26362 134741089 +26356 131382998 +26249 129571190 +26193 128461060 +26203 125528898 +26296 125772324 +26356 127272308 +26510 128659463 +26803 129420466 +26965 130811709 +27050 129187186 +27343 128796859 +27408 126306858 +27344 124109316 +27400 123585673 +27354 124051058 +27479 124120333 +27752 124602137 +27936 126110194 +28045 127727168 +28334 129412894 +28508 127266450 +28641 125300988 +28748 124441135 +29000 122351487 diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp new file mode 100644 index 000000000..85c469391 --- /dev/null +++ b/tests/difficulty/difficulty.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <cstddef> +#include <cstdint> +#include <fstream> +#include <iostream> +#include <vector> + +#include "cryptonote_config.h" +#include "cryptonote_core/difficulty.h" + +using namespace std; + +#define DEFAULT_TEST_DIFFICULTY_TARGET 120 + +int main(int argc, char *argv[]) { + if (argc != 2) { + cerr << "Wrong arguments" << endl; + return 1; + } + vector<uint64_t> timestamps, cumulative_difficulties; + fstream data(argv[1], fstream::in); + data.exceptions(fstream::badbit); + data.clear(data.rdstate()); + uint64_t timestamp, difficulty, cumulative_difficulty = 0; + size_t n = 0; + while (data >> timestamp >> difficulty) { + size_t begin, end; + if (n < DIFFICULTY_WINDOW + DIFFICULTY_LAG) { + begin = 0; + end = min(n, (size_t) DIFFICULTY_WINDOW); + } else { + end = n - DIFFICULTY_LAG; + begin = end - DIFFICULTY_WINDOW; + } + uint64_t res = cryptonote::next_difficulty( + vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end), + vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET); + if (res != difficulty) { + cerr << "Wrong difficulty for block " << n << endl + << "Expected: " << difficulty << endl + << "Found: " << res << endl; + return 1; + } + timestamps.push_back(timestamp); + cumulative_difficulties.push_back(cumulative_difficulty += difficulty); + ++n; + } + if (!data.eof()) { + data.clear(fstream::badbit); + } + return 0; +} diff --git a/tests/difficulty/generate-data b/tests/difficulty/generate-data new file mode 100755 index 000000000..77d384bbc --- /dev/null +++ b/tests/difficulty/generate-data @@ -0,0 +1,52 @@ +#!/usr/bin/python3 + +from random import randint + +DIFFICULTY_TARGET = 120 +DIFFICULTY_WINDOW = 720 +DIFFICULTY_LAG = 15 +DIFFICULTY_CUT = 60 + +UINT_MAX = (1 << 64) - 1 + +def difficulty(): + times = [] + diffs = [] + while True: + if len(times) <= 1: + diff = 1 + else: + begin = max(len(times) - DIFFICULTY_WINDOW - DIFFICULTY_LAG, 0) + end = min(begin + DIFFICULTY_WINDOW, len(times)) + length = end - begin + assert length >= 2 + if length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT: + cut_begin = 0 + cut_end = length + else: + excess = length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT) + cut_begin = (excess + 1) // 2 + cut_end = length - excess // 2 + assert cut_begin + 2 <= cut_end + wnd = times[begin:end] + wnd.sort() + dtime = wnd[cut_end - 1] - wnd[cut_begin] + assert 0 <= dtime <= UINT_MAX + dtime = max(dtime, 1) + ddiff = sum(diffs[begin + cut_begin + 1:begin + cut_end]) + assert 0 < ddiff <= UINT_MAX + assert dtime <= ddiff * DIFFICULTY_TARGET + dtime - 1 <= UINT_MAX + diff = (ddiff * DIFFICULTY_TARGET + dtime - 1) // dtime + assert 0 < diff <= UINT_MAX + times.append((yield diff)) + diffs.append(diff) + +time = 1000 +gen = difficulty() +diff = next(gen) +for i in range(1000): + power = 10 if i < 100 else 10000 if i < 500 else 1000000 + time += randint(-diff // power - 10, 3 * diff // power + 10) + assert 0 <= time <= UINT_MAX + print(time, diff) + diff = gen.send(time)
\ No newline at end of file |