Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 committed Oct 1, 2024
1 parent 1c94d67 commit 7e5c6e2
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion silkworm/core/execution/execution_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_CASE("Execute two blocks") {

static constexpr auto kEncoder = [](Bytes& to, const Receipt& r) { rlp::encode(to, r); };
std::vector<Receipt> receipts{
{TransactionType::kDynamicFee, true, block.header.gas_used, block.header.gas_used, {}, {}},
{TransactionType::kDynamicFee, true, block.header.gas_used, {}, {}},
};
block.header.receipts_root = trie::root_hash(receipts, kEncoder);

Expand Down
1 change: 0 additions & 1 deletion silkworm/core/execution/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ void ExecutionProcessor::execute_transaction(const Transaction& txn, Receipt& re
receipt.type = txn.type;
receipt.success = vm_res.status == EVMC_SUCCESS;
receipt.cumulative_gas_used = cumulative_gas_used_;
receipt.gas_used = gas_used;
receipt.bloom = logs_bloom(state_.logs());
std::swap(receipt.logs, state_.logs());
}
Expand Down
2 changes: 0 additions & 2 deletions silkworm/core/execution/processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ TEST_CASE("No refund on error") {
processor.execute_transaction(txn, receipt2);
CHECK(!receipt2.success);
CHECK(receipt2.cumulative_gas_used - receipt1.cumulative_gas_used == txn.gas_limit);
CHECK(receipt2.gas_used == txn.gas_limit);
}

TEST_CASE("Self-destruct") {
Expand Down Expand Up @@ -218,7 +217,6 @@ TEST_CASE("Self-destruct") {
CHECK(processor.evm().state().get_balance(suicidal_address) == 0);

CHECK(receipt2.cumulative_gas_used == receipt1.cumulative_gas_used + protocol::fee::kGTransaction);
CHECK(receipt2.gas_used == protocol::fee::kGTransaction);
}

TEST_CASE("Out of Gas during account re-creation") {
Expand Down
5 changes: 2 additions & 3 deletions silkworm/core/trie/vector_root_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ TEST_CASE("Empty root hash") {

TEST_CASE("Hardcoded root hash") {
std::vector<Receipt> receipts{
{TransactionType::kLegacy, true, 0, 21'000, {}, {}},
{TransactionType::kLegacy, true, 0, 42'000, {}, {}},
{TransactionType::kLegacy, true, 21'000, {}, {}},
{TransactionType::kLegacy, true, 42'000, {}, {}},
{TransactionType::kLegacy,
true,
0,
65'092,
{},
{Log{0x8d12a197cb00d4747a1fe03395095ce2a5cc6819_address,
Expand Down
1 change: 0 additions & 1 deletion silkworm/core/types/receipt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace silkworm {
struct Receipt {
TransactionType type{TransactionType::kLegacy};
bool success{false};
uint64_t gas_used{0};
uint64_t cumulative_gas_used{0};
Bloom bloom{};
std::vector<Log> logs;
Expand Down
12 changes: 9 additions & 3 deletions silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ ExecutionResult EVMExecutor::call(
ExecutionResult EVMExecutor::call_with_receipt(
const silkworm::Block& block,
const silkworm::Transaction& txn,
silkworm::Receipt& receipt,
Receipt& receipt,
const Tracers& tracers,
bool refund,
bool gas_bailout) {
Expand Down Expand Up @@ -409,8 +409,14 @@ ExecutionResult EVMExecutor::call_with_receipt(
receipt.success = result.status == EVMC_SUCCESS;
receipt.bloom = logs_bloom(ibs_state_.logs());
receipt.gas_used = gas_used;
receipt.type = txn.type;
std::swap(receipt.logs, ibs_state_.logs());
receipt.type = static_cast<uint8_t>(txn.type);
for (size_t j{0}; j < ibs_state_.logs().size(); j++) {
Log rpc_log;
rpc_log.address = ibs_state_.logs()[j].address;
rpc_log.data = ibs_state_.logs()[j].data;
rpc_log.topics = ibs_state_.logs()[j].topics;
receipt.logs.push_back(rpc_log);
}

ExecutionResult exec_result{result.status, gas_left, result.data};

Expand Down
3 changes: 2 additions & 1 deletion silkworm/rpc/core/evm_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <silkworm/db/chain/chain_storage.hpp>
#include <silkworm/db/state/state_reader.hpp>
#include <silkworm/rpc/common/worker_pool.hpp>
#include <silkworm/rpc/types/receipt.hpp>

namespace silkworm::rpc {

Expand Down Expand Up @@ -129,7 +130,7 @@ class EVMExecutor {
ExecutionResult call_with_receipt(
const silkworm::Block& block,
const silkworm::Transaction& txn,
silkworm::Receipt& receipt,
Receipt& receipt,
const Tracers& tracers = {},
bool refund = true,
bool gas_bailout = false);
Expand Down
17 changes: 3 additions & 14 deletions silkworm/rpc/core/receipts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,13 @@ Task<std::optional<Receipts>> generate_receipts(db::kv::api::Transaction& tx, co
uint64_t cumulative_gas_used{0};

for (size_t index = 0; index < transactions.size(); index++) {
silkworm::Receipt evm_receipt{};
Receipt receipt{};
Receipt receipt;

const silkworm::Transaction& transaction{block.transactions[index]};
auto result = executor.call_with_receipt(block, transaction, evm_receipt, {}, /*refund=*/true, /*gas_bailout=*/false);
auto result = executor.call_with_receipt(block, transaction, receipt, {}, /*refund=*/true, /*gas_bailout=*/false);

cumulative_gas_used += evm_receipt.gas_used;
cumulative_gas_used += receipt.gas_used;
receipt.cumulative_gas_used = cumulative_gas_used;
receipt.success = result.success();
receipt.gas_used = evm_receipt.gas_used;
receipt.bloom = evm_receipt.bloom;
for (size_t j{0}; j < evm_receipt.logs.size(); j++) {
Log rpc_log;
rpc_log.address = evm_receipt.logs[j].address;
rpc_log.data = evm_receipt.logs[j].data;
rpc_log.topics = evm_receipt.logs[j].topics;
receipt.logs.push_back(rpc_log);
}
rpc_receipts.push_back(receipt);

executor.reset();
Expand Down

0 comments on commit 7e5c6e2

Please sign in to comment.