Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas for network usage #2205

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2205-network-gas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Charge gas for network usage.
([\#2205](https://github.com/anoma/namada/pull/2205))
9 changes: 8 additions & 1 deletion core/src/ledger/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const STORAGE_OCCUPATION_GAS_PER_BYTE: u64 =
// codebase. For these two reasons we just set an arbitrary value (based on
// actual SSDs latency) per byte here
const PHYSICAL_STORAGE_LATENCY_PER_BYTE: u64 = 75;
// This is based on the global avarage bandwidth
const NETWORK_TRANSMISSION_GAS_PER_BYTE: u64 = 13;

/// The cost of accessing data from memory (both read and write mode), per byte
pub const MEMORY_ACCESS_GAS_PER_BYTE: u64 = 2;
Expand Down Expand Up @@ -273,13 +275,18 @@ impl TxGasMeter {
/// Add the gas required by a wrapper transaction which is comprised of:
/// - cost of validating the wrapper tx
/// - space that the transaction requires in the block
/// - cost of downloading (as part of the block) the transaction bytes over
/// the network
pub fn add_wrapper_gas(&mut self, tx_bytes: &[u8]) -> Result<()> {
self.consume(WRAPPER_TX_VALIDATION_GAS)?;

let bytes_len = tx_bytes.len() as u64;
self.consume(
bytes_len
.checked_mul(STORAGE_OCCUPATION_GAS_PER_BYTE)
.checked_mul(
STORAGE_OCCUPATION_GAS_PER_BYTE
+ NETWORK_TRANSMISSION_GAS_PER_BYTE,
)
.ok_or(Error::GasOverflow)?,
)
}
Expand Down
Loading