Skip to content

Commit

Permalink
refactor(rooch-da): upgrade turboDA from v0.1 to v1 (#3281)
Browse files Browse the repository at this point in the history
changes configs and API according to upgrade
  • Loading branch information
popcnt1 authored Feb 8, 2025
1 parent 3693f1d commit 41db52a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:
'${{ secrets.OPENDA_GCP_TESTNET_BUCKET }}' \
'${{ secrets.OPENDA_GCP_TESTNET_CREDENTIAL }}' \
'${{ secrets.TURBO_DA_TURING_ENDPOINT }}' \
'${{ secrets.TURBO_DA_TURING_TOKEN }}'"
'${{ secrets.TURBO_DA_TURING_API_KEY }}'"
8 changes: 4 additions & 4 deletions crates/rooch-config/src/da_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum OpenDAScheme {
///
/// Main configuration:
/// - `turbo_endpoint`: The TurboDA service endpoint.
/// - `turbo_auth_token`: The authentication token for TurboDA.
/// - `turbo_api_key`: The x-api-key for TurboDA.
/// - `light_endpoint`: The Light Client service endpoint.
Avail,

Expand Down Expand Up @@ -520,7 +520,7 @@ mod tests {
}
}

let da_config_str = "{\"da-backend\":{\"backends\":[{\"open-da\":{\"scheme\":\"gcs\",\"config\":{\"bucket\":\"$OPENDA_GCP_TESTNET_BUCKET\",\"credential\":\"$OPENDA_GCP_TESTNET_CREDENTIAL\"}}},{\"open-da\":{\"scheme\":\"avail\",\"config\":{\"turbo_endpoint\":\"$TURBO_DA_TURING_ENDPOINT\",\"turbo_auth_token\":\"$TURBO_DA_TURING_TOKEN\"}}}]}}";
let da_config_str = "{\"da-backend\":{\"backends\":[{\"open-da\":{\"scheme\":\"gcs\",\"config\":{\"bucket\":\"$OPENDA_GCP_TESTNET_BUCKET\",\"credential\":\"$OPENDA_GCP_TESTNET_CREDENTIAL\"}}},{\"open-da\":{\"scheme\":\"avail\",\"config\":{\"turbo_endpoint\":\"$TURBO_DA_TURING_ENDPOINT\",\"turbo_api_key\":\"$TURBO_DA_TURING_API_KEY\"}}}]}}";
let exp_da_config = DAConfig {
da_backend: Some(DABackendConfig {
submit_strategy: None,
Expand Down Expand Up @@ -551,8 +551,8 @@ mod tests {
"$TURBO_DA_TURING_ENDPOINT".to_string(),
),
(
"turbo_auth_token".to_string(),
"$TURBO_DA_TURING_TOKEN".to_string(),
"turbo_api_key".to_string(),
"$TURBO_DA_TURING_API_KEY".to_string(),
),
]
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-da/src/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ v
|
v
+-------------------+ +-------------------+
| CelestiaAdapter | | AvailAdapter | <- Actual backend-specific adapter implementations
| AvailAdapter | | CelestiaAdapter | <- Actual backend-specific adapter implementations
+-------------------+ +-------------------+
```

39 changes: 12 additions & 27 deletions crates/rooch-da/src/backend/openda/avail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const MIN_BACKOFF_DELAY: Duration = Duration::from_millis(3000);
const SUBMIT_API_PATH: &str = "v2/submit";

const TURBO_MIN_BACKOFF_DELAY: Duration = Duration::from_millis(500);
const TURBO_SUBMIT_API_PATH: &str = "user/submit_raw_data";
const DEFAULT_TURBO_PAYMENT_TOKEN: &str = "ethereum";
const TURBO_SUBMIT_API_PATH: &str = "v1/submit_raw_data";

/// Avail client: A turbo and Light
/// Turbo client has higher priority, if not available, use the Light client
Expand Down Expand Up @@ -86,8 +85,7 @@ impl OpenDAAdapter for AvailFusionAdapter {

pub struct AvailFusionClientConfig {
pub turbo_endpoint: Option<String>,
pub turbo_auth_token: Option<String>,
pub turbo_payment_token: Option<String>,
pub turbo_api_key: Option<String>,
pub light_endpoint: Option<String>,
pub max_retries: usize,
}
Expand All @@ -98,22 +96,20 @@ impl AvailFusionClientConfig {
max_retries: usize,
) -> anyhow::Result<Self> {
let turbo_endpoint = scheme_config.get("turbo_endpoint").cloned();
let turbo_auth_token = scheme_config.get("turbo_auth_token").cloned();
let turbo_payment_token = scheme_config.get("turbo_payment_token").cloned();
let turbo_api_key = scheme_config.get("turbo_api_key").cloned();
let light_endpoint = scheme_config.get("light_endpoint").cloned();

if turbo_endpoint.is_none() && light_endpoint.is_none() {
return Err(anyhow!("turbo_endpoint or light_endpoint must be provided"));
}
if turbo_endpoint.is_some() && turbo_auth_token.is_none() {
return Err(anyhow!("turbo_auth_token must be provided"));
if turbo_endpoint.is_some() && turbo_api_key.is_none() {
return Err(anyhow!("turbo_api_key must be provided"));
}

Ok(AvailFusionClientConfig {
turbo_endpoint,
turbo_auth_token,
turbo_api_key,
light_endpoint,
turbo_payment_token,
max_retries,
})
}
Expand All @@ -123,10 +119,7 @@ impl AvailFusionClientConfig {
Some(AvailTurboClient::new(
endpoint,
self.max_retries,
self.turbo_auth_token.as_ref().unwrap(),
self.turbo_payment_token
.as_deref()
.unwrap_or(DEFAULT_TURBO_PAYMENT_TOKEN),
self.turbo_api_key.as_ref().unwrap(),
)?)
} else {
None
Expand All @@ -150,25 +143,18 @@ pub(crate) struct AvailTurboClient {
endpoint: String,
http_client: Client,
max_retries: usize,
auth_token: String,
payment_token: String,
api_key: String,
}

impl AvailTurboClient {
pub(crate) fn new(
endpoint: &str,
max_retries: usize,
auth_token: &str,
payment_token: &str,
) -> anyhow::Result<Self> {
pub(crate) fn new(endpoint: &str, max_retries: usize, api_key: &str) -> anyhow::Result<Self> {
let client = Client::new();

Ok(AvailTurboClient {
endpoint: endpoint.to_string(),
http_client: client,
max_retries,
auth_token: auth_token.to_string(),
payment_token: payment_token.to_string(),
api_key: api_key.to_string(),
})
}

Expand Down Expand Up @@ -215,9 +201,8 @@ impl AvailTurboClient {
let request = self
.http_client
.post(&submit_url)
.query(&[("token", self.payment_token.clone())])
.bearer_auth(&self.auth_token)
.header("Content-Type", "text/plain")
.header("x-api-key", &self.api_key)
.header("Content-Type", "application/octet-stream")
.body(segment_bytes.to_vec());

let response = request.send().await?;
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy_rooch_testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BTC_TEST_RPC_PWD="$3"
OPENDA_GCP_TESTNET_BUCKET="$4"
OPENDA_GCP_TESTNET_CREDENTIAL="$5"
TURBO_DA_TURING_ENDPOINT="$6"
TURBO_DA_TURING_TOKEN="$7"
TURBO_DA_TURING_API_KEY="$7"

sleep 30
docker image prune -a -f
Expand All @@ -21,7 +21,7 @@ docker run -d --name rooch-testnet --restart unless-stopped -v /data:/root -p 67
--btc-rpc-url "$BTC_TEST_RPC_URL" \
--btc-rpc-username rooch-test \
--btc-rpc-password "$BTC_TEST_RPC_PWD" \
--da "{\"da-backend\":{\"backends\":[{\"open-da\":{\"scheme\":\"gcs\",\"config\":{\"bucket\":\"$OPENDA_GCP_TESTNET_BUCKET\",\"credential\":\"$OPENDA_GCP_TESTNET_CREDENTIAL\"}}},{\"open-da\":{\"scheme\":\"avail\",\"config\":{\"turbo_endpoint\":\"$TURBO_DA_TURING_ENDPOINT\",\"turbo_auth_token\":\"$TURBO_DA_TURING_TOKEN\"}}}]}}" \
--da "{\"da-backend\":{\"backends\":[{\"open-da\":{\"scheme\":\"gcs\",\"config\":{\"bucket\":\"$OPENDA_GCP_TESTNET_BUCKET\",\"credential\":\"$OPENDA_GCP_TESTNET_CREDENTIAL\"}}},{\"open-da\":{\"scheme\":\"avail\",\"config\":{\"turbo_endpoint\":\"$TURBO_DA_TURING_ENDPOINT\",\"turbo_api_key\":\"$TURBO_DA_TURING_API_KEY\"}}}]}}" \
--traffic-burst-size 200 \
--traffic-per-second 0.1 \
--rocksdb-row-cache-size 4294967296 \
Expand Down

0 comments on commit 41db52a

Please sign in to comment.