36 #include "blockchain_db/testdb.h" 38 #define LONG_TERM_BLOCK_WEIGHT_WINDOW 5000 50 class TestDB:
public cryptonote::BaseTestDB
60 TestDB() { m_open =
true; }
70 blocks.push_back({block_weight, long_term_block_weight});
73 virtual size_t get_block_weight(
const uint64_t &h)
const override {
return blocks[h].weight; }
74 virtual uint64_t get_block_long_term_weight(
const uint64_t &h)
const override {
return blocks[h].long_term_weight; }
75 virtual std::vector<uint64_t> get_block_weights(
uint64_t start_height,
size_t count)
const override {
76 std::vector<uint64_t> ret;
78 while (
count-- && start_height <
blocks.size()) ret.push_back(
blocks[start_height++].weight);
81 virtual std::vector<uint64_t> get_long_term_block_weights(
uint64_t start_height,
size_t count)
const override {
82 std::vector<uint64_t> ret;
84 while (
count-- && start_height <
blocks.size()) ret.push_back(
blocks[start_height++].long_term_weight);
98 *block_height = h - 1;
101 virtual void pop_block(
cryptonote::block &blk, std::vector<cryptonote::transaction> &txs)
override {
blocks.pop_back(); }
106 std::vector<block_t>
blocks;
107 std::vector<uint8_t> hf;
112 #define PREFIX_WINDOW(hf_version,window) \ 113 std::unique_ptr<cryptonote::Blockchain> bc; \ 114 cryptonote::tx_memory_pool txpool(*bc); \ 115 bc.reset(new cryptonote::Blockchain(txpool)); \ 116 struct get_test_options { \ 117 const std::pair<uint8_t, uint64_t> hard_forks[3]; \ 118 const cryptonote::test_options test_options = { \ 122 get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)LONG_TERM_BLOCK_WEIGHT_WINDOW), std::make_pair((uint8_t)0, (uint64_t)0)} {} \ 124 cryptonote::Blockchain *blockchain = bc.get(); \ 125 bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \ 128 fprintf(stderr, "Failed to init blockchain\n"); \ 132 #define PREFIX(hf_version) PREFIX_WINDOW(hf_version, LONG_TERM_BLOCK_WEIGHT_WINDOW) 138 lcg_seed = (lcg_seed * 0x100000001b3 + 0xcbf29ce484222325) & 0xffffffff;
151 bc->get_db().add_block(std::make_pair(b,
""), 300000, 300000, bc->get_db().height(), bc->get_db().height(), {});
152 if (!bc->update_next_cumulative_weight_limit())
154 fprintf(stderr,
"Failed to update cumulative weight limit 1\n");
162 uint64_t effective_block_weight_median = bc->get_current_cumulative_block_weight_median();
168 int64_t wi = 90 + r % 500000 + 250000 + sin(h / 200.) * 350000;
169 w = wi < 90 ? 90 : wi;
173 w = bc->get_current_cumulative_block_weight_limit();
181 uint64_t ltw = bc->get_next_long_term_block_weight(w);
185 bc->get_db().add_block(std::make_pair(
std::move(b),
""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
187 if (!bc->update_next_cumulative_weight_limit())
189 fprintf(stderr,
"Failed to update cumulative weight limit\n");
192 std::cout <<
"H " << h <<
", BW " << w <<
", EMBW " << effective_block_weight_median <<
", LTBW " << ltw << std::endl;
#define LONG_TERM_BLOCK_WEIGHT_WINDOW
#define PREFIX(hf_version)
#define HF_VERSION_LONG_TERM_BLOCK_WEIGHT
mdb_size_t count(MDB_cursor *cur)
unsigned __int64 uint64_t
version
Supported socks variants.
const T & move(const T &t)
boost::multiprecision::uint128_t difficulty_type
#define CATCH_ENTRY_L0(lacation, return_val)