48{
50
52
53 std::string default_db_type = "lmdb";
54
56 available_dbs = "available: " + available_dbs;
57
59
61
62 boost::filesystem::path output_file_path;
63
64 po::options_description desc_cmd_only("Command line options");
65 po::options_description desc_cmd_sett("Command line options and settings options");
68 "database", available_dbs.c_str(), default_db_type
69 };
73
83
84 po::options_description desc_options("Allowed options");
85 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
86
87 po::variables_map vm;
89 {
90 auto parser = po::command_line_parser(argc, argv).options(desc_options);
91 po::store(parser.run(), vm);
92 po::notify(vm);
93 return true;
94 });
95 if (! r)
96 return 1;
97
99 {
101 std::cout << desc_options << std::endl;
102 return 1;
103 }
104
108 else
109 mlog_set_log(std::string(std::to_string(log_level) +
",bcutil:INFO").c_str());
110
112
120
121 if (!opt_txid_string.empty() && opt_height)
122 {
123 std::cerr << "txid and height cannot be given at the same time" << std::endl;
124 return 1;
125 }
127 if (!opt_txid_string.empty())
128 {
130 {
131 std::cerr << "Invalid txid" << std::endl;
132 return 1;
133 }
134 }
135
138 {
139 std::cerr << "Invalid database type: " << db_type << std::endl;
140 return 1;
141 }
142
143
144
145
146
147
148
149
150
151
152
153
154 LOG_PRINT_L0(
"Initializing source blockchain (BlockchainDB)");
155 std::unique_ptr<Blockchain> core_storage;
157 core_storage.reset(
new Blockchain(m_mempool));
159 if (db == NULL)
160 {
161 LOG_ERROR(
"Attempted to use non-existent database type: " << db_type);
162 throw std::runtime_error("Attempting to use non-existent database type");
163 }
165
166 const std::string filename = (boost::filesystem::path(opt_data_dir) / db->
get_db_name()).
string();
167 LOG_PRINT_L0(
"Loading blockchain from folder " << filename <<
" ...");
168
169 try
170 {
172 }
173 catch (const std::exception& e)
174 {
176 return 1;
177 }
178 r = core_storage->init(db, net_type);
179
181 LOG_PRINT_L0(
"Source blockchain storage initialized OK");
182
183 std::vector<crypto::hash> start_txids;
184 if (!opt_txid_string.empty())
185 {
186 start_txids.push_back(opt_txid);
187 }
188 else
189 {
193 {
195 return 1;
196 }
198 start_txids.push_back(txid);
199 if (opt_include_coinbase)
201 }
202
203 if (start_txids.empty())
204 {
206 return 1;
207 }
208
209 std::vector<uint64_t> depths;
211 {
213 bool coinbase = false;
214
216 std::vector<crypto::hash> txids(1, start_txid);
217 while (!coinbase)
218 {
219 LOG_PRINT_L0(
"Considering "<< txids.size() <<
" transaction(s) at depth " << depth);
220 std::vector<crypto::hash> new_txids;
222 {
225 {
226 LOG_PRINT_L0(
"Failed to get txid " << txid <<
" from db");
227 return 1;
228 }
231 {
233 return 1;
234 }
235 for (
size_t ring = 0; ring < tx.
vin.size(); ++ring)
236 {
238 {
239 MDEBUG(txid <<
" is a coinbase transaction");
240 coinbase = true;
241 goto done;
242 }
244 {
248 for (
uint64_t offset: absolute_offsets)
249 {
255 {
257 return 1;
258 }
259
260 bool found = false;
262 {
264 {
265 const auto &txout = boost::get<cryptonote::txout_to_key>(b.
miner_tx.
vout[out].target);
266 if (txout.key == od.
pubkey)
267 {
268 found = true;
271 break;
272 }
273 }
274 else
275 {
277 return 1;
278 }
279 }
281 {
282 if (found)
283 break;
285 {
286 LOG_PRINT_L0(
"Failed to get txid " << block_txid <<
" from db");
287 return 1;
288 }
291 {
293 return 1;
294 }
295 for (
size_t out = 0;
out < tx2.
vout.size(); ++
out)
296 {
298 {
299 const auto &txout = boost::get<cryptonote::txout_to_key>(tx2.
vout[out].target);
300 if (txout.key == od.
pubkey)
301 {
302 found = true;
303 new_txids.push_back(block_txid);
304 MDEBUG(
"adding txid: " << block_txid);
305 break;
306 }
307 }
308 else
309 {
311 return 1;
312 }
313 }
314 }
315 if (!found)
316 {
317 LOG_PRINT_L0(
"Output originating transaction not found");
318 return 1;
319 }
320 }
321 }
322 else
323 {
325 return 1;
326 }
327 }
328 }
329 if (!coinbase)
330 {
331 std::swap(txids, new_txids);
332 ++depth;
333 }
334 }
335done:
336 LOG_PRINT_L0(
"Min depth for txid " << start_txid <<
": " << depth);
337 depths.push_back(depth);
338 }
339
342 cumulative_depth += depth;
343 LOG_PRINT_L0(
"Average min depth for " << start_txids.size() <<
" transaction(s): " << cumulative_depth/(
float)depths.size());
345
346 core_storage->deinit();
347 return 0;
348
350}
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 std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
virtual cryptonote::blobdata get_block_blob(const crypto::hash &h) const =0
fetches the block with the given hash
virtual bool get_pruned_tx_blob(const crypto::hash &h, cryptonote::blobdata &tx) const =0
fetches the pruned transaction blob with the given hash
virtual output_data_t get_output_key(const uint64_t &amount, const uint64_t &index, bool include_commitmemt=true) const =0
get some of an output's data
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
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
std::vector< uint64_t > relative_output_offsets_to_absolute(const std::vector< uint64_t > &off)
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)
crypto::hash get_transaction_hash(const transaction &t)
bool blockchain_valid_db_type(const std::string &db_type)
const command_line::arg_descriptor< bool, false > arg_stagenet_on
std::string blockchain_db_types(const std::string &sep)
bool parse_and_validate_tx_base_from_blob(const blobdata &tx_blob, transaction &tx)
const command_line::arg_descriptor< std::string > arg_log_level
type_vec_type median(std::vector< type_vec_type > &v)
unsigned __int64 uint64_t
std::vector< crypto::hash > tx_hashes
a struct containing output metadata
uint64_t height
the height of the block which created the output
crypto::public_key pubkey
the output's public key (for spend verification)
std::vector< uint64_t > key_offsets
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL