@@ -131,13 +131,11 @@ pub struct AllocatorUpdateInfo {
131
131
pub multisig_threshold : Option < i32 > ,
132
132
}
133
133
134
-
135
134
#[ derive( Deserialize ) ]
136
135
pub struct InstallationIdUpdateInfo {
137
136
pub installation_id : i64 ,
138
137
}
139
138
140
-
141
139
#[ derive( Deserialize ) ]
142
140
pub struct GithubQueryParams {
143
141
pub owner : String ,
@@ -693,20 +691,24 @@ impl LDNApplication {
693
691
owner : String ,
694
692
repo : String ,
695
693
) -> 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
- } ;
701
694
// TODO: Convert DB errors to LDN Error
702
695
// Get multisig threshold from the database
703
696
let db_allocator = match get_allocator ( & owner, & repo) . await {
704
- Ok ( allocator) => allocator,
697
+ Ok ( allocator) => allocator. unwrap ( ) ,
705
698
Err ( err) => {
706
699
return Err ( LDNError :: New ( format ! ( "Database: get_allocator: {}" , err) ) ) ;
707
700
}
708
701
} ;
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 ;
710
712
711
713
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
712
714
if let Some ( blockchain_threshold) = blockchain_threshold {
@@ -809,33 +811,17 @@ impl LDNApplication {
809
811
owner : String ,
810
812
repo : String ,
811
813
) -> 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
-
818
814
// Get multisig threshold from the database
819
815
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) ) ) ;
832
819
}
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 ;
837
822
838
823
let app_state = self . app_state ( ) . await ?;
824
+
839
825
if app_state != AppState :: StartSignDatacap
840
826
&& !( threshold_to_use == 1 && app_state == AppState :: ReadyToSign )
841
827
{
@@ -844,6 +830,7 @@ impl LDNApplication {
844
830
self . application_id
845
831
) ) ) ;
846
832
}
833
+
847
834
let app_file: ApplicationFile = self . file ( ) . await ?;
848
835
let app_lifecycle = app_file. lifecycle . finish_approval ( ) ;
849
836
@@ -879,10 +866,6 @@ impl LDNApplication {
879
866
request_id. clone ( ) ,
880
867
app_lifecycle,
881
868
) ;
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
- }
886
869
887
870
let file_content = serde_json:: to_string_pretty ( & app_file) . unwrap ( ) ;
888
871
let commit_result = LDNPullRequest :: add_commit_to (
@@ -1652,37 +1635,30 @@ impl LDNApplication {
1652
1635
return Ok ( false ) ;
1653
1636
}
1654
1637
} ;
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 ;
1661
1638
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) ) ) ;
1672
1643
}
1673
1644
} ;
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
+
1675
1648
// 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 {
1677
1650
log:: warn!( "Not enough signers for approval" ) ;
1678
1651
return Ok ( false ) ;
1679
1652
}
1680
- let signer_index = if multisig_threshold <= 1 { 0 } else { 1 } ;
1653
+ let signer_index = if db_multisig_threshold <= 1 { 0 } else { 1 } ;
1681
1654
1682
1655
let signer = signers. 0 . get ( signer_index) . unwrap ( ) ;
1683
1656
let signer_gh_handle = signer. github_username . clone ( ) ;
1657
+
1684
1658
let valid_verifiers: ValidVerifierList =
1685
1659
Self :: fetch_verifiers ( owner. clone ( ) , repo. clone ( ) ) . await ?;
1660
+
1661
+
1686
1662
if valid_verifiers. is_valid ( & signer_gh_handle) {
1687
1663
log:: info!( "Val Approval (G)- Validated!" ) ;
1688
1664
Self :: issue_datacap_request_signature (
@@ -1795,17 +1771,16 @@ impl LDNApplication {
1795
1771
}
1796
1772
}
1797
1773
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 > {
1799
1779
let gh = github_async_new ( owner, repo) . await ;
1800
1780
let request = gh. build_remove_ref_request ( branch_name. clone ( ) ) . unwrap ( ) ;
1801
1781
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) ) ;
1809
1784
} ) ?;
1810
1785
1811
1786
Ok ( true )
0 commit comments