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

Commit

Permalink
Revert "Merge pull request #9061 from EOSIO/prune-cfd-stage-1-merge"
Browse files Browse the repository at this point in the history
This reverts commit 76cccfc, reversing
changes made to 19082ed.
  • Loading branch information
heifner committed May 12, 2020
1 parent 351bdce commit 87f7d98
Show file tree
Hide file tree
Showing 69 changed files with 1,517 additions and 3,130 deletions.
42 changes: 13 additions & 29 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ void apply_context::schedule_deferred_transaction( const uint128_t& sender_id, a
"deferred transaction generaction context contains mismatching sender_id",
("expected", sender_id)("actual", context.sender_id)
);
EOS_ASSERT( context.sender_trx_id == trx_context.packed_trx.id(), ill_formed_deferred_transaction_generation_context,
EOS_ASSERT( context.sender_trx_id == trx_context.id, ill_formed_deferred_transaction_generation_context,
"deferred transaction generaction context contains mismatching sender_trx_id",
("expected", trx_context.packed_trx.id())("actual", context.sender_trx_id)
("expected", trx_context.id)("actual", context.sender_trx_id)
);
} else {
emplace_extension(
trx.transaction_extensions,
deferred_transaction_generation_context::extension_id(),
fc::raw::pack( deferred_transaction_generation_context( trx_context.packed_trx.id(), sender_id, receiver ) )
fc::raw::pack( deferred_transaction_generation_context( trx_context.id, sender_id, receiver ) )
);
}
trx.expiration = time_point_sec();
Expand Down Expand Up @@ -762,6 +762,11 @@ vector<account_name> apply_context::get_active_producers() const {
return accounts;
}

bytes apply_context::get_packed_transaction() {
auto r = fc::raw::pack( static_cast<const transaction&>(trx_context.trx) );
return r;
}

