Skip to content

Commit

Permalink
add: update_hash parameter for update_l2_from_l1
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Sep 19, 2024
1 parent ba9f3f5 commit 247a5db
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 79 deletions.
32 changes: 22 additions & 10 deletions pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,12 @@ pub mod pallet {
pub fn update_l2_from_l1(
origin: OriginFor<T>,
requests: messages::L1Update,
update_hash: H256,
) -> DispatchResult {
let sequencer = ensure_signed(origin)?;

let update_hash = requests.abi_encode_hash();

Self::update_impl(sequencer, requests)
}

Expand Down Expand Up @@ -839,7 +843,6 @@ pub mod pallet {
Ok(().into())
}


#[pallet::call_index(11)]
#[pallet::weight(T::DbWeight::get().reads_writes(1, 1).saturating_add(Weight::from_parts(40_000_000, 0)))]
pub fn ferry_deposit_unsafe(
Expand Down Expand Up @@ -867,6 +870,16 @@ pub mod pallet {

Ok(().into())
}

#[pallet::call_index(12)]
#[pallet::weight(T::DbWeight::get().reads_writes(3, 3).saturating_add(Weight::from_parts(40_000_000, 0)))]
pub fn update_l2_from_l1_unsafe(
origin: OriginFor<T>,
requests: messages::L1Update,
) -> DispatchResult {
let sequencer = ensure_signed(origin)?;
Self::update_impl(sequencer, requests)
}
}
}

Expand Down Expand Up @@ -1609,10 +1622,15 @@ impl<T: Config> Pallet<T> {
}
}

fn ferry_desposit_impl(sender: T::AccountId, chain: T::ChainId, deposit: messages::Deposit) -> Result<(), Error::<T>> {
fn ferry_desposit_impl(
sender: T::AccountId,
chain: T::ChainId,
deposit: messages::Deposit,
) -> Result<(), Error<T>> {
let deposit_hash = deposit.abi_encode_hash();

let amount = deposit.amount
let amount = deposit
.amount
.checked_sub(deposit.ferryTip)
.and_then(|v| TryInto::<u128>::try_into(v).ok())
.and_then(|v| TryInto::<BalanceOf<T>>::try_into(v).ok())
Expand All @@ -1627,13 +1645,7 @@ impl<T: Config> Pallet<T> {

let account = T::AddressConverter::convert(deposit.depositRecipient);

T::Tokens::transfer(
asset_id,
&sender,
&account,
amount,
ExistenceRequirement::KeepAlive,
)
T::Tokens::transfer(asset_id, &sender, &account, amount, ExistenceRequirement::KeepAlive)
.map_err(|_| Error::<T>::NotEnoughAssets)?;
FerriedDeposits::<T>::insert((chain, deposit_hash), sender);

Expand Down
7 changes: 7 additions & 0 deletions pallets/rolldown/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ pub struct L1Update {
pub pendingCancelResolutions: Vec<CancelResolution>,
}

impl NativeToEthMapping for L1Update
where
Self: Clone,
{
type EthType = eth_abi::L1Update;
}

#[derive(Eq, PartialEq, RuntimeDebug, Clone, Encode, Decode, TypeInfo, Serialize)]
pub enum L1UpdateRequest {
Deposit(Deposit),
Expand Down
Loading

0 comments on commit 247a5db

Please sign in to comment.