Skip to content

Commit 905c516

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 2a2c1bd + f897d22 commit 905c516

File tree

2 files changed

+39
-64
lines changed

2 files changed

+39
-64
lines changed

fplus-http-server/src/router/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use actix_web::{get, post, put, delete, web, HttpResponse, Responder};
22
use fplus_database::database::allocators as allocators_db;
3-
use fplus_lib::core::{allocator::{
3+
use fplus_lib::{core::{allocator::{
44
create_allocator_repo, is_allocator_repo_created, process_allocator_file, update_single_installation_id_logic
5-
}, AllocatorUpdateInfo, ChangedAllocator, InstallationIdUpdateInfo};
5+
}, AllocatorUpdateInfo, ChangedAllocator, InstallationIdUpdateInfo}, external_services::filecoin::get_multisig_threshold_for_actor};
66

77
/**
88
* Get all allocators

fplus-lib/src/core/mod.rs

Lines changed: 37 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,11 @@ pub struct AllocatorUpdateInfo {
131131
pub multisig_threshold: Option<i32>,
132132
}
133133

134-
135134
#[derive(Deserialize)]
136135
pub struct InstallationIdUpdateInfo {
137136
pub installation_id: i64,
138137
}
139138

140-
141139
#[derive(Deserialize)]
142140
pub struct GithubQueryParams {
143141
pub owner: String,
@@ -693,20 +691,24 @@ impl LDNApplication {
693691
owner: String,
694692
repo: String,
695693
) -> Result<ApplicationFile, LDNError> {
696-
// Get multisig threshold from blockchain
697-
let blockchain_threshold = match get_multisig_threshold_for_actor(&signer.signing_address).await {
698-
Ok(threshold) => Some(threshold),
699-
Err(_) => None,
700-
};
701694
// TODO: Convert DB errors to LDN Error
702695
// Get multisig threshold from the database
703696
let db_allocator = match get_allocator(&owner, &repo).await {
704-
Ok(allocator) => allocator,
697+
Ok(allocator) => allocator.unwrap(),
705698
Err(err) => {
706699
return Err(LDNError::New(format!("Database: get_allocator: {}", err)));
707700
}
708701
};
709-
let db_threshold: u64 = db_allocator.unwrap().multisig_threshold.unwrap_or(2) as u64;
702+
let db_multisig_address = db_allocator.multisig_address.unwrap();
703+
704+
// Get multisig threshold from blockchain
705+
let blockchain_threshold =
706+
match get_multisig_threshold_for_actor(&db_multisig_address).await {
707+
Ok(threshold) => Some(threshold),
708+
Err(_) => None,
709+
};
710+
711+
let db_threshold: u64 = db_allocator.multisig_threshold.unwrap_or(2) as u64;
710712

711713
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
712714
if let Some(blockchain_threshold) = blockchain_threshold {
@@ -809,33 +811,17 @@ impl LDNApplication {
809811
owner: String,
810812
repo: String,
811813
) -> Result<ApplicationFile, LDNError> {
812-
// Get multisig threshold from blockchain
813-
let blockchain_threshold = match get_multisig_threshold_for_actor(&signer.signing_address).await {
814-
Ok(threshold) => Some(threshold),
815-
Err(_) => None,
816-
};
817-
818814
// Get multisig threshold from the database
819815
let db_allocator = match get_allocator(&owner, &repo).await {
820-
Ok(allocator) => allocator,
821-
Err(err) => return Err(LDNError::New(format!("Database: get_allocator: {}", err))),
822-
};
823-
let db_threshold: u64 = db_allocator.unwrap().multisig_threshold.unwrap_or(2) as u64;
824-
825-
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
826-
if let Some(blockchain_threshold) = blockchain_threshold {
827-
if blockchain_threshold != db_threshold {
828-
match update_allocator_threshold(&owner, &repo, blockchain_threshold as i32).await {
829-
Ok(_) => log::info!("Database updated with new multisig threshold"),
830-
Err(e) => log::error!("Failed to update database: {}", e),
831-
};
816+
Ok(allocator) => allocator.unwrap(),
817+
Err(err) => {
818+
return Err(LDNError::New(format!("Database: get_allocator: {}", err)));
832819
}
833-
}
834-
835-
// Use the blockchain threshold if available; otherwise, fall back to the database value
836-
let threshold_to_use = blockchain_threshold.unwrap_or(db_threshold);
820+
};
821+
let threshold_to_use = db_allocator.multisig_threshold.unwrap_or(2) as usize;
837822

838823
let app_state = self.app_state().await?;
824+
839825
if app_state != AppState::StartSignDatacap
840826
&& !(threshold_to_use == 1 && app_state == AppState::ReadyToSign)
841827
{
@@ -844,6 +830,7 @@ impl LDNApplication {
844830
self.application_id
845831
)));
846832
}
833+
847834
let app_file: ApplicationFile = self.file().await?;
848835
let app_lifecycle = app_file.lifecycle.finish_approval();
849836

@@ -879,10 +866,6 @@ impl LDNApplication {
879866
request_id.clone(),
880867
app_lifecycle,
881868
);
882-
// If the number of current signers plus this one is less than the threshold, return early
883-
if current_signers.len() + 1 < multisig_threshold_usize as usize {
884-
return Ok(app_file);
885-
}
886869

887870
let file_content = serde_json::to_string_pretty(&app_file).unwrap();
888871
let commit_result = LDNPullRequest::add_commit_to(
@@ -1652,37 +1635,30 @@ impl LDNApplication {
16521635
return Ok(false);
16531636
}
16541637
};
1655-
let signers: application::file::Verifiers = active_request.signers.clone();
1656-
let signer = signers.0.get(1).unwrap();
1657-
1658-
// Try getting the multisig threshold from the blockchain
1659-
let blockchain_threshold =
1660-
get_multisig_threshold_for_actor(&signer.signing_address).await;
16611638

1662-
// Fallback to database value if blockchain query fails
1663-
let multisig_threshold = match blockchain_threshold {
1664-
Ok(threshold) => threshold as usize,
1665-
Err(_) => {
1666-
let db_allocator = get_allocator(&owner, &repo).await
1667-
.map_err(|e| LDNError::Load(format!("Database error: {}", e)))?;
1668-
db_allocator
1669-
.as_ref()
1670-
.and_then(|allocator| allocator.multisig_threshold)
1671-
.unwrap_or(2) as usize
1639+
let db_allocator = match get_allocator(&owner, &repo).await {
1640+
Ok(allocator) => allocator.unwrap(),
1641+
Err(err) => {
1642+
return Err(LDNError::New(format!("Database: get_allocator: {}", err)));
16721643
}
16731644
};
1674-
1645+
let db_multisig_threshold = db_allocator.multisig_threshold.unwrap_or(2) as usize;
1646+
let signers: application::file::Verifiers = active_request.signers.clone();
1647+
16751648
// Check if the number of signers meets or exceeds the multisig threshold
1676-
if signers.0.len() < multisig_threshold {
1649+
if signers.0.len() < db_multisig_threshold {
16771650
log::warn!("Not enough signers for approval");
16781651
return Ok(false);
16791652
}
1680-
let signer_index = if multisig_threshold <= 1 { 0 } else { 1 };
1653+
let signer_index = if db_multisig_threshold <= 1 { 0 } else { 1 };
16811654

16821655
let signer = signers.0.get(signer_index).unwrap();
16831656
let signer_gh_handle = signer.github_username.clone();
1657+
16841658
let valid_verifiers: ValidVerifierList =
16851659
Self::fetch_verifiers(owner.clone(), repo.clone()).await?;
1660+
1661+
16861662
if valid_verifiers.is_valid(&signer_gh_handle) {
16871663
log::info!("Val Approval (G)- Validated!");
16881664
Self::issue_datacap_request_signature(
@@ -1795,17 +1771,16 @@ impl LDNApplication {
17951771
}
17961772
}
17971773

1798-
pub async fn delete_merged_branch(owner: String, repo: String, branch_name: String) -> Result<bool, LDNError> {
1774+
pub async fn delete_merged_branch(
1775+
owner: String,
1776+
repo: String,
1777+
branch_name: String,
1778+
) -> Result<bool, LDNError> {
17991779
let gh = github_async_new(owner, repo).await;
18001780
let request = gh.build_remove_ref_request(branch_name.clone()).unwrap();
18011781

1802-
gh.remove_branch(request)
1803-
.await
1804-
.map_err(|e| {
1805-
return LDNError::New(format!(
1806-
"Error deleting branch {} /// {}",
1807-
branch_name, e
1808-
));
1782+
gh.remove_branch(request).await.map_err(|e| {
1783+
return LDNError::New(format!("Error deleting branch {} /// {}", branch_name, e));
18091784
})?;
18101785

18111786
Ok(true)

0 commit comments

Comments
 (0)