Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
blocklog Struct Reference

Public Member Functions

 blocklog ()
 
void read_log ()
 
void set_program_options (options_description &cli)
 
void initialize (const variables_map &options)
 
void do_vacuum ()
 

Public Attributes

bfs::path blocks_dir
 
bfs::path output_file
 
uint32_t first_block = 0
 
uint32_t last_block = std::numeric_limits<uint32_t>::max()
 
bool no_pretty_print = false
 
bool as_json_array = false
 
bool make_index = false
 
bool trim_log = false
 
bool smoke_test = false
 
bool vacuum = false
 
bool help = false
 
std::optional< block_log_prune_configblog_keep_prune_conf
 

Detailed Description

Definition at line 33 of file main.cpp.

Constructor & Destructor Documentation

◆ blocklog()

blocklog::blocklog ( )
inline

Definition at line 34 of file main.cpp.

35 {}

Member Function Documentation

◆ do_vacuum()

void blocklog::do_vacuum ( )

Definition at line 72 of file main.cpp.

72 {
73 SYS_ASSERT( blog_keep_prune_conf, block_log_exception, "blocks.log is not a pruned log; nothing to vacuum" );
74 block_log blocks(blocks_dir, std::optional<block_log_prune_config>()); //passing an unset block_log_prune_config turns off pruning this performs a vacuum
75 ilog("Successfully vacuumed block log");
76}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
#define ilog(FORMAT,...)
Definition logger.hpp:118
std::optional< block_log_prune_config > blog_keep_prune_conf
Definition main.cpp:54
bfs::path blocks_dir
Definition main.cpp:42
Here is the caller graph for this function:

◆ initialize()

void blocklog::initialize ( const variables_map & options)

Definition at line 205 of file main.cpp.

205 {
206 try {
207 auto bld = options.at( "blocks-dir" ).as<bfs::path>();
208 if( bld.is_relative())
209 blocks_dir = bfs::current_path() / bld;
210 else
211 blocks_dir = bld;
212
213 if (options.count( "output-file" )) {
214 bld = options.at( "output-file" ).as<bfs::path>();
215 if( bld.is_relative())
216 output_file = bfs::current_path() / bld;
217 else
218 output_file = bld;
219 }
220
221 //if the log is pruned, keep it that way by passing in a config with a large block pruning value. There is otherwise no
222 // way to tell block_log "keep the current non/pruneness of the log"
224 blog_keep_prune_conf.emplace();
225 blog_keep_prune_conf->prune_blocks = UINT32_MAX;
226 }
228
229}
static bool is_pruned_log(const fc::path &data_dir)
#define FC_LOG_AND_RETHROW()
#define UINT32_MAX
Definition stdint.h:188
bfs::path output_file
Definition main.cpp:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_log()

void blocklog::read_log ( )

Definition at line 78 of file main.cpp.

78 {
79 report_time rt("reading log");
81 const auto end = block_logger.read_head();
82 SYS_ASSERT( end, block_log_exception, "No blocks found in block log" );
83 SYS_ASSERT( end->block_num() > 1, block_log_exception, "Only one block found in block log" );
84
85 //fix message below, first block might not be 1, first_block_num is not set yet
86 ilog( "existing block log contains block num ${first} through block num ${n}",
87 ("first",block_logger.first_block_num())("n",end->block_num()) );
88 if (first_block < block_logger.first_block_num()) {
89 first_block = block_logger.first_block_num();
90 }
91
92 sysio::chain::branch_type fork_db_branch;
93 if( fc::exists( blocks_dir / config::reversible_blocks_dir_name / config::forkdb_filename ) ) {
94 ilog( "opening fork_db" );
95 fork_database fork_db( blocks_dir / config::reversible_blocks_dir_name );
96
97 fork_db.open( []( block_timestamp_type timestamp,
98 const flat_set<digest_type>& cur_features,
99 const vector<digest_type>& new_features ) {}
100 );
101
102 fork_db_branch = fork_db.fetch_branch( fork_db.head()->id );
103 if( fork_db_branch.empty() ) {
104 elog( "no blocks available in reversible block database: only block_log blocks are available" );
105 } else {
106 auto first = fork_db_branch.rbegin();
107 auto last = fork_db_branch.rend() - 1;
108 ilog( "existing reversible fork_db block num ${first} through block num ${last} ",
109 ("first", (*first)->block_num)( "last", (*last)->block_num ) );
110 SYS_ASSERT( end->block_num() + 1 == (*first)->block_num, block_log_exception,
111 "fork_db does not start at end of block log" );
112 }
113 }
114
115 std::ofstream output_blocks;
116 std::ostream* out;
117 if (!output_file.empty()) {
118 output_blocks.open(output_file.generic_string().c_str());
119 if (output_blocks.fail()) {
120 std::ostringstream ss;
121 ss << "Unable to open file '" << output_file.string() << "'";
122 throw std::runtime_error(ss.str());
123 }
124 out = &output_blocks;
125 }
126 else
127 out = &std::cout;
128
129 if (as_json_array)
130 *out << "[";
131 uint32_t block_num = (first_block < 1) ? 1 : first_block;
133 fc::variant pretty_output;
134 const fc::microseconds deadline = fc::seconds(10);
135 auto print_block = [&](signed_block_ptr& next) {
137 pretty_output,
138 []( account_name n ) { return std::optional<abi_serializer>(); },
140 const auto block_id = next->calculate_id();
141 const uint32_t ref_block_prefix = block_id._hash[1];
142 const auto enhanced_object = fc::mutable_variant_object
143 ("block_num",next->block_num())
144 ("id", block_id)
145 ("ref_block_prefix", ref_block_prefix)
146 (pretty_output.get_object());
147 fc::variant v(std::move(enhanced_object));
148 if (no_pretty_print)
150 else
151 *out << fc::json::to_pretty_string(v) << "\n";
152 };
153 bool contains_obj = false;
154 while((block_num <= last_block) && (next = block_logger.read_block_by_num( block_num ))) {
155 if (as_json_array && contains_obj)
156 *out << ",";
157 print_block(next);
158 ++block_num;
159 contains_obj = true;
160 }
161
162 if( !fork_db_branch.empty() ) {
163 for( auto bitr = fork_db_branch.rbegin(); bitr != fork_db_branch.rend() && block_num <= last_block; ++bitr ) {
164 if (as_json_array && contains_obj)
165 *out << ",";
166 auto next = (*bitr)->block;
167 print_block(next);
168 ++block_num;
169 contains_obj = true;
170 }
171 }
172
173 if (as_json_array)
174 *out << "]";
175 rt.report();
176}
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
Definition json.cpp:674
static string to_pretty_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
Definition json.cpp:775
An order-preserving dictionary of variants.
static constexpr time_point maximum()
Definition time.hpp:46
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
variant_object & get_object()
Definition variant.cpp:554
manages light-weight state for all potential unconfirmed forks
#define elog(FORMAT,...)
Definition logger.hpp:130
static const Segment ss(Segment::ss)
bool exists(const path &p)
constexpr microseconds seconds(int64_t s)
Definition time.hpp:32
deque< block_state_ptr > branch_type
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
uint32_t next(octet_iterator &it, octet_iterator end)
Definition checked.h:137
unsigned int uint32_t
Definition stdint.h:126
uint32_t last_block
Definition main.cpp:45
bool no_pretty_print
Definition main.cpp:46
bool as_json_array
Definition main.cpp:47
uint32_t first_block
Definition main.cpp:44
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
static void to_variant(const T &o, fc::variant &vo, Resolver resolver, const yield_function_t &yield)
namespace sysio::chain::impl
Immutable except for fc::from_variant.
Definition name.hpp:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_program_options()

