Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit cd2a23a

Browse files
authored
refactor: upgrade crabtensor and related dependencies (#136)
1 parent 8477a7c commit cd2a23a

File tree

8 files changed

+2471
-8419
lines changed

8 files changed

+2471
-8419
lines changed

Cargo.lock

Lines changed: 2432 additions & 8390 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ storb_miner = { version = "*", path = "crates/storb_miner" }
1919
storb_validator = { version = "*", path = "crates/storb_validator" }
2020

2121
# Crabtensor
22-
crabtensor = { git = "https://github.com/storb-tech/crabtensor.git", version = "0.5.2" }
23-
sp-runtime = "=39.0.2"
24-
subxt = "=0.38.0"
22+
crabtensor = { git = "https://github.com/storb-tech/crabtensor.git", tag = "v0.6.0" }
23+
sp-core = "36.1.0"
24+
subxt = "0.41.0"
2525

2626
# Third party
2727
anyhow = "1.0.95"

crates/storb_validator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ rustls.workspace = true
3333
rusqlite.workspace = true
3434
serde.workspace = true
3535
serde_json.workspace = true
36+
sp-core.workspace = true
3637
subxt.workspace = true
3738
tokio.workspace = true
3839
tokio-serde.workspace = true

crates/storb_validator/src/download.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use base::constants::MIN_BANDWIDTH;
1111
use base::piece::PieceHash;
1212
use base::verification::{HandshakePayload, KeyRegistrationInfo, VerificationMessage};
1313
use base::{AddressBook, BaseNeuron, NodeInfo};
14-
use crabtensor::sign::sign_message;
14+
use crabtensor::sign::{sign_message, PairSigner};
1515
use futures::stream::FuturesUnordered;
1616
use tokio::sync::{mpsc, Mutex, RwLock};
1717
use tokio_stream::StreamExt;
@@ -47,7 +47,7 @@ pub async fn get_piece_from_miner(
4747
req_client: reqwest::Client,
4848
node_info: &NodeInfo,
4949
piece_hash: PieceHash,
50-
signer: Arc<subxt::tx::PairSigner<subxt::SubstrateConfig, subxt::ext::sp_core::sr25519::Pair>>,
50+
signer: Arc<PairSigner>,
5151
vali_uid: u16,
5252
scoring_system: Arc<RwLock<ScoringSystem>>,
5353
) -> Result<reqwest::Response> {
@@ -66,7 +66,10 @@ pub async fn get_piece_from_miner(
6666
},
6767
};
6868
let signature = sign_message(&signer, &message);
69-
let payload = HandshakePayload { signature, message };
69+
let payload = HandshakePayload {
70+
signature: signature?,
71+
message,
72+
};
7073
let payload_bytes = bincode::serialize(&payload)?;
7174

7275
// Create URL

crates/storb_validator/src/metadata/db.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ mod tests {
27402740
let message = infohash_value.get_signature_message(&nonce);
27412741
let signature = sign_message(&signer, &message);
27422742
let infohash_value = InfohashValue {
2743-
signature, // Use the signed signature
2743+
signature: signature.unwrap(), // Use the signed signature
27442744
..infohash_value
27452745
};
27462746

@@ -2851,7 +2851,7 @@ mod tests {
28512851
let message = infohash_value.get_signature_message(&nonce);
28522852
let signature = sign_message(&signer, &message);
28532853
let infohash_value = InfohashValue {
2854-
signature, // Use the signed signature
2854+
signature: signature.unwrap(), // Use the signed signature
28552855
..infohash_value
28562856
};
28572857

@@ -2932,7 +2932,7 @@ mod tests {
29322932
let message = infohash_value.get_signature_message(&nonce);
29332933
let signature = sign_message(&signer, &message);
29342934
let infohash_value = InfohashValue {
2935-
signature, // Use the signed signature
2935+
signature: signature.unwrap(), // Use the signed signature
29362936
..infohash_value
29372937
};
29382938

@@ -3049,7 +3049,7 @@ mod tests {
30493049
let message = infohash_value.get_signature_message(&nonce);
30503050
let signature = sign_message(&signer, &message);
30513051
let infohash_value = InfohashValue {
3052-
signature, // Use the signed signature
3052+
signature: signature.unwrap(), // Use the signed signature
30533053
..infohash_value
30543054
};
30553055

@@ -3152,7 +3152,7 @@ mod tests {
31523152
let message = infohash_value.get_signature_message(&nonce);
31533153
let signature = sign_message(&signer, &message);
31543154
let infohash_value = InfohashValue {
3155-
signature, // Use the signed signature
3155+
signature: signature.unwrap(), // Use the signed signature
31563156
..infohash_value
31573157
};
31583158

@@ -3283,7 +3283,7 @@ mod tests {
32833283
let message = infohash_value1.get_signature_message(&nonce);
32843284
let signature = sign_message(&signer, &message);
32853285
let infohash_value1 = InfohashValue {
3286-
signature, // Use the signed signature
3286+
signature: signature.unwrap(), // Use the signed signature
32873287
..infohash_value1
32883288
};
32893289

@@ -3342,7 +3342,7 @@ mod tests {
33423342
let message = infohash_value2.get_signature_message(&nonce);
33433343
let signature = sign_message(&signer, &message);
33443344
let infohash_value2 = InfohashValue {
3345-
signature, // Use the signed signature
3345+
signature: signature.unwrap(), // Use the signed signature
33463346
..infohash_value2
33473347
};
33483348

@@ -3425,7 +3425,7 @@ mod tests {
34253425
let message = infohash_value3.get_signature_message(&nonce);
34263426
let signature = sign_message(&signer, &message);
34273427
let infohash_value3 = InfohashValue {
3428-
signature, // Use the signed signature
3428+
signature: signature.unwrap(), // Use the signed signature
34293429
..infohash_value3
34303430
};
34313431

@@ -3512,7 +3512,7 @@ mod tests {
35123512
let message = infohash_value.get_signature_message(&nonce);
35133513
let signature = sign_message(&signer, &message);
35143514
let infohash_value = InfohashValue {
3515-
signature, // Use the signed signature
3515+
signature: signature.unwrap(), // Use the signed signature
35163516
..infohash_value
35173517
};
35183518
let chunk = ChunkValue {
@@ -3562,7 +3562,7 @@ mod tests {
35623562
let message = infohash_value.get_signature_message(&nonce);
35633563
let signature = sign_message(&signer, &message);
35643564
let infohash_value = InfohashValue {
3565-
signature, // Use the signed signature
3565+
signature: signature.unwrap(), // Use the signed signature
35663566
..infohash_value.clone()
35673567
};
35683568

crates/storb_validator/src/routes.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::str::FromStr;
23
use std::sync::Arc;
34

45
use anyhow::Result;
@@ -9,9 +10,8 @@ use axum::response::{AppendHeaders, IntoResponse};
910
use base::piece::InfoHash;
1011
use crabtensor::sign::KeypairSignature;
1112
use crabtensor::AccountId;
12-
use subxt::ext::sp_core::crypto::Ss58Codec;
13-
use subxt::ext::sp_core::ByteArray;
14-
use subxt::ext::sp_runtime::AccountId32;
13+
use sp_core::ByteArray;
14+
use subxt::utils::AccountId32;
1515
use tokio::sync::RwLock;
1616
use tracing::{debug, error, info, trace};
1717

@@ -136,8 +136,8 @@ pub async fn generate_nonce(
136136
debug!("Generating nonce for account_id: {}", account_id);
137137
let metadatadb_sender = state.validator.metadatadb_sender.clone();
138138
// create an AccountId from the ss58 string account_id
139-
let acc_id: AccountId = match AccountId32::from_string(account_id) {
140-
Ok(acc_id) => acc_id.into(),
139+
let acc_id: AccountId = match AccountId32::from_str(account_id) {
140+
Ok(acc_id) => acc_id,
141141
Err(e) => {
142142
error!("Failed to parse account_id: {}: {}", account_id, e);
143143
return Err((
@@ -216,8 +216,8 @@ pub async fn upload_file(
216216
)
217217
})?;
218218

219-
let account_id: AccountId = match AccountId32::from_string(account_id_str) {
220-
Ok(acc_id) => acc_id.into(),
219+
let account_id: AccountId = match AccountId32::from_str(account_id_str) {
220+
Ok(acc_id) => acc_id,
221221
Err(e) => {
222222
error!("Failed to parse account_id: {}: {}", account_id_str, e);
223223
return Err((
@@ -531,8 +531,8 @@ pub async fn delete_file(
531531
)
532532
})?;
533533

534-
let account_id: AccountId = match AccountId32::from_string(account_id_str) {
535-
Ok(acc_id) => acc_id.into(),
534+
let account_id: AccountId = match AccountId32::from_str(account_id_str) {
535+
Ok(acc_id) => acc_id,
536536
Err(e) => {
537537
error!("Failed to parse account_id: {}: {}", account_id_str, e);
538538
return Err((

crates/storb_validator/src/upload.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use quinn::Connection;
2020
use rand::rngs::StdRng;
2121
use rand::seq::SliceRandom;
2222
use rand::SeedableRng;
23+
use sp_core::hexdisplay::AsBytesRef;
2324
use subxt::ext::codec::Compact;
24-
use subxt::ext::sp_core::hexdisplay::AsBytesRef;
2525
use tokio::sync::{mpsc, RwLock};
2626
use tracing::{debug, error, info, trace, warn};
2727

@@ -74,7 +74,10 @@ pub async fn upload_piece_data(
7474
},
7575
};
7676
let signature = sign_message(&signer, &message);
77-
let payload = HandshakePayload { signature, message };
77+
let payload = HandshakePayload {
78+
signature: signature?,
79+
message,
80+
};
7881
let payload_bytes = bincode::serialize(&payload)?;
7982
debug!("payload_bytes: {:?}", payload_bytes);
8083

crates/storb_validator/src/validator.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Validator {
188188
let signature = sign_message(&signer, message);
189189

190190
let infohash_value = metadata::models::InfohashValue {
191-
signature,
191+
signature: signature?,
192192
..infohash_value
193193
};
194194

@@ -643,7 +643,10 @@ impl Validator {
643643
let piece_len = piece_size;
644644

645645
let signature = sign_message(&signer, &message);
646-
let payload = HandshakePayload { signature, message };
646+
let payload = HandshakePayload {
647+
signature: signature?,
648+
message,
649+
};
647650
let payload_bytes = match bincode::serialize(&payload) {
648651
Ok(bytes) => bytes,
649652
Err(e) => {

0 commit comments

Comments
 (0)