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

TransactionView: summary of transaction effects #4943

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

TalDerei
Copy link
Collaborator

Describe your changes

References #4939

Issue ticket number and link

Checklist before requesting a review

  • I have added guiding text to explain how a reviewer should test these changes.

  • If this code contains consensus-breaking changes, I have added the "consensus-breaking" label. Otherwise, I declare my belief that there are not consensus-breaking changes, for the following reason:


impl From<Balance> for pb::Balance {
fn from(_v: Balance) -> Self {
todo!() // todo: implement fallible conversion
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

comment: need to implement fallible conversion (proto to domain type)

pub fn summary(&self) -> TransactionSummary {
let mut effects = Vec::new();

for action_view in &self.body_view.action_views {
Copy link
Collaborator Author

@TalDerei TalDerei Nov 25, 2024

Choose a reason for hiding this comment

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

comment: Iterates through the visible action views and adds the contributing balances to the transaction's effects. Sanity check the required and provided balances are correct.

Comment on lines +134 to +135
ActionView::Swap(_) => todo!(),
ActionView::SwapClaim(_) => todo!(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

comment: need to implement other action views

let amount = NonZeroU128::new(value.amount.into())
.ok_or_else(|| anyhow::anyhow!("amount must be non-zero"))?;

let imbalance = Imbalance::Provided(amount); // todo: fix this placeholder
Copy link
Collaborator Author

@TalDerei TalDerei Nov 25, 2024

Choose a reason for hiding this comment

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

comment: Values cannot be negative, and a negative Balance is formed by negating a balance derived from a value. How do we calculate the Imbalance and differentiate between provided and required balances?

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 the modeling suggested by henry here: https://github.com/penumbra-zone/penumbra/pull/4943/files#r1855950445 takes care of that

@TalDerei TalDerei marked this pull request as draft November 25, 2024 04:05
pub struct Balance {
negated: bool,
#[serde_as(as = "Vec<(_, _)>")]
Copy link
Collaborator Author

@TalDerei TalDerei Nov 25, 2024

Choose a reason for hiding this comment

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

comment: confirmed the previous derived serde policy wasn't used.

@@ -7,14 +7,15 @@ use anyhow::{Context, Error};
use ark_ff::Zero;
use decaf377::Fr;
use decaf377_rdsa::{Binding, Signature, VerificationKey, VerificationKeyBytes};
use penumbra_asset::Balance;
use penumbra_community_pool::{CommunityPoolDeposit, CommunityPoolOutput, CommunityPoolSpend};
use penumbra_dex::{
lp::action::{PositionClose, PositionOpen},
swap::Swap,
};
Copy link
Collaborator Author

@TalDerei TalDerei Nov 25, 2024

Choose a reason for hiding this comment

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

impl From<&Transaction> for pbt::Transaction {
fn from(msg: &Transaction) -> Self {
msg.into()
}
}

comment: does this lead to infinite recursion?

Copy link
Member

Choose a reason for hiding this comment

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

Yup. good catch

Comment on lines +95 to +100
message Balance {
// Indicates if the balance is negated.
bool negated = 1;
// Represents the vector of 'Values' in the balance.
repeated Value balance = 2;
}
Copy link
Member

Choose a reason for hiding this comment

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

xref https://github.com/penumbra-zone/penumbra/pull/4943/files#r1855748563

Since Values can't be negative, I think we'll want to have a list of pairs, each with a negation flag, something like

message Balance {
  message SignedValue {
    Value value = 1;
    bool negated = 2;
  }
  repeated SignedValue values = 1;
}

The top-level bool in the Rust Balance struct is an optimization that makes sign changes less expensive (unclear this was really necessary perf-wise, but, we have it now), IMO it should be excluded from serialization by having the serialized form always be "normalized" with individual sign bools.

Comment on lines +57 to +61
// Represents an individual effect of a transaction.
message Effects {
keys.v1.AddressView address = 1;
asset.v1.Balance balance = 2;
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this into a sub-message so it's clear that it's logically scoped to be part of the TransactionSummary.

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.

3 participants