BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
debug_api.cpp
Go to the documentation of this file.
1 
2 #include <fc/filesystem.hpp>
3 #include <fc/optional.hpp>
4 #include <fc/variant_object.hpp>
5 
7 
11 
13 
16 
17 namespace graphene { namespace debug_witness {
18 
19 namespace detail {
20 
22 {
23  public:
25 
26  void debug_push_blocks( const std::string& src_filename, uint32_t count );
27  void debug_generate_blocks( const std::string& debug_key, uint32_t count );
28  void debug_update_object( const fc::variant_object& update );
29  void debug_stream_json_objects( const std::string& filename );
31  std::shared_ptr< graphene::debug_witness_plugin::debug_witness_plugin > get_plugin();
32 
34 };
35 
37 {
38  // Nothing else to do
39 }
40 
41 
42 void debug_api_impl::debug_push_blocks( const std::string& src_filename, uint32_t count )
43 {
44  if( count == 0 )
45  return;
46 
47  std::shared_ptr< graphene::chain::database > db = app.chain_database();
48  fc::path src_path = fc::path( src_filename );
49  if( fc::is_directory( src_path ) )
50  {
51  ilog( "Loading ${n} from block_database ${fn}", ("n", count)("fn", src_filename) );
53  bdb.open( src_path );
54  uint32_t first_block = db->head_block_num()+1;
55  for( uint32_t i=0; i<count; i++ )
56  {
58  if( !block.valid() )
59  {
60  wlog( "Block database ${fn} only contained ${i} of ${n} requested blocks", ("i", i)("n", count)("fn", src_filename) );
61  return;
62  }
63  try
64  {
65  db->push_block( *block );
66  }
67  catch( const fc::exception& e )
68  {
69  elog( "Got exception pushing block ${bn} : ${bid} (${i} of ${n})", ("bn", block->block_num())("bid", block->id())("i", i)("n", count) );
70  elog( "Exception backtrace: ${bt}", ("bt", e.to_detail_string()) );
71  }
72  }
73  ilog( "Completed loading block_database successfully" );
74  }
75 }
76 
77 void debug_api_impl::debug_generate_blocks( const std::string& debug_key, uint32_t count )
78 {
79  if( count == 0 )
80  return;
81 
83  FC_ASSERT( debug_private_key.valid() );
84  graphene::chain::public_key_type debug_public_key = debug_private_key->get_public_key();
85 
86  std::shared_ptr< graphene::chain::database > db = app.chain_database();
87  for( uint32_t i=0; i<count; i++ )
88  {
89  graphene::chain::witness_id_type scheduled_witness = db->get_scheduled_witness( 1 );
90  fc::time_point_sec scheduled_time = db->get_slot_time( 1 );
91  graphene::chain::public_key_type scheduled_key = scheduled_witness( *db ).signing_key;
92  if( scheduled_key != debug_public_key )
93  {
94  ilog( "Modified key for witness ${w}", ("w", scheduled_witness) );
96  update("_action", "update")("id", scheduled_witness)("signing_key", debug_public_key);
97  db->debug_update( update );
98  }
99  db->generate_block( scheduled_time, scheduled_witness, *debug_private_key, graphene::chain::database::skip_nothing );
100  }
101 }
102 
104 {
105  std::shared_ptr< graphene::chain::database > db = app.chain_database();
106  db->debug_update( update );
107 }
108 
109 std::shared_ptr< graphene::debug_witness_plugin::debug_witness_plugin > debug_api_impl::get_plugin()
110 {
112 }
113 
114 void debug_api_impl::debug_stream_json_objects( const std::string& filename )
115 {
116  get_plugin()->set_json_object_stream( filename );
117 }
118 
120 {
121  get_plugin()->flush_json_object_stream();
122 }
123 
124 } // detail
125 
127 {
128  my = std::make_shared< detail::debug_api_impl >(app);
129 }
130 
131 void debug_api::debug_push_blocks( std::string source_filename, uint32_t count )
132 {
133  my->debug_push_blocks( source_filename, count );
134 }
135 
136 void debug_api::debug_generate_blocks( std::string debug_key, uint32_t count )
137 {
138  my->debug_generate_blocks( debug_key, count );
139 }
140 
142 {
143  my->debug_update_object( update );
144 }
145 
146 void debug_api::debug_stream_json_objects( std::string filename )
147 {
148  my->debug_stream_json_objects( filename );
149 }
150 
152 {
153  my->debug_stream_json_objects_flush();
154 }
155 
156 
157 } } // graphene::debug_witness
fc::variant_object
An order-perserving dictionary of variant's.
Definition: variant_object.hpp:20
graphene::chain::block_database::open
void open(const fc::path &dbdir)
Definition: block_database.cpp:46
wlog
#define wlog(FORMAT,...)
Definition: logger.hpp:123
fc::exception
Used to generate a useful error report when an exception is thrown.
Definition: exception.hpp:56
database.hpp
debug_witness.hpp
graphene::debug_witness_plugin::debug_witness_plugin
Definition: debug_witness.hpp:35
graphene::debug_witness::debug_api::debug_stream_json_objects
void debug_stream_json_objects(std::string filename)
Definition: debug_api.cpp:146
graphene::utilities::wif_to_key
fc::optional< fc::ecc::private_key > wif_to_key(const std::string &wif_key)
Definition: key_conversion.cpp:47
variant_object.hpp
filesystem.hpp
fc::is_directory
bool is_directory(const path &p)
Definition: filesystem.cpp:217
graphene::app::application::chain_database
std::shared_ptr< chain::database > chain_database() const
Definition: application.cpp:1404
graphene::protocol::public_key_type
Definition: types.hpp:312
graphene::debug_witness::debug_api::my
std::shared_ptr< detail::debug_api_impl > my
Definition: debug_api.hpp:85
graphene::protocol::block_header::block_num
uint32_t block_num() const
Definition: block.hpp:34
graphene::app::application
Definition: application.hpp:91
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
graphene::chain::block_database::fetch_by_number
optional< signed_block > fetch_by_number(uint32_t block_num) const
Definition: block_database.cpp:184
ilog
#define ilog(FORMAT,...)
Definition: logger.hpp:117
graphene::debug_witness::detail::debug_api_impl::debug_api_impl
debug_api_impl(graphene::app::application &_app)
Definition: debug_api.cpp:36
graphene::debug_witness::detail::debug_api_impl::get_plugin
std::shared_ptr< graphene::debug_witness_plugin::debug_witness_plugin > get_plugin()
Definition: debug_api.cpp:109
fc::optional::valid
bool valid() const
Definition: optional.hpp:186
graphene::app::application::get_plugin
std::shared_ptr< abstract_plugin > get_plugin(const string &name) const
Definition: application.cpp:1389
fc::time_point_sec
Definition: time.hpp:74
fc::exception::to_detail_string
std::string to_detail_string(log_level ll=log_level::all) const
Definition: exception.cpp:183
graphene::debug_witness::detail::debug_api_impl::debug_push_blocks
void debug_push_blocks(const std::string &src_filename, uint32_t count)
Definition: debug_api.cpp:42
graphene::debug_witness::debug_api::debug_push_blocks
void debug_push_blocks(std::string src_filename, uint32_t count)
Definition: debug_api.cpp:131
fc::ecc::private_key::get_public_key
public_key get_public_key() const
Definition: elliptic_impl_priv.cpp:70
fc::limited_mutable_variant_object
Definition: variant_object.hpp:220
graphene::debug_witness::detail::debug_api_impl::debug_stream_json_objects_flush
void debug_stream_json_objects_flush()
Definition: debug_api.cpp:119
graphene::debug_witness::debug_api::debug_generate_blocks
void debug_generate_blocks(std::string debug_key, uint32_t count)
Definition: debug_api.cpp:136
FC_ASSERT
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
application.hpp
graphene::debug_witness::detail::debug_api_impl::app
graphene::app::application & app
Definition: debug_api.cpp:33
graphene::debug_witness::debug_api::debug_api
debug_api(graphene::app::application &app)
Definition: debug_api.cpp:126
GRAPHENE_MAX_NESTED_OBJECTS
#define GRAPHENE_MAX_NESTED_OBJECTS
Definition: config.hpp:33
graphene::debug_witness::detail::debug_api_impl
Definition: debug_api.cpp:21
graphene::protocol::signed_block_header::id
const block_id_type & id() const
Definition: block.cpp:41
graphene::chain::block_database
Definition: block_database.hpp:34
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::debug_witness::detail::debug_api_impl::debug_generate_blocks
void debug_generate_blocks(const std::string &debug_key, uint32_t count)
Definition: debug_api.cpp:77
key_conversion.hpp
graphene::debug_witness::detail::debug_api_impl::debug_stream_json_objects
void debug_stream_json_objects(const std::string &filename)
Definition: debug_api.cpp:114
witness_object.hpp
graphene::debug_witness::debug_api::debug_stream_json_objects_flush
void debug_stream_json_objects_flush()
Definition: debug_api.cpp:151
graphene::debug_witness::debug_api::debug_update_object
void debug_update_object(fc::variant_object update)
Definition: debug_api.cpp:141
block_database.hpp
debug_api.hpp
graphene
Definition: api.cpp:48
graphene::chain::database::skip_nothing
@ skip_nothing
Definition: database.hpp:79
graphene::debug_witness::detail::debug_api_impl::debug_update_object
void debug_update_object(const fc::variant_object &update)
Definition: debug_api.cpp:103
elog
#define elog(FORMAT,...)
Definition: logger.hpp:129
optional.hpp