void apply_context::update_db_usage( const account_name& payer, int64_t delta, const storage_usage_trace& trace ) {
if( delta > 0 ) {
if( !(privileged || payer == account_name(receiver)
Expand All @@ -778,7 +783,7 @@ void apply_context::update_db_usage( const account_name& payer, int64_t delta, c

int apply_context::get_action( uint32_t type, uint32_t index, char* buffer, size_t buffer_size )const
{
const auto& trx = trx_context.packed_trx.get_transaction();
const auto& trx = trx_context.trx;
const action* act_ptr = nullptr;

if( type == 0 ) {
Expand All @@ -804,36 +809,15 @@ int apply_context::get_action( uint32_t type, uint32_t index, char* buffer, size

int apply_context::get_context_free_data( uint32_t index, char* buffer, size_t buffer_size )const
{
const packed_transaction::prunable_data_type::prunable_data_t& data = trx_context.packed_trx.get_prunable_data().prunable_data;
const bytes* cfd = nullptr;
if( data.contains<packed_transaction::prunable_data_type::none>() ) {
} else if( data.contains<packed_transaction::prunable_data_type::partial>() ) {
if( index >= data.get<packed_transaction::prunable_data_type::partial>().context_free_segments.size() ) return -1;
const auto& trx = trx_context.trx;

cfd = trx_context.packed_trx.get_context_free_data(index);
} else {
const std::vector<bytes>& context_free_data =
data.contains<packed_transaction::prunable_data_type::full_legacy>() ?
data.get<packed_transaction::prunable_data_type::full_legacy>().context_free_segments :
data.get<packed_transaction::prunable_data_type::full>().context_free_segments;
if( index >= context_free_data.size() ) return -1;

cfd = &context_free_data[index];
}

if( !cfd ) {
if( control.is_producing_block() ) {
EOS_THROW( subjective_block_production_exception, "pruned context free data not available" );
} else {
EOS_THROW( pruned_context_free_data_bad_block_exception, "pruned context free data not available" );
}
}
if( index >= trx.context_free_data.size() ) return -1;

auto s = cfd->size();
auto s = trx.context_free_data[index].size();
if( buffer_size == 0 ) return s;

auto copy_size = std::min( buffer_size, s );
memcpy( buffer, cfd->data(), copy_size );
memcpy( buffer, trx.context_free_data[index].data(), copy_size );

return copy_size;
}
Expand Down
73 changes: 26 additions & 47 deletions libraries/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,16 @@ namespace eosio { namespace chain {
}
}

struct transaction_receipt_translator {
bool legacy = true;
fc::static_variant<transaction_id_type, packed_transaction> operator()(const transaction_id_type& tid) const {
return tid;
}
fc::static_variant<transaction_id_type, packed_transaction> operator()(const packed_transaction_v0& ptrx) const {
return packed_transaction(ptrx, legacy);
}
fc::static_variant<transaction_id_type, packed_transaction> operator()(packed_transaction_v0&& ptrx) const {
return packed_transaction(std::move(ptrx), legacy);
}
};
static fc::static_variant<transaction_id_type, pruned_transaction> translate_transaction_receipt(const transaction_id_type& tid, bool) {
return tid;
}
static fc::static_variant<transaction_id_type, pruned_transaction> translate_transaction_receipt(const packed_transaction& ptrx, bool legacy) {
return pruned_transaction(ptrx, legacy);
}

transaction_receipt::transaction_receipt(const transaction_receipt_v0& other, bool legacy)
pruned_transaction_receipt::pruned_transaction_receipt(const transaction_receipt& other, bool legacy)
: transaction_receipt_header(static_cast<const transaction_receipt_header&>(other)),
trx( other.trx.visit(transaction_receipt_translator{legacy}))
{}

transaction_receipt::transaction_receipt(transaction_receipt_v0&& other, bool legacy)
: transaction_receipt_header(std::move(static_cast<transaction_receipt_header&>(other))),
trx( std::move(other.trx).visit(transaction_receipt_translator{legacy}))
trx(other.trx.visit([&](const auto& obj) { return translate_transaction_receipt(obj, legacy); }))
{}

static flat_multimap<uint16_t, block_extension> validate_and_extract_block_extensions(const extensions_type& block_extensions) {
Expand Down Expand Up @@ -85,11 +74,11 @@ namespace eosio { namespace chain {

}

flat_multimap<uint16_t, block_extension> signed_block_v0::validate_and_extract_extensions()const {
flat_multimap<uint16_t, block_extension> signed_block::validate_and_extract_extensions()const {
return validate_and_extract_block_extensions( block_extensions );
}

signed_block::signed_block( const signed_block_v0& other, bool legacy )
pruned_block::pruned_block( const signed_block& other, bool legacy )
: signed_block_header(static_cast<const signed_block_header&>(other)),
prune_state(legacy ? prune_state_type::complete_legacy : prune_state_type::complete),
block_extensions(other.block_extensions)
Expand All @@ -99,56 +88,46 @@ namespace eosio { namespace chain {
}
}

signed_block::signed_block( signed_block_v0&& other, bool legacy )
: signed_block_header(std::move(static_cast<signed_block_header&>(other))),
prune_state(legacy ? prune_state_type::complete_legacy : prune_state_type::complete),
block_extensions(std::move(other.block_extensions))
{
for(auto& trx : other.transactions) {
transactions.emplace_back(std::move(trx), legacy);
}
}

static std::size_t pruned_trx_receipt_packed_size(const packed_transaction& obj, packed_transaction::cf_compression_type segment_compression) {
static std::size_t pruned_trx_receipt_packed_size(const pruned_transaction& obj, pruned_transaction::cf_compression_type segment_compression) {
return obj.maximum_pruned_pack_size(segment_compression);
}
static std::size_t pruned_trx_receipt_packed_size(const transaction_id_type& obj, packed_transaction::cf_compression_type) {
static std::size_t pruned_trx_receipt_packed_size(const transaction_id_type& obj, pruned_transaction::cf_compression_type) {
return fc::raw::pack_size(obj);
}

std::size_t transaction_receipt::maximum_pruned_pack_size( packed_transaction::cf_compression_type segment_compression ) const {
std::size_t pruned_transaction_receipt::maximum_pruned_pack_size( pruned_transaction::cf_compression_type segment_compression ) const {
return fc::raw::pack_size(*static_cast<const transaction_receipt_header*>(this)) + 1 +
trx.visit([&](const auto& obj){ return pruned_trx_receipt_packed_size(obj, segment_compression); });
}

std::size_t signed_block::maximum_pruned_pack_size( packed_transaction::cf_compression_type segment_compression ) const {
std::size_t pruned_block::maximum_pruned_pack_size( pruned_transaction::cf_compression_type segment_compression ) const {
std::size_t result = fc::raw::pack_size(fc::unsigned_int(transactions.size()));
for(const transaction_receipt& r: transactions) {
for(const pruned_transaction_receipt& r: transactions) {
result += r.maximum_pruned_pack_size( segment_compression );
}
return fc::raw::pack_size(*static_cast<const signed_block_header*>(this)) + fc::raw::pack_size(prune_state) + result + fc::raw::pack_size(block_extensions);
}

flat_multimap<uint16_t, block_extension> signed_block::validate_and_extract_extensions()const {
flat_multimap<uint16_t, block_extension> pruned_block::validate_and_extract_extensions()const {
return validate_and_extract_block_extensions( block_extensions );
}

fc::optional<signed_block_v0> signed_block::to_signed_block_v0() const {
signed_block_ptr pruned_block::to_signed_block() const {
if (prune_state != prune_state_type::complete_legacy)
return {};
return signed_block_ptr{};

signed_block_v0 result(*static_cast<const signed_block_header*>(this));
result.block_extensions = this->block_extensions;
auto result = std::make_shared<signed_block>(*static_cast<const signed_block_header*>(this));
result->block_extensions = this->block_extensions;

auto visitor = overloaded{
[](const transaction_id_type &id) -> transaction_receipt_v0::trx_type { return id; },
[](const packed_transaction &trx) -> transaction_receipt_v0::trx_type {
const auto& legacy = trx.get_prunable_data().prunable_data.get<packed_transaction::prunable_data_type::full_legacy>();
return packed_transaction_v0(trx.get_packed_transaction(), legacy.signatures, legacy.packed_context_free_data, trx.get_compression());
[](const transaction_id_type &id) -> transaction_receipt::trx_type { return id; },
[](const pruned_transaction &trx) -> transaction_receipt::trx_type {
const auto& legacy = trx.get_prunable_data().prunable_data.get<prunable_transaction_data::full_legacy>();
return packed_transaction(trx.get_packed_transaction(), legacy.signatures, legacy.packed_context_free_data, trx.get_compression());
}};

for (const transaction_receipt &r : transactions){
result.transactions.emplace_back(transaction_receipt_v0{r, r.trx.visit(visitor)});
for (const pruned_transaction_receipt &r : transactions){
result->transactions.emplace_back(transaction_receipt{r, r.trx.visit(visitor)});
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/block_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace eosio { namespace chain {
return fc::endian_reverse_u32(id._hash[0]);
}

block_id_type block_header::calculate_id()const
block_id_type block_header::id()const
{
// Do not include signed_block_header attributes in id, specifically exclude producer_signature.
block_id_type result = digest(); //fc::sha256::hash(*static_cast<const block_header*>(this));
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ namespace eosio { namespace chain {

block_header_state result( std::move( *static_cast<detail::block_header_state_common*>(this) ) );

result.id = h.calculate_id();
result.id = h.id();
result.header = h;

result.header_exts = std::move(exts);
Expand Down
Loading

0 comments on commit 87f7d98

Please sign in to comment.