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

Commit

Permalink
Merge pull request #7703 from EOSIO/7681-transaction-extensions
Browse files Browse the repository at this point in the history
return flat_multimap from transaction::validate_and_extract_extensions
  • Loading branch information
arhag authored Jul 30, 2019
2 parents 41860ad + a70daca commit 3a78a00
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
10 changes: 7 additions & 3 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,14 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
if( control.is_builtin_activated( builtin_protocol_feature_t::no_duplicate_deferred_id ) ) {
auto exts = trx.validate_and_extract_extensions();
if( exts.size() > 0 ) {
EOS_ASSERT( exts.size() == 1, invalid_transaction_extension,
"only one extension is currently supported for deferred transactions"
auto itr = exts.lower_bound( deferred_transaction_generation_context::extension_id() );

EOS_ASSERT( exts.size() == 1 && itr != exts.end(), invalid_transaction_extension,
"only the deferred_transaction_generation_context extension is currently supported for deferred transactions"
);
const auto& context = exts.front().get<deferred_transaction_generation_context>();

const auto& context = itr->second.get<deferred_transaction_generation_context>();

EOS_ASSERT( context.sender == receiver, ill_formed_deferred_transaction_generation_context,
"deferred transaction generaction context contains mismatching sender",
("expected", receiver)("actual", context.sender)
Expand Down
10 changes: 3 additions & 7 deletions libraries/chain/block_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ namespace eosio { namespace chain {
return result;
}

flat_multimap<uint16_t, block_header_extensions> block_header::validate_and_extract_header_extensions()const {
using block_header_extensions_t = block_header_extension_types::block_header_extensions_t;
flat_multimap<uint16_t, block_header_extension> block_header::validate_and_extract_header_extensions()const {
using decompose_t = block_header_extension_types::decompose_t;

static_assert( std::is_same<block_header_extensions_t, block_header_extensions>::value,
"block_header_extensions is not setup as expected" );

flat_multimap<uint16_t, block_header_extensions> results;
flat_multimap<uint16_t, block_header_extension> results;

uint16_t id_type_lower_bound = 0;

Expand All @@ -52,7 +48,7 @@ namespace eosio { namespace chain {
std::forward_as_tuple()
);

auto match = decompose_t::extract<block_header_extensions_t>( id, e.second, iter->second );
auto match = decompose_t::extract<block_header_extension>( id, e.second, iter->second );
EOS_ASSERT( match, invalid_block_header_extension,
"Block header extension with id type ${id} is not supported",
("id", id)
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/eosio/chain/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace eosio { namespace chain {
namespace detail {
template<typename... Ts>
struct block_header_extension_types {
using block_header_extensions_t = fc::static_variant< Ts... >;
using block_header_extension_t = fc::static_variant< Ts... >;
using decompose_t = decompose< Ts... >;
};
}
Expand All @@ -20,7 +20,7 @@ namespace eosio { namespace chain {
producer_schedule_change_extension
>;

using block_header_extensions = block_header_extension_types::block_header_extensions_t;
using block_header_extension = block_header_extension_types::block_header_extension_t;

struct block_header
{
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace eosio { namespace chain {
uint32_t block_num() const { return num_from_id(previous) + 1; }
static uint32_t num_from_id(const block_id_type& id);

flat_multimap<uint16_t, block_header_extensions> validate_and_extract_header_extensions()const;
flat_multimap<uint16_t, block_header_extension> validate_and_extract_header_extensions()const;
};


Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct block_header_state : public detail::block_header_state_common {

/// this data is redundant with the data stored in header, but it acts as a cache that avoids
/// duplication of work
flat_multimap<uint16_t, block_header_extensions> header_exts;
flat_multimap<uint16_t, block_header_extension> header_exts;

block_header_state() = default;

Expand Down
8 changes: 4 additions & 4 deletions libraries/chain/include/eosio/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace eosio { namespace chain {
namespace detail {
template<typename... Ts>
struct transaction_extension_types {
using transaction_extensions_t = fc::static_variant< Ts... >;
using transaction_extension_t = fc::static_variant< Ts... >;
using decompose_t = decompose< Ts... >;
};
}
Expand All @@ -40,7 +40,7 @@ namespace eosio { namespace chain {
deferred_transaction_generation_context
>;

using transaction_extensions = transaction_extension_types::transaction_extensions_t;
using transaction_extension = transaction_extension_types::transaction_extension_t;

/**
* The transaction header contains the fixed-sized data
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace eosio { namespace chain {
bool allow_duplicate_keys = false) const;

uint32_t total_actions()const { return context_free_actions.size() + actions.size(); }

account_name first_authorizer()const {
for( const auto& a : actions ) {
for( const auto& u : a.authorization )
Expand All @@ -108,7 +108,7 @@ namespace eosio { namespace chain {
return account_name();
}

vector<eosio::chain::transaction_extensions> validate_and_extract_extensions()const;
flat_multimap<uint16_t, transaction_extension> validate_and_extract_extensions()const;
};

struct signed_transaction : public transaction
Expand Down
15 changes: 7 additions & 8 deletions libraries/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ fc::microseconds transaction::get_signature_keys( const vector<signature_type>&
return sig_cpu_usage;
} FC_CAPTURE_AND_RETHROW() }

vector<transaction_extensions> transaction::validate_and_extract_extensions()const {
using transaction_extensions_t = transaction_extension_types::transaction_extensions_t;
flat_multimap<uint16_t, transaction_extension> transaction::validate_and_extract_extensions()const {
using decompose_t = transaction_extension_types::decompose_t;

static_assert( std::is_same<transaction_extensions_t, eosio::chain::transaction_extensions>::value,
"transaction_extensions is not setup as expected" );

vector<transaction_extensions_t> results;
flat_multimap<uint16_t, transaction_extension> results;

uint16_t id_type_lower_bound = 0;

Expand All @@ -163,9 +159,12 @@ vector<transaction_extensions> transaction::validate_and_extract_extensions()con
"Transaction extensions are not in the correct order (ascending id types required)"
);

results.emplace_back();
auto iter = results.emplace(std::piecewise_construct,
std::forward_as_tuple(id),
std::forward_as_tuple()
);

auto match = decompose_t::extract<transaction_extensions_t>( id, e.second, results.back() );
auto match = decompose_t::extract<transaction_extension>( id, e.second, iter->second );
EOS_ASSERT( match, invalid_transaction_extension,
"Transaction extension with id type ${id} is not supported",
("id", id)
Expand Down

0 comments on commit 3a78a00

Please sign in to comment.