50{
52
54
55 std::string default_db_type = "lmdb";
56
58 available_dbs = "available: " + available_dbs;
59
63
65
66 boost::filesystem::path output_file_path;
67
68 po::options_description desc_cmd_only("Command line options");
69 po::options_description desc_cmd_sett("Command line options and settings options");
72 "database", available_dbs.c_str(), default_db_type
73 };
80
93
94 po::options_description desc_options("Allowed options");
95 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
96
97 po::variables_map vm;
99 {
100 auto parser = po::command_line_parser(argc, argv).options(desc_options);
101 po::store(parser.run(), vm);
102 po::notify(vm);
103 return true;
104 });
105 if (! r)
106 return 1;
107
109 {
111 std::cout << desc_options << std::endl;
112 return 1;
113 }
114
118 else
119 mlog_set_log(std::string(std::to_string(log_level) +
",bcutil:INFO").c_str());
120
122
133
136 {
137 std::cerr << "Invalid database type: " << db_type << std::endl;
138 return 1;
139 }
140
141 LOG_PRINT_L0(
"Initializing source blockchain (BlockchainDB)");
142 std::unique_ptr<Blockchain> core_storage;
144 core_storage.reset(
new Blockchain(m_mempool));
146 if (db == NULL)
147 {
148 LOG_ERROR(
"Attempted to use non-existent database type: " << db_type);
149 throw std::runtime_error("Attempting to use non-existent database type");
150 }
152
153 const std::string filename = (boost::filesystem::path(opt_data_dir) / db->
get_db_name()).
string();
154 LOG_PRINT_L0(
"Loading blockchain from folder " << filename <<
" ...");
155
156 try
157 {
159 }
160 catch (const std::exception& e)
161 {
163 return 1;
164 }
165 r = core_storage->init(db, net_type);
166
168 LOG_PRINT_L0(
"Source blockchain storage initialized OK");
169
171 stop_requested = true;
172 });
173
175 if (!block_stop)
176 block_stop = db_height;
177 MINFO(
"Starting from height " << block_start <<
", stopping at height " << block_stop);
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 std::cout <<
ENDL <<
"# DATA" <<
ENDL;
197 std::cout << "Date\tBlocks/day\tBlocks\tTxs/Day\tTxs\tBytes/Day\tBytes";
198 if (do_inputs)
199 std::cout << "\tInMin\tInMax\tInAvg";
200 if (do_outputs)
201 std::cout << "\tOutMin\tOutMax\tOutAvg";
202 if (do_ringsize)
203 std::cout << "\tRingMin\tRingMax\tRingAvg";
204 if (do_hours) {
206 unsigned int i;
207 for (i=0; i<24; i++) {
208 sprintf(
buf,
"\t%02u:00", i);
210 }
211 }
213
214 struct tm prevtm = {0}, currtm;
218 uint64_t totins = 0, totouts = 0, totrings = 0;
221 uint32_t minrings = 50, maxrings = 0;
224 unsigned int i;
225
226 for (
uint64_t h = block_start; h < block_stop; ++h)
227 {
231 {
233 return 1;
234 }
236 char timebuf[64];
238 if (!prevtm.tm_year)
239 prevtm = currtm;
240
241 if (currtm.tm_mday > prevtm.tm_mday || (currtm.tm_mday == 1 && prevtm.tm_mday > 27))
242 {
243
244 if (prevtm.tm_mday == 1 && currtm.tm_mday > 27)
245 goto skip;
246 strftime(timebuf, sizeof(timebuf), "%Y-%m-%d", &prevtm);
247 prevtm = currtm;
248 std::cout << timebuf << "\t" << currblks << "\t" << h << "\t" << currtxs << "\t" << prevtxs + currtxs << "\t" << currsz << "\t" << prevsz + currsz;
249 prevsz += currsz;
250 currsz = 0;
251 currblks = 0;
252 prevtxs += currtxs;
253 currtxs = 0;
254 if (!tottxs)
255 tottxs = 1;
256 if (do_inputs) {
257 std::cout << "\t" << (maxins ? minins : 0) << "\t" << maxins << "\t" << totins / tottxs;
258 minins = 10; maxins = 0; totins = 0;
259 }
260 if (do_outputs) {
261 std::cout << "\t" << (maxouts ? minouts : 0) << "\t" << maxouts << "\t" << totouts / tottxs;
262 minouts = 10; maxouts = 0; totouts = 0;
263 }
264 if (do_ringsize) {
265 std::cout << "\t" << (maxrings ? minrings : 0) << "\t" << maxrings << "\t" << totrings / tottxs;
266 minrings = 50; maxrings = 0; totrings = 0;
267 }
268 tottxs = 0;
269 if (do_hours) {
270 for (i=0; i<24; i++) {
271 std::cout << "\t" << txhr[i];
272 txhr[i] = 0;
273 }
274 }
276 }
277skip:
278 currsz += bd.size();
280 {
281 if (tx_id == crypto::null_hash)
282 {
283 throw std::runtime_error("Aborting: tx == null_hash");
284 }
286 {
287 throw std::runtime_error("Aborting: tx not found");
288 }
291 {
293 return 1;
294 }
295 currsz += bd.size();
296 currtxs++;
297 if (do_hours)
298 txhr[currtm.tm_hour]++;
299 if (do_inputs) {
301 if (io < minins)
302 minins = io;
303 else if (io > maxins)
304 maxins = io;
305 totins += io;
306 }
307 if (do_ringsize) {
309 = boost::get<cryptonote::txin_to_key>(tx.
vin[0]);
311 if (io < minrings)
312 minrings = io;
313 else if (io > maxrings)
314 maxrings = io;
315 totrings += io;
316 }
317 if (do_outputs) {
319 if (io < minouts)
320 minouts = io;
321 else if (io > maxouts)
322 maxouts = io;
323 totouts += io;
324 }
325 tottxs++;
326 }
327 currblks++;
328
329 if (stop_requested)
330 break;
331 }
332
333 core_storage->deinit();
334 return 0;
335
337}
The BlockchainDB backing store interface declaration/contract.
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t &height) const =0
fetch a block blob by height
virtual bool get_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the transaction blob with the given hash
virtual uint64_t height() const =0
fetch the current blockchain height
virtual std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
std::vector< txin_v > vin
std::vector< tx_out > vout
Transaction pool, handles transactions which are not part of a block.
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
#define CATCH_ENTRY(location, return_val)
std::string mlog_get_default_log_path(const char *default_filename)
void mlog_set_log(const char *log)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
const arg_descriptor< bool > arg_help
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
const command_line::arg_descriptor< bool, false > arg_testnet_on
BlockchainDB * new_db(const std::string &db_type)
bool blockchain_valid_db_type(const std::string &db_type)
const command_line::arg_descriptor< bool, false > arg_stagenet_on
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
std::string blockchain_db_types(const std::string &sep)
const command_line::arg_descriptor< std::string > arg_log_level
bool get_gmt_time(time_t t, struct tm &tm)
unsigned __int64 uint64_t
std::vector< crypto::hash > tx_hashes
std::vector< uint64_t > key_offsets
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL