未验证 提交 993215c1 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #2762 from wanderingbort/feature/integrate-slim-net

integrate slim net plugin
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class hello : public eosio::contract {
......
......@@ -3,7 +3,7 @@
## ACTION NAME: hi
### Parameters
Input paramters:
Input parameters:
* `user` (string to include in the output)
......
......@@ -130,6 +130,9 @@ struct controller_impl {
}
}
void emit_transaction(const transaction_metadata_ptr& trx, const transaction_trace_ptr& trace) {
}
void on_irreversible( const block_state_ptr& s ) {
if( !blog.head() )
......@@ -547,6 +550,11 @@ struct controller_impl {
(trx->on_result)(trace);
trx->on_result = decltype(trx->on_result)(); //assign empty std::function
}
if (!trx->accepted) {
emit( self.accepted_transaction, trx);
trx->accepted = true;
}
}
/**
......@@ -609,8 +617,8 @@ struct controller_impl {
fc::move_append( pending->_actions, move(trx_context.executed) );
transaction_trace_notify( trx, trace );
emit( self.applied_transaction, trace );
trx_context.squash();
return;
} catch( ... ) {
......@@ -620,8 +628,10 @@ struct controller_impl {
throw;
}
} catch( const fc::exception& e ) {
trace->hard_except = e;
trace->hard_except_ptr = std::current_exception();
if (trace) {
trace->hard_except = e;
trace->hard_except_ptr = std::current_exception();
}
}
transaction_trace_notify( trx, trace );
} FC_CAPTURE_AND_RETHROW() } /// push_transaction
......@@ -1163,13 +1173,10 @@ void controller::log_irreversible_blocks() {
*/
}
signed_block_ptr controller::fetch_block_by_id( block_id_type id )const {
idump((id));
auto state = my->fork_db.get_block(id);
if( state ) return state->block;
edump((block_header::num_from_id(id)));
auto bptr = fetch_block_by_number( block_header::num_from_id(id) );
if( bptr && bptr->id() == id ) return bptr;
elog( "not found" );
return signed_block_ptr();
}
......@@ -1179,10 +1186,18 @@ signed_block_ptr controller::fetch_block_by_number( uint32_t block_num )const {
return blk_state->block;
}
ilog( "blog read by number ${n}", ("n", block_num) );
return my->blog.read_block_by_num(block_num);
} FC_CAPTURE_AND_RETHROW( (block_num) ) }
block_id_type controller::get_block_id_for_num( uint32_t block_num )const { try {
auto blk_state = my->fork_db.get_block_in_current_chain_by_num( block_num );
if( blk_state ) {
return blk_state->id;
}
return my->blog.read_block_by_num(block_num)->id();
} FC_CAPTURE_AND_RETHROW( (block_num) ) }
void controller::pop_block() {
my->pop_block();
}
......
......@@ -136,6 +136,8 @@ namespace eosio { namespace chain {
signed_block_ptr fetch_block_by_number( uint32_t block_num )const;
signed_block_ptr fetch_block_by_id( block_id_type id )const;
block_id_type get_block_id_for_num( uint32_t block_num )const;
void validate_referenced_accounts( const transaction& t )const;
void validate_expiration( const transaction& t )const;
void validate_tapos( const transaction& t )const;
......
......@@ -128,6 +128,7 @@ namespace eosio { namespace chain {
bytes packed_context_free_data;
bytes packed_trx;
time_point_sec expiration()const;
transaction_id_type id()const;
bytes get_raw_transaction()const;
vector<bytes> get_context_free_data()const;
......@@ -135,6 +136,10 @@ namespace eosio { namespace chain {
signed_transaction get_signed_transaction()const;
void set_transaction(const transaction& t, compression_type _compression = none);
void set_transaction(const transaction& t, const vector<bytes>& cfd, compression_type _compression = none);
private:
mutable optional<transaction> unpacked_trx; // <-- intermediate buffer used to retrieve values
void local_unpack()const;
};
using packed_transaction_ptr = std::shared_ptr<packed_transaction>;
......
......@@ -20,6 +20,7 @@ class transaction_metadata {
signed_transaction trx;
packed_transaction packed_trx;
optional<flat_set<public_key_type>> signing_keys;
bool accepted = false;
std::function<void(const transaction_trace_ptr&)> on_result;
......
......@@ -281,25 +281,40 @@ vector<bytes> packed_transaction::get_context_free_data()const
} FC_CAPTURE_AND_RETHROW((compression)(packed_context_free_data))
}
time_point_sec packed_transaction::expiration()const
{
local_unpack();
return unpacked_trx->expiration;
}
transaction_id_type packed_transaction::id()const
{
try {
return get_transaction().id();
} FC_CAPTURE_AND_RETHROW((compression)(packed_trx))
local_unpack();
return get_transaction().id();
}
transaction packed_transaction::get_transaction()const
void packed_transaction::local_unpack()const
{
try {
switch(compression) {
if (!unpacked_trx) {
try {
switch(compression) {
case none:
return unpack_transaction(packed_trx);
unpacked_trx = unpack_transaction(packed_trx);
break;
case zlib:
return zlib_decompress_transaction(packed_trx);
unpacked_trx = zlib_decompress_transaction(packed_trx);
break;
default:
FC_THROW("Unknown transaction compression algorithm");
}
} FC_CAPTURE_AND_RETHROW((compression)(packed_trx))
}
} FC_CAPTURE_AND_RETHROW((compression)(packed_trx))
}
}
transaction packed_transaction::get_transaction()const
{
local_unpack();
return transaction(*unpacked_trx);
}
signed_transaction packed_transaction::get_signed_transaction() const
......
......@@ -138,15 +138,6 @@ else()
set( ZLIB_LIBRARIES "" )
endif( ZLIB_FOUND )
find_package( BZip2 )
if( BZIP2_FOUND )
MESSAGE( STATUS "bzip2 found" )
add_definitions( -DHAS_BZIP2 )
else()
MESSAGE( STATUS "bzip2 not found" )
set( BZIP2_LIBRARIES "" )
endif( BZIP2_FOUND )
# This will become unnecessary once we update to websocketpp which fixes upstream issue #395
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBSOCKETPP_STRICT_MASKING")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_ASIO_HAS_STD_CHRONO")
......@@ -162,7 +153,7 @@ target_include_directories(fc
IF(NOT WIN32)
set(LINK_USR_LOCAL_LIB -L/usr/local/lib)
ENDIF()
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} )
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} )
SET(OPENSSL_CONF_TARGET )
......
......@@ -34,15 +34,14 @@ namespace fc { namespace crypto {
template<typename Result, const char * const * Prefixes, int Position, typename KeyType, typename ...Rem>
struct base58_str_parser_impl<Result, Prefixes, Position, KeyType, Rem...> {
static Result apply(const std::string& base58str)
static Result apply(const std::string& prefix_str, const std::string& data_str)
{
using data_type = typename KeyType::data_type;
using wrapper = checksummed_data<data_type>;
constexpr auto prefix = Prefixes[Position];
if (prefix_matches(prefix, base58str)) {
auto str = base58str.substr(const_strlen(prefix));
auto bin = fc::from_base58(str);
if (prefix == prefix_str) {
auto bin = fc::from_base58(data_str);
FC_ASSERT(bin.size() >= sizeof(data_type) + sizeof(uint32_t));
auto wrapped = fc::raw::unpack<wrapper>(bin);
auto checksum = wrapper::calculate_checksum(wrapped.data, prefix);
......@@ -50,14 +49,14 @@ namespace fc { namespace crypto {
return Result(KeyType(wrapped.data));
}
return base58_str_parser_impl<Result, Prefixes, Position + 1, Rem...>::apply(base58str);
return base58_str_parser_impl<Result, Prefixes, Position + 1, Rem...>::apply(prefix_str, data_str);
}
};
template<typename Result, const char * const * Prefixes, int Position>
struct base58_str_parser_impl<Result, Prefixes, Position> {
static Result apply(const std::string& base58str) {
FC_ASSERT(false, "No matching prefix for ${str}", ("str", base58str));
static Result apply(const std::string& prefix_str, const std::string& data_str ) {
FC_ASSERT(false, "No matching suite type for ${prefix}_${data}", ("prefix", prefix_str)("data",data_str));
}
};
......@@ -73,7 +72,14 @@ namespace fc { namespace crypto {
template<const char * const * Prefixes, typename ...Ts>
struct base58_str_parser<fc::static_variant<Ts...>, Prefixes> {
static fc::static_variant<Ts...> apply(const std::string& base58str) {
return base58_str_parser_impl<fc::static_variant<Ts...>, Prefixes, 0, Ts...>::apply(base58str);
const auto pivot = base58str.find('_');
FC_ASSERT(pivot != std::string::npos, "No delimiter in data, cannot determine suite type: ${str}", ("str", base58str));
const auto prefix_str = base58str.substr(0, pivot);
auto data_str = base58str.substr(pivot + 1);
FC_ASSERT(!data_str.empty(), "Data only has suite type prefix: ${str}", ("str", base58str));
return base58_str_parser_impl<fc::static_variant<Ts...>, Prefixes, 0, Ts...>::apply(prefix_str, data_str);
}
};
......@@ -91,7 +97,7 @@ namespace fc { namespace crypto {
auto packed = raw::pack( wrapper );
auto data_str = to_base58( packed.data(), packed.size() );
if (!is_default) {
data_str = string(Prefixes[position]) + data_str;
data_str = string(Prefixes[position]) + "_" + data_str;
}
return data_str;
......
......@@ -9,7 +9,7 @@
namespace fc { namespace crypto {
namespace config {
constexpr const char* private_key_base_prefix = "EOS";
constexpr const char* private_key_base_prefix = "PVT";
constexpr const char* private_key_prefix[] = {
"K1",
"R1"
......
......@@ -8,7 +8,8 @@
namespace fc { namespace crypto {
namespace config {
constexpr const char* public_key_base_prefix = "EOS";
constexpr const char* public_key_legacy_prefix = "EOS";
constexpr const char* public_key_base_prefix = "PUB";
constexpr const char* public_key_prefix[] = {
"K1",
"R1"
......
......@@ -7,7 +7,7 @@
namespace fc { namespace crypto {
namespace config {
constexpr const char* signature_base_prefix = "EOS";
constexpr const char* signature_base_prefix = "SIG";
constexpr const char* signature_prefix[] = {
"K1",
"R1"
......
......@@ -90,18 +90,23 @@ namespace fc { namespace crypto {
static private_key::storage_type parse_base58(const string& base58str)
{
try {
if (base58str.find('_') == std::string::npos) {
// wif import
using default_type = private_key::storage_type::template type_at<0>;
return private_key::storage_type(from_wif<default_type>(base58str));
} catch (...) {
// wif import failed
}
} else {
constexpr auto prefix = config::private_key_base_prefix;
const auto pivot = base58str.find('_');
FC_ASSERT(pivot != std::string::npos, "No delimiter in string, cannot determine type: ${str}", ("str", base58str));
constexpr auto prefix = config::private_key_base_prefix;
FC_ASSERT(prefix_matches(prefix, base58str), "Private Key has invalid prefix: ${str}", ("str", base58str));
auto sub_str = base58str.substr(const_strlen(prefix));
return base58_str_parser<private_key::storage_type, config::private_key_prefix>::apply(sub_str);
const auto prefix_str = base58str.substr(0, pivot);
FC_ASSERT(prefix == prefix_str, "Private Key has invalid prefix: ${str}", ("str", base58str)("prefix_str", prefix_str));
auto data_str = base58str.substr(pivot + 1);
FC_ASSERT(!data_str.empty(), "Private Key has no data: ${str}", ("str", base58str));
return base58_str_parser<private_key::storage_type, config::private_key_prefix>::apply(data_str);
}
}
private_key::private_key(const std::string& base58str)
......@@ -118,7 +123,7 @@ namespace fc { namespace crypto {
}
auto data_str = _storage.visit(base58str_visitor<storage_type, config::private_key_prefix>());
return std::string(config::private_key_base_prefix) + data_str;
return std::string(config::private_key_base_prefix) + "_" + data_str;
}
std::ostream& operator<<(std::ostream& s, const private_key& k) {
......
......@@ -26,25 +26,30 @@ namespace fc { namespace crypto {
static public_key::storage_type parse_base58(const std::string& base58str)
{
constexpr auto prefix = config::public_key_base_prefix;
FC_ASSERT(prefix_matches(prefix, base58str), "Public Key has invalid prefix: ${str}", ("str", base58str));
auto sub_str = base58str.substr(const_strlen(prefix));
try {
constexpr auto legacy_prefix = config::public_key_legacy_prefix;
if(prefix_matches(legacy_prefix, base58str) && base58str.find('_') == std::string::npos ) {
auto sub_str = base58str.substr(const_strlen(legacy_prefix));
using default_type = typename public_key::storage_type::template type_at<0>;
using data_type = default_type::data_type;
using wrapper = checksummed_data<data_type>;
auto bin = fc::from_base58(sub_str);
if (bin.size() == sizeof(data_type) + sizeof(uint32_t)) {
auto wrapped = fc::raw::unpack<wrapper>(bin);
FC_ASSERT(wrapper::calculate_checksum(wrapped.data) == wrapped.check);
return public_key::storage_type(default_type(wrapped.data));
}
} catch (...) {
// default import failed
FC_ASSERT(bin.size() == sizeof(data_type) + sizeof(uint32_t), "");
auto wrapped = fc::raw::unpack<wrapper>(bin);
FC_ASSERT(wrapper::calculate_checksum(wrapped.data) == wrapped.check);
return public_key::storage_type(default_type(wrapped.data));
} else {
constexpr auto prefix = config::public_key_base_prefix;
const auto pivot = base58str.find('_');
FC_ASSERT(pivot != std::string::npos, "No delimiter in string, cannot determine data type: ${str}", ("str", base58str));
const auto prefix_str = base58str.substr(0, pivot);
FC_ASSERT(prefix == prefix_str, "Public Key has invalid prefix: ${str}", ("str", base58str)("prefix_str", prefix_str));
auto data_str = base58str.substr(pivot + 1);
FC_ASSERT(!data_str.empty(), "Public Key has no data: ${str}", ("str", base58str));
return base58_str_parser<public_key::storage_type, config::public_key_prefix>::apply(data_str);
}
return base58_str_parser<public_key::storage_type, config::public_key_prefix>::apply(sub_str);
}
public_key::public_key(const std::string& base58str)
......@@ -66,7 +71,13 @@ namespace fc { namespace crypto {
public_key::operator std::string() const
{
auto data_str = _storage.visit(base58str_visitor<storage_type, config::public_key_prefix, 0>());
return std::string(config::public_key_base_prefix) + data_str;
auto which = _storage.which();
if (which == 0) {
return std::string(config::public_key_legacy_prefix) + data_str;
} else {
return std::string(config::public_key_base_prefix) + "_" + data_str;
}
}
std::ostream& operator<<(std::ostream& s, const public_key& k) {
......
......@@ -15,24 +15,16 @@ namespace fc { namespace crypto {
static signature::storage_type parse_base58(const std::string& base58str)
{
constexpr auto prefix = config::signature_base_prefix;
FC_ASSERT(prefix_matches(prefix, base58str), "Signature has invalid prefix: ${str}", ("str", base58str));
auto sub_str = base58str.substr(const_strlen(prefix));
try {
using default_type = signature::storage_type::template type_at<0>;
using data_type = default_type::data_type;
using wrapper = checksummed_data<data_type>;
auto bin = fc::from_base58(sub_str);
if (bin.size() == sizeof(data_type) + sizeof(uint32_t)) {
auto wrapped = fc::raw::unpack<wrapper>(bin);
FC_ASSERT(wrapper::calculate_checksum(wrapped.data) == wrapped.check);
return signature::storage_type(default_type(wrapped.data));
}
} catch (...) {
// default import failed
}
const auto pivot = base58str.find('_');
FC_ASSERT(pivot != std::string::npos, "No delimiter in string, cannot determine type: ${str}", ("str", base58str));
const auto prefix_str = base58str.substr(0, pivot);
FC_ASSERT(prefix == prefix_str, "Signature Key has invalid prefix: ${str}", ("str", base58str)("prefix_str", prefix_str));
return base58_str_parser<signature::storage_type, config::signature_prefix>::apply(sub_str);
auto data_str = base58str.substr(pivot + 1);
FC_ASSERT(!data_str.empty(), "Signature has no data: ${str}", ("str", base58str));
return base58_str_parser<signature::storage_type, config::signature_prefix>::apply(data_str);
}
signature::signature(const std::string& base58str)
......@@ -41,8 +33,8 @@ namespace fc { namespace crypto {
signature::operator std::string() const
{
auto data_str = _storage.visit(base58str_visitor<storage_type, config::signature_prefix, 0>());
return std::string(config::signature_base_prefix) + data_str;
auto data_str = _storage.visit(base58str_visitor<storage_type, config::signature_prefix>());
return std::string(config::signature_base_prefix) + "_" + data_str;
}
std::ostream& operator<<(std::ostream& s, const signature& k) {
......
......@@ -21,8 +21,8 @@ BOOST_AUTO_TEST_CASE(test_k1) try {
} FC_LOG_AND_RETHROW();
BOOST_AUTO_TEST_CASE(test_r1) try {
auto private_key_string = std::string("EOSR1iyQmnyPEGvFd8uffnk152WC2WryBjgTrg22fXQryuGL9mU6qW");
auto expected_public_key = std::string("EOSR16EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4");
auto private_key_string = std::string("PVT_R1_iyQmnyPEGvFd8uffnk152WC2WryBjgTrg22fXQryuGL9mU6qW");
auto expected_public_key = std::string("PUB_R1_6EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4");
auto test_private_key = private_key(private_key_string);
auto test_public_key = test_private_key.get_public_key();
......
#add_subdirectory(net_plugin)
#add_subdirectory(net_api_plugin)
add_subdirectory(net_plugin)
add_subdirectory(net_api_plugin)
add_subdirectory(http_plugin)
add_subdirectory(chain_plugin)
add_subdirectory(chain_api_plugin)
......@@ -11,7 +11,7 @@ add_subdirectory(history_api_plugin)
#add_subdirectory(account_history_api_plugin)
add_subdirectory(wallet_plugin)
add_subdirectory(wallet_api_plugin)
#add_subdirectory(txn_test_gen_plugin)
add_subdirectory(txn_test_gen_plugin)
#add_subdirectory(faucet_testnet_plugin)
#add_subdirectory(mongo_db_plugin)
......
......@@ -76,7 +76,7 @@ public:
// transaction.id -> actions
std::map<std::string, std::vector<chain::action>> reversible_actions;
boost::mutex mtx;
boost::condition_variable condtion;
boost::condition_variable condition;
boost::thread consume_thread;
boost::atomic<bool> done{false};
boost::atomic<bool> startup{true};
......@@ -116,7 +116,7 @@ void mongo_db_plugin_impl::applied_irreversible_block(const signed_block& block)
boost::mutex::scoped_lock lock(mtx);
signed_block_queue.push_back(block);
lock.unlock();
condtion.notify_one();
condition.notify_one();
}
} catch (fc::exception& e) {
elog("FC Exception while applied_irreversible_block ${e}", ("e", e.to_string()));
......@@ -136,7 +136,7 @@ void mongo_db_plugin_impl::applied_block(const block_trace& bt) {
boost::mutex::scoped_lock lock(mtx);
block_trace_queue.emplace_back(std::make_pair(bt, bt.block));
lock.unlock();
condtion.notify_one();
condition.notify_one();
}
} catch (fc::exception& e) {
elog("FC Exception while applied_block ${e}", ("e", e.to_string()));
......@@ -152,7 +152,7 @@ void mongo_db_plugin_impl::consume_blocks() {
while (true) {
boost::mutex::scoped_lock lock(mtx);
while (signed_block_queue.empty() && block_trace_queue.empty() && !done) {
condtion.wait(lock);
condition.wait(lock);
}
// capture blocks for processing
size_t block_trace_size = block_trace_queue.size();
......@@ -705,7 +705,7 @@ mongo_db_plugin_impl::mongo_db_plugin_impl()
mongo_db_plugin_impl::~mongo_db_plugin_impl() {
try {
done = true;
condtion.notify_one();
condition.notify_one();
consume_thread.join();
} catch (std::exception& e) {
......
......@@ -14,6 +14,13 @@ namespace eosio {
static_assert(sizeof(std::chrono::system_clock::duration::rep) >= 8, "system_clock is expected to be at least 64 bits");
typedef std::chrono::system_clock::duration::rep tstamp;
struct chain_size_message {
uint32_t last_irreversible_block_num = 0;
block_id_type last_irreversible_block_id;
uint32_t head_num = 0;
block_id_type head_id;
};
struct handshake_message {
uint16_t network_version = 0; ///< incremental value above a computed base
chain_id_type chain_id; ///< used to identify chain
......@@ -32,6 +39,7 @@ namespace eosio {
int16_t generation;
};
enum go_away_reason {
no_reason, ///< no reason to go away
self, ///< the connection is to itself
......@@ -130,18 +138,21 @@ namespace eosio {
};
using net_message = static_variant<handshake_message,
chain_size_message,
go_away_message,
time_message,
notice_message,
request_message,
sync_request_message,
signed_block_ptr,
signed_transaction,
signed_block,
packed_transaction>;
} // namespace eosio
FC_REFLECT( eosio::select_ids<fc::sha256>, (mode)(pending)(ids) )
FC_REFLECT( eosio::chain_size_message,
(last_irreversible_block_num)(last_irreversible_block_id)
(head_num)(head_id))
FC_REFLECT( eosio::handshake_message,
(network_version)(chain_id)(node_id)(key)
(time)(token)(sig)(p2p_address)
......
此差异已折叠。
......@@ -117,6 +117,12 @@ class producer_plugin_impl {
});
// push the new block
chain.push_block(block);
ilog("Received block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, confirmed: ${confs}]",
("p",block->producer)("id",fc::variant(block->id()).as_string().substr(0,16))
("n",block_header::num_from_id(block->id()))("t",block->timestamp)
("count",block->transactions.size())("lib",chain.last_irreversible_block_num())("confs", block->confirmed) );
}
transaction_trace_ptr on_incoming_transaction(const packed_transaction_ptr& trx) {
......@@ -403,7 +409,7 @@ block_production_condition::block_production_condition_enum producer_plugin_impl
auto producer = db.head_block_producer();
auto pending = db.head_block_state();
wlog("\r${p} generated block ${id}... #${n} @ ${t} with ${count} trxs, lib: ${lib}, confirmed: ${confs}",
ilog("Produced block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, confirmed: ${confs}]",
("p",producer)("id",fc::variant(pending->id).as_string().substr(0,16))
("n",pending->block_num)("t",pending->block->timestamp)
("count",pending->block->transactions.size())("lib",db.last_irreversible_block_num())("confs", pending->header.confirmed)(capture) );
......@@ -508,7 +514,7 @@ block_production_condition::block_production_condition_enum producer_plugin_impl
}
}
// idump( (fc::time_point::now() - chain.pending_block_time()) );
//idump( (fc::time_point::now() - chain.pending_block_time()) );
chain.finalize_block();
chain.sign_block( [&]( const digest_type& d ) { return private_key_itr->second.sign(d); } );
chain.commit_block();
......
......@@ -71,9 +71,9 @@ using namespace eosio::chain;
eosio::detail::txn_test_gen_empty result;
struct txn_test_gen_plugin_impl {
transaction_trace_ptr push_transaction( signed_transaction& trx ) { try {
controller& cc = app().get_plugin<chain_plugin>().chain();
return cc.push_transaction( std::make_shared<transaction_metadata>(trx) );
void push_transaction( signed_transaction& trx ) { try {
chain_plugin& cp = app().get_plugin<chain_plugin>();
return cp.accept_transaction( packed_transaction(trx) );
} FC_CAPTURE_AND_RETHROW( (transaction_header(trx)) ) }
void create_test_accounts(const std::string& init_name, const std::string& init_priv_key) {
......@@ -147,12 +147,10 @@ struct txn_test_gen_plugin_impl {
{
setabi handler;
handler.account = newaccountC;
handler.abi = eosio_token_abi_def;
handler.abi = json::from_string(eosio_token_abi).as<abi_def>();
trx.actions.emplace_back( vector<chain::permission_level>{{newaccountC,"active"}}, handler);
}
abi_serializer eosio_token_serializer(eosio_token_abi_def);
{
action act;
act.account = N(eosio.token);
......@@ -252,6 +250,9 @@ struct txn_test_gen_plugin_impl {
fc::crypto::private_key a_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'a')));
fc::crypto::private_key b_priv_key = fc::crypto::private_key::regenerate(fc::sha256(std::string(64, 'b')));
static uint64_t nonce = static_cast<uint64_t>(fc::time_point::now().sec_since_epoch()) << 32;
abi_serializer eosio_serializer(cc.db().find<account_object, by_name>(config::system_account_name)->get_abi());
uint32_t reference_block_num = cc.last_irreversible_block_num();
if (txn_reference_block_lag >= 0) {
reference_block_num = cc.head_block_num();
......@@ -306,9 +307,9 @@ struct txn_test_gen_plugin_impl {
action act_a_to_b;
action act_b_to_a;
uint64_t nonce = static_cast<uint64_t>(fc::time_point::now().sec_since_epoch()) << 32;
int32_t txn_reference_block_lag;
abi_serializer eosio_token_serializer = fc::json::from_string(eosio_token_abi).as<contracts::abi_def>();
abi_serializer eosio_token_serializer = fc::json::from_string(eosio_token_abi).as<abi_def>();
};
txn_test_gen_plugin::txn_test_gen_plugin() {}
......
......@@ -48,6 +48,12 @@ class validator_plugin_impl {
// push the new block
chain.push_block(block);
ilog("Received block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, confirmed: ${confs}]",
("p",block->producer)("id",fc::variant(block->id()).as_string().substr(0,16))
("n",block_header::num_from_id(block->id()))("t",block->timestamp)
("count",block->transactions.size())("lib",chain.last_irreversible_block_num())("confs", block->confirmed) );
}
transaction_trace_ptr on_incoming_transaction(const packed_transaction_ptr& trx) {
......
......@@ -207,7 +207,7 @@ const char* error_advice_3120010 = R"=====(Ensure that your packed transaction
}
e.g.
{
"signatures" : [ "EOSJze4m1ZHQ4UjuHpBcX6uHPN4Xyggv52raQMTBZJghzDLepaPcSGCNYTxaP2NiaF4yRF5RaYwqsQYAwBwFtfuTJr34Z5GJX" ],
"signatures" : [ "SIG_K1_Jze4m1ZHQ4UjuHpBcX6uHPN4Xyggv52raQMTBZJghzDLepaPcSGCNYTxaP2NiaF4yRF5RaYwqsQYAwBwFtfuTJr34Z5GJX" ],
"compression" : "none",
"hex_transaction" : "6c36a25a00002602626c5e7f0000000000010000001e4d75af460000000000a53176010000000000ea305500000000a8ed3232180000001e4d75af4680969800000000000443555200000000"
})=====";
......
......@@ -50,7 +50,7 @@ that requires usage of a fingerprint when signing a digest (such a signing a tra
```
$ applesedemo.app/Contents/MacOS/applesedemo --create-se-touch-only
Successfully created
public_key(EOSR17iKCZrb1JqSjUncCbDGQenzSqyuNmPU8iUA15efNW5KD1iHd9x)
public_key(PUB_R1_7iKCZrb1JqSjUncCbDGQenzSqyuNmPU8iUA15efNW5KD1iHd9x)
```
The public key for the private key is printed; note it somewhere. It is possible to ask the Secure Enclave to
create multiple private keys and assign labels to them but this application only allows a single key at once.
......@@ -64,14 +64,14 @@ Now, ask the Secure Enclave to sign the digest with the private key only it know
generated until a valid fingerprint is used.
```
$ applesedemo.app/Contents/MacOS/applesedemo --sign 0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8
signature(EOSR1Jx4sBidhFV6PSvS8hWbG5oh77HKud8xpkoHLvWaZVaBeWttRpyEjaGbPRVEKu3JePTyVjANmP4GKFtG2DAuB4MTVqsdC9W)
signature(SIG_R1_Jx4sBidhFV6PSvS8hWbG5oh77HKud8xpkoHLvWaZVaBeWttRpyEjaGbPRVEKu3JePTyVjANmP4GKFtG2DAuB4MTVqsdC9W)
```
## Key Recovery
Given the signature and digest, we must be able to correlate that with the public key that signed the digest.
```
$ applesedemo.app/Contents/MacOS/applesedemo --recover 0ba904eae8773b70c75333db4de2f3ac45a8ad4ddba1b242f0b3cfc199391dd8 \
EOSR1Jx4sBidhFV6PSvS8hWbG5oh77HKud8xpkoHLvWaZVaBeWttRpyEjaGbPRVEKu3JePTyVjANmP4GKFtG2DAuB4MTVqsdC9W
public_key(EOSR17iKCZrb1JqSjUncCbDGQenzSqyuNmPU8iUA15efNW5KD1iHd9x)
SIG_R1_Jx4sBidhFV6PSvS8hWbG5oh77HKud8xpkoHLvWaZVaBeWttRpyEjaGbPRVEKu3JePTyVjANmP4GKFtG2DAuB4MTVqsdC9W
public_key(PUB_R1_7iKCZrb1JqSjUncCbDGQenzSqyuNmPU8iUA15efNW5KD1iHd9x)
```
Indeed, the public key recovered from this digest and signature matches the public key from the key stored in the Secure
Enclave.
\ No newline at end of file
......@@ -76,7 +76,7 @@ void print_pub_for_key(SecKeyRef key) {
pub_wrapper.check = fc::crypto::checksummed_data<fc::crypto::r1::public_key_data>::calculate_checksum(pub_wrapper.data, "R1");
std::vector<char> checksummed = fc::raw::pack(pub_wrapper);
cout << "public_key(EOSR1" << fc::to_base58(checksummed.data(), checksummed.size()) << ")" << endl;
cout << "public_key(PUB_R1_" << fc::to_base58(checksummed.data(), checksummed.size()) << ")" << endl;
}
void print_attributes() {
......@@ -221,7 +221,7 @@ void sign(const string& hex) {
signature_wrapper.check = fc::crypto::checksummed_data<fc::crypto::r1::compact_signature>::calculate_checksum(signature_wrapper.data, "R1");
checksummed = fc::raw::pack(signature_wrapper);
cout << "signature(EOSR1" << fc::to_base58(checksummed.data(), checksummed.size()) << ")" << endl;
cout << "signature(SIG_R1_" << fc::to_base58(checksummed.data(), checksummed.size()) << ")" << endl;
err:
CFRelease(key);
......
......@@ -1042,6 +1042,11 @@ launcher_def::write_logging_config_file(tn_node_def &node) {
( "host", instance.name )
) );
log_config.loggers.front().appenders.push_back("net");
fc::logger_config p2p ("net_plugin_impl");
p2p.level=fc::log_level::debug;
p2p.appenders.push_back ("stderr");
p2p.appenders.push_back ("net");
log_config.loggers.emplace_back(p2p);
}
auto str = fc::json::to_pretty_string( log_config, fc::json::stringify_large_ints_and_doubles );
......
......@@ -49,9 +49,10 @@ target_link_libraries( nodeos
PRIVATE -Wl,${whole_archive_flag} history_api_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} chain_api_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} wallet_api_plugin -Wl,${no_whole_archive_flag}
# PRIVATE -Wl,${whole_archive_flag} net_api_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} net_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} net_api_plugin -Wl,${no_whole_archive_flag}
# PRIVATE -Wl,${whole_archive_flag} faucet_testnet_plugin -Wl,${no_whole_archive_flag}
# PRIVATE -Wl,${whole_archive_flag} txn_test_gen_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} txn_test_gen_plugin -Wl,${no_whole_archive_flag}
PRIVATE -Wl,${whole_archive_flag} producer_plugin -Wl,${no_whole_archive_flag}
PRIVATE chain_plugin http_plugin validator_plugin
PRIVATE eosio_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
......
......@@ -7,7 +7,7 @@
#include <eosio/chain_plugin/chain_plugin.hpp>
#include <eosio/http_plugin/http_plugin.hpp>
#include <eosio/history_plugin.hpp>
//#include <eosio/net_plugin/net_plugin.hpp>
#include <eosio/net_plugin/net_plugin.hpp>
#include <eosio/producer_plugin/producer_plugin.hpp>
#include <eosio/validator_plugin/validator_plugin.hpp>
#include <eosio/utilities/common.hpp>
......@@ -86,10 +86,10 @@ int main(int argc, char** argv)
app().set_version(eosio::nodeos::config::version);
app().register_plugin<history_plugin>();
auto root = fc::app_path();
auto root = fc::app_path();
app().set_default_data_dir(root / "eosio/nodeos/data" );
app().set_default_config_dir(root / "eosio/nodeos/config" );
if(!app().initialize<chain_plugin, http_plugin, validator_plugin>(argc, argv))
if(!app().initialize<chain_plugin, http_plugin, validator_plugin, net_plugin>(argc, argv))
return -1;
initialize_logging();
ilog("nodeos version ${ver}", ("ver", eosio::utilities::common::itoh(static_cast<uint32_t>(app().version()))));
......
......@@ -2,14 +2,14 @@
OS_MAJ=`echo "${OS_VER}" | cut -d'.' -f1`
OS_MIN=`echo "${OS_VER}" | cut -d'.' -f2`
MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 )
CPU_SPEED=$( lscpu | grep "MHz" | tr -s ' ' | cut -d\ -f3 | cut -d'.' -f1 )
CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 )
MEM_MEG=$( free -m | grep Mem | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 )
CPU_SPEED=$( lscpu | grep -m1 "MHz" | tr -s ' ' | cut -d\ -f3 || cut -d' ' -f3 | cut -d'.' -f1 )
CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 )
MEM_GIG=$(( (($MEM_MEG / 1000) / 2) ))
JOBS=$(( ${MEM_GIG} > ${CPU_CORE} ? ${CPU_CORE} : ${MEM_GIG} ))
DISK_INSTALL=`df -h . | tail -1 | tr -s ' ' | cut -d\ -f1`
DISK_INSTALL=`df -h . | tail -1 | tr -s ' ' | cut -d\ -f1 || cut -d' ' -f1`
DISK_TOTAL_KB=`df . | tail -1 | awk '{print $2}'`
DISK_AVAIL_KB=`df . | tail -1 | awk '{print $4}'`
DISK_TOTAL=$(( $DISK_TOTAL_KB / 1048576 ))
......@@ -324,4 +324,4 @@ mongodconf
printf '\texport PATH=${HOME}/opt/mongodb/bin:$PATH\n'
printf "\tcd ${HOME}/eos/build; make test\n\n"
return 0
}
\ No newline at end of file
}
......@@ -13,8 +13,8 @@ if [ -z "$biosport" ]; then
fi
wddir=eosio-ignition-wd
wdport=8899
wdhost=127.0.0.1
wdaddr=localhost:8899
wdurl=http://$wdaddr
# Manual deployers, add a line below this block that looks like:
# bioshost=$BIOS_HOSTNAME
# biosport=$BIOS_HTTP_PORT
......@@ -35,7 +35,7 @@ mkdir $wddir
step=1
echo Initializing ignition sequence at $(date) | tee $logfile
echo "http-server-address = 127.0.0.1:$wdport" > $wddir/config.ini
echo "http-server-address = $wdaddr" > $wddir/config.ini
programs/keosd/keosd --config-dir $wddir --data-dir $wddir 2> $wddir/wdlog.txt &
echo $$ > ignition_wallet.pid
......@@ -44,9 +44,9 @@ sleep 1
ecmd () {
echo ===== Start: $step ============ >> $logfile
echo executing: cleos --wallet-port $wdport -p $biosport -H $bioshost $* | tee -a $logfile
echo executing: cleos --wallet-url $wdurl --url http://$bioshost:$biosport $* | tee -a $logfile
echo ----------------------- >> $logfile
programs/cleos/cleos --wallet-port $wdport --wallet-host $wdhost -p $biosport -H $bioshost $* >> $logfile 2>&1
programs/cleos/cleos --wallet-url $wdurl --url http://$bioshost:$biosport $* >> $logfile 2>&1
echo ==== End: $step ============== >> $logfile
step=$(($step + 1))
}
......@@ -89,18 +89,18 @@ ecmd set contract eosio contracts/eosio.bios contracts/eosio.bios/eosio.bios.was
#the setprods.json argument cannot pass through the function call due to embedded quotes
echo ===== Start: $step ============ >> $logfile
echo executing: cleos --wallet-port $wdport -p $biosport -H $bioshost push action eosio setprods setprods.json -p eosio@active | tee -a $logfile
echo executing: cleos --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio setprods setprods.json -p eosio@active | tee -a $logfile
echo ----------------------- >> $logfile
programs/cleos/cleos --wallet-port $wdport --wallet-host $wdhost -p $biosport -H $bioshost push action eosio setprods setprods.json -p eosio@active >> $logfile 2>&1
programs/cleos/cleos --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio setprods setprods.json -p eosio@active >> $logfile 2>&1
echo ==== End: $step ============== >> $logfile
step=$(($step + 1))
ecmd set contract eosio contracts/eosio.system contracts/eosio.system/eosio.system.wast contracts/eosio.system/eosio.system.abi
echo ===== Start: $step ============ >> $logfile
echo executing: cleos --wallet-port $wdport -p $biosport -H $bioshost push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS","memo":"init"}' -p eosio@active | tee -a $logfile
echo executing: cleos --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS","memo":"init"}' -p eosio@active | tee -a $logfile
echo ----------------------- >> $logfile
programs/cleos/cleos --wallet-port $wdport --wallet-host $wdhost -p $biosport -H $bioshost push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS","memo":"init"}' -p eosio@active >> $logfile 2>&1
programs/cleos/cleos --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio issue '{"to":"eosio","quantity":"1000000000.0000 EOS","memo":"init"}' -p eosio@active >> $logfile 2>&1
echo ==== End: $step ============== >> $logfile
step=$(($step + 1))
......
......@@ -1802,8 +1802,8 @@ BOOST_AUTO_TEST_CASE(general)
"string_arr" : ["ola ke ase","ola ke desi"],
"time" : "2021-12-20T15:30",
"time_arr" : ["2021-12-20T15:30","2021-12-20T15:31"],
"signature" : "EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U",
"signature_arr" : ["EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U","EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U"],
"signature" : "SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5",
"signature_arr" : ["SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5","SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5"],
"checksum256" : "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
"checksum256_arr" : ["ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad","ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"],
"fieldname" : "name1",
......@@ -1891,7 +1891,8 @@ BOOST_AUTO_TEST_CASE(general)
"ref_block_num":"1",
"ref_block_prefix":"2",
"expiration":"2021-12-20T15:30",
"signatures" : ["EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U"],
"region": "1",
"signatures" : ["SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5"],
"context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"],
"context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}],
"actions":[{"account":"accountname1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}],
......@@ -1903,7 +1904,8 @@ BOOST_AUTO_TEST_CASE(general)
"ref_block_num":"1",
"ref_block_prefix":"2",
"expiration":"2021-12-20T15:30",
"signatures" : ["EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U"],
"region": "1",
"signatures" : ["SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5"],
"context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"],
"context_free_actions":[{"account":"contextfree1", "name":"cfactionname1", "authorization":[{"actor":"cfacc1","permission":"cfpermname1"}], "data":"778899"}],
"actions":[{"account":"acc1", "name":"actionname1", "authorization":[{"actor":"acc1","permission":"permname1"}], "data":"445566"}],
......@@ -1914,7 +1916,8 @@ BOOST_AUTO_TEST_CASE(general)
"ref_block_num":"2",
"ref_block_prefix":"3",
"expiration":"2021-12-20T15:40",
"signatures" : ["EOSJzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwT77X1U"],
"region": "1",
"signatures" : ["SIG_K1_Jzdpi5RCzHLGsQbpGhndXBzcFs8vT5LHAtWLMxPzBdwRHSmJkcCdVu6oqPUQn1hbGUdErHvxtdSTS1YA73BThQFwV1v4G5"],
"context_free_data" : ["abcdef","0123456789","ABCDEF0123456789abcdef"],
"context_free_actions":[{"account":"contextfree2", "name":"cfactionname2", "authorization":[{"actor":"cfacc2","permission":"cfpermname2"}], "data":"667788"}],
"actions":[{"account":"acc2", "name":"actionname2", "authorization":[{"actor":"acc2","permission":"permname2"}], "data":""}],
......
......@@ -607,7 +607,7 @@ BOOST_FIXTURE_TEST_CASE( producer_register_unregister, eosio_system_tester ) try
//call regproducer again to change parameters
fc::variant params2 = producer_parameters_example(2);
vector<char> key2 = fc::raw::pack( fc::crypto::public_key( std::string("EOSR16EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4") ) );
vector<char> key2 = fc::raw::pack( fc::crypto::public_key( std::string("PUB_R1_6EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4") ) );
BOOST_REQUIRE_EQUAL( success(), push_action(N(alice), N(regproducer), mvo()
("producer", "alice")
("producer_key", key2 )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册