Skip to content

Commit

Permalink
Merge branch 'master' into evik42/deploy-detailed-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Sep 12, 2023
2 parents 11fe40e + 7e93719 commit 8a19231
Show file tree
Hide file tree
Showing 19 changed files with 2,692 additions and 2,464 deletions.
10 changes: 8 additions & 2 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ YAGNA_DATADIR="."
#ACCOUNT_LIST="${YAGNA_DATADIR}/accounts.json"
#PAYMENT_SHUTDOWN_TIMEOUT_SECS=10

## All drivers
#RINKEBY_GETH_ADDR=http://1.geth.testnet.golem.network:55555
### All drivers

## Set list of Ethereum nodes used by payment driver for specified networks.
## By default payment driver will query nodes addresses from DNS record `{network_name}.rpc-node.dev.golem.network`.
## Setting any of these variables will disable DNS lookup mechanism and use custom list of nodes instead for chosen network.
#MAINNET_GETH_ADDR=https://geth.golem.network:55555
#GOERLI_GETH_ADDR=https://rpc.ankr.com/eth_goerli
#POLYGON_GETH_ADDR=https://bor.golem.network,https://polygon-rpc.com
#MUMBAI_GETH_ADDR=https://matic-mumbai.chainstacklabs.com

## ERC20 driver.
#ETH_FAUCET_ADDRESS=http://faucet.testnet.golem.network:4000/donate
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/binaries-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
- master
- release/*

env:
rust_stable: 1.71.1

jobs:
build:
name: Build binaries (aarch64)
Expand All @@ -23,7 +26,7 @@ jobs:
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: ${{ env.rust_stable }}
target: aarch64-unknown-linux-musl
override: true

Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/binaries-x86-64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ jobs:
- name: Build binaries
run: |
cargo build --features static-openssl --target x86_64-unknown-linux-musl
(cd core/gftp && cargo build --bin gftp -p gftp --features bin --target x86_64-unknown-linux-musl)
(cd golem_cli && cargo build --bin golemsp -p golemsp --target x86_64-unknown-linux-musl)
(cd agent/provider && cargo build --bin ya-provider -p ya-provider --target x86_64-unknown-linux-musl)
(cd exe-unit && cargo build --bin exe-unit -p ya-exe-unit --features openssl/vendored --target x86_64-unknown-linux-musl)
cargo build --features static-openssl --target x86_64-unknown-linux-musl -p yagna -p ya-exe-unit -p gftp -p golemsp -p ya-provider
- name: Copy binaries
shell: bash
Expand Down
73 changes: 10 additions & 63 deletions Cargo.lock

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

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yagna"
version = "0.12.2"
version = "0.12.3"
description = "Open platform and marketplace for distributed computations"
readme = "README.md"
authors = ["Golem Factory <contact@golem.network>"]
Expand Down Expand Up @@ -167,8 +167,6 @@ assets = [
"644",
],
]
[workspace.dependencies]
libsqlite3-sys = { version = "0.26.0", features = ["bundled"] }

[workspace]
members = [
Expand Down Expand Up @@ -219,6 +217,12 @@ members = [
"test-utils/test-framework/framework-macro"
]

[workspace.dependencies]
rand = "0.8.5"
url = "2.3.1"
trust-dns-resolver = "0.22"
libsqlite3-sys = { version = "0.26.0", features = ["bundled"] }

[patch.crates-io]
## SERVICES
ya-identity = { path = "core/identity" }
Expand Down
14 changes: 13 additions & 1 deletion core/payment-driver/base/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,19 @@ pub struct PaymentEntity {
pub network: Network,
}

#[derive(AsExpression, FromSqlRow, PartialEq, Eq, Debug, Clone, Copy, FromPrimitive, Default)]
#[derive(
AsExpression,
FromSqlRow,
PartialEq,
Eq,
PartialOrd,
Ord,
Debug,
Clone,
Copy,
FromPrimitive,
Default,
)]
#[sql_type = "Integer"]
pub enum Network {
Mainnet = 1, //Main Ethereum chain
Expand Down
6 changes: 5 additions & 1 deletion core/payment-driver/erc20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[features]
default = []
integration = []

[dependencies]
async-trait = "0.1"
Expand Down Expand Up @@ -33,7 +34,9 @@ tiny-keccak = { version = "2.0", features = ["keccak"] }
tokio = { version = "1", features = ["full"] }
uuid = { version = "0.8", features = ["v4"] }
web3 = { version = "0.16", default-features = false, features = [ "http-tls", "signing", "ws-tls-tokio" ] }

rand = { workspace = true }
url = { workspace=true }
trust-dns-resolver = { workspace=true, default-features = false }
## yagna dependencies
ya-payment-driver = "0.3"
ya-client-model = "0.5"
Expand All @@ -46,3 +49,4 @@ actix-rt = "2.7"
dotenv = "0.15.0"
env_logger = "0.7.1"
structopt = "0.3"
test-case = "3.1.0"
76 changes: 12 additions & 64 deletions core/payment-driver/erc20/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(clippy::too_many_arguments)]

use futures::prelude::*;
use std::collections::HashMap;
use std::pin::pin;
use std::sync::Arc;

use bigdecimal::BigDecimal;
Expand Down Expand Up @@ -199,12 +201,19 @@ async fn get_next_nonce_pending_with(
pub async fn with_clients<T, F, R>(network: Network, mut f: F) -> Result<T, GenericError>
where
F: FnMut(Web3<Http>) -> R,
R: futures::Future<Output = Result<T, ClientError>>,
R: Future<Output = Result<T, ClientError>>,
{
let clients = get_clients(network).await?;
lazy_static! {
static ref RESOLVER: super::rpc_resolv::RpcResolver = super::rpc_resolv::RpcResolver::new();
};

let mut clients = pin!(RESOLVER
.clients_for(network)
.await
.map_err(GenericError::new)?);
let mut last_err: Option<ClientError> = None;

for client in clients {
while let Some(client) = clients.next().await {
match f(client).await {
Ok(result) => return Ok(result),
Err(ClientError::Web3(e)) => match e {
Expand Down Expand Up @@ -526,67 +535,6 @@ async fn get_tx_receipt_with(
.map_err(Into::into)
}

fn get_rpc_addr_from_env(network: Network) -> Vec<String> {
match network {
Network::Mainnet => {
collect_rpc_addr_from("MAINNET_GETH_ADDR", "https://geth.golem.network:55555")
}
Network::Rinkeby => collect_rpc_addr_from(
"RINKEBY_GETH_ADDR",
"http://geth.testnet.golem.network:55555",
),
Network::Goerli => {
collect_rpc_addr_from("GOERLI_GETH_ADDR", "https://rpc.ankr.com/eth_goerli")
}
Network::Polygon => collect_rpc_addr_from(
"POLYGON_GETH_ADDR",
"https://bor.golem.network,https://polygon-rpc.com",
),
Network::Mumbai => collect_rpc_addr_from(
"MUMBAI_GETH_ADDR",
"https://matic-mumbai.chainstacklabs.com",
),
}
}

fn collect_rpc_addr_from(env: &str, default: &str) -> Vec<String> {
std::env::var(env)
.ok()
.unwrap_or_else(|| default.to_string())
.split(',')
.map(|path| path.to_string())
.collect()
}

async fn get_clients(network: Network) -> Result<Vec<Web3<Http>>, GenericError> {
let geth_addrs = get_rpc_addr_from_env(network);
let mut clients: Vec<Web3<Http>> = Default::default();

for geth_addr in geth_addrs {
{
let client_map = WEB3_CLIENT_MAP.read().await;
if let Some(client) = client_map.get(&geth_addr).cloned() {
clients.push(client);
continue;
}
}

let transport = match web3::transports::Http::new(&geth_addr) {
Ok(t) => t,
Err(_) => continue,
};

let client = Web3::new(transport);

let mut client_map = WEB3_CLIENT_MAP.write().await;
client_map.insert(geth_addr, client.clone());

clients.push(client);
}

Ok(clients)
}

fn get_env(network: Network) -> config::EnvConfiguration {
match network {
Network::Mainnet => *config::MAINNET_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions core/payment-driver/erc20/src/erc20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub mod wallet;
mod config;
pub mod eth_utils;
mod gasless_transfer;
mod rpc_resolv;
pub mod transaction;
Loading

0 comments on commit 8a19231

Please sign in to comment.