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

Add support for a gas-based storage limit #173

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
6 changes: 3 additions & 3 deletions core/src/external.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use primitive_types::H160;
use primitive_types::{H160, U256};

/// Operations for recording external costs
pub enum ExternalOperation {
Expand All @@ -8,6 +8,6 @@ pub enum ExternalOperation {
AddressCodeRead(H160),
/// Basic check for account emptiness. Fixed size.
IsEmpty,
/// Writing to storage. Fixed size.
Write,
/// Writing to storage (Number of bytes written).
Write(U256),
}
11 changes: 6 additions & 5 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pub trait StackState<'config>: Backend {
&mut self,
_ref_time: Option<u64>,
_proof_size: Option<u64>,
_storage_growth: Option<u64>,
) -> Result<(), ExitError> {
Ok(())
}
Expand Down Expand Up @@ -1009,10 +1010,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
{
Ok(()) => {
let exit_result = self.exit_substate(StackExitKind::Succeeded);

if let Err(e) =
self.record_external_operation(crate::ExternalOperation::Write)
{
if let Err(e) = self.record_external_operation(
crate::ExternalOperation::Write(U256::from(out.len())),
) {
return (e.into(), None, Vec::new());
}
self.state.set_code(address, out);
Expand Down Expand Up @@ -1465,10 +1465,11 @@ impl<'inner, 'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Pr
&mut self,
ref_time: Option<u64>,
proof_size: Option<u64>,
storage_growth: Option<u64>,
) -> Result<(), ExitError> {
self.executor
.state
.record_external_cost(ref_time, proof_size)
.record_external_cost(ref_time, proof_size, storage_growth)
}

/// Refund Substrate specific cost.
Expand Down
1 change: 1 addition & 0 deletions src/executor/stack/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub trait PrecompileHandle {
&mut self,
ref_time: Option<u64>,
proof_size: Option<u64>,
storage_growth: Option<u64>,
) -> Result<(), ExitError>;

/// Refund Substrate specific cost.
Expand Down
Loading