Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Jul 31, 2024
1 parent cc1edf5 commit eeaa52e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
21 changes: 14 additions & 7 deletions pallets/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub mod pallet {
pallet_prelude::*,
traits::{
fungible::{Inspect, Mutate},
nonfungible::Mutate as NftMutate,
tokens::Balance,
ReservableCurrency,
},
Expand Down Expand Up @@ -83,6 +84,7 @@ pub mod pallet {
//
// The item id is `u128` encoded RegionId.
type Regions: Transfer<Self::AccountId, ItemId = u128>
+ NftMutate<Self::AccountId, ItemId = u128>
+ LockableNonFungible<Self::AccountId, ItemId = u128>
+ RegionInspect<Self::AccountId, Self::Balance, ItemId = u128>
+ RegionFactory<Self::AccountId, RegionRecordOf<Self>>;
Expand Down Expand Up @@ -187,11 +189,7 @@ pub mod pallet {
// transfer it to the order creator. This way in case the assignment fails the region
// will still be owned by the creator.
T::Regions::transfer(&region_id.into(), &order.creator)?;
// Lock the region so the order creator cannot transfer it.
T::Regions::lock(&region_id.into(), None)?;
// Even though the region will be owned by the creator, anyone can assign it to the task
// by calling the `assign` extrinsic.
RegionAssignments::<T>::insert(region_id, order.para_id);

let order_account = T::OrderToAccountId::convert(order_id);
let amount = T::Currency::free_balance(&order_account);
Expand All @@ -208,14 +206,20 @@ pub mod pallet {

Self::deposit_event(Event::OrderProcessed { order_id, region_id, seller: who });

// NOTE: if an error occurs we don't return error, we instead return ok and emit
// appropriate event so the transaction doesn't get reverted in case the assignment
// fails.
// NOTE: If the assignment fails, we don't return an error; instead, we return ok and
// allow anyone to attempt to assign the region.
if let Err(err) = T::RegionAssigner::assign(region_id, order.para_id) {
// Even though the region will be owned by the creator, anyone can assign it to the
// task by calling the `assign` extrinsic.
RegionAssignments::<T>::insert(region_id, order.para_id);

Self::deposit_event(Event::AssignmentFailed(err));
return Ok(())
}

// We will burn the region since it has been assigned with `Final` finality.
T::Regions::burn(&region_id.into(), None)?;

Self::deposit_event(Event::RegionAssigned { region_id, para_id: order.para_id });
Ok(())
}
Expand All @@ -235,6 +239,9 @@ pub mod pallet {

T::RegionAssigner::assign(region_id, para_id)?;

// We will burn the region since it has been assigned with `Final` finality.
T::Regions::burn(&region_id.into(), None)?;

Self::deposit_event(Event::RegionAssigned { region_id, para_id });
Ok(())
}
Expand Down
5 changes: 4 additions & 1 deletion pallets/processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ fn fulfill_order_works() {

// Region owner receives as the contributions for fulfilling the order:
assert_eq!(Balances::free_balance(region_owner), 1500);
assert_eq!(Regions::regions(region_id).unwrap().owner, 2000);
// The region is removed since the assignment was successful:
assert!(Regions::regions(region_id).is_none());

// Assignment request is emmited:
assert_eq!(assignments(), vec![(region_id, 2000.into())]);
Expand All @@ -111,7 +112,9 @@ fn assign_works() {
Error::<Test>::RegionAssignmentNotFound
);

Regions::mint_into(&region_id.into(), &1).unwrap();
crate::RegionAssignments::<Test>::insert(&region_id, para_id);

assert_ok!(Processor::assign(RuntimeOrigin::signed(1), region_id));
System::assert_last_event(Event::RegionAssigned { region_id, para_id: 2000.into() }.into());
});
Expand Down
2 changes: 1 addition & 1 deletion runtime/cocos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl pallet_orders::Config for Runtime {
}

parameter_types! {
pub const FeeBuffer: Balance = MILLI_ROC;
pub const FeeBuffer: Balance = MILLI_ROC / 10;
}

impl pallet_processor::Config for Runtime {
Expand Down

0 comments on commit eeaa52e

Please sign in to comment.