Skip to content

Commit

Permalink
Merge pull request #2759 from golemfactory/add-golemsp-to-deb
Browse files Browse the repository at this point in the history
Add golemsp to deb (provider variant)
  • Loading branch information
nieznanysprawiciel authored Sep 26, 2023
2 parents 2396ac5 + 32cd292 commit a6a921b
Show file tree
Hide file tree
Showing 26 changed files with 590 additions and 607 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

integration-test-groups:
name: Integration Tests (hybrid-net) group
runs-on: [goth, ubuntu-18.04]
runs-on: [goth2, ubuntu-22.04]
needs: test_check
strategy:
matrix:
Expand All @@ -50,17 +50,16 @@ jobs:
- name: Configure Python
uses: actions/setup-python@v2
with:
python-version: "3.8.0"
python-version: "3.10"

- name: Configure Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: 1.2.2
poetry-version: 1.6.1
working-directory: "./goth_tests"

- name: Install dependencies
run: |
poetry config experimental.new-installer false
poetry install --no-root
- name: Disconnect Docker containers from default network
Expand Down Expand Up @@ -115,7 +114,7 @@ jobs:
# Python version below should agree with the version set up by this job.
# In the future we'll be able to use the `--all` flag here to remove envs for
# all Python versions (https://github.com/python-poetry/poetry/issues/3208).
run: poetry env remove python3.8
run: poetry env remove --all

