-
Notifications
You must be signed in to change notification settings - Fork 107
Remove asset_witnesses field from TransactionInputs
#2298
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
Changes from 1 commit
cfea856
d75af0e
41d6978
168f865
7139863
b6ee9de
d26357d
2ef192c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,25 +318,32 @@ where | |
| AccountProcedureIndexMap::new([tx_inputs.account().code()]); | ||
|
|
||
| let initial_fee_asset_balance = { | ||
| let vault_root = tx_inputs.account().vault().root(); | ||
| let native_asset_id = tx_inputs.block_header().fee_parameters().native_asset_id(); | ||
| let fee_asset_vault_key = AssetVaultKey::from_account_id(native_asset_id) | ||
| .expect("fee asset should be a fungible asset"); | ||
|
|
||
| let fee_asset_witness = tx_inputs | ||
| .asset_witnesses() | ||
| .iter() | ||
| .find_map(|witness| witness.find(fee_asset_vault_key)); | ||
|
|
||
| match fee_asset_witness { | ||
| Some(Asset::Fungible(fee_asset)) => fee_asset.amount(), | ||
| Some(Asset::NonFungible(_)) => { | ||
| return Err(TransactionExecutorError::FeeAssetMustBeFungible); | ||
| }, | ||
| // If the witness does not contain the asset, its balance is zero. | ||
| None => 0, | ||
| // extract the fee asset amount from the transaction inputs | ||
| let fee_asset_witnesses = | ||
| tx_inputs.read_vault_asset_witnesses(vault_root, [fee_asset_vault_key].into()); | ||
| if let Ok(witnesses) = fee_asset_witnesses { | ||
|
||
| // we requested one witness and if there was no error only one witness should have | ||
| // been returned | ||
| assert_eq!(witnesses.len(), 1, "expected exactly one witness"); | ||
| match witnesses[0].find(fee_asset_vault_key) { | ||
| Some(Asset::Fungible(fee_asset)) => fee_asset.amount(), | ||
| Some(Asset::NonFungible(_)) => { | ||
| return Err(TransactionExecutorError::FeeAssetMustBeFungible); | ||
| }, | ||
| // If the witness does not contain the asset, its balance is zero. | ||
| None => 0, | ||
| } | ||
| } else { | ||
| // if read_vault_asset_witnesses() returned an error, we assume that the witness | ||
| // was not found because because otherwise the read request was valid | ||
| 0 | ||
| } | ||
| }; | ||
|
|
||
| let host = TransactionExecutorHost::new( | ||
| tx_inputs.account(), | ||
| input_notes.clone(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the approach from #2099 more or less strongly requires that we extend both
self.advice_inputsandself.tx_args.advice_inputs. I'm actually not sure how necessary this is (I find this pretty hard to think about now), but it seems it would be more consistent. So I would add the function added in #2274 for this:And then here do:
This reuses the existing asset witness -> advice input conversion and we don't duplicate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is needed because
TransactionInputs::set_advice_inputs()should already take care of this. But I agree the whole structure is confusing. I hope that with the structure I described in #1286 (comment), we'd be able to clarify the structure somewhat.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically yes, but it's not obvious that
set_advice_inputsis called later (only after tx execution) and so this leaves this "invariant" temporarily broken. Not sure if this is a real problem, and I think it's fine to address this in #1286 or #2293.Nit: I would prefer using
TransactionAdviceInputshere so we use the lower-level leaf -> advice inputs conversion implementation (TransactionAdviceInputs::add_asset_witness) rather than move it outside that type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've actually removed
TransactionAdviceInputs::add_asset_witness()in this PR since it was no longer needed. I think we can bring it back if needed depending on how we address #1286 and #2293.