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

feat(sequencer)!: implement bridge unlock action and derestrict transfers #1034

Merged
merged 10 commits into from
May 14, 2024

Conversation

Lilyjjo
Copy link
Contributor

@Lilyjjo Lilyjjo commented May 2, 2024

Summary

Implements bridge accounts' BridgeUnlock action and allows bridge accounts to transfer assets like normal.

Background

We need a BridgeUnlock action to help with tracking/proving that withdraws for rollup specific events happened. This PR implements the ground work for that by adding a new action with a memo:bytes field that is currently unused.

We also decided that it's unnecessary to have restrictions on the bridge account in terms of normal transfers in/out of the account. The bridge account is already a privileged actor and having the restrictions on transfer would make normal account maintenance (like gas funding) messy.

Changes

  • implement BridgeUnlockAction for transferring out a bridge's bridged asset
  • derestricted the transfer function to let bridge account also act like normal accounts

Testing

unit tests

Breaking Changelist

  • one new action is added: BridgeUnlock
  • bridge account now can transfer assets in/out like normal sequencer accounts

Related Issues

closes #983

@github-actions github-actions bot added proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate labels May 2, 2024
@Lilyjjo Lilyjjo changed the title Lilyjjo/bridge unlock action feat(sequencer)!: implement bridge unlock action May 2, 2024
@Lilyjjo Lilyjjo force-pushed the lilyjjo/bridge-unlock-action branch from 1f18d0e to 6921aaf Compare May 3, 2024 14:04
@Lilyjjo Lilyjjo marked this pull request as ready for review May 3, 2024 14:09
@Lilyjjo Lilyjjo requested review from a team as code owners May 3, 2024 14:09
Copy link
Contributor

@Fraser999 Fraser999 left a comment

Choose a reason for hiding this comment

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

Just a few minor comments/questions.

if state
.get_bridge_account_rollup_id(&from)
.await
.context("failed to get bridge account rollup ID from state")?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is identical to the context being applied just above (at line 95) and a third in ics20_transfer.rs. It might be useful to change both strings in this file to hold a little more info to disambiguate the three, e.g. "failed to get bridge account rollup ID for transfer [sender|recipient] from state"

crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
crates/astria-sequencer/src/bridge/bridge_unlock_action.rs Outdated Show resolved Hide resolved
let bridged_asset_id = state
.get_bridge_account_asset_ids(&from)
.await
.context("failed to get bridge account asset ID")?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This context appears in four different places. Maybe there should be a separate PR where we deduplicate error contexts across the crate?

Comment on lines 99 to 101
// ensure that if the sender is a bridge account, that the asset being transferred is not
// the same asset as the bridge account's asset. The bridge account should be using
// the `BridgeUnlockAction` for that.
Copy link
Collaborator

Choose a reason for hiding this comment

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

i'm not sure if we need this logic - i think we should either not allow Transfers out of bridge accounts at all, or allow them but not place any restrictions on them. this seems unnecessary, as if the bridge account owner wanted to transfer out the same asset but was restricted from using Transfer, they could still just use BridgeUnlock and leave the memo empty (or put something random)

I think we should remove this part for now and have a bigger discussion on what actions/accounting should look like


// ensure the bridge account's tracked asset is being transferred.
let allowed_asset_id = state
.get_bridge_account_asset_ids(&from)
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this returns just 1 asset id now, can you rename the fn to get_bridge_account_asset_id?

Comment on lines 196 to 197
// the asset to be transferred
bytes asset_id = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't think we need this field - since bridge accounts only allow one asset to be bridged, we know using BridgeUnlockAction must also withdraw that same asset

// It's the same as a `TransferAction` but with the added
// `memo` field.
message BridgeUnlockAction {
// the address of the bridge account to transfer to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// the address of the bridge account to transfer to
// the address to withdraw funds to


#[instrument(skip_all)]
async fn execute<S: StateWriteExt>(&self, state: &mut S, from: Address) -> Result<()> {
let transfer_action = TransferAction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the memo is unused, which is fine, when we decide on the memo structure we should also store that (or data extracted from it). maybe add a comment here about that?

@@ -1142,7 +1142,7 @@ async fn update_mempool_after_finalization<S: StateReadExt>(

for (tx, priority) in mempool.inner().await.iter_mut() {
match TransactionPriority::new(
tx.nonce(),
(*tx).nonce(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the change here?

Copy link
Contributor Author

@Lilyjjo Lilyjjo May 14, 2024

Choose a reason for hiding this comment

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

it was giving me linting errors, i think i messed up my vscode. i removed it!

let signed_tx = tx.into_signed(&bridge_signing_key);
app.execute_transaction(signed_tx)
.await
.expect("failed while executing bridge unlock action");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.expect("failed while executing bridge unlock action");
.expect("executing bridge unlock action should succeed");

app.state
.get_account_balance(bridge_address, asset_id)
.await
.expect("failed while getting account balance"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.expect("failed while getting account balance"),
.expect("getting account balance should succeed"),

Copy link
Collaborator

@noot noot left a comment

Choose a reason for hiding this comment

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

nice, this looks good!

@Lilyjjo Lilyjjo enabled auto-merge May 14, 2024 13:05
@Lilyjjo Lilyjjo added this pull request to the merge queue May 14, 2024
Merged via the queue into main with commit dbd3aec May 14, 2024
36 checks passed
@Lilyjjo Lilyjjo deleted the lilyjjo/bridge-unlock-action branch May 14, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridging proto pertaining to the Astria Protobuf spec sequencer pertaining to the astria-sequencer crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update bridge accounts to allow incoming Transfers
4 participants