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

Extract solana network, fix mobile packet verifier #453

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
41 changes: 24 additions & 17 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"iot_config",
"price",
"mobile_config",
"solana",
]

[workspace.package]
Expand All @@ -29,6 +30,7 @@ edition = "2021"

[workspace.dependencies]
anchor-lang = "0.26.0"
anchor-client = "0.26"
anyhow = {version = "1", features = ["backtrace"]}
thiserror = "1"
clap = {version = "3", features = ["derive"]}
Expand Down Expand Up @@ -60,6 +62,8 @@ helium-proto = {git = "https://github.com/helium/proto", branch = "master", feat
hextree = "*"
solana-client = "1.14"
solana-sdk = "1.14"
solana-program = "1.11"
spl-token = "3.5.0"
reqwest = {version = "0", default-features=false, features = ["gzip", "json", "rustls-tls"]}
beacon = {git = "https://github.com/helium/gateway-rs.git", branch = "main"}
humantime = "2"
Expand Down
11 changes: 2 additions & 9 deletions iot_packet_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ license.workspace = true

[dependencies]
anyhow = {workspace = true}
anchor-lang = {workspace = true}
anchor-client = "0.26"
async-trait = {workspace = true}
clap = {workspace = true}
config = {workspace = true}
Expand All @@ -20,14 +18,11 @@ futures-util = {workspace = true}
file-store = {path = "../file_store"}
helium-proto = {workspace = true}
helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "solana"]}
solana-client = {workspace = true}
solana-sdk = {workspace = true}
solana-program = "1.11"
spl-token = "3.5.0"
poc-metrics = {path = "../metrics"}
prost = {workspace = true}
serde = {workspace = true}
sqlx = {workspace = true}
solana = {path = "../solana"}
thiserror = {workspace = true}
tokio = {workspace = true}
tonic = {workspace = true}
Expand All @@ -36,9 +31,7 @@ tracing-subscriber = {workspace = true}
triggered = {workspace = true}
http = {workspace = true}
http-serde = {workspace = true}
sha2 = {workspace = true}
data-credits = {workspace = true}
helium-sub-daos = {workspace = true}




32 changes: 14 additions & 18 deletions iot_packet_verifier/pkg/settings-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,11 @@
# Cache location for generated verified reports; Required
cache = "/var/data/verified-reports"

# Data credit burn period in minutes. (Default is 1)
# burn_period = 1

# Public key for the Data Credits Mint (devnet mint provided here)
dc_mint = "dcuc8Amr83Wz27ZkQ2K9NS6r8zRpf1J6cvArEBDZDmm"
# Public key for the DNT Mint (devnet mint provided here)
dnt_mint = "iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns"
# Public key for the HNT Mint (devnet mint provided here)
hnt_mint = "hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux"
# URL for the config server
org_url = ""

# Solana RPC. This may contain a secret
solana_rpc = "http://localhost:8899"
# Path to the keypair used to sign data credit burn solana transactions
burn_keypair = ""
# Path to the keypair used to authorize config server rpc calls
config_keypair = ""
# Solana cluster to use. "devnet" or "mainnet"
cluster = "devnet"

# URL for the config server
org_url = ""

# We will burn data credits from the solana chain every `burn_period` minutes.
burn_period = 1
Expand All @@ -38,6 +22,18 @@ burn_period = 1
# default.
enable_solana_integration = "false"

[solana]
# Solana RPC. This may contain a secret
rpc_url = "http://localhost:8899"
# Path to the keypair used to sign data credit burn solana transactions
burn_keypair = ""
# Solana cluster to use. "devnet" or "mainnet"
cluster = "devnet"
# Public key for the Data Credits Mint
dc_mint = "dcuc8Amr83Wz27ZkQ2K9NS6r8zRpf1J6cvArEBDZDmm"
# Public key for the DNT Mint (IOT mint)
dnt_mint = "iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns"

[database]

url = "postgresql://postgres:password@localhost:5432/postgres"
Expand Down
2 changes: 1 addition & 1 deletion iot_packet_verifier/src/balances.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
pending_burns::{Burn, PendingBurns},
solana::SolanaNetwork,
verifier::Debiter,
};
use futures_util::StreamExt;
use helium_crypto::PublicKeyBinary;
use solana::SolanaNetwork;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::Mutex;

Expand Down
2 changes: 1 addition & 1 deletion iot_packet_verifier/src/burner.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
balances::{BalanceCache, BalanceStore},
pending_burns::{Burn, PendingBurns},
solana::SolanaNetwork,
};
use solana::SolanaNetwork;
use std::time::Duration;
use tokio::task;

