提交 692c49a8 编写于 作者: N Nathan Hourt

Cleanup in chain_controller

Remove the node_property_object, and other cruft.
上级 8eb17ff1
......@@ -178,9 +178,9 @@ bool chain_controller::push_block(const signed_block& new_block, uint32_t skip)
bool chain_controller::_push_block(const signed_block& new_block)
{ try {
uint32_t skip = get_node_properties().skip_flags;
uint32_t skip = _skip_flags;
if (!(skip&skip_fork_db)) {
/// TODO: if the block is greater than the head block and before the next maitenance interval
/// TODO: if the block is greater than the head block and before the next maintenance interval
// verify that the block signer is in the current set of active producers.
shared_ptr<fork_item> new_head = _fork_db.push_block(new_block);
......@@ -259,10 +259,8 @@ bool chain_controller::_push_block(const signed_block& new_block)
void chain_controller::push_transaction(const SignedTransaction& trx, uint32_t skip)
{ try {
with_skip_flags(skip, [&]() {
with_producing([&](){
_db.with_write_lock([&]() {
_push_transaction(trx);
});
_db.with_write_lock([&]() {
_push_transaction(trx);
});
});
} FC_CAPTURE_AND_RETHROW((trx)) }
......@@ -293,15 +291,13 @@ signed_block chain_controller::generate_block(
uint32_t skip /* = 0 */
)
{ try {
return with_producing( [&]() {
return with_skip_flags( skip, [&](){
auto b = _db.with_write_lock( [&](){
return _generate_block( when, producer, block_signing_private_key );
});
push_block(b);
return b;
return with_skip_flags( skip, [&](){
auto b = _db.with_write_lock( [&](){
return _generate_block( when, producer, block_signing_private_key );
});
});
push_block(b, skip);
return b;
});
} FC_CAPTURE_AND_RETHROW( (when) ) }
signed_block chain_controller::_generate_block(
......@@ -311,7 +307,7 @@ signed_block chain_controller::_generate_block(
)
{
try {
uint32_t skip = get_node_properties().skip_flags;
uint32_t skip = _skip_flags;
uint32_t slot_num = get_slot_at_time( when );
FC_ASSERT( slot_num > 0 );
AccountName scheduled_producer = get_scheduled_producer( slot_num );
......@@ -454,11 +450,10 @@ void chain_controller::apply_block(const signed_block& next_block, uint32_t skip
with_skip_flags(skip, [&](){ _apply_block(next_block); });
}
void chain_controller::_apply_block(const signed_block& next_block)
{ try {
uint32_t next_block_num = next_block.block_num();
uint32_t skip = get_node_properties().skip_flags;
uint32_t skip = _skip_flags;
FC_ASSERT((skip & skip_merkle_check) || next_block.transaction_merkle_root == next_block.calculate_merkle_root(),
"", ("next_block.transaction_merkle_root", next_block.transaction_merkle_root)
......@@ -752,18 +747,10 @@ types::AccountName chain_controller::head_block_producer() const {
return {};
}
const node_property_object& chain_controller::get_node_properties()const {
return _node_property_object;
}
const producer_object& chain_controller::get_producer(const types::AccountName& ownerName) const {
return _db.get<producer_object, by_owner>(ownerName);
}
node_property_object& chain_controller::node_properties() {
return _node_property_object;
}
uint32_t chain_controller::last_irreversible_block_num() const {
return get_dynamic_global_properties().last_irreversible_block_num;
}
......@@ -785,16 +772,6 @@ void chain_controller::initialize_chain(chain_initializer_interface& starter)
{ try {
if (!_db.find<global_property_object>()) {
_db.with_write_lock([this, &starter] {
struct auth_inhibitor {
auth_inhibitor(chain_controller& db) : db(db), old_flags(db.node_properties().skip_flags)
{ db.node_properties().skip_flags |= skip_authority_check; }
~auth_inhibitor()
{ db.node_properties().skip_flags = old_flags; }
private:
chain_controller& db;
uint32_t old_flags;
} inhibitor(*this);
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,
......
......@@ -24,7 +24,6 @@
#pragma once
#include <eos/chain/global_property_object.hpp>
#include <eos/chain/account_object.hpp>
#include <eos/chain/node_property_object.hpp>
#include <eos/chain/fork_database.hpp>
#include <eos/chain/block_log.hpp>
......@@ -149,16 +148,6 @@ namespace eos { namespace chain {
return f();
}
template<typename Function>
auto with_producing( Function&& f ) -> decltype((*((Function*)nullptr))())
{
auto old_producing = _producing;
auto on_exit = fc::make_scoped_exit( [&](){ _producing = old_producing; } );
_producing = true;
return f();
}
template<typename Function>
auto without_pending_transactions( Function&& f ) -> decltype((*((Function*)nullptr))())
{
......@@ -174,13 +163,9 @@ namespace eos { namespace chain {
return f();
}
void pop_block();
void clear_pending();
/**
* @brief Get the producer scheduled for block production in a slot.
*
......@@ -219,7 +204,6 @@ namespace eos { namespace chain {
const global_property_object& get_global_properties()const;
const dynamic_global_property_object& get_dynamic_global_properties()const;
const node_property_object& get_node_properties()const;
const producer_object& get_producer(const AccountName& ownerName)const;
time_point_sec head_block_time()const;
......@@ -229,8 +213,6 @@ namespace eos { namespace chain {
uint32_t block_interval()const { return config::BlockIntervalSeconds; }
node_property_object& node_properties();
uint32_t last_irreversible_block_num() const;
protected:
......@@ -297,14 +279,11 @@ namespace eos { namespace chain {
optional<database::session> _pending_tx_session;
deque<SignedTransaction> _pending_transactions;
bool _producing = false;
bool _pushing = false;
uint64_t _skip_flags = 0;
flat_map<uint32_t,block_id_type> _checkpoints;
node_property_object _node_property_object;
typedef pair<AccountName,TypeName> handler_key;
map< AccountName, map<handler_key, message_validate_handler> > message_validate_handlers;
map< AccountName, map<handler_key, precondition_validate_handler> > precondition_validate_handlers;
......
/*
* Copyright (c) 2017, Respective Authors.
*
* 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 <eos/chain/types.hpp>
namespace eos { namespace chain {
/**
* @brief Contains per-node database configuration.
*
* Transactions are evaluated differently based on per-node state.
* Settings here may change based on whether the node is syncing or up-to-date.
* Or whether the node is a producer node. Or if we're processing a
* transaction in a producer-signed block vs. a fresh transaction
* from the p2p network. Or configuration-specified tradeoffs of
* performance/hardfork resilience vs. paranoia.
*/
class node_property_object
{
public:
node_property_object(){}
~node_property_object(){}
uint32_t skip_flags = 0;
std::map< block_id_type, std::vector< fc::variant_object > > debug_updates;
};
} } // eos::chain
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册