void blocklog::set_program_options ( options_description & cli)

Definition at line 178 of file main.cpp.

179{
180 cli.add_options()
181 ("blocks-dir", bpo::value<bfs::path>()->default_value("blocks"),
182 "the location of the blocks directory (absolute path or relative to the current directory)")
183 ("output-file,o", bpo::value<bfs::path>(),
184 "the file to write the output to (absolute or relative path). If not specified then output is to stdout.")
185 ("first,f", bpo::value<uint32_t>(&first_block)->default_value(0),
186 "the first block number to log or the first to keep if trim-blocklog")
187 ("last,l", bpo::value<uint32_t>(&last_block)->default_value(std::numeric_limits<uint32_t>::max()),
188 "the last block number to log or the last to keep if trim-blocklog")
189 ("no-pretty-print", bpo::bool_switch(&no_pretty_print)->default_value(false),
190 "Do not pretty print the output. Useful if piping to jq to improve performance.")
191 ("as-json-array", bpo::bool_switch(&as_json_array)->default_value(false),
192 "Print out json blocks wrapped in json array (otherwise the output is free-standing json objects).")
193 ("make-index", bpo::bool_switch(&make_index)->default_value(false),
194 "Create blocks.index from blocks.log. Must give 'blocks-dir'. Give 'output-file' relative to current directory or absolute path (default is <blocks-dir>/blocks.index).")
195 ("trim-blocklog", bpo::bool_switch(&trim_log)->default_value(false),
196 "Trim blocks.log and blocks.index. Must give 'blocks-dir' and 'first and/or 'last'.")
197 ("smoke-test", bpo::bool_switch(&smoke_test)->default_value(false),
198 "Quick test that blocks.log and blocks.index are well formed and agree with each other.")
199 ("vacuum", bpo::bool_switch(&vacuum)->default_value(false),
200 "Vacuum a pruned blocks.log in to an un-pruned blocks.log")
201 ("help,h", bpo::bool_switch(&help)->default_value(false), "Print this help message and exit.")
202 ;
203}
bool help
Definition main.cpp:52
bool make_index
Definition main.cpp:48
bool smoke_test
Definition main.cpp:50
bool trim_log
Definition main.cpp:49
bool vacuum
Definition main.cpp:51
void cli()
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ as_json_array

bool blocklog::as_json_array = false

Definition at line 47 of file main.cpp.

◆ blocks_dir

bfs::path blocklog::blocks_dir

Definition at line 42 of file main.cpp.

◆ blog_keep_prune_conf

std::optional<block_log_prune_config> blocklog::blog_keep_prune_conf

Definition at line 54 of file main.cpp.

◆ first_block

uint32_t blocklog::first_block = 0

Definition at line 44 of file main.cpp.

◆ help

bool blocklog::help = false

Definition at line 52 of file main.cpp.

◆ last_block

uint32_t blocklog::last_block = std::numeric_limits<uint32_t>::max()

Definition at line 45 of file main.cpp.

◆ make_index

bool blocklog::make_index = false

Definition at line 48 of file main.cpp.

◆ no_pretty_print

bool blocklog::no_pretty_print = false

Definition at line 46 of file main.cpp.

◆ output_file

bfs::path blocklog::output_file

Definition at line 43 of file main.cpp.

◆ smoke_test

bool blocklog::smoke_test = false

Definition at line 50 of file main.cpp.

◆ trim_log

bool blocklog::trim_log = false

Definition at line 49 of file main.cpp.

◆ vacuum

bool blocklog::vacuum = false

Definition at line 51 of file main.cpp.


The documentation for this struct was generated from the following file: