Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 committed Nov 29, 2023
1 parent 5bf08bd commit 117172d
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 259 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

173 changes: 4 additions & 169 deletions config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,94 +30,6 @@ automatic-recover = false
ignore-deadlines = false


[chain.ethereum]
chain-name = "Ethereum"
chain-id = 1
currency-symbol = "ETH"
priority-fee = 1.01
max-fee-per-gas = 40.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429", symbol = "GLM" }
confirmation-blocks = 1
block-explorer-url = "https://etherscan.io"

[[chain.ethereum.rpc-endpoints]]
names = """
virginia.rpc.blxrbdn.com,
public.blastapi.io,
rpc.ankr.com/eth,rpc.flashbots.net,
cloudflare-eth.com,
ethereum.publicnode.com,
rpc.payload.de
"""
endpoints = """
https://virginia.rpc.blxrbdn.com,
https://eth-mainnet.public.blastapi.io,
https://rpc.ankr.com/eth,
https://rpc.flashbots.net,
https://cloudflare-eth.com,
https://ethereum.publicnode.com,
https://rpc.payload.de
"""
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 120


[chain.goerli]
chain-name = "Goerli"
chain-id = 5
currency-symbol = "tETH"
priority-fee = 0.000001
max-fee-per-gas = 10.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x33af15c79d64b85ba14aaffaa4577949104b22e8", symbol = "tGLM" }
multi-contract = { address = "0x7777784f803a7bf1d7f115f849d29ce5706da64a", max-at-once = 10 }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_eth-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4001 }
mint-contract = { address = "0xCCA41b09C1F50320bFB41BD6822BD0cdBDC7d85C", max-glm-allowed = 400 }
confirmation-blocks = 0
block-explorer-url = "https://goerli.etherscan.io"

[[chain.goerli.rpc-endpoints]]
names = """
eth-goerli.g.alchemy.com/v2/demo,
eth-goerli.public.blastapi.io,
eth-goerli.api.onfinality.io/public,
rpc.goerli.mudit.blog,
endpoints.omniatech.io/v1/eth/goerli/public,
rpc.goerli.eth.gateway.fm,
goerli.blockpi.network/v1/rpc/public,
goerli.infura.io/v3/9aa,
rpc.ankr.com/eth_goerli,
ethereum-goerli-rpc.allthatnode.com,
rpc.slock.it/goerli,
www.ethercluster.com/goerli,
rpc.ankr.com/eth_goerli,
"""
endpoints = """
https://eth-goerli.g.alchemy.com/v2/demo,
https://eth-goerli.public.blastapi.io,
https://eth-goerli.api.onfinality.io/public,
https://rpc.goerli.mudit.blog,
https://endpoints.omniatech.io/v1/eth/goerli/public,
https://rpc.goerli.eth.gateway.fm,
https://goerli.blockpi.network/v1/rpc/public,
https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161,
https://rpc.ankr.com/eth_goerli,
https://ethereum-goerli-rpc.allthatnode.com,
https://rpc.slock.it/goerli,
https://www.ethercluster.com/goerli,
https://rpc.ankr.com/eth_goerli,
"""
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 60


[chain.holesky]
chain-name = "Holesky"
chain-id = 17000
Expand Down Expand Up @@ -154,88 +66,11 @@ priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 120
dns-source = "https://raw.githubusercontent.com/golemfactory/erc20_payment_lib/scx1332/dns_suport/endpoints/holesky.json"
json-source = "https://raw.githubusercontent.com/golemfactory/erc20_payment_lib/scx1332/dns_suport/endpoints/holesky.json"


