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

added node side withdraw fn #690

Merged
merged 8 commits into from
Feb 29, 2024
Merged

Conversation

stanieltron
Copy link
Member

added node side withdraw fn

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 66.03774% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 51.84%. Comparing base (385118e) to head (86498fa).

Files Patch % Lines
pallets/rolldown/src/lib.rs 67.30% 17 Missing ⚠️
pallets/rolldown/src/messages.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                   @@
##           eth-rollup-develop     #690      +/-   ##
======================================================
- Coverage               51.84%   51.84%   -0.01%     
======================================================
  Files                      44       44              
  Lines                    7389     7390       +1     
======================================================
  Hits                     3831     3831              
- Misses                   3558     3559       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -311,6 +311,50 @@ pub mod pallet {
Ok(().into())
}

#[pallet::call_index(3)]
#[pallet::weight(T::DbWeight::get().reads_writes(1, 1).saturating_add(Weight::from_parts(40_000_000, 0)))]
pub fn withdraw(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests for the method that covers basic scenarios:

  • check if total allocation of tokens has changed
  • counter is updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

) -> DispatchResultWithPostInfo {
let account = ensure_signed(origin)?;

let eth_token_address: [u8; 20] = array_bytes::hex2array::<_, 20>(tokenAddress.clone())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tjoken address is already of a type, convertion is not needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<T as Config>::Tokens::ensure_can_withdraw(
asset_id.into(),
&account,
amount.try_into().map_err(|_| "u128 to Balance failed")?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use regular substrate Errors and not string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

WithdrawReasons::all(),
Default::default(),
)
.or(Err("NotEnoughAssets"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create dedicated error type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

T::Tokens::burn_and_settle(
asset_id,
&account,
amount.try_into().map_err(|_| "u128 to Balance failed")?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use dedicated error type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)?;

// increase counter for updates originating on l2
l2_origin_updates_counter::<T>::put(Self::get_l2_origin_updates_counter() + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use safe math instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@stanieltron stanieltron reopened this Feb 15, 2024

Ok(())
}
// fn process_withdraw(withdraw_request_details: &messages::Withdraw) -> Result<(), &'static str> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why its commented out ? please either uncomment or delete. (its in git history either way)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment removed

@@ -625,6 +675,7 @@ impl<T: Config> Pallet<T> {
// slash is after adding rights, since slash can reduce stake below required level and remove all rights
Self::slash(&to_be_slashed);

log!(info, "Cancel resolutiuon processed successfully: {:?}", cancel_resolution);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make logs debug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced

Deposit[] pendingDeposits;
CancelResolution[] pendingCancelResultions;
L2UpdatesToRemove[] pendingL2UpdatesToRemove;
}


#[derive(Debug, Eq, PartialEq, Encode, Decode, TypeInfo)]
enum UpdateType{ DEPOSIT, WITHDRAWAL, INDEX_UPDATE, CANCEL_RESOLUTION}
enum UpdateType{ DEPOSIT, WITHDRAW, INDEX_UPDATE, CANCEL_RESOLUTION}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be withdrawal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

@@ -170,6 +156,11 @@ pub mod eth_abi {
bool status;
}

struct Withdraw {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be withdrawal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Error::<Test>::NotEnoughAssets
);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add ut that makes sure that now with new request_id the tx will be removed from the list of pending updates after proper l1update is received

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it will be rejected because of too high request_id or sth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mateuszaaa mateuszaaa merged commit 01a32a9 into eth-rollup-develop Feb 29, 2024
@mateuszaaa mateuszaaa deleted the feature/l2-side-withdraw branch February 29, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants