Skip to content

Commit

Permalink
rpcdaemon: fix ots_getContractCreator (#2061) (#2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Jun 10, 2024
1 parent c95fc40 commit 0005b66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
15 changes: 9 additions & 6 deletions silkworm/rpc/commands/ots_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,12 @@ Task<void> OtsRpcApi::handle_ots_get_contract_creator(const nlohmann::json& requ
BlockNum max_block_prev_chunk = 0;
roaring::Roaring64Map bitmap;

if (key_value.key.empty() || !key_value.key.starts_with(contract_address_byte_view)) {
reply = make_json_content(request, nlohmann::detail::value_t::null);
co_await tx->close();
co_return;
}
while (true) {
if (key_value.key.empty() || !key_value.key.starts_with(contract_address_byte_view)) {
reply = make_json_content(request, nlohmann::detail::value_t::null);
co_await tx->close();
co_return;
}

bitmap = db::bitmap::parse(key_value.value);
auto const max_block = bitmap.maximum();
auto block_key{db::block_key(max_block)};
Expand All @@ -451,6 +450,10 @@ Task<void> OtsRpcApi::handle_ots_get_contract_creator(const nlohmann::json& requ
}
max_block_prev_chunk = max_block;
key_value = co_await account_history_cursor->next();

if (key_value.key.empty() || !key_value.key.starts_with(contract_address_byte_view)) {
break;
}
}

uint64_t cardinality = bitmap.cardinality();
Expand Down
8 changes: 6 additions & 2 deletions silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,15 @@ std::optional<EVMExecutor::PreCheckResult> EVMExecutor::pre_check(const EVM& evm
return PreCheckResult{error, PreCheckErrorCode::kTipHigherThanFeeCap};
}
}
} else {
if (txn.type != silkworm::TransactionType::kLegacy && txn.type != silkworm::TransactionType::kAccessList) {
return PreCheckResult{"eip-1559 transactions require london", PreCheckErrorCode::kIsNotLondon};
}
}

if (rev >= EVMC_CANCUN) {
if (!evm.block().header.excess_blob_gas) {
std::string error = "internal Error Cancun is active but ExcessBlobGas is nil";
std::string error = "internal failure: Cancun is active but ExcessBlobGas is nil";
return PreCheckResult{error, PreCheckErrorCode::kInternalError};
}
}
Expand Down Expand Up @@ -264,7 +268,7 @@ ExecutionResult EVMExecutor::call(
intx::uint256 want;
if (txn.max_fee_per_gas > 0 || txn.max_priority_fee_per_gas > 0) {
// This method should be called after check (max_fee and base_fee) present in pre_check() method
const intx::uint256 effective_gas_price{txn.effective_gas_price(base_fee_per_gas)};
const intx::uint256 effective_gas_price{txn.max_fee_per_gas};
want = txn.gas_limit * effective_gas_price;
} else {
want = 0;
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 @@ -45,8 +45,9 @@ enum PreCheckErrorCode {
kInsufficientFunds,
kInternalError,
kIntrinsicGasTooLow,
kIsNotLondon,
kMaxFeePerBlobGasTooLowError,
kTipHigherThanFeeCap
kTipHigherThanFeeCap,
};

struct ExecutionResult {
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/evm_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TEST_CASE_METHOD(EVMExecutorTest, "EVMExecutor") {
EVMExecutor executor{*chain_config_ptr, workers, state};
const auto result = executor.call(block, txn, {});
CHECK(result.error_code == std::nullopt);
CHECK(result.pre_check_error.value() == "insufficient funds for gas * price + value: address 0xa872626373628737383927236382161739290870 have 0 want 60000");
CHECK(result.pre_check_error.value() == "insufficient funds for gas * price + value: address 0xa872626373628737383927236382161739290870 have 0 want 120000");
}

SECTION("doesn't fail if transaction cost greater user amount && gasBailout == true") {
Expand Down

0 comments on commit 0005b66

Please sign in to comment.