Graphene Updates and DApp Support #643

Closed
nathanielhourt wants to merge 84 commits from dapp-support into develop
16 changed files with 146 additions and 45 deletions
Showing only changes of commit 25faf9b084 - Show all commits

View file

@ -142,7 +142,12 @@ set<address> 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<const account_object*>(&obj) ); // for debug only
const account_object& a = static_cast<const account_object&>(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 )

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -62,7 +62,7 @@ class proposal_object : public abstract_object<proposal_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<proposal_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{};

View file

@ -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;

View file

@ -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<const offer_object *>(&obj));
const offer_object &oo = static_cast<const offer_object &>(obj);
@ -47,4 +52,4 @@ namespace graphene
}
} // namespace chain
} // namespace graphene
} // namespace graphene

View file

@ -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<const proposal_object*>(&obj) );
const proposal_object& p = static_cast<const proposal_object&>(obj);

View file

@ -653,7 +653,12 @@ namespace graphene { namespace chain {
return vector<tournament_id_type>();
}
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<const tournament_details_object*>(&obj) ); // for debug only
const tournament_details_object& details = static_cast<const tournament_details_object&>(obj);

View file

@ -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<object_type>( 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;
}

View file

@ -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{};

View file

@ -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<primary_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<bet_object_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<const bet_object*>(&obj);
_bookie_plugin->database().create<persistent_bet_object>([&](persistent_bet_object& saved_bet_obj) {
@ -103,7 +136,8 @@ class persistent_betting_market_object_helper : public secondary_index
using watched_index = primary_index<betting_market_object_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<const betting_market_object*>(&obj);
_bookie_plugin->database().create<persistent_betting_market_object>([&](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<betting_market_group_object_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<const betting_market_group_object*>(&obj);
_bookie_plugin->database().create<persistent_betting_market_group_object>([&](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<event_object_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<const event_object*>(&obj);
_bookie_plugin->database().create<persistent_event_object>([&](persistent_event_object& saved_event_obj) {
@ -485,18 +521,19 @@ void bookie_plugin::plugin_initialize(const boost::program_options::variables_ma
database().add_index<primary_index<detail::persistent_betting_market_group_index> >();
database().add_index<primary_index<detail::persistent_betting_market_index> >();
database().add_index<primary_index<detail::persistent_bet_index> >();
// Register secondary indexes
database().add_secondary_index<detail::persistent_bet_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_betting_market_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_betting_market_group_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_event_object_helper>()->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<detail::persistent_bet_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_betting_market_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_betting_market_group_object_helper>()->set_plugin_instance(this);
database().add_secondary_index<detail::persistent_event_object_helper>()->set_plugin_instance(this);
ilog("bookie plugin: plugin_startup()");
my->fill_localized_event_strings();
}

View file

@ -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_id_type, set<persistent_event_id_type> > 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<const persistent_event_object*>(&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

View file

@ -55,7 +55,8 @@ class limit_order_group_index : public secondary_index
public:
limit_order_group_index( const flat_set<uint16_t>& 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<const limit_order_object&>( 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 )

View file

@ -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

View file

@ -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 )