Skip to content

Commit f897d22

Browse files
authored
Merge pull request #163 from filecoin-project/approve-validation-signers-count
Approve-validation-signers-count
2 parents 47cebee + e91b4f4 commit f897d22

File tree

2 files changed

+31
-81
lines changed

2 files changed

+31
-81
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: 29 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -691,21 +691,24 @@ impl LDNApplication {
691691
owner: String,
692692
repo: String,
693693
) -> Result<ApplicationFile, LDNError> {
694-
// Get multisig threshold from blockchain
695-
let blockchain_threshold =
696-
match get_multisig_threshold_for_actor(&signer.signing_address).await {
697-
Ok(threshold) => Some(threshold),
698-
Err(_) => None,
699-
};
700694
// TODO: Convert DB errors to LDN Error
701695
// Get multisig threshold from the database
702696
let db_allocator = match get_allocator(&owner, &repo).await {
703-
Ok(allocator) => allocator,
697+
Ok(allocator) => allocator.unwrap(),
704698
Err(err) => {
705699
return Err(LDNError::New(format!("Database: get_allocator: {}", err)));
706700
}
707701
};
708-
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;
709712

710713
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
711714
if let Some(blockchain_threshold) = blockchain_threshold {
@@ -808,34 +811,17 @@ impl LDNApplication {
808811
owner: String,
809812
repo: String,
810813
) -> Result<ApplicationFile, LDNError> {
811-
// Get multisig threshold from blockchain
812-
let blockchain_threshold =
813-
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,63 +1635,30 @@ impl LDNApplication {
16521635
return Ok(false);
16531636
}
16541637
};
1655-
let signers: application::file::Verifiers = active_request.signers.clone();
1656-
let num_signers = signers.0.len();
1657-
// Default to first signer for validation
1658-
let mut signer_index = 0;
1659-
1660-
// If there are multiple signers, fetch the multisig threshold to determine which signer to validate
1661-
if num_signers > 1 {
1662-
let blockchain_threshold =
1663-
get_multisig_threshold_for_actor(&signers.0[0].signing_address).await;
1664-
let multisig_threshold = match blockchain_threshold {
1665-
Ok(threshold) => threshold as usize,
1666-
Err(_) => {
1667-
let db_allocator =
1668-
get_allocator(&owner, &repo).await.map_err(|e| {
1669-
LDNError::Load(format!("Database error: {}", e))
1670-
})?;
1671-
db_allocator
1672-
.as_ref()
1673-
.and_then(|allocator| allocator.multisig_threshold)
1674-
.unwrap_or(2) as usize
1675-
}
1676-
};
1677-
// Adjust signer index based on multisig threshold
1678-
signer_index = if multisig_threshold <= 1 { 0 } else { 1 };
1679-
}
1680-
1681-
let signer = signers.0.get(signer_index).unwrap();
16821638

1683-
// Try getting the multisig threshold from the blockchain
1684-
let blockchain_threshold =
1685-
get_multisig_threshold_for_actor(&signer.signing_address).await;
1686-
1687-
// Fallback to database value if blockchain query fails
1688-
let multisig_threshold = match blockchain_threshold {
1689-
Ok(threshold) => threshold as usize,
1690-
Err(_) => {
1691-
let db_allocator = get_allocator(&owner, &repo)
1692-
.await
1693-
.map_err(|e| LDNError::Load(format!("Database error: {}", e)))?;
1694-
db_allocator
1695-
.as_ref()
1696-
.and_then(|allocator| allocator.multisig_threshold)
1697-
.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)));
16981643
}
16991644
};
1645+
let db_multisig_threshold = db_allocator.multisig_threshold.unwrap_or(2) as usize;
1646+
let signers: application::file::Verifiers = active_request.signers.clone();
17001647

17011648
// Check if the number of signers meets or exceeds the multisig threshold
1702-
if signers.0.len() < multisig_threshold {
1649+
if signers.0.len() < db_multisig_threshold {
17031650
log::warn!("Not enough signers for approval");
17041651
return Ok(false);
17051652
}
1706-
let signer_index = if multisig_threshold <= 1 { 0 } else { 1 };
1653+
let signer_index = if db_multisig_threshold <= 1 { 0 } else { 1 };
17071654

17081655
let signer = signers.0.get(signer_index).unwrap();
17091656
let signer_gh_handle = signer.github_username.clone();
1657+
17101658
let valid_verifiers: ValidVerifierList =
17111659
Self::fetch_verifiers(owner.clone(), repo.clone()).await?;
1660+
1661+
17121662
if valid_verifiers.is_valid(&signer_gh_handle) {
17131663
log::info!("Val Approval (G)- Validated!");
17141664
Self::issue_datacap_request_signature(

0 commit comments

Comments
 (0)