-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for storing overhead/storage price in the block extra data
- Loading branch information
Showing
9 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "gas_prices.hpp" | ||
|
||
#if not defined(ANTELOPE) | ||
#include <silkworm/core/common/assert.hpp> | ||
#include <silkworm/core/common/endian.hpp> | ||
#include <silkworm/core/common/util.hpp> | ||
#endif | ||
|
||
namespace eosevm { | ||
|
||
bool operator==(const eosevm::gas_prices& a, const eosevm::gas_prices& b) { | ||
return a.overhead_price == b.overhead_price && a.storage_price == b.storage_price; | ||
} | ||
|
||
#if not defined(ANTELOPE) | ||
[[nodiscard]] silkworm::Bytes gas_prices::encode() const noexcept { | ||
silkworm::Bytes ret(16, '\0'); | ||
silkworm::endian::store_big_u64(&ret[0], overhead_price); | ||
silkworm::endian::store_big_u64(&ret[8], storage_price); | ||
return ret; | ||
} | ||
|
||
std::optional<gas_prices> gas_prices::decode(silkworm::ByteView encoded) noexcept { | ||
SILKWORM_ASSERT(encoded.length() >= 16); | ||
gas_prices prices; | ||
prices.overhead_price= silkworm::endian::load_big_u64(&encoded[0]); | ||
prices.storage_price = silkworm::endian::load_big_u64(&encoded[8]); | ||
return prices; | ||
} | ||
|
||
[[nodiscard]] evmc::bytes32 gas_prices::hash() const noexcept { | ||
auto encoded = this->encode(); | ||
evmc::bytes32 header_hash = std::bit_cast<evmc_bytes32>(silkworm::keccak256(encoded)); | ||
return header_hash; | ||
} | ||
#endif | ||
|
||
} // namespace eosevm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <algorithm> | ||
|
||
#if not defined(ANTELOPE) | ||
#include <silkworm/core/common/base.hpp> | ||
#endif | ||
|
||
namespace eosevm { | ||
|
||
struct gas_prices { | ||
uint64_t overhead_price; | ||
uint64_t storage_price; | ||
|
||
#if not defined(ANTELOPE) | ||
// Encode for storage in db. | ||
[[nodiscard]] silkworm::Bytes encode() const noexcept; | ||
|
||
// Decode from storage in db. | ||
static std::optional<gas_prices> decode(silkworm::ByteView encoded) noexcept; | ||
evmc::bytes32 hash() const noexcept; | ||
#endif | ||
|
||
friend bool operator==(const gas_prices&, const gas_prices&); | ||
}; | ||
|
||
inline uint64_t calculate_base_fee_per_gas(uint64_t overhead_price, uint64_t storage_price) { | ||
return std::max(overhead_price, storage_price); | ||
} | ||
|
||
} // namespace eosevm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters