diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp
index 15a41443..8b8f656e 100644
--- a/libraries/chain/account_object.cpp
+++ b/libraries/chain/account_object.cpp
@@ -142,7 +142,12 @@ set
account_member_index::get_address_members(const account_object& a)c
return result;
}
-void account_member_index::object_inserted(const object& obj)
+void account_member_index::object_loaded(const object& obj)
+{
+ object_created(obj);
+}
+
+void account_member_index::object_created(const object& obj)
{
assert( dynamic_cast(&obj) ); // for debug only
const account_object& a = static_cast(obj);
@@ -256,7 +261,10 @@ void account_member_index::object_modified(const object& after)
}
-void account_referrer_index::object_inserted( const object& obj )
+void account_referrer_index::object_loaded( const object& obj )
+{
+}
+void account_referrer_index::object_created( const object& obj )
{
}
void account_referrer_index::object_removed( const object& obj )
@@ -272,7 +280,12 @@ void account_referrer_index::object_modified( const object& after )
const uint8_t balances_by_account_index::bits = 20;
const uint64_t balances_by_account_index::mask = (1ULL << balances_by_account_index::bits) - 1;
-void balances_by_account_index::object_inserted( const object& obj )
+void balances_by_account_index::object_loaded( const object& obj )
+{
+ object_created(obj);
+}
+
+void balances_by_account_index::object_created( const object& obj )
{
const auto& abo = dynamic_cast< const account_balance_object& >( obj );
while( balances.size() < (abo.owner.instance.value >> bits) + 1 )
diff --git a/libraries/chain/hardfork.d/GPOS.hf b/libraries/chain/hardfork.d/GPOS.hf
index 1cf9c75c..58ff85bf 100644
--- a/libraries/chain/hardfork.d/GPOS.hf
+++ b/libraries/chain/hardfork.d/GPOS.hf
@@ -1,4 +1,5 @@
// GPOS HARDFORK Monday, 17 February 2020 22:00:00 GMT
+// The value should be harmonized with the protcol constant named GPOS_PERIOD_START
#ifndef HARDFORK_GPOS_TIME
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1581976800 ))
#endif
diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp
index c547af22..3f7cb984 100644
--- a/libraries/chain/include/graphene/chain/account_object.hpp
+++ b/libraries/chain/include/graphene/chain/account_object.hpp
@@ -323,7 +323,8 @@ namespace graphene { namespace chain {
};
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
@@ -354,7 +355,8 @@ namespace graphene { namespace chain {
class account_referrer_index : public secondary_index
{
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
@@ -395,7 +397,8 @@ namespace graphene { namespace chain {
class balances_by_account_index : public secondary_index
{
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
diff --git a/libraries/chain/include/graphene/chain/offer_object.hpp b/libraries/chain/include/graphene/chain/offer_object.hpp
index cb6440c8..917a4f0f 100644
--- a/libraries/chain/include/graphene/chain/offer_object.hpp
+++ b/libraries/chain/include/graphene/chain/offer_object.hpp
@@ -60,7 +60,8 @@ namespace graphene
class offer_item_index : public secondary_index
{
public:
- virtual void object_inserted(const object &obj) override;
+ virtual void object_loaded(const object &obj) override;
+ virtual void object_created(const object &obj) override;
virtual void object_removed(const object &obj) override;
virtual void about_to_modify(const object &before) override{};
virtual void object_modified(const object &after) override;
diff --git a/libraries/chain/include/graphene/chain/proposal_object.hpp b/libraries/chain/include/graphene/chain/proposal_object.hpp
index 3b83b748..8809aea0 100644
--- a/libraries/chain/include/graphene/chain/proposal_object.hpp
+++ b/libraries/chain/include/graphene/chain/proposal_object.hpp
@@ -62,7 +62,7 @@ class proposal_object : public abstract_object
};
/**
- * @brief tracks all of the proposal objects that requrie approval of
+ * @brief tracks all of the proposal objects that require approval of
* an individual account.
*
* @ingroup object
@@ -75,7 +75,8 @@ class proposal_object : public abstract_object
class required_approval_index : public secondary_index
{
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override{};
virtual void object_modified( const object& after ) override{};
diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp
index 9f2e5860..51964f60 100644
--- a/libraries/chain/include/graphene/chain/tournament_object.hpp
+++ b/libraries/chain/include/graphene/chain/tournament_object.hpp
@@ -224,7 +224,8 @@ namespace graphene { namespace chain {
class tournament_players_index : public secondary_index
{
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
diff --git a/libraries/chain/offer_object.cpp b/libraries/chain/offer_object.cpp
index 35ac47d2..795648f3 100644
--- a/libraries/chain/offer_object.cpp
+++ b/libraries/chain/offer_object.cpp
@@ -6,7 +6,12 @@ namespace graphene
namespace chain
{
- void offer_item_index::object_inserted(const object &obj)
+ void offer_item_index::object_loaded(const object &obj)
+ {
+ object_created(obj);
+ }
+
+ void offer_item_index::object_created(const object &obj)
{
assert(dynamic_cast(&obj));
const offer_object &oo = static_cast(obj);
@@ -47,4 +52,4 @@ namespace graphene
}
} // namespace chain
-} // namespace graphene
\ No newline at end of file
+} // namespace graphene
diff --git a/libraries/chain/proposal_object.cpp b/libraries/chain/proposal_object.cpp
index 662c700a..2841daa9 100644
--- a/libraries/chain/proposal_object.cpp
+++ b/libraries/chain/proposal_object.cpp
@@ -52,7 +52,12 @@ bool proposal_object::is_authorized_to_execute( database& db ) const
return true;
}
-void required_approval_index::object_inserted( const object& obj )
+void required_approval_index::object_loaded( const object& obj )
+{
+ object_created(obj);
+}
+
+void required_approval_index::object_created( const object& obj )
{
assert( dynamic_cast(&obj) );
const proposal_object& p = static_cast(obj);
diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp
index 715ef1d3..9465e048 100644
--- a/libraries/chain/tournament_object.cpp
+++ b/libraries/chain/tournament_object.cpp
@@ -653,7 +653,12 @@ namespace graphene { namespace chain {
return vector();
}
- void tournament_players_index::object_inserted(const object& obj)
+ void tournament_players_index::object_loaded(const object& obj)
+ {
+ object_created(obj);
+ }
+
+ void tournament_players_index::object_created(const object& obj)
{
assert( dynamic_cast(&obj) ); // for debug only
const tournament_details_object& details = static_cast(obj);
diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp
index c02aeb69..2aa7cb9a 100644
--- a/libraries/db/include/graphene/db/index.hpp
+++ b/libraries/db/include/graphene/db/index.hpp
@@ -135,13 +135,23 @@ namespace graphene { namespace db {
virtual void object_default( object& obj )const = 0;
};
+ /** @class secondary_index
+ * @brief A secondary index is intended to observe a primary index.
+ * A secondary index is not automatically persisted when the node shuts own.
+ */
class secondary_index
{
public:
virtual ~secondary_index(){};
- virtual void object_inserted( const object& obj ){};
+ // Called when an object from a previous node session is loaded from persistence
+ virtual void object_loaded( const object& obj ){};
+ // Called when an object from the current node session is created
+ virtual void object_created( const object& obj ){};
+ // Called when an object is removed
virtual void object_removed( const object& obj ){};
+ // Called when an object is about to be modified
virtual void about_to_modify( const object& before ){};
+ // Called when an object is modified
virtual void object_modified( const object& after ){};
};
@@ -226,7 +236,12 @@ namespace graphene { namespace db {
virtual ~direct_index(){}
- virtual void object_inserted( const object& obj )
+ virtual void object_loaded( const object& obj )
+ {
+ object_created(obj);
+ }
+
+ virtual void object_created( const object& obj )
{
uint64_t instance = obj.id.instance();
if( instance == next )
@@ -386,7 +401,7 @@ namespace graphene { namespace db {
{
const auto& result = DerivedIndex::insert( fc::raw::unpack( data ) );
for( const auto& item : _sindex )
- item->object_inserted( result );
+ item->object_loaded( result );
return result;
}
@@ -395,7 +410,7 @@ namespace graphene { namespace db {
{
const auto& result = DerivedIndex::create( constructor );
for( const auto& item : _sindex )
- item->object_inserted( result );
+ item->object_created( result );
on_add( result );
return result;
}
diff --git a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp
index 84315013..9f042a13 100644
--- a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp
+++ b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp
@@ -84,7 +84,8 @@ class account_history_plugin : public graphene::app::plugin
class affiliate_reward_index : public secondary_index
{
public:
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override{};
virtual void object_modified( const object& after ) override{};
diff --git a/libraries/plugins/bookie/bookie_plugin.cpp b/libraries/plugins/bookie/bookie_plugin.cpp
index a8c06a0d..e9f8a9bd 100644
--- a/libraries/plugins/bookie/bookie_plugin.cpp
+++ b/libraries/plugins/bookie/bookie_plugin.cpp
@@ -54,10 +54,42 @@ namespace detail
/* As a plugin, we get notified of new/changed objects at the end of every block processed.
* For most objects, that's fine, because we expect them to always be around until the end of
* the block. However, with bet objects, it's possible that the user places a bet and it fills
- * and is removed during the same block, so need another strategy to detect them immediately after
- * they are created.
+ * and is removed during the same block, so need another strategy to detect these "ephemeral"
+ * node objects immediately after they are created.
* We do this by creating a secondary index on bet_object. We don't actually use it
* to index any property of the bet, we just use it to register for callbacks.
+ *
+ * One objective of the plugin's helper is to watch for database objects known by the the node
+ * (node objects) in order for the plugin to populate and persist a copy (plugin objects)
+ * within its own primary index.
+ *
+ * The life cycle of a naive helper object is:
+ *
+ * 1. During `plugin_initialize()`
+ * The helper registers with the database for future notifications (Step 2) of the creation of
+ * a watched object
+ * (`database().add_secondary_index<...>()`).
+ * The helper also delegates the future persistence (Step 3) of its own primary index
+ * to the database by registering it.
+ * (`database().add_index>()`).
+ * This primary index will be used to index plugin objects that are copies of node objects
+ * observed during Step 2.
+ * 2. During a node session: the helper is notified by the database about the watched node objects
+ * that are created during the node session through its `object_created()` callback.
+ * During that callback, the helper will create its own copy (plugin object) of the of node
+ * objectand inject it into its own primary index.
+ * 3. When the node session shuts down, the database will persist the helper's primary index
+ * that was registered during Step 1.
+ * 4. When the node is restarted, the database will automatically load the previous session(s)'s
+ * node objectsinto the helper's primary index.
+ *
+ * The helper can ignore the `object_loaded()` events that are triggered when the watched node
+ * objects are loaded from persistence by the database because those objects were already processed
+ * by the the helper's `object_created()` during the prior sessions.
+ *
+ * NOTE: The helper should register itself for notifications of new node objects
+ * during `plugin_initialize()` rather than `plugin_startup()`
+ * for compatibility with a blockchain replay.
*/
class persistent_bet_object_helper : public secondary_index
{
@@ -66,7 +98,8 @@ class persistent_bet_object_helper : public secondary_index
using watched_index = primary_index;
- virtual void object_inserted(const object& obj) override;
+ //virtual void object_loaded(const object& obj) override;
+ virtual void object_created(const object& obj) override;
//virtual void object_removed( const object& obj ) override;
//virtual void about_to_modify( const object& before ) override;
virtual void object_modified(const object& after) override;
@@ -75,7 +108,7 @@ class persistent_bet_object_helper : public secondary_index
bookie_plugin* _bookie_plugin;
};
-void persistent_bet_object_helper::object_inserted(const object& obj)
+void persistent_bet_object_helper::object_created(const object& obj)
{
const bet_object& bet_obj = *boost::polymorphic_downcast(&obj);
_bookie_plugin->database().create([&](persistent_bet_object& saved_bet_obj) {
@@ -103,7 +136,8 @@ class persistent_betting_market_object_helper : public secondary_index
using watched_index = primary_index;
- virtual void object_inserted(const object& obj) override;
+ //virtual void object_loaded(const object& obj) override;
+ virtual void object_created(const object& obj) override;
//virtual void object_removed( const object& obj ) override;
//virtual void about_to_modify( const object& before ) override;
virtual void object_modified(const object& after) override;
@@ -112,7 +146,7 @@ class persistent_betting_market_object_helper : public secondary_index
bookie_plugin* _bookie_plugin;
};
-void persistent_betting_market_object_helper::object_inserted(const object& obj)
+void persistent_betting_market_object_helper::object_created(const object& obj)
{
const betting_market_object& betting_market_obj = *boost::polymorphic_downcast(&obj);
_bookie_plugin->database().create([&](persistent_betting_market_object& saved_betting_market_obj) {
@@ -140,7 +174,8 @@ class persistent_betting_market_group_object_helper : public secondary_index
using watched_index = primary_index;
- virtual void object_inserted(const object& obj) override;
+ //virtual void object_loaded(const object& obj) override;
+ virtual void object_created(const object& obj) override;
//virtual void object_removed( const object& obj ) override;
//virtual void about_to_modify( const object& before ) override;
virtual void object_modified(const object& after) override;
@@ -149,7 +184,7 @@ class persistent_betting_market_group_object_helper : public secondary_index
bookie_plugin* _bookie_plugin;
};
-void persistent_betting_market_group_object_helper::object_inserted(const object& obj)
+void persistent_betting_market_group_object_helper::object_created(const object& obj)
{
const betting_market_group_object& betting_market_group_obj = *boost::polymorphic_downcast(&obj);
_bookie_plugin->database().create([&](persistent_betting_market_group_object& saved_betting_market_group_obj) {
@@ -177,7 +212,8 @@ class persistent_event_object_helper : public secondary_index
using watched_index = primary_index;
- virtual void object_inserted(const object& obj) override;
+ //virtual void object_loaded(const object& obj) override;
+ virtual void object_created(const object& obj) override;
//virtual void object_removed( const object& obj ) override;
//virtual void about_to_modify( const object& before ) override;
virtual void object_modified(const object& after) override;
@@ -186,7 +222,7 @@ class persistent_event_object_helper : public secondary_index
bookie_plugin* _bookie_plugin;
};
-void persistent_event_object_helper::object_inserted(const object& obj)
+void persistent_event_object_helper::object_created(const object& obj)
{
const event_object& event_obj = *boost::polymorphic_downcast(&obj);
_bookie_plugin->database().create([&](persistent_event_object& saved_event_obj) {
@@ -485,18 +521,19 @@ void bookie_plugin::plugin_initialize(const boost::program_options::variables_ma
database().add_index >();
database().add_index >();
database().add_index >();
+
+ // Register secondary indexes
+ database().add_secondary_index()->set_plugin_instance(this);
+ database().add_secondary_index()->set_plugin_instance(this);
+ database().add_secondary_index()->set_plugin_instance(this);
+ database().add_secondary_index()->set_plugin_instance(this);
+
ilog("bookie plugin: plugin_initialize() end");
}
void bookie_plugin::plugin_startup()
{
- ilog("bookie plugin: plugin_startup()");
-
- // Register secondary indexes
- database().add_secondary_index()->set_plugin_instance(this);
- database().add_secondary_index()->set_plugin_instance(this);
- database().add_secondary_index()->set_plugin_instance(this);
- database().add_secondary_index()->set_plugin_instance(this);
+ ilog("bookie plugin: plugin_startup()");
my->fill_localized_event_strings();
}
diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp
index c9e20b8e..bd91ef17 100644
--- a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp
+++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp
@@ -68,7 +68,8 @@ class events_by_competitor_index : public secondary_index
public:
virtual ~events_by_competitor_index() {}
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
@@ -77,7 +78,12 @@ class events_by_competitor_index : public secondary_index
map > competitor_to_events;
};
-void events_by_competitor_index::object_inserted( const object& obj )
+void events_by_competitor_index::object_loaded( const object& obj )
+{
+ object_created(obj);
+}
+
+void events_by_competitor_index::object_created( const object& obj )
{
const persistent_event_object& event_obj = *boost::polymorphic_downcast(&obj);
for (const competitor_id_type& competitor_id : event_obj.competitors)
@@ -97,7 +103,7 @@ void events_by_competitor_index::about_to_modify( const object& before )
}
void events_by_competitor_index::object_modified( const object& after )
{
- object_inserted(after);
+ object_created(after);
}
#endif
diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp
index ef1ae04c..99a77b5a 100644
--- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp
+++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp
@@ -55,7 +55,8 @@ class limit_order_group_index : public secondary_index
public:
limit_order_group_index( const flat_set& groups ) : _tracked_groups( groups ) {};
- virtual void object_inserted( const object& obj ) override;
+ virtual void object_loaded( const object& obj ) override;
+ virtual void object_created( const object& obj ) override;
virtual void object_removed( const object& obj ) override;
virtual void about_to_modify( const object& before ) override;
virtual void object_modified( const object& after ) override;
@@ -76,7 +77,12 @@ class limit_order_group_index : public secondary_index
map< limit_order_group_key, limit_order_group_data > _og_data;
};
-void limit_order_group_index::object_inserted( const object& objct )
+void limit_order_group_index::object_loaded( const object& objct )
+{
+ object_created(objct);
+}
+
+void limit_order_group_index::object_created( const object& objct )
{ try {
const limit_order_object& o = static_cast( objct );
@@ -201,7 +207,7 @@ void limit_order_group_index::about_to_modify( const object& objct )
void limit_order_group_index::object_modified( const object& objct )
{ try {
- object_inserted( objct );
+ object_created( objct );
} FC_CAPTURE_AND_RETHROW( (objct) ); }
void limit_order_group_index::remove_order( const limit_order_object& o, bool remove_empty )
diff --git a/libraries/protocol/include/graphene/protocol/config.hpp b/libraries/protocol/include/graphene/protocol/config.hpp
index c855b339..b230e216 100644
--- a/libraries/protocol/include/graphene/protocol/config.hpp
+++ b/libraries/protocol/include/graphene/protocol/config.hpp
@@ -222,7 +222,8 @@
#define SWEEPS_DEFAULT_DISTRIBUTION_ASSET (graphene::protocol::asset_id_type(0))
#define SWEEPS_VESTING_BALANCE_MULTIPLIER 100000000
#define SWEEPS_ACCUMULATOR_ACCOUNT (graphene::protocol::account_id_type(0))
-#define GPOS_PERIOD_START (fc::time_point_sec(1578272400))
+// // The value should be harmonized with the chain constant named HARDFORK_GPOS_TIME
+#define GPOS_PERIOD_START (fc::time_point_sec(1581976800))
#define GPOS_PERIOD (60*60*24*30*6) // 6 months
#define GPOS_SUBPERIOD (60*60*24*30) // 1 month
#define GPOS_VESTING_LOCKIN_PERIOD (60*60*24*30) // 1 month
diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt
index ba73cdca..d9c82346 100644
--- a/programs/CMakeLists.txt
+++ b/programs/CMakeLists.txt
@@ -1,5 +1,5 @@
add_subdirectory( build_helpers )
-if( BUILD_BITSHARES_PROGRAMS )
+if( BUILD_PEERPLAYS_PROGRAMS )
add_subdirectory( cli_wallet )
add_subdirectory( genesis_util )
add_subdirectory( witness_node )
@@ -7,4 +7,4 @@ if( BUILD_BITSHARES_PROGRAMS )
add_subdirectory( delayed_node )
add_subdirectory( js_operation_serializer )
add_subdirectory( size_checker )
-endif( BUILD_BITSHARES_PROGRAMS )
+endif( BUILD_PEERPLAYS_PROGRAMS )