Skip to content

Commit

Permalink
Fix: Transfer debt (#1615)
Browse files Browse the repository at this point in the history
* fix: blocking transfer debt by epoch and redemptions.

* feat: make change_id deterministic

* fix: build
  • Loading branch information
mustermeiszer committed Nov 21, 2023
1 parent 6330858 commit 1a952f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,13 @@ impl<T: Config> ChangeGuard for Pallet<T> {
type PoolId = T::PoolId;

fn note(pool_id: Self::PoolId, change: Self::Change) -> Result<Self::ChangeId, DispatchError> {
// NOTE: Essentially, this key-generation allows to override previously
// submitted changes, if they are identical.
let change_id: Self::ChangeId = T::Hashing::hash(&change.encode());
let noted_change = NotedPoolChange {
submitted_time: T::Time::now(),
change,
};

let change_id: Self::ChangeId = T::Hashing::hash(&noted_change.encode());
NotedChange::<T>::insert(pool_id, change_id, noted_change.clone());

Self::deposit_event(Event::ProposedChange {
Expand Down
6 changes: 4 additions & 2 deletions pallets/pool-system/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2449,12 +2449,14 @@ mod changes {
let change = PoolChangeProposal::new([Requirement::DelayTime(2)]);
let change_id_3 = PoolSystem::note(DEFAULT_POOL_ID, change).unwrap();

// Same change but different moment;
// Same change but different moment so overwrites
util::advance_secs(1);
let change = PoolChangeProposal::new([Requirement::DelayTime(2)]);
let change_id_4 = PoolSystem::note(DEFAULT_POOL_ID, change).unwrap();

let ids = [change_id_1, change_id_2, change_id_3, change_id_4];
assert_eq!(change_id_4, change_id_3);

let ids = [change_id_1, change_id_2, change_id_3];
assert_eq!(BTreeSet::from(ids.clone()).len(), ids.len());
});
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub mod changes {
},
},
LoansChange::<T>::Policy(_) => vec![week, blocked],
LoansChange::<T>::TransferDebt(_, _, _, _) => vec![epoch, blocked],
LoansChange::<T>::TransferDebt(_, _, _, _) => vec![],
};

PoolChangeProposal::new(requirements)
Expand Down

0 comments on commit 1a952f3

Please sign in to comment.