Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Support receiving old/new packed_transaction & signed_block
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Apr 1, 2020
1 parent 855d83b commit eba4d9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
6 changes: 4 additions & 2 deletions plugins/net_plugin/include/eosio/net_plugin/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ namespace eosio {
notice_message,
request_message,
sync_request_message,
signed_block, // which = 7
packed_transaction>; // which = 8
signed_block_v0, // which = 7
packed_transaction_v0, // which = 8
signed_block, // which = 9
packed_transaction>; // which = 10

} // namespace eosio

Expand Down
32 changes: 24 additions & 8 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,10 @@ namespace eosio {
constexpr auto def_sync_fetch_span = 100;

constexpr auto message_header_size = 4;
constexpr uint32_t signed_block_which = 7; // see protocol net_message
constexpr uint32_t packed_transaction_which = 8; // see protocol net_message
constexpr uint32_t signed_block_v0_which = 7; // see protocol net_message
constexpr uint32_t packed_transaction_v0_which = 8; // see protocol net_message
constexpr uint32_t signed_block_which = 9; // see protocol net_message
constexpr uint32_t packed_transaction_which = 10; // see protocol net_message

/**
* For a while, network version was a 16 bit value equal to the second set of 16 bits
Expand Down Expand Up @@ -2365,7 +2367,7 @@ namespace eosio {
auto peek_ds = pending_message_buffer.create_peek_datastream();
unsigned_int which{};
fc::raw::unpack( peek_ds, which );
if( which == signed_block_which ) {
if( which == signed_block_v0_which || which == signed_block_which ) {
block_header bh;
fc::raw::unpack( peek_ds, bh );

Expand Down Expand Up @@ -2405,10 +2407,17 @@ namespace eosio {
}
}

shared_ptr<signed_block> ptr;
auto ds = pending_message_buffer.create_datastream();
fc::raw::unpack( ds, which ); // throw away
shared_ptr<signed_block> ptr = std::make_shared<signed_block>();
fc::raw::unpack( ds, *ptr );
if( which == signed_block_which ) {
ptr = std::make_shared<signed_block>();
fc::raw::unpack( ds, *ptr );
} else { // signed_block_v0_which
signed_block_v0 v0;
fc::raw::unpack( ds, v0 );
ptr = std::make_shared<signed_block>( std::move( v0 ), true);
}

auto is_webauthn_sig = []( const fc::crypto::signature& s ) {
return s.which() == fc::crypto::signature::storage_type::position<fc::crypto::webauthn::signature>();
Expand All @@ -2430,17 +2439,24 @@ namespace eosio {

handle_message( blk_id, std::move( ptr ) );

} else if( which == packed_transaction_which ) {
} else if( which == packed_transaction_v0_which || which == packed_transaction_which ) {
if( !my_impl->p2p_accept_transactions ) {
fc_dlog( logger, "p2p-accept-transaction=false - dropping txn" );
pending_message_buffer.advance_read_ptr( message_length );
return true;
}

shared_ptr<packed_transaction> ptr;
auto ds = pending_message_buffer.create_datastream();
fc::raw::unpack( ds, which ); // throw away
shared_ptr<packed_transaction> ptr = std::make_shared<packed_transaction>();
fc::raw::unpack( ds, *ptr );
if( which == packed_transaction_which ) {
ptr = std::make_shared<packed_transaction>();
fc::raw::unpack( ds, *ptr );
} else { // packed_transaction_v0_which
packed_transaction_v0 v0;
fc::raw::unpack( ds, v0 );
ptr = std::make_shared<packed_transaction>( std::move( v0 ), true );
}
handle_message( std::move( ptr ) );

} else {
Expand Down

0 comments on commit eba4d9b

Please sign in to comment.