[chain.mumbai]
chain-name = "Mumbai testnet"
chain-id = 80001
currency-symbol = "tMATIC"
priority-fee = 1.0
max-fee-per-gas = 14.0
gas-left-warning-limit = 1000000
transaction-timeout = 60
token = { address = "0x2036807B0B3aaf5b1858EE822D0e111fDdac7018", symbol = "tGLM" }
multi-contract = { address = "0x800010D7d0d315DCA795110ecCf0127cBd76b89f", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://mumbai.polygonscan.com"

[[chain.mumbai.rpc-endpoints]]
names = """
polygon-mumbai.g.alchemy.com/v2/demo,
polygon-testnet.public.blastapi.io,
endpoints.omniatech.io/v1/matic/mumbai/public,
rpc-mumbai.maticvigil.com,
polygontestapi.terminet.io/rpc,
matic-mumbai.chainstacklabs.com,
matic-testnet-archive-rpc.bwarelabs.com,
rpc.ankr.com/polygon_mumbai,
polygon-testnet-archive.allthatnode.com:8545,
polygon-testnet-rpc.allthatnode.com:8545,
"""
endpoints = """
https://polygon-mumbai.g.alchemy.com/v2/demo,
https://polygon-testnet.public.blastapi.io,
https://endpoints.omniatech.io/v1/matic/mumbai/public,
https://rpc-mumbai.maticvigil.com,
https://polygontestapi.terminet.io/rpc,
https://matic-mumbai.chainstacklabs.com,
https://matic-testnet-archive-rpc.bwarelabs.com,
https://rpc.ankr.com/polygon_mumbai,
https://polygon-testnet-archive.allthatnode.com:8545,
https://polygon-testnet-rpc.allthatnode.com:8545,
"""
priority = 0
max-timeout-ms = 5000
allowed-head-behind-secs = 60



[chain.polygon]
chain-name = "Polygon mainnet"
chain-id = 137
currency-symbol = "MATIC"
priority-fee = 30.111
max-fee-per-gas = 500.0
gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x0B220b82F3eA3B7F6d9A1D8ab58930C064A2b5Bf", symbol = "GLM" }
# multi-contract = { address = "0x50100d4faf5f3b09987dea36dc2eddd57a3e561b", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://polygonscan.com"

[[chain.polygon.rpc-endpoints]]
names = """
polygon-rpc.com,
rpc-mainnet.maticvigil.com,
rpc-mainnet.matic.quiknode.pro,
bor.golem.network,
polygon-mainnet-archive.allthatnode.com:8545,
polygon-mainnet-rpc.allthatnode.com:8545,
"""
endpoints = """
https://polygon-rpc.com,
https://rpc-mainnet.maticvigil.com,
https://rpc-mainnet.matic.quiknode.pro,
https://bor.golem.network,
https://polygon-mainnet-archive.allthatnode.com:8545,
https://polygon-mainnet-rpc.allthatnode.com:8545,
"""
[[chain.holesky.rpc-endpoints]]
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 120





dns-source = "holesky.rpc-node.dev.golem.network."
4 changes: 2 additions & 2 deletions crates/erc20_payment_lib/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ gas-left-warning-limit = 1000000
transaction-timeout = 100
token = { address = "0x33af15c79d64b85ba14aaffaa4577949104b22e8", symbol = "tGLM" }
multi-contract = { address = "0x7777784f803a7bf1d7f115f849d29ce5706da64a", max-at-once = 10 }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_eth-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4001 }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_goerli-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4001 }
mint-contract = { address = "0xCCA41b09C1F50320bFB41BD6822BD0cdBDC7d85C", max-glm-allowed = 400 }
confirmation-blocks = 0
block-explorer-url = "https://goerli.etherscan.io"
Expand Down Expand Up @@ -130,7 +130,7 @@ token = { address = "0x8888888815bf4DB87e57B609A50f938311EEd068", symbol = "tGLM
multi-contract = { address = "0xAaAAAaA00E1841A63342db7188abA84BDeE236c7", max-at-once = 10 }
mint-contract = { address = "0xFACe100969FF47EB58d2CF603321B581A84bcEaC", max-glm-allowed = 400 }
lock-contract = { address = "0xCE78e3fe557E3754781Cc89eB7B01e940733e3F1" }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_eth-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4002 }
faucet-client = { max-eth-allowed = 0.009, faucet-srv = "_holesky-faucet._tcp", faucet-host = "faucet.testnet.golem.network", faucet-lookup-domain = "dev.golem.network", faucet-srv-port = 4002 }
confirmation-blocks = 0
block-explorer-url = "https://holesky.etherscan.io"

Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub struct RpcSettings {
pub names: Option<String>,
pub endpoints: Option<String>,
pub dns_source: Option<String>,
pub json_source: Option<String>,
pub skip_validation: Option<bool>,
pub backup_level: Option<i64>,
pub verify_interval_secs: Option<u64>,
Expand Down
19 changes: 17 additions & 2 deletions crates/erc20_payment_lib/src/faucet_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ async fn resolve_faucet_url(
) -> Result<String, PaymentError> {
let faucet_host = resolve_yagna_srv_record(default_lookup_domain, faucet_srv_prefix)
.await
.unwrap_or_else(|_| default_faucet_host.to_string());
.unwrap_or_else(|_| format!("{}:{}", default_faucet_host, port));

Ok(format!("http://{faucet_host}:{port}/donate"))
println!("resolve_faucet_url: {}", faucet_host);
Ok(format!("http://{faucet_host}/donate"))
}

pub async fn resolve_srv_record(record: &str) -> std::io::Result<String> {
println!("resolve_srv_record: {}", record);
let resolver: TokioAsyncResolver =
TokioAsyncResolver::tokio(ResolverConfig::google(), ResolverOpts::default())?;
let lookup = resolver.srv_lookup(record).await?;
Expand All @@ -51,11 +53,24 @@ pub async fn resolve_srv_record(record: &str) -> std::io::Result<String> {
srv.target().to_string().trim_end_matches('.'),
srv.port()
);
println!("resolve_srv_record: {}", addr);

log::debug!("Resolved address: {}", addr);
Ok(addr)
}

pub async fn resolve_txt_record(record: &str) -> std::io::Result<String> {
let resolver: TokioAsyncResolver =
TokioAsyncResolver::tokio(ResolverConfig::google(), ResolverOpts::default())?;
let lookup = resolver.txt_lookup(record).await?;
let txt = lookup
.iter()
.next()
.ok_or_else(|| IoError::from(IoErrorKind::NotFound))?;

Ok(txt.to_string())
}

/// Replace domain name in URL with resolved IP address
/// Hack required on windows to bypass failing resolution on Windows 10
/// Not needed when https://github.com/actix/actix-web/issues/1047 is resolved
Expand Down
26 changes: 22 additions & 4 deletions crates/erc20_payment_lib/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use crate::error::PaymentError;
use crate::utils::DecimalConvExt;
use crate::{err_custom_create, err_from};
use erc20_payment_lib_common::DriverEvent;
use erc20_rpc_pool::{
Web3EndpointParams, Web3ExternalJsonSource, Web3PoolType, Web3RpcPool, Web3RpcSingleParams,
};
use erc20_rpc_pool::{Web3EndpointParams, Web3ExternalDnsSource, Web3ExternalJsonSource, Web3PoolType, Web3RpcPool, Web3RpcSingleParams};
use rust_decimal::Decimal;
use secp256k1::SecretKey;
use serde::Serialize;
Expand Down Expand Up @@ -150,6 +148,7 @@ impl PaymentSetup {
for chain_config in &config.chain {
let mut single_endpoints = Vec::new();
let mut json_sources = Vec::new();
let mut dns_sources = Vec::new();
for rpc_settings in &chain_config.1.rpc_endpoints {
let endpoint_names = split_string_by_coma(&rpc_settings.names).unwrap_or_default();
if let Some(endpoints) = split_string_by_coma(&rpc_settings.endpoints) {
Expand Down Expand Up @@ -177,9 +176,27 @@ impl PaymentSetup {
single_endpoints.push(endpoint);
}
} else if let Some(dns_source) = &rpc_settings.dns_source {
dns_sources.push(Web3ExternalDnsSource {
chain_id: chain_config.1.chain_id as u64,
dns_url: dns_source.clone(),
endpoint_params: Web3EndpointParams {
backup_level: rpc_settings.backup_level.unwrap_or(0),
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
verify_interval_secs: rpc_settings.verify_interval_secs.unwrap_or(120),
max_response_time_ms: rpc_settings.max_timeout_ms.unwrap_or(10000),
max_head_behind_secs: Some(
rpc_settings.allowed_head_behind_secs.unwrap_or(120),
),
max_number_of_consecutive_errors: rpc_settings
.max_consecutive_errors
.unwrap_or(5),
min_interval_requests_ms: rpc_settings.min_interval_ms,
},
});
} else if let Some(json_source) = &rpc_settings.json_source {
json_sources.push(Web3ExternalJsonSource {
chain_id: chain_config.1.chain_id as u64,
url: dns_source.clone(),
url: json_source.clone(),
endpoint_params: Web3EndpointParams {
backup_level: rpc_settings.backup_level.unwrap_or(0),
skip_validation: rpc_settings.skip_validation.unwrap_or(false),
Expand All @@ -200,6 +217,7 @@ impl PaymentSetup {
chain_config.1.chain_id as u64,
single_endpoints,
json_sources,
dns_sources,
mpsc_sender.as_ref().map(|s| s.downgrade()),
);

Expand Down
1 change: 1 addition & 0 deletions crates/erc20_payment_lib_test/src/config_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub async fn create_default_config_setup(proxy_url_base: &str, proxy_key: &str)
names: Some(format!("{}/web3/{}", proxy_url_base, proxy_key)),
endpoints: Some(format!("{}/web3/{}", proxy_url_base, proxy_key)),
dns_source: None,
json_source: None,
skip_validation: None,
backup_level: None,
verify_interval_secs: None,
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_rpc_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ actix-web = { workspace = true }
actix-files = { workspace = true }
serde_json = { workspace = true }
thunderdome = { workspace = true }
trust-dns-resolver = { workspace = true }
uuid = { workspace = true }
env_logger = { workspace = true }
reqwest = "0.11.22"
Expand Down
1 change: 1 addition & 0 deletions crates/erc20_rpc_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use rpc_pool::VerifyEndpointStatus;
pub use rpc_pool::Web3EndpointParams;
pub use rpc_pool::Web3ExternalEndpointList;
pub use rpc_pool::Web3ExternalJsonSource;
pub use rpc_pool::Web3ExternalDnsSource;
pub use rpc_pool::Web3PoolType;
pub use rpc_pool::Web3RpcEndpoint;
pub use rpc_pool::Web3RpcInfo;
Expand Down
Loading

0 comments on commit 117172d

Please sign in to comment.