提交 b0d596bd 编写于 作者: D Daniel Larimer

misc cleanup

上级 44a679b8
......@@ -353,7 +353,8 @@ signed_block database::_generate_block(
pending_block.previous = head_block_id();
pending_block.timestamp = when;
pending_block.transaction_merkle_root = pending_block.calculate_merkle_root();
pending_block.producer = producer_id;
pending_block.producer = static_cast<uint16_t>(producer_id._id); //pa.name.c_str(); //producer_id;
if( !(skip & skip_producer_signature) )
pending_block.sign( block_signing_private_key );
......@@ -662,11 +663,10 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create initial producers
std::vector<producer_id_type> initial_producers;
for (const auto& producer : genesis_state.initial_producers) {
auto owner = find<account_object, by_name>(producer.owner_name);
FC_ASSERT(owner != nullptr, "Producer belongs to an unknown account: ${acct}", ("acct", producer.owner_name));
auto id = create<producer_object>([&producer](producer_object& w) {
const auto& owner = get<account_object, by_name>(producer.owner_name);
auto id = create<producer_object>([&](producer_object& w) {
w.signing_key = producer.block_signing_key;
w.owner_name = producer.owner_name.c_str();
w.owner = owner.id;
}).id;
initial_producers.push_back(id);
}
......@@ -679,13 +679,12 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create global properties
create<global_property_object>([&](global_property_object& p) {
p.parameters = genesis_state.initial_parameters;
p.active_producers.resize(initial_producers.size());
//p.active_producers.resize(initial_producers.size());
std::copy(initial_producers.begin(), initial_producers.end(), p.active_producers.begin());
});
create<dynamic_global_property_object>([&](dynamic_global_property_object& p) {
p.time = genesis_state.initial_timestamp;
p.dynamic_flags = 0;
p.recent_slots_filled = fc::uint128::max_value();
p.recent_slots_filled = uint64_t(-1);
});
FC_ASSERT( (genesis_state.immutable_parameters.min_producer_count & 1) == 1, "min_producer_count must be odd" );
......@@ -973,7 +972,7 @@ uint32_t database::get_slot_at_time(fc::time_point_sec when)const
uint32_t database::producer_participation_rate()const
{
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
return uint64_t(EOS_100_PERCENT) * dpo.recent_slots_filled.popcount() / 128;
return uint64_t(EOS_100_PERCENT) * __builtin_popcountll(dpo.recent_slots_filled) / 64;
}
void database::update_producer_schedule()
......
......@@ -128,13 +128,13 @@ namespace eos { namespace chain {
signed_block generate_block(
const fc::time_point_sec when,
producer_id_type producer_id,
producer_id_type producer,
const fc::ecc::private_key& block_signing_private_key,
uint32_t skip
);
signed_block _generate_block(
const fc::time_point_sec when,
producer_id_type producer_id,
producer_id_type producer,
const fc::ecc::private_key& block_signing_private_key
);
......
......@@ -45,15 +45,15 @@ namespace eos { namespace chain {
*/
class global_property_object : public chainbase::object<global_property_object_type, global_property_object>
{
OBJECT_CTOR(global_property_object, (active_producers))
OBJECT_CTOR(global_property_object)
id_type id;
chain_parameters parameters;
optional<chain_parameters> pending_parameters;
shared_vector<producer_id_type> active_producers;
id_type id;
chain_parameters parameters;
std::array<producer_id_type,21> active_producers;
};
/**
* @class dynamic_global_property_object
* @brief Maintains global state information (committee_member list, current fees)
......@@ -65,44 +65,28 @@ namespace eos { namespace chain {
*/
class dynamic_global_property_object : public chainbase::object<dynamic_global_property_object_type, dynamic_global_property_object>
{
OBJECT_CTOR(dynamic_global_property_object)
id_type id;
uint32_t head_block_number = 0;
block_id_type head_block_id;
time_point_sec time;
producer_id_type current_producer;
uint32_t accounts_registered_this_interval = 0;
/**
* Every time a block is missed this increases by
* RECENTLY_MISSED_COUNT_INCREMENT,
* every time a block is found it decreases by
* RECENTLY_MISSED_COUNT_DECREMENT. It is
* never less than 0.
*
* If the recently_missed_count hits 2*UNDO_HISTORY then no new blocks may be pushed.
OBJECT_CTOR(dynamic_global_property_object)
id_type id;
uint32_t head_block_number = 0;
block_id_type head_block_id;
time_point_sec time;
producer_id_type current_producer;
uint32_t accounts_registered_this_interval = 0;
/**
* The current absolute slot number. Equal to the total
* number of slots since genesis. Also equal to the total
* number of missed slots plus head_block_number.
*/
uint64_t current_aslot = 0;
/**
* Used to compute producer participation.
*/
uint32_t recently_missed_count = 0;
/**
* The current absolute slot number. Equal to the total
* number of slots since genesis. Also equal to the total
* number of missed slots plus head_block_number.
*/
uint64_t current_aslot = 0;
/**
* used to compute producer participation.
*/
fc::uint128_t recent_slots_filled;
/**
* dynamic_flags specifies chain state properties that can be
* expressed in one bit.
*/
uint32_t dynamic_flags = 0;
uint32_t last_irreversible_block_num = 0;
uint64_t recent_slots_filled;
uint32_t last_irreversible_block_num = 0;
};
using global_property_multi_index = chainbase::shared_multi_index_container<
......@@ -113,6 +97,7 @@ namespace eos { namespace chain {
>
>
>;
using dynamic_global_property_multi_index = chainbase::shared_multi_index_container<
dynamic_global_property_object,
indexed_by<
......@@ -136,12 +121,10 @@ FC_REFLECT(eos::chain::dynamic_global_property_object,
(accounts_registered_this_interval)
(current_aslot)
(recent_slots_filled)
(dynamic_flags)
(last_irreversible_block_num)
)
FC_REFLECT(eos::chain::global_property_object,
(parameters)
(pending_parameters)
(active_producers)
)
......@@ -7,24 +7,32 @@ namespace eos { namespace chain {
/**
* @brief The message struct defines a blockchain message
*
* Messages are the heart of all activity on the blockchain -- all events and actions which take place in the chain are
* recorded as messages. Messages are sent from one account (@ref sender) to another account (@ref recipient), and are
* Messages are the heart of all activity on the blockchain,
* -- all events and actions which take place in the chain are
* recorded as messages. Messages are sent from one account
* (@ref sender) to another account (@ref recipient), and are
* optionally also delivered to several other accounts (@ref notify_accounts).
*
* A message has a header that defines who sent it and who will be processing it. The message content is a binary blob,
* @ref data, whose type is determined by @ref type, which is dynamic and defined by the scripting language.
* A message has a header that defines who sent it and who will
* be processing it. The message content is a binary blob,
* @ref data, whose type is determined by @ref type, which is
* dynamic and defined by the scripting language.
*/
struct message {
/// The account which sent the message
account_name sender;
account_name sender;
/// The account to receive the message
account_name recipient;
account_name recipient;
/// Other accounts to notify about this message
vector<account_name> notify_accounts;
/// The message type -- this is defined by the contract(s) which create and/or process this message
message_type type;
message_type type;
/// The message contents
vector<char> data;
vector<char> data;
};
} } // namespace eos::chain
......
......@@ -29,22 +29,23 @@
namespace eos { namespace chain {
class producer_object : public chainbase::object<producer_object_type, producer_object>
{
OBJECT_CTOR(producer_object, (owner_name)(url))
OBJECT_CTOR(producer_object)
id_type id;
shared_string owner_name;
account_id_type owner;
uint64_t last_aslot = 0;
public_key_type signing_key;
shared_string url;
int64_t total_missed = 0;
uint32_t last_confirmed_block_num = 0;
};
struct by_key;
struct by_owner;
using producer_multi_index = chainbase::shared_multi_index_container<
producer_object,
indexed_by<
ordered_unique<tag<by_id>, member<producer_object, producer_object::id_type, &producer_object::id>>,
ordered_unique<tag<by_owner>, member<producer_object, account_id_type, &producer_object::owner>>,
ordered_non_unique<tag<by_key>, member<producer_object, public_key_type, &producer_object::signing_key>>
>
>;
......@@ -54,10 +55,9 @@ CHAINBASE_SET_INDEX_TYPE(eos::chain::producer_object, eos::chain::producer_multi
FC_REFLECT(eos::chain::producer_object,
(id)
(owner_name)
(owner)
(last_aslot)
(signing_key)
(url)
(total_missed)
(last_confirmed_block_num)
)
......@@ -29,13 +29,14 @@ namespace eos { namespace chain {
struct block_header
{
digest_type digest()const;
block_id_type previous;
uint32_t block_num()const { return num_from_id(previous) + 1; }
static uint32_t num_from_id(const block_id_type& id);
block_id_type previous;
fc::time_point_sec timestamp;
producer_id_type producer;
checksum_type transaction_merkle_root;
static uint32_t num_from_id(const block_id_type& id);
uint16_t producer = 0;
};
struct signed_block_header : public block_header
......@@ -66,7 +67,7 @@ namespace eos { namespace chain {
} } // eos::chain
FC_REFLECT(eos::chain::block_header, (previous)(timestamp)(producer)(transaction_merkle_root))
FC_REFLECT(eos::chain::block_header, (previous)(timestamp)(transaction_merkle_root)(producer) )
FC_REFLECT_DERIVED(eos::chain::signed_block_header, (eos::chain::block_header), (producer_signature))
FC_REFLECT(eos::chain::thread, (generated_input)(user_input)(output_transactions))
FC_REFLECT_DERIVED(eos::chain::signed_block, (eos::chain::signed_block_header), (cycles))
......@@ -131,7 +131,7 @@ namespace eos { namespace chain {
class account_object;
class producer_object;
using account_id_type = chainbase::oid<account_object>;
using account_id_type = chainbase::oid<account_object>;
using producer_id_type = chainbase::oid<producer_object>;
using block_id_type = fc::ripemd160;
......
......@@ -156,12 +156,12 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
auto rsf = [&]() -> string
{
fc::uint128 rsf = db.get_dynamic_global_properties().recent_slots_filled;
auto rsf = db.get_dynamic_global_properties().recent_slots_filled;
string result = "";
result.reserve(128);
for( int i=0; i<128; i++ )
result.reserve(64);
for( int i=0; i<64; i++ )
{
result += ((rsf.lo & 1) == 0) ? '0' : '1';
result += ((rsf & 1) == 0) ? '0' : '1';
rsf >>= 1;
}
return result;
......@@ -169,104 +169,96 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
auto pct = []( uint32_t x ) -> uint32_t
{
return uint64_t( EOS_100_PERCENT ) * x / 128;
return uint64_t( EOS_100_PERCENT ) * x / 64;
};
BOOST_CHECK_EQUAL( rsf(),
"1111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), EOS_100_PERCENT );
db.produce_blocks(1, 1);
BOOST_CHECK_EQUAL( rsf(),
"0111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(127) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(127-64) );
db.produce_blocks(1, 1);
BOOST_CHECK_EQUAL( rsf(),
"0101111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(126) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(126-64) );
db.produce_blocks(1, 2);
BOOST_CHECK_EQUAL( rsf(),
"0010101111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(124) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(124-64) );
db.produce_blocks(1, 3);
BOOST_CHECK_EQUAL( rsf(),
"0001001010111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(121) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(121-64) );
db.produce_blocks(1, 5);
BOOST_CHECK_EQUAL( rsf(),
"0000010001001010111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(116) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(116-64) );
db.produce_blocks(1, 8);
BOOST_CHECK_EQUAL( rsf(),
"0000000010000010001001010111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(108) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(108-64) );
db.produce_blocks(1, 13);
BOOST_CHECK_EQUAL( rsf(),
"0000000000000100000000100000100010010101111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );
db.produce_blocks();
BOOST_CHECK_EQUAL( rsf(),
"1000000000000010000000010000010001001010111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );
db.produce_blocks();
BOOST_CHECK_EQUAL( rsf(),
"1100000000000001000000001000001000100101011111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );
db.produce_blocks();
BOOST_CHECK_EQUAL( rsf(),
"1110000000000000100000000100000100010010101111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );
db.produce_blocks();
BOOST_CHECK_EQUAL( rsf(),
"1111000000000000010000000010000010001001010111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95) );
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(95-64) );
db.produce_blocks(1, 64);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000000000000000000000000000000000000"
"1111100000000000001000000001000001000100101011111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(31) );
*/
db.produce_blocks(1, 32);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000010000000000000000000000000000000"
"0000000000000000000000000000000001111100000000000001000000001000"
);
*/
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(8) );
} FC_LOG_AND_RETHROW() }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册