Skip to content

Commit

Permalink
Merge remote-tracking branch 'stylus/stylus' into hostio-caching2
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Sep 5, 2023
2 parents 1d089b5 + cf0d64c commit 78a0770
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["stylus-sdk", "stylus-proc"]
resolver = "2"

[workspace.package]
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Offchain Labs"]
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions stylus-proc/src/methods/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub fn external(_attr: TokenStream, input: TokenStream) -> TokenStream {
is_clause.extend(inherits.iter().enumerate().map(|(i, ty)| {
let comma = (i > 0).then_some(", ").unwrap_or_default();
quote! {
write!(f, "{}{}", #comma, <#ty as GenerateAbi>::NAME)?;
write!(f, "{}I{}", #comma, <#ty as GenerateAbi>::NAME)?;
}
}));

Expand All @@ -285,7 +285,7 @@ pub fn external(_attr: TokenStream, input: TokenStream) -> TokenStream {
use stylus_sdk::abi::internal::write_solidity_returns;
use stylus_sdk::abi::export::{underscore_if_sol};
#(#inherited_abis)*
write!(f, "interface {}", #name)?;
write!(f, "interface I{}", #name)?;
#is_clause
write!(f, " {{")?;
#abi
Expand Down
32 changes: 31 additions & 1 deletion stylus-sdk/src/call/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

use crate::{
contract::{self, read_return_data},
hostio, tx, ArbResult,
hostio,
storage::StorageCache,
tx, ArbResult,
};
use alloy_primitives::{Address, B256, U256};

Expand All @@ -16,6 +18,7 @@ pub struct RawCall {
gas: Option<u64>,
offset: usize,
size: Option<usize>,
cache_policy: CachePolicy,
}

/// What kind of call to perform.
Expand All @@ -27,6 +30,14 @@ enum CallKind {
Static,
}

#[derive(Clone, Default, PartialEq, PartialOrd)]
enum CachePolicy {
#[default]
DoNothing,
Flush,
Clear,
}

#[derive(Copy, Clone)]
#[repr(C)]
struct RustVec {
Expand Down Expand Up @@ -110,6 +121,20 @@ impl RawCall {
self.limit_return_data(0, 0)
}

/// Write all cached values to persistent storage before the call.
pub fn flush_storage_cache(mut self) -> Self {
if self.cache_policy < CachePolicy::Flush {
self.cache_policy = CachePolicy::Flush;
}
self
}

/// Flush and clear the storage cache before the call.
pub fn clear_storage_cache(mut self) -> Self {
self.cache_policy = CachePolicy::Clear;
self
}

/// Performs a raw call to another contract at the given address with the given `calldata`.
///
/// # Safety
Expand All @@ -123,6 +148,11 @@ impl RawCall {
let gas = self.gas.unwrap_or(u64::MAX); // will be clamped by 63/64 rule
let value = B256::from(self.callvalue);
let status = unsafe {
match self.cache_policy {
CachePolicy::Clear => StorageCache::clear(),
CachePolicy::Flush => StorageCache::flush(),
CachePolicy::DoNothing => {}
}
match self.kind {
CallKind::Basic => hostio::call_contract(
contract.as_ptr(),
Expand Down

0 comments on commit 78a0770

Please sign in to comment.