Skip to content

Commit

Permalink
Merge branch 'grarco/network-gas' (#2205)
Browse files Browse the repository at this point in the history
* origin/grarco/network-gas:
  Changelog #2205
  Charges wrapper gas for network usage
  • Loading branch information
tzemanovic committed Nov 28, 2023
2 parents 1a321b2 + 13ce967 commit 4f8ed64
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit 4f8ed64

Please sign in to comment.