Expand Down
20 changes: 4 additions & 16 deletions iot_packet_verifier/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{
balances::BalanceCache,
burner::Burner,
settings::Settings,
solana::SolanaRpc,
verifier::{CachedOrgClient, Verifier},
};
use anyhow::{bail, Error, Result};
Expand All @@ -15,8 +14,7 @@ use file_store::{
FileSinkBuilder, FileStore, FileType,
};
use futures_util::TryFutureExt;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::signature::read_keypair_file;
use solana::SolanaRpc;
use sqlx::{Pool, Postgres};
use std::sync::Arc;
use tokio::sync::mpsc::Receiver;
Expand Down Expand Up @@ -94,21 +92,11 @@ impl Cmd {
sqlx::migrate!().run(&pool).await?;

let solana = if settings.enable_solana_integration {
let burn_keypair = match read_keypair_file(&settings.burn_keypair) {
Ok(kp) => kp,
Err(e) => bail!("Failed to read keypair file ({})", e),
let Some(ref solana_settings) = settings.solana else {
bail!("Missing solana section in settings");
};
// Set up the solana RpcClient:
Some(
SolanaRpc::new(
RpcClient::new(settings.solana_rpc.clone()),
settings.cluster.clone(),
burn_keypair,
settings.dc_mint()?,
settings.dnt_mint()?,
)
.await?,
)
Some(SolanaRpc::new(solana_settings).await?)
} else {
None
};
Expand Down
2 changes: 0 additions & 2 deletions iot_packet_verifier/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pub mod balances;
pub mod burner;
pub mod daemon;
pub mod pdas;
pub mod pending_burns;
pub mod settings;
pub mod solana;
pub mod verifier;
22 changes: 0 additions & 22 deletions iot_packet_verifier/src/pdas.rs

This file was deleted.

22 changes: 1 addition & 21 deletions iot_packet_verifier/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use config::{Config, ConfigError, Environment, File};
use helium_proto::services::{iot_config::config_org_client::OrgClient, Channel, Endpoint};
use serde::Deserialize;
use solana_sdk::pubkey::{ParsePubkeyError, Pubkey};
use std::path::{Path, PathBuf};

#[derive(Debug, Deserialize)]
Expand All @@ -12,18 +11,10 @@ pub struct Settings {
pub log: String,
/// Cache location for generated verified reports
pub cache: String,
/// Solana RpcClient URL:
pub solana_rpc: String,
/// Path to the keypair for signing burn transactions
pub burn_keypair: PathBuf,
/// Path to the keypair for signing config changes
pub config_keypair: PathBuf,
/// Data credit burn period in minutes. Default is 1.
pub burn_period: u64,
pub cluster: String,
pub dc_mint: String,
pub dnt_mint: String,
pub hnt_mint: String,
pub database: db_store::Settings,
pub ingest: file_store::Settings,
pub output: file_store::Settings,
Expand All @@ -32,6 +23,7 @@ pub struct Settings {
pub org_url: http::Uri,
#[serde(default)]
pub enable_solana_integration: bool,
pub solana: Option<solana::Settings>,
}

pub fn default_burn_period() -> u64 {
Expand Down Expand Up @@ -65,18 +57,6 @@ impl Settings {
.and_then(|config| config.try_deserialize())
}

pub fn dc_mint(&self) -> Result<Pubkey, ParsePubkeyError> {
self.dc_mint.parse()
}

pub fn dnt_mint(&self) -> Result<Pubkey, ParsePubkeyError> {
self.dnt_mint.parse()
}

pub fn hnt_mint(&self) -> Result<Pubkey, ParsePubkeyError> {
self.hnt_mint.parse()
}

pub fn connect_org(&self) -> OrgClient<Channel> {
OrgClient::new(Endpoint::from(self.org_url.clone()).connect_lazy())
}
Expand Down
10 changes: 2 additions & 8 deletions mobile_packet_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ license.workspace = true

[dependencies]
anyhow = {workspace = true}
anchor-lang = {workspace = true}
anchor-client = "0.26"
async-trait = {workspace = true}
clap = {workspace = true}
config = {workspace = true}
Expand All @@ -20,14 +18,12 @@ futures-util = {workspace = true}
file-store = {path = "../file_store"}
helium-proto = {workspace = true}
helium-crypto = {workspace = true, features = ["sqlx-postgres", "multisig", "solana"]}
solana-client = {workspace = true}
solana-sdk = {workspace = true}
solana-program = "1.11"
spl-token = "3.5.0"
poc-metrics = {path = "../metrics"}
prost = {workspace = true}
serde = {workspace = true}
sqlx = {workspace = true}
solana = {path = "../solana"}
mobile-config = {path = "../mobile_config"}
thiserror = {workspace = true}
tokio = {workspace = true}
tonic = {workspace = true}
Expand All @@ -37,5 +33,3 @@ triggered = {workspace = true}
http = {workspace = true}
http-serde = {workspace = true}
sha2 = {workspace = true}
data-credits = {workspace = true}
helium-sub-daos = {workspace = true}
Loading