integration-test:
name: Integration Tests (hybrid-net)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ assets = [
"usr/lib/yagna/plugins/",
"755",
],
[
"target/release/golemsp",
"usr/bin/",
"755",
],
[
"README.md",
"usr/share/doc/yagna/",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Other ExeUnit types are to come (see below).
Important milestones for Golem development were [Beta I](https://github.com/golemfactory/yagna/releases/tag/v0.6.1) and most recent [Beta II](https://github.com/golemfactory/yagna/releases/tag/v0.7.0). With those releases we have delivered:
* MVP (minimum viable product), though not feature rich yet, it is usable for early adopters
* Clean and easy experience for new and existing users.
* Support for GLM payments (both L1 & L2 on Ethreum Mainnet)
* Support for GLM payments (both L1 & L2 on Ethereum Mainnet)
* **Production-ready** and **easy to maintain** code base.
* **Modular architecture** with all the building blocks beeing replaceable.
* **Modular architecture** with all the building blocks being replaceable.
* Small binaries (under 30Mb).
* [Documentation and SDK](https://handbook.golem.network/) for Golem app developers.

Expand Down
4 changes: 2 additions & 2 deletions core/payment-driver/erc20/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ya_payment_driver::{
};

// Local uses
use crate::{dao::Erc20Dao, network::SUPPORTED_NETWORKS, DRIVER_NAME, RINKEBY_NETWORK};
use crate::{dao::Erc20Dao, network::SUPPORTED_NETWORKS, DRIVER_NAME, GOERLI_NETWORK};

mod api;
mod cli;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl PaymentDriver for Erc20Driver {
}

fn get_default_network(&self) -> String {
RINKEBY_NETWORK.to_string()
GOERLI_NETWORK.to_string()
}

fn get_networks(&self) -> HashMap<String, NetworkConfig> {
Expand Down
31 changes: 25 additions & 6 deletions core/payment-driver/erc20/src/driver/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use chrono::Utc;

// Workspace uses
use ya_payment_driver::driver::PaymentDriver;
use ya_payment_driver::{
bus,
db::models::Network,
Expand All @@ -32,13 +33,31 @@ pub async fn init(driver: &Erc20Driver, msg: Init) -> Result<(), GenericError> {
driver.is_account_active(&address)?
}

wallet::init_wallet(&msg)
.timeout(Some(30))
.await
.map_err(GenericError::new)??;
wallet::init_wallet(
msg.address(),
msg.network()
.unwrap_or_else(|| driver.get_default_network()),
)
.timeout(Some(30))
.await
.map_err(GenericError::new)??;

let network = network::network_like_to_network(msg.network());
let token = network::get_network_token(network, msg.token());
let token = match network::get_network_token(network, msg.token()) {
Ok(token) => token,
Err(e) => {
return Err(GenericError::new(format!(
"Failed to initialize payment account. mode={:?}, address={}, driver={}, network={}, token={}: {}",
mode,
&msg.address(),
DRIVER_NAME,
network,
msg.token().unwrap_or_default(),
e
)));
}
};

bus::register_account(driver, &msg.address(), &network.to_string(), &token, mode).await?;

log::info!(
Expand Down Expand Up @@ -111,7 +130,7 @@ To be able to use mainnet Ethereum driver please send some GLM tokens and ETH fo
pub async fn transfer(dao: &Erc20Dao, msg: Transfer) -> Result<String, GenericError> {
log::debug!("transfer: {:?}", msg);
let network = network::network_like_to_network(msg.network);
let token = network::get_network_token(network, None);
let token = network::get_network_token(network, None)?;
let sender = msg.sender;
let sender_h160 = utils::str_to_addr(&sender)?;
let recipient = msg.to;
Expand Down
2 changes: 1 addition & 1 deletion core/payment-driver/erc20/src/driver/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub async fn confirm_payments(dao: &Erc20Dao, name: &str, network_key: &str) {
.map(|payment| payment.order_id.clone())
.collect();

let platform = match network::network_token_to_platform(Some(network), None) {
let platform = match network::network_token_to_platform(network, None) {
Ok(platform) => platform,
Err(e) => {
log::error!(
Expand Down
9 changes: 3 additions & 6 deletions core/payment-driver/erc20/src/erc20/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use web3::types::{H160, H256, U256, U64};
// Workspace uses
use ya_payment_driver::{
db::models::{Network, TransactionEntity, TxType},
model::{GenericError, Init, PaymentDetails},
model::{GenericError, PaymentDetails},
};

// Local uses
Expand All @@ -35,7 +35,6 @@ use crate::{
convert_u256_gas_to_float, str_to_addr, topic_to_str_address, u256_to_big_dec,
},
},
RINKEBY_NETWORK,
};
use ya_payment_driver::db::models::TransactionStatus;

Expand Down Expand Up @@ -70,10 +69,8 @@ pub async fn account_gas_balance(
Ok(balance)
}

pub async fn init_wallet(msg: &Init) -> Result<(), GenericError> {
log::debug!("init_wallet. msg={:?}", msg);
let address = msg.address();
let network = msg.network().unwrap_or_else(|| RINKEBY_NETWORK.to_string());
pub async fn init_wallet(address: String, network: String) -> Result<(), GenericError> {
log::debug!("init_wallet. address={}, network={}", address, network);
let network = Network::from_str(&network).map_err(GenericError::new)?;

// Validate address and that checking balance of GLM and ETH works.
Expand Down
41 changes: 21 additions & 20 deletions core/payment-driver/erc20/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,10 @@ pub fn platform_to_network_token(platform: String) -> Result<(DbNetwork, String)
}

pub fn network_token_to_platform(
network: Option<DbNetwork>,
network: DbNetwork,
token: Option<String>,
) -> Result<String, GenericError> {
let network = network.unwrap_or(*RINKEBY_DB_NETWORK);
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string()));
let network_config = match network_config {
Some(nc) => nc,
None => {
return Err(GenericError::new(format!(
"Unable to find platform for network={}",
network
)))
}
};

let network_config = get_network_config(&network)?;
let token = token.unwrap_or_else(|| network_config.default_token.clone());
let platform = network_config.tokens.get(&token);
let platform = match platform {
Expand Down Expand Up @@ -132,16 +121,28 @@ pub fn platform_to_currency(platform: String) -> Result<(String, String), Generi
}
}

pub fn get_network_token(network: DbNetwork, token: Option<String>) -> String {
// Fetch network config, safe as long as all DbNetwork entries are in SUPPORTED_NETWORKS
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string())).unwrap();
// TODO: Check if token in network.tokens
token.unwrap_or_else(|| network_config.default_token.clone())
pub fn get_network_token(
network: DbNetwork,
token: Option<String>,
) -> Result<String, GenericError> {
let network_config = get_network_config(&network)?;
Ok(token.unwrap_or_else(|| network_config.default_token.clone()))
}

pub fn network_like_to_network(network_like: Option<String>) -> DbNetwork {
match network_like {
Some(n) => DbNetwork::from_str(&n).unwrap_or(*RINKEBY_DB_NETWORK),
None => *RINKEBY_DB_NETWORK,
Some(n) => DbNetwork::from_str(&n).unwrap_or(*GOERLI_DB_NETWORK),
None => *GOERLI_DB_NETWORK,
}
}

pub fn get_network_config(network: &DbNetwork) -> Result<&Network, GenericError> {
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string()));
match network_config {
Some(network_config) => Ok(network_config),
None => Err(GenericError::new(format!(
"Network {} is not supported",
network
))),
}
}
4 changes: 2 additions & 2 deletions core/payment-driver/zksync/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl PaymentDriver for ZksyncDriver {
let token = get_network_token(
DbNetwork::from_str(&network).map_err(GenericError::new)?,
msg.token(),
);
)?;
bus::register_account(self, &address, &network, &token, mode).await?;

log::info!(
Expand Down Expand Up @@ -513,7 +513,7 @@ impl PaymentDriverCron for ZksyncDriver {
}

// TODO: Add token support
let platform = network_token_to_platform(Some(network), None).unwrap(); // TODO: Catch error?
let platform = network_token_to_platform(network, None).unwrap(); // TODO: Catch error?
let details = match wallet::verify_tx(tx_hash, network).await {
Ok(a) => a,
Err(e) => {
Expand Down
8 changes: 4 additions & 4 deletions core/payment-driver/zksync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
// Public
pub const DRIVER_NAME: &str = "zksync";

pub const DEFAULT_NETWORK: &str = "rinkeby";
pub const DEFAULT_TOKEN: &str = "tGLM";
pub const DEFAULT_PLATFORM: &str = "zksync-rinkeby-tglm";

pub const MAINNET_NETWORK: &str = "mainnet";
pub const MAINNET_TOKEN: &str = "GLM";
pub const MAINNET_PLATFORM: &str = "zksync-mainnet-glm";

pub const DEFAULT_NETWORK: &str = MAINNET_NETWORK;
pub const DEFAULT_TOKEN: &str = MAINNET_TOKEN;
pub const DEFAULT_PLATFORM: &str = MAINNET_PLATFORM;

pub use service::ZksyncService as PaymentDriverService;

// Private
Expand Down
50 changes: 20 additions & 30 deletions core/payment-driver/zksync/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@ use std::str::FromStr;
use ya_payment_driver::{db::models::Network as DbNetwork, driver::Network, model::GenericError};

// Local uses
use crate::{
DEFAULT_NETWORK, DEFAULT_PLATFORM, DEFAULT_TOKEN, MAINNET_NETWORK, MAINNET_PLATFORM,
MAINNET_TOKEN,
};
use crate::{DEFAULT_NETWORK, MAINNET_NETWORK, MAINNET_PLATFORM, MAINNET_TOKEN};

lazy_static::lazy_static! {
pub static ref SUPPORTED_NETWORKS: HashMap<String, Network> = hashmap! {
DEFAULT_NETWORK.to_string() => Network {
default_token: DEFAULT_TOKEN.to_string(),
tokens: hashmap! {
DEFAULT_TOKEN.to_string() => DEFAULT_PLATFORM.to_string()
}
},
MAINNET_NETWORK.to_string() => Network {
default_token: MAINNET_TOKEN.to_string(),
tokens: hashmap! {
Expand All @@ -32,7 +23,6 @@ lazy_static::lazy_static! {

pub fn platform_to_network_token(platform: String) -> Result<(DbNetwork, String), GenericError> {
match platform.as_str() {
DEFAULT_PLATFORM => Ok((*DEFAULT_DB_NETWORK, DEFAULT_TOKEN.to_owned())),
MAINNET_PLATFORM => Ok((*MAINNET_DB_NETWORK, MAINNET_TOKEN.to_owned())),
other => Err(GenericError::new(format!(
"Unable to find network for platform: {}",
Expand All @@ -42,22 +32,10 @@ pub fn platform_to_network_token(platform: String) -> Result<(DbNetwork, String)
}

pub fn network_token_to_platform(
network: Option<DbNetwork>,
network: DbNetwork,
token: Option<String>,
) -> Result<String, GenericError> {
let network =
network.unwrap_or(DbNetwork::from_str(DEFAULT_NETWORK).map_err(GenericError::new)?);
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string()));
let network_config = match network_config {
Some(nc) => nc,
None => {
return Err(GenericError::new(format!(
"Unable to find platform for network={}",
network
)))
}
};

let network_config = get_network_config(&network)?;
let token = token.unwrap_or_else(|| network_config.default_token.clone());
let platform = network_config.tokens.get(&token);
let platform = match platform {
Expand All @@ -72,9 +50,21 @@ pub fn network_token_to_platform(
Ok(platform.to_string())
}

pub fn get_network_token(network: DbNetwork, token: Option<String>) -> String {
// Fetch network config, safe as long as all DbNetwork entries are in SUPPORTED_NETWORKS
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string())).unwrap();
// TODO: Check if token in network.tokens
token.unwrap_or_else(|| network_config.default_token.clone())
pub fn get_network_token(
network: DbNetwork,
token: Option<String>,
) -> Result<String, GenericError> {
let network_config = get_network_config(&network)?;
Ok(token.unwrap_or_else(|| network_config.default_token.clone()))
}

pub fn get_network_config(network: &DbNetwork) -> Result<&Network, GenericError> {
let network_config = (*SUPPORTED_NETWORKS).get(&(network.to_string()));
match network_config {
Some(network_config) => Ok(network_config),
None => Err(GenericError::new(format!(
"Network {} is not supported",
network
))),
}
}
Loading

0 comments on commit a6a921b

Please sign in to comment.