提交 411da9d8 编写于 作者: N Nathan Hourt

Create initial producers with messages

Previously, we created the initial producers by manually making the
producer_object's in prepare_database. Now we create them by creating
Messages directing their creation, and invoking the normal
CreateProducer infrastructure.
上级 d0b21702
......@@ -802,8 +802,6 @@ void chain_controller::initialize_chain(chain_initializer& starter)
uint32_t old_flags;
} inhibitor(*this);
auto messages = starter.prepare_database(*this, _db);
auto initial_timestamp = starter.get_chain_start_time();
FC_ASSERT(initial_timestamp != time_point_sec(), "Must initialize genesis timestamp." );
FC_ASSERT(initial_timestamp.sec_since_epoch() % config::BlockIntervalSeconds == 0,
......@@ -823,6 +821,7 @@ void chain_controller::initialize_chain(chain_initializer& starter)
for (int i = 0; i < 0x10000; i++)
_db.create<block_summary_object>([&](block_summary_object&) {});
auto messages = starter.prepare_database(*this, _db);
std::for_each(messages.begin(), messages.end(), [this](const auto& m) { process_message(m); });
});
}
......
......@@ -53,6 +53,14 @@ namespace eos { namespace chain {
class chain_initializer {
public:
virtual ~chain_initializer();
/// Retrieve the timestamp to use as the blockchain start time
virtual types::Time get_chain_start_time() = 0;
/// Retrieve the BlockchainConfiguration to use at blockchain start
virtual BlockchainConfiguration get_chain_start_configuration() = 0;
/// Retrieve the first round of block producers
virtual std::array<AccountName, config::ProducerCount> get_chain_start_producers() = 0;
/**
* @brief Prepare the database, creating objects and defining state which should exist before the first block
* @param chain A reference to the @ref chain_controller
......@@ -60,24 +68,22 @@ namespace eos { namespace chain {
* @param A list of @ref Message "Messages" to be applied before the first block
*
* This method creates the @ref account_object "account_objects" and @ref producer_object "producer_objects" for
* at least the initial block producers.
* at least the initial block producers returned by @ref get_chain_start_producers
*
* This method also provides an opportunity to create objects and setup the database to the state it should be in
* prior to the first block. This method should only initialize state that the @ref chain_controller itself does
* not understand. The other methods will be called to retrieve the data necessary to initialize chain state the
* controller does understand.
* not understand. The other methods on @ref chain_initializer are called to retrieve the data necessary to
* initialize chain state the controller does understand, including the initial round of block producers and the
* initial @ref BlockchainConfiguration.
*
* Finally, this method may perform any necessary initializations on the chain and/or database, such as
* installing indexes and message handlers that should be defined before the first block is processed. This may
* be necessary in order for the returned list of messages to be processed successfully.
*
* This method is called at the end of chain initialization, after setting the state used in core chain
* operations.
*/
virtual vector<Message> prepare_database(chain_controller& chain, database& db) = 0;
/// Retrieve the timestamp to use as the blockchain start time
virtual types::Time get_chain_start_time() = 0;
/// Retrieve the BlockchainConfiguration to use at blockchain start
virtual BlockchainConfiguration get_chain_start_configuration() = 0;
/// Retrieve the first round of block producers
virtual std::array<AccountName, config::ProducerCount> get_chain_start_producers() = 0;
};
/**
......
......@@ -6,6 +6,9 @@
#include <eos/chain/producer_object.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/copy.hpp>
namespace eos { namespace native_contract {
using namespace chain;
......@@ -90,14 +93,11 @@ std::vector<chain::Message> native_contract_chain_initializer::prepare_database(
}
// Create initial producers
std::vector<types::AccountName> initial_producers;
for (const auto& producer : genesis.initial_producers) {
db.create<producer_object>([&](producer_object& p) {
p.signing_key = producer.block_signing_key;
p.owner = producer.owner_name;
});
initial_producers.push_back(producer.owner_name);
}
auto CreateProducer = boost::adaptors::transformed([config = genesis.initial_configuration](const auto& p) {
return chain::Message(config::SystemContractName, config::StakedBalanceContractName, vector<AccountName>{},
"CreateProducer", types::CreateProducer(p.owner_name, p.block_signing_key, config));
});
boost::copy(genesis.initial_producers | CreateProducer, std::back_inserter(messages_to_process));
return messages_to_process;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册