Externalize serialization of blocks, tx, ops

This commit is contained in:
Peter Conrad 2019-05-11 12:39:15 +02:00 committed by gladcow
parent 4df7298a0d
commit 71d8bfd843
24 changed files with 135 additions and 24 deletions

View file

@ -25,6 +25,8 @@
#include <fstream>
#include <graphene/chain/protocol/block.hpp>
#include <fc/filesystem.hpp>
namespace graphene { namespace chain {
class index_entry;

View file

@ -69,3 +69,8 @@ FC_REFLECT( graphene::chain::block_header,
(extensions) )
FC_REFLECT_DERIVED( graphene::chain::signed_block_header, (graphene::chain::block_header), (witness_signature) )
FC_REFLECT_DERIVED( graphene::chain::signed_block, (graphene::chain::signed_block_header), (transactions) )
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::block_header)
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_block_header)
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_block)

View file

@ -230,3 +230,8 @@ FC_REFLECT( graphene::chain::transaction, (ref_block_num)(ref_block_prefix)(expi
// Note: not reflecting signees field for backward compatibility; in addition, it should not be in p2p messages
FC_REFLECT_DERIVED( graphene::chain::signed_transaction, (graphene::chain::transaction), (signatures) )
FC_REFLECT_DERIVED( graphene::chain::processed_transaction, (graphene::chain::signed_transaction), (operation_results) )
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::transaction)
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::signed_transaction)
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::chain::processed_transaction)

View file

@ -33,7 +33,8 @@
#include <fc/safe.hpp>
#include <fc/container/flat.hpp>
#include <fc/string.hpp>
#include <fc/io/raw.hpp>
#include <fc/io/datastream.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/uint128.hpp>
#include <fc/static_variant.hpp>
#include <fc/smart_ref_fwd.hpp>
@ -46,6 +47,31 @@
#include <graphene/db/object_id.hpp>
#include <graphene/chain/protocol/config.hpp>
#define GRAPHENE_EXTERNAL_SERIALIZATION(ext, type) \
namespace fc { \
ext template void from_variant( const variant& v, type& vo, uint32_t max_depth ); \
ext template void to_variant( const type& v, variant& vo, uint32_t max_depth ); \
namespace raw { \
ext template void pack< datastream<size_t>, type >( datastream<size_t>& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \
ext template void pack< datastream<char*>, type >( datastream<char*>& s, const type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \
ext template void unpack< datastream<const char*>, type >( datastream<const char*>& s, type& tx, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); \
} } // fc::raw
#define FC_REFLECT_DERIVED_NO_TYPENAME( TYPE, INHERITS, MEMBERS ) \
namespace fc { \
template<> struct reflector<TYPE> {\
typedef TYPE type; \
typedef fc::true_type is_defined; \
typedef fc::false_type is_enum; \
enum member_count_enum { \
local_member_count = 0 BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_MEMBER_COUNT, +, MEMBERS ),\
total_member_count = local_member_count BOOST_PP_SEQ_FOR_EACH( FC_REFLECT_BASE_MEMBER_COUNT, +, INHERITS )\
}; \
FC_REFLECT_DERIVED_IMPL_INLINE( TYPE, INHERITS, MEMBERS ) \
}; \
} // fc
namespace graphene { namespace chain {
using namespace graphene::db;

View file

@ -24,6 +24,9 @@
#include <graphene/chain/protocol/account.hpp>
#include <graphene/chain/hardfork.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
/**

View file

@ -24,6 +24,8 @@
#include <graphene/chain/protocol/asset_ops.hpp>
#include <graphene/chain/database.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
/**

View file

@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include <graphene/chain/protocol/block.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/io/raw.hpp>
#include <fc/bitutil.hpp>
#include <algorithm>
@ -90,3 +91,7 @@ namespace graphene { namespace chain {
}
} }
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::block_header)
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_block_header)
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_block)

View file

@ -23,6 +23,8 @@
*/
#include <graphene/chain/protocol/custom.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
void custom_operation::validate()const

View file

@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include <graphene/chain/protocol/operations.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
namespace graphene { namespace chain {

View file

@ -25,6 +25,8 @@
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/smart_ref_impl.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
proposal_create_operation proposal_create_operation::committee_proposal(const chain_parameters& global_params, fc::time_point_sec head_block_time )

View file

@ -390,3 +390,7 @@ void signed_transaction::verify_authority(
} FC_CAPTURE_AND_RETHROW( (*this) ) }
} } // graphene::chain
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::transaction)
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::signed_transaction)
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::chain::processed_transaction)

View file

@ -23,6 +23,8 @@
*/
#include <graphene/chain/protocol/transfer.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
share_type transfer_operation::calculate_fee( const fee_parameters_type& schedule )const

View file

@ -23,6 +23,8 @@
*/
#include <graphene/chain/protocol/withdraw_permission.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace chain {
void withdraw_permission_update_operation::validate()const

View file

@ -24,6 +24,8 @@
#include <graphene/egenesis/egenesis.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace egenesis {
using namespace graphene::chain;

View file

@ -5,6 +5,7 @@ set(SOURCES node.cpp
core_messages.cpp
peer_database.cpp
peer_connection.cpp
message.cpp
message_oriented_connection.cpp)
add_library( graphene_net ${SOURCES} ${HEADERS} )

View file

