Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Transfer debt #1615

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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