Skip to content

Commit f436d5c

Browse files
authored
Merge pull request #153 from filecoin-project/update-threshold-from-blockchain
Updating threshold db inside propose and approve
2 parents 89ba93e + ab7f25e commit f436d5c

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

fplus-database/src/database/allocators.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,36 @@ pub async fn create_or_update_allocator(
151151
}
152152
}
153153

154+
/**
155+
* Update the multisig threshold of an allocator in the database
156+
*
157+
* This function specifically targets and updates only the multisig threshold of an existing allocator.
158+
*
159+
* # Arguments
160+
* @param owner: &str - The owner of the repository.
161+
* @param repo: &str - The name of the repository.
162+
* @param multisig_threshold: i32 - The new multisig threshold to be updated in the allocator.
163+
*
164+
* # Returns
165+
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation.
166+
* On successful update, it returns the updated AllocatorModel.
167+
* On failure, it returns an error of type DbErr.
168+
*/
169+
pub async fn update_allocator_threshold(
170+
owner: &str,
171+
repo: &str,
172+
multisig_threshold: i32,
173+
) -> Result<AllocatorModel, sea_orm::DbErr> {
174+
let conn = get_database_connection().await?;
175+
let mut existing_allocator = get_allocator(owner, repo).await?
176+
.ok_or_else(|| DbErr::Custom("Allocator not found".into()))?
177+
.into_active_model();
178+
179+
existing_allocator.multisig_threshold = Set(Some(multisig_threshold));
180+
181+
existing_allocator.update(&conn).await
182+
}
183+
154184
/**
155185
* Delete an allocator from the database
156186
*

fplus-lib/src/core/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
}},
2222
parsers::ParsedIssue,
2323
};
24-
use fplus_database::database::{self, allocators::get_allocator};
24+
use fplus_database::database::{self, allocators::{get_allocator, update_allocator_threshold}};
2525
use fplus_database::models::applications::Model as ApplicationModel;
2626

2727
use self::application::file::{
@@ -677,7 +677,10 @@ impl LDNApplication {
677677
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
678678
if let Some(blockchain_threshold) = blockchain_threshold {
679679
if blockchain_threshold != db_threshold {
680-
// TODO: Update the database with the new threshold from the blockchain
680+
match update_allocator_threshold(&owner, &repo, blockchain_threshold as i32).await {
681+
Ok(_) => log::info!("Database updated with new multisig threshold"),
682+
Err(e) => log::error!("Failed to update database: {}", e),
683+
};
681684
}
682685
}
683686
// Use the blockchain threshold if available; otherwise, fall back to the database value
@@ -788,7 +791,10 @@ impl LDNApplication {
788791
// If blockchain threshold is available and different from DB, update DB (placeholder for update logic)
789792
if let Some(blockchain_threshold) = blockchain_threshold {
790793
if blockchain_threshold != db_threshold {
791-
// TODO: Update the database with the new threshold from the blockchain
794+
match update_allocator_threshold(&owner, &repo, blockchain_threshold as i32).await {
795+
Ok(_) => log::info!("Database updated with new multisig threshold"),
796+
Err(e) => log::error!("Failed to update database: {}", e),
797+
};
792798
}
793799
}
794800

0 commit comments

Comments
 (0)