Skip to content

Commit

Permalink
Merge pull request #1440 from bitshares/release
Browse files Browse the repository at this point in the history
merge release to master
  • Loading branch information
jmjatlanta authored Nov 20, 2018
2 parents 3ea5287 + 1ba4b28 commit a0e7dff
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 30 deletions.
2 changes: 2 additions & 0 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/block_summary_object.hpp>
#include <graphene/chain/budget_record_object.hpp>
#include <graphene/chain/buyback_object.hpp>
#include <graphene/chain/chain_property_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
Expand Down Expand Up @@ -213,6 +214,7 @@ void database::initialize_indexes()
add_index< primary_index<simple_index<block_summary_object >> >();
add_index< primary_index<simple_index<chain_property_object > > >();
add_index< primary_index<simple_index<witness_schedule_object > > >();
add_index< primary_index<simple_index<budget_record_object > > >();
add_index< primary_index< special_authority_index > >();
add_index< primary_index< buyback_index > >();
add_index< primary_index<collateral_bid_index > >();
Expand Down
34 changes: 7 additions & 27 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <graphene/chain/account_object.hpp>
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/budget_record_object.hpp>
#include <graphene/chain/buyback_object.hpp>
#include <graphene/chain/chain_property_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
Expand Down Expand Up @@ -131,33 +132,6 @@ struct worker_pay_visitor
}
};

/// @brief A budget record struct to be used in initialize_budget_record and process_budget
struct budget_record
{
uint64_t time_since_last_budget = 0;

// sources of budget
share_type from_initial_reserve = 0;
share_type from_accumulated_fees = 0;
share_type from_unused_witness_budget = 0;

// witness budget requested by the committee
share_type requested_witness_budget = 0;

// funds that can be released from reserve at maximum rate
share_type total_budget = 0;

// sinks of budget, should sum up to total_budget
share_type witness_budget = 0;
share_type worker_budget = 0;

// unused budget
share_type leftover_worker_funds = 0;

// change in supply due to budget operations
share_type supply_delta = 0;
};

void database::update_worker_votes()
{
const auto& idx = get_index_type<worker_index>().indices().get<by_account>();
Expand Down Expand Up @@ -560,6 +534,12 @@ void database::process_budget()
_dpo.last_budget_time = now;
});

create< budget_record_object >( [&]( budget_record_object& _rec )
{
_rec.time = head_block_time();
_rec.record = rec;
});

// available_funds is money we could spend, but don't want to.
// we simply let it evaporate back into the reserve.
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/db_notify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
break;
case impl_witness_schedule_object_type:
break;
case impl_reserved1_object_type:
case impl_budget_record_object_type:
break;
case impl_special_authority_object_type:
break;
Expand Down
90 changes: 90 additions & 0 deletions libraries/chain/include/graphene/chain/budget_record_object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2015 Cryptonomex, Inc., 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/chain/protocol/types.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>

namespace graphene { namespace chain {

struct budget_record
{
uint64_t time_since_last_budget = 0;

// sources of budget
share_type from_initial_reserve = 0;
share_type from_accumulated_fees = 0;
share_type from_unused_witness_budget = 0;

// witness budget requested by the committee
share_type requested_witness_budget = 0;

// funds that can be released from reserve at maximum rate
share_type total_budget = 0;

// sinks of budget, should sum up to total_budget
share_type witness_budget = 0;
share_type worker_budget = 0;

// unused budget
share_type leftover_worker_funds = 0;

// change in supply due to budget operations
share_type supply_delta = 0;
};

class budget_record_object;

class budget_record_object : public graphene::db::abstract_object<budget_record_object>
{
public:
static const uint8_t space_id = implementation_ids;
static const uint8_t type_id = impl_budget_record_object_type;

fc::time_point_sec time;
budget_record record;
};

} }

FC_REFLECT(
graphene::chain::budget_record,
(time_since_last_budget)
(from_initial_reserve)
(from_accumulated_fees)
(from_unused_witness_budget)
(requested_witness_budget)
(total_budget)
(witness_budget)
(worker_budget)
(leftover_worker_funds)
(supply_delta)
)

FC_REFLECT_DERIVED(
graphene::chain::budget_record_object,
(graphene::db::object),
(time)
(record)
)
7 changes: 5 additions & 2 deletions libraries/chain/include/graphene/chain/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace graphene { namespace chain {
impl_blinded_balance_object_type,
impl_chain_property_object_type,
impl_witness_schedule_object_type,
impl_reserved1_object_type, // formerly impl_budget_record_object_type, TODO: delete me
impl_budget_record_object_type,
impl_special_authority_object_type,
impl_buyback_object_type,
impl_fba_accumulator_object_type,
Expand Down Expand Up @@ -210,6 +210,7 @@ namespace graphene { namespace chain {
class account_transaction_history_object;
class chain_property_object;
class witness_schedule_object;
class budget_record_object;
class special_authority_object;
class buyback_object;
class fba_accumulator_object;
Expand All @@ -229,6 +230,7 @@ namespace graphene { namespace chain {
account_transaction_history_object> account_transaction_history_id_type;
typedef object_id< implementation_ids, impl_chain_property_object_type, chain_property_object> chain_property_id_type;
typedef object_id< implementation_ids, impl_witness_schedule_object_type, witness_schedule_object> witness_schedule_id_type;
typedef object_id< implementation_ids, impl_budget_record_object_type, budget_record_object > budget_record_id_type;
typedef object_id< implementation_ids, impl_blinded_balance_object_type, blinded_balance_object > blinded_balance_id_type;
typedef object_id< implementation_ids, impl_special_authority_object_type, special_authority_object > special_authority_id_type;
typedef object_id< implementation_ids, impl_buyback_object_type, buyback_object > buyback_id_type;
Expand Down Expand Up @@ -359,7 +361,7 @@ FC_REFLECT_ENUM( graphene::chain::impl_object_type,
(impl_blinded_balance_object_type)
(impl_chain_property_object_type)
(impl_witness_schedule_object_type)
(impl_reserved1_object_type)
(impl_budget_record_object_type)
(impl_special_authority_object_type)
(impl_buyback_object_type)
(impl_fba_accumulator_object_type)
Expand Down Expand Up @@ -391,6 +393,7 @@ FC_REFLECT_TYPENAME( graphene::chain::account_statistics_id_type )
FC_REFLECT_TYPENAME( graphene::chain::transaction_obj_id_type )
FC_REFLECT_TYPENAME( graphene::chain::block_summary_id_type )
FC_REFLECT_TYPENAME( graphene::chain::account_transaction_history_id_type )
FC_REFLECT_TYPENAME( graphene::chain::budget_record_id_type )
FC_REFLECT_TYPENAME( graphene::chain::special_authority_id_type )
FC_REFLECT_TYPENAME( graphene::chain::buyback_id_type )
FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type )
Expand Down
1 change: 1 addition & 0 deletions tests/tests/bitasset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <graphene/chain/hardfork.hpp>

#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/budget_record_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/operation_tests2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <graphene/chain/hardfork.hpp>

#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/budget_record_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/withdraw_permission_object.hpp>
Expand Down Expand Up @@ -2148,6 +2149,14 @@ BOOST_AUTO_TEST_CASE(zero_second_vbo)
BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(0) );
generate_block();
BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(10000) );

/*
db.get_index_type< simple_index<budget_record_object> >().inspect_all_objects(
[&](const object& o)
{
ilog( "budget: ${brec}", ("brec", static_cast<const budget_record_object&>(o)) );
});
*/
}
} FC_LOG_AND_RETHROW()
}
Expand Down

0 comments on commit a0e7dff

Please sign in to comment.