Skip to content

Commit

Permalink
feat(su): attest On-Boot and allow process string data #730
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Sep 13, 2024
1 parent 0eb23bb commit 30a4cba
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
23 changes: 6 additions & 17 deletions servers/su/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Create a .env file with the following variables, or set them in the OS:
- `SU_DATA_DIR` if `USE_DISK` is `true`, this is where rocksdb will be initialized
- `MIGRATION_BATCH_SIZE` when running the migration binary how many to fetch at once from postgres
- `ENABLE_METRICS` enable application level prometheus metrics to be available on the `/metrics` endpoint
- `MAX_READ_MEMORY` max size in bytes of the message list returned on the /txid endpoint. Defaults to 1GB
- `PROCESS_CACHE_SIZE` max size of the in memory cache of processes held by the data store
- `ENABLE_PROCESS_ASSIGNMENT` enables AOP-6 boot loader, if enabled, the Process on a new spawn will become the first Message/Nonce in its message list. It will get an Assignment.
- `ARWEAVE_URL_LIST` list of arweave urls that have tx access aka url/txid returns the tx. Used by gateway calls for checking transactions etc...

> You can also use a `.env` file to set environment variables when running in
> development mode, See the `.env.example` for an example `.env`
Expand Down Expand Up @@ -106,23 +110,8 @@ docker run --env-file .env.su -v ./.wallet.json:/app/.wallet.json su-runner su 9
When running the binary in docker you will need to make sure the environment
variables are set in the container. If not see a NotPresent error you are missing the
environment variables. You will also need to make sure the database url is accessible
in the container.

- `SU_WALLET_PATH` a local filepath to an arweave wallet the SU will use to write tx's
- `DATABASE_URL` a postgres database url, you must have a postgres database called `su`
- `DATABASE_READ_URL` an optional separate postgres database url for reads
- `GRAPHQL_URL`an url for the arweave graphql interface `https://arweave-search.goldsky.com`
- `ARWEAVE_URL`an arweave gateway url to fetch actual transactions and network info from `https://arweave.net/`
- `GATEWAY_URL`an default fallback for the above 2. Must provide graphql, network info, and tx fetching.
- `UPLOAD_NODE_URL` an uploader url such as `https://up.arweave.net`
- `MODE` can be either value `su` or `router` but for local development use `su`
- `SCHEDULER_LIST_PATH` a list of schedulers only used for `router` MODE. Ignore when in `su` MODE, just set it to `""`.
- `DB_WRITE_CONNECTIONS` how many db connections in the writer pool,defaults to 10
- `DB_READ_CONNECTIONS` how many db connections in the reader pool, default to 10
- `USE_DISK` whether or not to write and read rocksdb, this is a performance enhancement for the data storage layer
- `SU_DATA_DIR` if `USE_DISK` is `true`, this is where rocksdb will be initialized
- `MIGRATION_BATCH_SIZE` when running the migration binary how many to fetch at once from postgres
- `ENABLE_METRICS` enable application level prometheus metrics to be available on the `/metrics` endpoint
in the container. See the environment variables you must set in the Environment Variables
section above.



Expand Down
57 changes: 34 additions & 23 deletions servers/su/src/domain/clients/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,43 @@ impl ArweaveGateway {
impl Gateway for ArweaveGateway {
async fn check_head(&self, tx_id: String) -> Result<bool, String> {
let config = AoConfig::new(Some("su".to_string())).expect("Failed to read configuration");
let arweave_url = config.arweave_url;

let url = match Url::parse(&arweave_url) {
Ok(u) => u,
Err(e) => return Err(format!("{}", e)),
};

let arweave_urls = config.arweave_url_list;

let client = Client::new();

let response = client
.head(
url.join(&format!("{}", tx_id))
.map_err(|e| GatewayErrorType::CheckHeadError(e.to_string()))?,
)
.send()
.await
.map_err(|e| GatewayErrorType::CheckHeadError(e.to_string()))?;

let response_status = response.status();

if response_status.is_success() {
return Ok(true);

for arweave_url in arweave_urls {
let url = match Url::parse(&arweave_url) {
Ok(u) => u,
Err(e) => {
eprintln!("Invalid URL {}: {}", arweave_url, e);
continue; // Skip this URL and try the next one
}
};

let response = client
.head(
url.join(&format!("{}", tx_id))
.map_err(|e| GatewayErrorType::CheckHeadError(e.to_string()))?,
)
.send()
.await;

match response {
Ok(res) if res.status().is_success() => {
return Ok(true); // Return success if the request was successful
}
Ok(_) => {
eprintln!("Request failed with non-success status for URL: {}", arweave_url);
}
Err(e) => {
eprintln!("Error requesting URL {}: {}", arweave_url, e);
}
}
}

Ok(false)
Ok(false) // If none of the URLs worked, return false
}


async fn network_info(&self) -> Result<NetworkInfo, String> {
// bind these with let so they dont drop until returning
Expand Down
13 changes: 12 additions & 1 deletion servers/su/src/domain/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct AoConfig {
pub max_read_memory: usize,
pub process_cache_size: usize,
pub enable_process_assignment: bool,
pub arweave_url_list: Vec<String>
}

impl AoConfig {
Expand Down Expand Up @@ -80,6 +81,15 @@ impl AoConfig {
Ok(val) => val == "true",
Err(_e) => false,
};
let arweave_url_list: Vec<String> = match env::var("ARWEAVE_URL_LIST") {
Ok(val) => val.split(',')
.map(|s| s.trim().to_string())
.collect(),
Err(_e) => vec![
"https://arweave.net".to_string(),
"https://g8way.io".to_string()
],
};
Ok(AoConfig {
database_url: env::var("DATABASE_URL")?,
database_read_url,
Expand All @@ -97,7 +107,8 @@ impl AoConfig {
enable_metrics,
max_read_memory,
process_cache_size,
enable_process_assignment
enable_process_assignment,
arweave_url_list
})
}
}
Expand Down
Binary file modified servers/su/su
Binary file not shown.

0 comments on commit 30a4cba

Please sign in to comment.