Skip to content

Commit

Permalink
Addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed Nov 11, 2024
1 parent a3a325b commit 3b6ce2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
23 changes: 11 additions & 12 deletions crates/gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ pub type Result<T> = std::result::Result<T, Error>;
// This type should not implement the Copy trait to prevent charging gas more
// than once
#[derive(
Copy,
Clone,
Debug,
Default,
Expand Down Expand Up @@ -435,7 +434,7 @@ impl GasMetering for TxGasMeter {

if self.transaction_gas > self.tx_gas_limit {
return Err(Error::TransactionGasExceededError(
self.tx_gas_limit.into(),
self.tx_gas_limit.clone().into(),
));
}

Expand All @@ -445,15 +444,15 @@ impl GasMetering for TxGasMeter {
/// Get the entire gas used by the transaction up until this point
fn get_tx_consumed_gas(&self) -> Gas {
if !self.gas_overflow {
self.transaction_gas
self.transaction_gas.clone()
} else {
hints::cold();
u64::MAX.into()
}
}

fn get_gas_limit(&self) -> Gas {
self.tx_gas_limit
self.tx_gas_limit.clone()
}
}

Expand Down Expand Up @@ -491,7 +490,7 @@ impl TxGasMeter {
/// Get the amount of gas still available to the transaction
pub fn get_available_gas(&self) -> Gas {
self.tx_gas_limit
.checked_sub(self.transaction_gas)
.checked_sub(self.transaction_gas.clone())
.unwrap_or_default()
}
}
Expand All @@ -512,12 +511,12 @@ impl GasMetering for VpGasMeter {

let current_total = self
.initial_gas
.checked_add(self.current_gas)
.checked_add(self.current_gas.clone())
.ok_or(Error::GasOverflow)?;

if current_total > self.tx_gas_limit {
return Err(Error::TransactionGasExceededError(
self.tx_gas_limit.into(),
self.tx_gas_limit.clone().into(),
));
}

Expand All @@ -527,15 +526,15 @@ impl GasMetering for VpGasMeter {
/// Get the gas consumed by the tx alone before the vps were executed
fn get_tx_consumed_gas(&self) -> Gas {
if !self.gas_overflow {
self.initial_gas
self.initial_gas.clone()
} else {
hints::cold();
u64::MAX.into()
}
}

fn get_gas_limit(&self) -> Gas {
self.tx_gas_limit
self.tx_gas_limit.clone()
}
}

Expand All @@ -544,15 +543,15 @@ impl VpGasMeter {
pub fn new_from_tx_meter(tx_gas_meter: &TxGasMeter) -> Self {
Self {
gas_overflow: false,
tx_gas_limit: tx_gas_meter.tx_gas_limit,
initial_gas: tx_gas_meter.transaction_gas,
tx_gas_limit: tx_gas_meter.tx_gas_limit.clone(),
initial_gas: tx_gas_meter.transaction_gas.clone(),
current_gas: Gas::default(),
}
}

/// Get the gas consumed by the VP alone
pub fn get_vp_consumed_gas(&self) -> Gas {
self.current_gas
self.current_gas.clone()
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/node/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ where
|_| {
Err(Error::FeeError(format!(
"Masp fee payment unshielded an insufficient \
amount: Unshielded {balance} {}, required \
{fees}",
amount: Balance after unshielding: {balance} \
{}; required {fees}",
wrapper.fee.token
)))
},
Expand Down Expand Up @@ -1352,7 +1352,7 @@ where
))?;
gas_meter
.borrow()
.check_vps_limit(vps_gas)
.check_vps_limit(vps_gas.clone())
.map_err(|err| Error::GasError(err.to_string()))?;

Ok((result, vps_gas))
Expand Down Expand Up @@ -1384,7 +1384,7 @@ fn merge_vp_results(
.checked_add(b_gas)
.ok_or(Error::GasError(gas::Error::GasOverflow.to_string()))?;
tx_gas_meter
.check_vps_limit(vps_gas)
.check_vps_limit(vps_gas.clone())
.map_err(|err| Error::GasError(err.to_string()))?;

Ok((
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/src/native_vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ pub mod testing {
let current_epoch = tx_host_env::with(|env| {
// Reset the gas meter on each change, so that we never run
// out in this test
let gas_limit = env.gas_meter.borrow().tx_gas_limit;
let gas_limit = env.gas_meter.borrow().tx_gas_limit.clone();
env.gas_meter = RefCell::new(TxGasMeter::new(gas_limit));
env.state.in_mem().block.epoch
});
Expand Down

0 comments on commit 3b6ce2c

Please sign in to comment.