@ -22,12 +22,16 @@
* THE SOFTWARE.
*/
#pragma once
#include <boost/endian/buffers.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <fc/array.hpp>
#include <fc/io/varint.hpp>
#include <fc/network/ip.hpp>
#include <fc/io/raw.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/crypto/ripemd160.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/reflect/typename.hpp>
namespace graphene { namespace net {
@ -108,10 +112,10 @@ namespace graphene { namespace net {
}
};
} } // graphene::net
FC_REFLECT( graphene::net::message_header, (size)(msg_type) )
FC_REFLECT_DERIVED( graphene::net::message, (graphene::net::message_header), (data) )
FC_REFLECT_TYPENAME( graphene::net::message_header )
FC_REFLECT_TYPENAME( graphene::net::message )
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::net::message_header)
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::net::message)

View file

@ -26,7 +26,6 @@
#include <graphene/net/node.hpp>
#include <graphene/net/peer_database.hpp>
#include <graphene/net/message_oriented_connection.hpp>
#include <graphene/net/stcp_socket.hpp>
#include <graphene/net/config.hpp>
#include <boost/tuple/tuple.hpp>
@ -35,9 +34,7 @@
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/tag.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <queue>

View file

@ -24,13 +24,14 @@
#pragma once
#include <boost/iterator/iterator_facade.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <fc/network/ip.hpp>
#include <fc/time.hpp>
#include <fc/io/enum_type.hpp>
#include <fc/reflect/reflect.hpp>
#include <fc/reflect/variant.hpp>
#include <fc/exception/exception.hpp>
#include <fc/io/raw.hpp>
namespace graphene { namespace net {
@ -118,5 +119,6 @@ namespace graphene { namespace net {
} } // end namespace graphene::net
FC_REFLECT_ENUM(graphene::net::potential_peer_last_connection_disposition, (never_attempted_to_connect)(last_connection_failed)(last_connection_rejected)(last_connection_handshaking_failed)(last_connection_succeeded))
FC_REFLECT(graphene::net::potential_peer_record, (endpoint)(last_seen_time)(last_connection_disposition)(last_connection_attempt_time)(number_of_successful_connection_attempts)(number_of_failed_connection_attempts)(last_error) )
FC_REFLECT_TYPENAME( graphene::net::potential_peer_record )
GRAPHENE_EXTERNAL_SERIALIZATION(extern, graphene::net::potential_peer_record)

32
libraries/net/message.cpp Normal file
View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2019 BitShares Blockchain Foundation, 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.
*/
#include <fc/io/raw.hpp>
#include <graphene/net/message.hpp>
FC_REFLECT_DERIVED_NO_TYPENAME( graphene::net::message_header, BOOST_PP_SEQ_NIL, (size)(msg_type) )
FC_REFLECT_DERIVED_NO_TYPENAME( graphene::net::message, (graphene::net::message_header), (data) )
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::net::message_header)
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::net::message)

View file

@ -66,6 +66,7 @@
#include <fc/log/logger.hpp>
#include <fc/io/json.hpp>
#include <fc/io/enum_type.hpp>
#include <fc/io/raw.hpp>
#include <fc/crypto/rand.hpp>
#include <fc/network/rate_limiting.hpp>
#include <fc/network/ip.hpp>

View file

@ -25,8 +25,8 @@
#include <graphene/net/exceptions.hpp>
#include <graphene/net/config.hpp>
#include <graphene/chain/config.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <fc/io/raw.hpp>
#include <fc/thread/thread.hpp>
#include <boost/scope_exit.hpp>

View file

@ -274,3 +274,14 @@ namespace graphene { namespace net {
}
} } // end namespace graphene::net
FC_REFLECT_ENUM( graphene::net::potential_peer_last_connection_disposition,
(never_attempted_to_connect)
(last_connection_failed)(last_connection_rejected)
(last_connection_handshaking_failed)(last_connection_succeeded) )
FC_REFLECT_DERIVED_NO_TYPENAME( graphene::net::potential_peer_record, BOOST_PP_SEQ_NIL,
(endpoint)(last_seen_time)(last_connection_disposition)
(last_connection_attempt_time)(number_of_successful_connection_attempts)
(number_of_failed_connection_attempts)(last_error) )
GRAPHENE_EXTERNAL_SERIALIZATION(/*not extern*/, graphene::net::potential_peer_record)

View file

@ -229,12 +229,13 @@ struct worker_vote_delta
flat_set<worker_id_type> vote_abstain;
};
struct signed_block_with_info : public signed_block
struct signed_block_with_info
{
signed_block_with_info();
signed_block_with_info( const signed_block& block );
signed_block_with_info( const signed_block_with_info& block ) = default;
signed_block block;
block_id_type block_id;
public_key_type signing_key;
vector< transaction_id_type > transaction_ids;
@ -1978,8 +1979,7 @@ FC_REFLECT( graphene::wallet::worker_vote_delta,
(vote_abstain)
)
FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block),
(block_id)(signing_key)(transaction_ids) )
FC_REFLECT( graphene::wallet::signed_block_with_info, (block_id)(signing_key)(transaction_ids) )
FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object),
(allowed_withdraw)(allowed_withdraw_time) )

View file

@ -6191,13 +6191,13 @@ std::vector<matched_bet_object> wallet_api::get_all_matched_bets_for_bettor(acco
}
// default ctor necessary for FC_REFLECT
signed_block_with_info::signed_block_with_info( const signed_block& block )
: signed_block( block )
signed_block_with_info::signed_block_with_info( const signed_block& _block )
: block( _block )
{
block_id = id();
signing_key = signee();
transaction_ids.reserve( transactions.size() );
for( const processed_transaction& tx : transactions )
block_id = _block.id();
signing_key = _block.signee();
transaction_ids.reserve( _block.transactions.size() );
for( const processed_transaction& tx : _block.transactions )
transaction_ids.push_back( tx.id() );
}