Skip to content

Commit

Permalink
ethereum: Update web3 (#3338)
Browse files Browse the repository at this point in the history
  • Loading branch information
leoyvens authored Mar 16, 2022
1 parent 4852d9f commit 852161f
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 447 deletions.
657 changes: 249 additions & 408 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chain/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
futures = "0.1.21"
http = "0.2.4"
jsonrpc-core = "17.0.0"
jsonrpc-core = "18.0.0"
graph = { path = "../../graph" }
lazy_static = "1.2.0"
mockall = "0.9.1"
Expand Down
20 changes: 10 additions & 10 deletions chain/ethereum/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,18 @@ impl<'a> Into<web3::types::Transaction> for TransactionTraceAt<'a> {
transaction_index: Some(U64::from(self.trace.index as u64)),
from: Some(H160::from_slice(&self.trace.from)),
to: Some(H160::from_slice(&self.trace.to)),
value: self
.trace
.value
.as_ref()
.map_or_else(|| U256::from(0), |x| x.into()),
gas_price: self
.trace
.gas_price
.as_ref()
.map_or_else(|| U256::from(0), |x| x.into()),
value: self.trace.value.as_ref().map_or(U256::zero(), |x| x.into()),
gas_price: self.trace.gas_price.as_ref().map(|x| x.into()),
gas: U256::from(self.trace.gas_used),
input: Bytes::from(self.trace.input.clone()),
v: None,
r: None,
s: None,
raw: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
transaction_type: None,
}
}
}
Expand Down Expand Up @@ -282,6 +278,10 @@ impl Into<EthereumBlockWithCalls> for &Block {
_ => Some(H256::from_slice(&r.state_root)),
},
logs_bloom: H2048::from_slice(&r.logs_bloom),
from: H160::from_slice(&t.from),
to: Some(H160::from_slice(&t.to)),
transaction_type: None,
effective_gas_price: None,
})
})
.collect(),
Expand Down
8 changes: 6 additions & 2 deletions chain/ethereum/src/ethereum_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,16 @@ impl EthereumAdapter {

async move {
let req = CallRequest {
from: None,
to: Some(contract_address),
gas: Some(web3::types::U256::from(ETH_CALL_GAS)),
data: Some(call_data.clone()),
from: None,
gas_price: None,
value: None,
data: Some(call_data.clone()),
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
transaction_type: None,
};
let result = web3.eth().call(req, Some(block_id)).boxed().await;

Expand Down
12 changes: 8 additions & 4 deletions chain/ethereum/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use web3::transports::{http, ipc, ws};
use web3::RequestId;

use graph::prelude::*;
use graph::url::Url;
use std::future::Future;

/// Abstraction over the different web3 transports.
Expand Down Expand Up @@ -37,10 +38,13 @@ impl Transport {
///
/// Note: JSON-RPC over HTTP doesn't always support subscribing to new
/// blocks (one such example is Infura's HTTP endpoint).
pub fn new_rpc(rpc: &str, headers: ::http::HeaderMap) -> Self {
http::Http::with_headers(rpc, headers)
.map(|transport| Transport::RPC(transport))
.expect("Failed to connect to Ethereum RPC")
pub fn new_rpc(rpc: Url, headers: ::http::HeaderMap) -> Self {
// Unwrap: This only fails if something is wrong with the system's TLS config.
let client = reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap();
Transport::RPC(http::Http::with_client(client, rpc))
}
}

Expand Down
2 changes: 1 addition & 1 deletion chain/ethereum/src/trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl From<&'_ Transaction> for EthereumTransactionData {
to: tx.to,
value: tx.value,
gas_limit: tx.gas,
gas_price: tx.gas_price,
gas_price: tx.gas_price.unwrap_or(U256::zero()), // EIP-1559 made this optional.
input: tx.input.0.clone(),
nonce: tx.nonce.clone(),
}
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
async-trait = "0.1.50"
atomic_refcell = "0.1.8"
async-stream = "0.3"
bytes = "0.5"
bytes = "1.0"
futures01 = { package="futures", version="0.1.31" }
futures = { version="0.3.4", features=["compat"] }
graph = { path = "../graph" }
Expand Down
10 changes: 5 additions & 5 deletions graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chrono = "0.4.19"
Inflector = "0.11.3"
isatty = "0.1.9"
reqwest = { version = "0.11.2", features = ["json", "stream", "multipart"] }
ethabi = "16.0"
ethabi = "17.0"
hex = "0.4.3"
http = "0.2.3"
fail = { version = "0.5", features = ["failpoints"] }
Expand All @@ -26,7 +26,7 @@ lazy_static = "1.4.0"
num-bigint = { version = "^0.2.6", features = ["serde"] }
num_cpus = "1.13.1"
num-traits = "0.2.14"
rand = "0.6.1"
rand = "0.8.4"
semver = {version = "1.0.6", features = ["serde"]}
serde = { version = "1.0.126", features = ["rc"] }
serde_derive = "1.0.125"
Expand All @@ -53,12 +53,12 @@ prost-types = "0.8.0"
futures03 = { version = "0.3.1", package = "futures", features = ["compat"] }
wasmparser = "0.78.2"
thiserror = "1.0.25"
parking_lot = "0.11.2"
parking_lot = "0.12.0"
itertools = "0.10.3"

# Our fork contains patches for custom http headers and to make some block fields optional.
# Our fork contains patches to make some fields optional for Celo and Fantom compatibility.
# Without the "arbitrary_precision" feature, we get the error `data did not match any variant of untagged enum Response`.
web3 = { git = "https://github.com/graphprotocol/rust-web3", branch = "lutter/graph-0.15.0", features = ["arbitrary_precision"] }
web3 = { git = "https://github.com/graphprotocol/rust-web3", branch = "graph-patches-onto-0.18", features = ["arbitrary_precision"] }
serde_plain = "1.0.0"

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions graph/examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::iter::FromIterator;
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};

use graph::prelude::{lazy_static, q};
use rand::SeedableRng;
use rand::{rngs::SmallRng, Rng};
use rand::{FromEntropy, SeedableRng};
use structopt::StructOpt;

use graph::util::cache_weight::CacheWeight;
Expand Down Expand Up @@ -254,7 +254,7 @@ impl ValueMap {
for i in 0..size {
let kind = rng
.as_deref_mut()
.map(|rng| rng.gen_range(0, modulus))
.map(|rng| rng.gen_range(0..modulus))
.unwrap_or(i % modulus);

let value = match kind {
Expand Down Expand Up @@ -455,7 +455,7 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
let size = if opt.fixed || opt.obj_size == 0 {
opt.obj_size
} else {
rng.gen_range(0, opt.obj_size)
rng.gen_range(0..opt.obj_size)
};
let before = ALLOCATED.load(SeqCst);
let sample = cacheable.sample(size, maybe_rng(opt, &mut rng));
Expand Down
2 changes: 1 addition & 1 deletion graph/src/data/subgraph/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl StableHash for SubgraphError {

pub fn generate_entity_id() -> String {
// Fast crypto RNG from operating system
let mut rng = OsRng::new().unwrap();
let mut rng = OsRng::default();

// 128 random bits
let id_bytes: [u8; 16] = rng.gen();
Expand Down
3 changes: 1 addition & 2 deletions graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
crossbeam = "0.8"
futures01 = { package="futures", version="0.1.29" }
graph = { path = "../graph" }
graphql-parser = "0.4.0"
graphql-tools = "0.0.19"
Expand All @@ -15,7 +14,7 @@ lazy_static = "1.2.0"
stable-hash = { git = "https://github.com/graphprotocol/stable-hash" }
once_cell = "1.9.0"
defer = "0.1"
parking_lot = "0.11"
parking_lot = "0.12"
anyhow = "1.0"

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion node/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use graph::ipfs_client::IpfsClient;
use graph::prelude::{anyhow, tokio, BlockNumber};
use graph::prelude::{prost, MetricsRegistry as MetricsRegistryTrait};
use graph::slog::{debug, error, info, o, Logger};
use graph::url::Url;
use graph::util::security::SafeDisplay;
use graph_chain_ethereum::{self as ethereum, EthereumAdapterTrait, Transport};
use graph_core::MetricsRegistry;
Expand Down Expand Up @@ -142,7 +143,7 @@ pub async fn create_ethereum_networks(
use crate::config::Transport::*;

let transport = match web3.transport {
Rpc => Transport::new_rpc(&web3.url, web3.headers.clone()),
Rpc => Transport::new_rpc(Url::parse(&web3.url)?, web3.headers.clone()),
Ipc => Transport::new_ipc(&web3.url).await,
Ws => Transport::new_ws(&web3.url).await,
};
Expand Down
3 changes: 2 additions & 1 deletion node/src/manager/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use graph_core::{
};
use lazy_static::lazy_static;
use std::str::FromStr;
use url::Url;

pub async fn run(
logger: Logger,
Expand Down Expand Up @@ -362,7 +363,7 @@ async fn create_ethereum_networks(
use crate::config::Transport::*;

let transport = match web3.transport {
Rpc => Transport::new_rpc(&web3.url, web3.headers.clone()),
Rpc => Transport::new_rpc(Url::parse(&web3.url)?, web3.headers.clone()),
Ipc => Transport::new_ipc(&web3.url).await,
Ws => Transport::new_ws(&web3.url).await,
};
Expand Down
1 change: 0 additions & 1 deletion runtime/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ proc-macro = true
[dependencies]
syn = { version = "1.0", features = ["full"] }
quote = "1.0"
anyhow = "1.0"
2 changes: 1 addition & 1 deletion runtime/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ graph = { path = "../../graph" }
graph-chain-ethereum = { path = "../../chain/ethereum" }
graph-runtime-wasm = { path = "../wasm" }
graph-core = { path = "../../core" }
graph-mock = { path = "../../mock" }

[dev-dependencies]
test-store = { path = "../../store/test-store" }
graph-mock = { path = "../../mock" }
3 changes: 1 addition & 2 deletions runtime/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ edition = "2021"
[dependencies]
async-trait = "0.1.50"
atomic_refcell = "0.1.8"
ethabi = "16.0"
ethabi = "17.0"
futures = "0.1.21"
hex = "0.4.3"
graph = { path = "../../graph" }
graph-graphql = { path = "../../graphql" }
bs58 = "0.4.0"
graph-runtime-derive = { path = "../derive" }
semver = "1.0.6"
Expand Down
2 changes: 1 addition & 1 deletion server/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ lazy_static = "1.2.0"
serde = "1.0"
serde_derive = "1.0"
tokio-tungstenite = "0.14"
uuid = { version = "0.7.2", features = ["v4"] }
uuid = { version = "0.8.1", features = ["v4"] }
anyhow = "1.0"
3 changes: 1 addition & 2 deletions store/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ lazy_static = "1.1"
lru_time_cache = "0.11"
maybe-owned = "0.3.4"
postgres = "0.19.1"
rand = "0.6.1"
rand = "0.8.4"
serde = "1.0"
uuid = { version = "0.8.1", features = ["v4"] }
stable-hash = { git = "https://github.com/graphprotocol/stable-hash" }
backtrace = "0.3"
diesel_derives = "1.4.1"
anyhow = "1.0.54"
git-testament = "0.2.0"
Expand Down

0 comments on commit 852161f

Please sign in to comment.