forked from cryptonomex/graphene
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cryptonomex#437 from pmconrad/issue_433_429
Fix issues 433 + 429
- Loading branch information
Showing
11 changed files
with
437 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// bitshares-core #429 rounding issue when creating assets | ||
#ifndef HARDFORK_CORE_429_TIME | ||
#define HARDFORK_CORE_429_TIME (fc::time_point_sec( 1511793600 )) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
file(GLOB HEADERS "include/graphene/snapshot/*.hpp") | ||
|
||
add_library( graphene_snapshot | ||
snapshot.cpp | ||
) | ||
|
||
target_link_libraries( graphene_snapshot graphene_chain graphene_app ) | ||
target_include_directories( graphene_snapshot | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) | ||
|
||
install( TARGETS | ||
graphene_snapshot | ||
|
||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
) |
56 changes: 56 additions & 0 deletions
56
libraries/plugins/snapshot/include/graphene/snapshot/snapshot.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2017 Peter Conrad, and contributors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#pragma once | ||
|
||
#include <graphene/app/plugin.hpp> | ||
#include <graphene/chain/database.hpp> | ||
|
||
#include <fc/time.hpp> | ||
|
||
namespace graphene { namespace snapshot_plugin { | ||
|
||
class snapshot_plugin : public graphene::app::plugin { | ||
public: | ||
~snapshot_plugin() {} | ||
|
||
std::string plugin_name()const override; | ||
|
||
virtual void plugin_set_program_options( | ||
boost::program_options::options_description &command_line_options, | ||
boost::program_options::options_description &config_file_options | ||
) override; | ||
|
||
virtual void plugin_initialize( const boost::program_options::variables_map& options ) override; | ||
virtual void plugin_startup() override; | ||
virtual void plugin_shutdown() override; | ||
|
||
private: | ||
void check_snapshot( const graphene::chain::signed_block& b); | ||
|
||
uint32_t snapshot_block = -1, last_block = 0; | ||
fc::time_point_sec snapshot_time = fc::time_point_sec::maximum(), last_time = fc::time_point_sec(1); | ||
fc::path dest; | ||
}; | ||
|
||
} } //graphene::snapshot_plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright (c) 2017 Peter Conrad, and contributors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#include <graphene/snapshot/snapshot.hpp> | ||
|
||
#include <graphene/chain/database.hpp> | ||
|
||
#include <fc/io/fstream.hpp> | ||
|
||
using namespace graphene::snapshot_plugin; | ||
using std::string; | ||
using std::vector; | ||
|
||
namespace bpo = boost::program_options; | ||
|
||
static const char* OPT_BLOCK_NUM = "snapshot-at-block"; | ||
static const char* OPT_BLOCK_TIME = "snapshot-at-time"; | ||
static const char* OPT_DEST = "snapshot-to"; | ||
|
||
void snapshot_plugin::plugin_set_program_options( | ||
boost::program_options::options_description& command_line_options, | ||
boost::program_options::options_description& config_file_options) | ||
{ | ||
command_line_options.add_options() | ||
(OPT_BLOCK_NUM, bpo::value<uint32_t>(), "Block number after which to do a snapshot") | ||
(OPT_BLOCK_TIME, bpo::value<string>(), "Block time (ISO format) after which to do a snapshot") | ||
(OPT_DEST, bpo::value<string>(), "Pathname of JSON file where to store the snapshot") | ||
; | ||
config_file_options.add(command_line_options); | ||
} | ||
|
||
std::string snapshot_plugin::plugin_name()const | ||
{ | ||
return "snapshot"; | ||
} | ||
|
||
void snapshot_plugin::plugin_initialize(const boost::program_options::variables_map& options) | ||
{ try { | ||
ilog("snapshot plugin: plugin_initialize() begin"); | ||
|
||
if( options.count(OPT_BLOCK_NUM) || options.count(OPT_BLOCK_TIME) ) | ||
{ | ||
FC_ASSERT( options.count(OPT_DEST), "Must specify snapshot-to in addition to snapshot-at-block or snapshot-at-time!" ); | ||
dest = options[OPT_DEST].as<std::string>(); | ||
if( options.count(OPT_BLOCK_NUM) ) | ||
snapshot_block = options[OPT_BLOCK_NUM].as<uint32_t>(); | ||
if( options.count(OPT_BLOCK_TIME) ) | ||
snapshot_time = fc::time_point_sec::from_iso_string( options[OPT_BLOCK_TIME].as<std::string>() ); | ||
database().applied_block.connect( [&]( const graphene::chain::signed_block& b ) { | ||
check_snapshot( b ); | ||
}); | ||
} | ||
else | ||
FC_ASSERT( !options.count("snapshot-to"), "Must specify snapshot-at-block or snapshot-at-time in addition to snapshot-to!" ); | ||
ilog("snapshot plugin: plugin_initialize() end"); | ||
} FC_LOG_AND_RETHROW() } | ||
|
||
void snapshot_plugin::plugin_startup() {} | ||
|
||
void snapshot_plugin::plugin_shutdown() {} | ||
|
||
static void create_snapshot( const graphene::chain::database& db, const fc::path& dest ) | ||
{ | ||
ilog("snapshot plugin: creating snapshot"); | ||
fc::ofstream out; | ||
try | ||
{ | ||
out.open( dest ); | ||
} | ||
catch ( fc::exception e ) | ||
{ | ||
wlog( "Failed to open snapshot destination: ${ex}", ("ex",e) ); | ||
return; | ||
} | ||
for( uint32_t space_id = 0; space_id < 256; space_id++ ) | ||
for( uint32_t type_id = 0; type_id < 256; type_id++ ) | ||
{ | ||
try | ||
{ | ||
db.get_index( (uint8_t)space_id, (uint8_t)type_id ); | ||
} | ||
catch (fc::assert_exception e) | ||
{ | ||
continue; | ||
} | ||
auto& index = db.get_index( (uint8_t)space_id, (uint8_t)type_id ); | ||
index.inspect_all_objects( [&out]( const graphene::db::object& o ) { | ||
out << fc::json::to_string( o.to_variant() ) << '\n'; | ||
}); | ||
} | ||
out.close(); | ||
ilog("snapshot plugin: created snapshot"); | ||
} | ||
|
||
void snapshot_plugin::check_snapshot( const graphene::chain::signed_block& b ) | ||
{ try { | ||
uint32_t current_block = b.block_num(); | ||
if( (last_block < snapshot_block && snapshot_block <= current_block) | ||
|| (last_time < snapshot_time && snapshot_time <= b.timestamp) ) | ||
create_snapshot( database(), dest ); | ||
last_block = current_block; | ||
last_time = b.timestamp; | ||
} FC_LOG_AND_RETHROW() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.