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 non default gas values (eth_estimateGas & zks_estimateFee) #31

Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
78011f3
feat: Implement eth_estimateGas
MexicanAce Aug 3, 2023
eba8189
Implement binary search algorithm and basic multiplier
MexicanAce Aug 4, 2023
ddcf967
Add println when call fails even with max gas
MexicanAce Aug 4, 2023
2b85742
Fix estimateGas
MexicanAce Aug 8, 2023
0922ba0
Only load the fee_estimate contract once. Implement balance adjusted …
MexicanAce Aug 9, 2023
363965e
Add launch configurations for local debugging.
MexicanAce Aug 9, 2023
c2978a5
Merge branch 'main' into nicolasvillanueva-devrl-130-add-support-for-…
MexicanAce Aug 9, 2023
3230e08
Update code to closer match what we do in production. Moved helper fu…
MexicanAce Aug 9, 2023
d46589a
Migrate all fee estimate code into a helper function on the InnerNode…
MexicanAce Aug 9, 2023
7de10d8
Move functions so they can be accessed by the zks namespace. Implemen…
MexicanAce Aug 9, 2023
3594b9b
Fix lint errors. Add lint-fix command to Makefile.
MexicanAce Aug 9, 2023
1623f3f
Merge branch 'main' into nicolasvillanueva-devrl-130-add-support-for-…
MexicanAce Aug 9, 2023
0eda41a
Update eth_estimateGas support in docs
MexicanAce Aug 9, 2023
e97b616
Fix test. Remove comments. Update comment docs for estimate_gas_impl.
MexicanAce Aug 9, 2023
cc7872f
Update src/node.rs
MexicanAce Aug 10, 2023
9ec6b78
Update src/utils.rs
MexicanAce Aug 10, 2023
a96b3dd
Update src/zks.rs
MexicanAce Aug 10, 2023
9b56216
Update src/utils.rs
MexicanAce Aug 10, 2023
f5cd4b5
Update src/utils.rs
MexicanAce Aug 10, 2023
ed30ec8
Move const variables to top of file. Remove unnecessary println state…
MexicanAce Aug 10, 2023
c3d9f37
Fix linting
MexicanAce Aug 10, 2023
5b7e262
Remove unused Clone logic for ForkStorage. Add more comments for vari…
MexicanAce Aug 10, 2023
6d5ae3b
Fix linting. Add too many arguments exception for estimate_gas_step n…
MexicanAce Aug 10, 2023
791e9d5
Fix unit test
MexicanAce Aug 10, 2023
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
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"recommendations": [
"rust-lang.rust-analyzer",
"humao.rest-client",
"vadimcn.vscode-lldb"
],
}
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ lint:
cargo fmt --all -- --check
cargo clippy -Zunstable-options -- -D warnings --allow clippy::unwrap_used

# Fix lint errors for Rust code
lint-fix:
cargo clippy --fix
cargo fmt

# Run unit tests for Rust code
test:
cargo test
Expand Down
2 changes: 1 addition & 1 deletion SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
| `EVM` | `evm_setTime` | NOT IMPLEMENTED | Sets the internal clock time to the given timestamp |
| `EVM` | `evm_snapshot` | NOT IMPLEMENTED | Snapshot the state of the blockchain at the current block |
| [`ETH`](#eth-namespace) | [`eth_chainId`](#eth_chainid) | SUPPORTED | Returns the currently configured chain id |
| [`ETH`](#eth-namespace) | [`eth_estimateGas`](#eth_estimategas) | PARTIALLY | Generates and returns an estimate of how much gas is necessary for the transaction to complete |
| [`ETH`](#eth-namespace) | [`eth_estimateGas`](#eth_estimategas) | SUPPORTED | Generates and returns an estimate of how much gas is necessary for the transaction to complete |
| [`ETH`](#eth-namespace) | [`eth_gasPrice`](#eth_gasprice) | SUPPORTED | Returns the current price per gas in wei |
| [`ETH`](#eth-namespace) | [`eth_getBalance`](#eth_getbalance) | SUPPORTED | Returns the balance of the account of given address |
| [`ETH`](#eth-namespace) | [`eth_getBlockByNumber`](#eth_getblockbynumber) | PARTIALLY | Returns information about a block by block number |
Expand Down
2 changes: 1 addition & 1 deletion src/deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt;
use self::system_contracts::COMPILED_IN_SYSTEM_CONTRACTS;

/// In-memory storage.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct InMemoryStorage {
pub(crate) state: HashMap<StorageKey, StorageValue>,
pub(crate) factory_deps: HashMap<H256, Vec<u8>>,
Expand Down
21 changes: 21 additions & 0 deletions src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ pub struct ForkStorage {
pub chain_id: L2ChainId,
}

impl Clone for ForkStorage {
fn clone(&self) -> Self {
let inner = Arc::new(RwLock::new(self.inner.read().unwrap().clone()));
MexicanAce marked this conversation as resolved.
Show resolved Hide resolved
Self {
inner,
chain_id: self.chain_id,
}
}
}

#[derive(Debug)]
pub struct ForkStorageInner {
// Underlying local storage
Expand All @@ -65,6 +75,17 @@ pub struct ForkStorageInner {
pub fork: Option<ForkDetails>,
}

impl Clone for ForkStorageInner {
MexicanAce marked this conversation as resolved.
Show resolved Hide resolved
fn clone(&self) -> Self {
Self {
raw_storage: self.raw_storage.clone(),
value_read_cache: self.value_read_cache.clone(),
factory_dep_cache: self.factory_dep_cache.clone(),
fork: self.fork.clone(),
}
}
}

impl ForkStorage {
pub fn new(fork: Option<ForkDetails>, dev_use_local_contracts: bool) -> Self {
let chain_id = fork
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async fn build_json_http(
node: InMemoryNode,
net: NetNamespace,
config_api: ConfigurationApiNamespace,
zks: ZkMockNamespaceImpl,
) -> tokio::task::JoinHandle<()> {
let (sender, recv) = oneshot::channel::<()>();

Expand All @@ -116,7 +117,7 @@ async fn build_json_http(
io.extend_with(node.to_delegate());
io.extend_with(net.to_delegate());
io.extend_with(config_api.to_delegate());
io.extend_with(ZkMockNamespaceImpl.to_delegate());
io.extend_with(zks.to_delegate());

io
};
Expand Down Expand Up @@ -292,14 +293,15 @@ async fn main() -> anyhow::Result<()> {
}

let net = NetNamespace::new(L2ChainId(TEST_NODE_NETWORK_ID));

let config_api = ConfigurationApiNamespace::new(node.get_inner());
let zks = ZkMockNamespaceImpl::new(node.get_inner());

let threads = build_json_http(
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), opt.port),
node,
net,
config_api,
zks,
)
.await;

Expand Down
Loading
Loading