Skip to content

Commit

Permalink
refactor(drs): remove awaiting commits status
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed May 30, 2024
1 parent 1dc8248 commit 3cf6ad5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 0 additions & 2 deletions contract/src/msgs/data_requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod tests;

#[derive(Clone)]
pub enum DataRequestStatus {
AwaitingCommits,
Committing,
Revealing,
}
Expand All @@ -31,7 +30,6 @@ impl<'a> PrimaryKey<'a> for &'a DataRequestStatus {
fn key(&self) -> Vec<Key> {
vec![Key::Ref(
match self {
DataRequestStatus::AwaitingCommits => "awaiting_commits",
DataRequestStatus::Committing => "committing",
DataRequestStatus::Revealing => "revealing",
}
Expand Down
14 changes: 2 additions & 12 deletions contract/src/msgs/data_requests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,17 @@ pub fn insert_req(store: &mut dyn Storage, dr_id: &Hash, dr: &DataRequest) -> Re

// set the status to AwaitingCommits
let mut statuses = DATA_REQUESTS_BY_STATUS
.may_load(store, &DataRequestStatus::AwaitingCommits)?
.may_load(store, &DataRequestStatus::Committing)?
.unwrap_or_default();
statuses.insert(*dr_id);
DATA_REQUESTS_BY_STATUS.save(store, &DataRequestStatus::AwaitingCommits, &statuses)?;
DATA_REQUESTS_BY_STATUS.save(store, &DataRequestStatus::Committing, &statuses)?;

Ok(())
}

pub fn commit(store: &mut dyn Storage, dr_id: &Hash, dr: &DataRequest) -> StdResult<()> {
DATA_REQUESTS.save(store, dr_id, dr)?;

// First, update the status from AwaitingCommits to Committing
update_req_status(
store,
dr_id,
&DataRequestStatus::AwaitingCommits,
&DataRequestStatus::Committing,
)?;

// and then, if the replication factor has been reached, update the status from Committing to Revealing
// we do in this order otherwise it fails for replication factor 1
if dr.replication_factor as usize == dr.commits.len() {
update_req_status(
store,
Expand Down
2 changes: 1 addition & 1 deletion contract/src/msgs/data_requests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn post_data_request() {
Some(test_helpers::construct_dr(constructed_dr_id, dr_args, vec![])),
received_value
);
let await_commits = state::requests_by_status(&deps.storage, &DataRequestStatus::AwaitingCommits).unwrap();
let await_commits = state::requests_by_status(&deps.storage, &DataRequestStatus::Committing).unwrap();
assert_eq!(1, await_commits.len());
assert!(await_commits.contains(&constructed_dr_id));

Expand Down

0 comments on commit 3cf6ad5

Please sign in to comment.