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

Fix blockstore get gas charge #751

Merged
merged 5 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions vm/interpreter/src/gas_block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ where
{
/// Get bytes from block store by Cid
fn get_bytes(&self, cid: &Cid) -> Result<Option<Vec<u8>>, Box<dyn StdError>> {
self.gas
.borrow_mut()
.charge_gas(self.price_list.on_ipld_get())?;
let ret = self
.store
.get_bytes(cid)
.map_err(|e| actor_error!(fatal("failed to get block from blockstore: {}", e)))?;
if let Some(bz) = &ret {
self.gas
.borrow_mut()
.charge_gas(self.price_list.on_ipld_get(bz.len()))?;
}
Ok(ret)
}

Expand All @@ -53,9 +51,14 @@ where
S: Serialize,
T: MultihashDigest,
{
// TODO try to avoid serializing all data twice (it adds up)
// The reason this is needed is because there is unintended interactions
// when writing to the store directly, because other blockstore implmentations
// expect bytes to be written through the put function.
// Consider maybe adding a put_raw function, which avoids serialization.
self.gas
.borrow_mut()
.charge_gas(self.price_list.on_ipld_put(to_vec(obj).unwrap().len()))?;
.charge_gas(self.price_list.on_ipld_put(to_vec(obj)?.len()))?;

Ok(self
.store
Expand Down
2 changes: 1 addition & 1 deletion vm/interpreter/src/gas_tracker/price_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl PriceList {
}
/// Returns the gas required for storing an object
#[inline]
pub fn on_ipld_get(&self, _: usize) -> GasCharge {
pub fn on_ipld_get(&self) -> GasCharge {
GasCharge::new("on_ipld_get", self.ipld_get_base, 0)
}
/// Returns the gas required for storing an object
Expand Down