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

dex: redesign value circuit breaker #4086

Merged
merged 3 commits into from
Mar 25, 2024
Merged

dex: redesign value circuit breaker #4086

merged 3 commits into from
Mar 25, 2024

Conversation

hdevalence
Copy link
Member

Closes #4025

This commit sketches a new mechanism but does not fix the existing tests; it needs to be picked up and pushed over the finish line. (We should be testing this).

Comment on lines +219 to +220
// Note that since we credited the DEX for _all_ inflows, we need to debit the
// unfilled amounts as well as the filled amounts.
Copy link
Member Author

Choose a reason for hiding this comment

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

this would be good to cover in a test

@erwanor erwanor added zellic-component-remediated Tag PRs that are remediating Zellic findings consensus-breaking breaking change to execution of on-chain data A-dex Area: Relates to the dex state-breaking breaking change to on-chain data labels Mar 22, 2024
Copy link
Member

@zbuc zbuc left a comment

Choose a reason for hiding this comment

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

Looks good overall, except the reduction in test coverage

}
}

impl<T: StateWrite + ?Sized> ValueCircuitBreaker for T {}

/*
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the tests are uncommented?

Copy link
Member Author

Choose a reason for hiding this comment

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

They don't compile, the tests need to be updated / rewritten, that's the remaining work on the PR that needs to be picked up.

@@ -570,32 +569,6 @@ pub(crate) trait Inner: StateWrite {
"updating position assets' aggregate balances"
Copy link
Member

Choose a reason for hiding this comment

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

the update of the aggregate balance was for debugging the value circuit breaker; this tracing message and the net_change_* variables are likely no longer needed

amount: Amount::from(0u64),
})
/// Debits a deposit from the DEX.
async fn vcb_debit(&mut self, value: Value) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

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

should we have some debug tracing messages here for the value circuit breaker credits/debits?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, or we could also / instead fire off an ABCI event, so that it's possible to build a dashboard of inflows and outflows.

// Debit the DEX for the swap outflows.
// Note that since we credited the DEX for _all_ inflows, we need to debit the
// unfilled amounts as well as the filled amounts.
self.vcb_debit(Value {
Copy link
Member

Choose a reason for hiding this comment

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

is the idea that the debit will underflow and cause an error to be returned in the value circuit breaker triggered case? it might be good to explicitly call that out

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep

@zbuc zbuc force-pushed the redesign-dex-vcb branch from f9b6d81 to c065dce Compare March 22, 2024 21:31
@zbuc zbuc marked this pull request as ready for review March 22, 2024 21:31
@erwanor
Copy link
Member

erwanor commented Mar 23, 2024

This breaks a few tests, as expected because we moved the vb credits to the action handlers:

        FAIL [   0.053s] penumbra-dex component::router::tests::best_position_route_and_fill
        FAIL [   0.116s] penumbra-dex component::router::tests::multi_hop_route_and_fill

I think we can fix them without too much effort by doing:

    let infinite_gm = Value {
        asset_id: gm.id(),
        amount: Amount::from(100000u128) * gm.unit_amount(),
    };

    let infinite_gn = Value {
        asset_id: gn.id(),
        amount: Amount::from(100000u128) * gn.unit_amount(),
    };

    let infinite_penumbra = Value {
        asset_id: penumbra.id(),
        amount: Amount::from(100000u128) * penumbra.unit_amount(),
    };

    state_tx.vcb_credit(infinite_gm).await?;
    state_tx.vcb_credit(infinite_gn).await?;
    state_tx.vcb_credit(infinite_penumbra).await?;

We will be able to replace them with something much better but in the meantime it seems useful to keep them around as basic checks.

Copy link
Member

@erwanor erwanor left a comment

Choose a reason for hiding this comment

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

ACK on general implementation, merge on green CI

hdevalence and others added 3 commits March 24, 2024 23:51
Closes #4025

This commit sketches a new mechanism but does not fix the existing tests; it
needs to be picked up and pushed over the finish line. (We should be testing
this).
@hdevalence hdevalence merged commit cdf449f into main Mar 25, 2024
7 checks passed
@hdevalence hdevalence deleted the redesign-dex-vcb branch March 25, 2024 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dex Area: Relates to the dex consensus-breaking breaking change to execution of on-chain data state-breaking breaking change to on-chain data zellic-component-remediated Tag PRs that are remediating Zellic findings
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

dex: move value circuit breaker accounting to dex engine boundaries
3 participants