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: Utilize expected notes from ExecutedTransaction #329

Merged
merged 22 commits into from
May 13, 2024

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented May 8, 2024

Closes #320

  • Now that ExecutedTransaction contains all output note details, we can use that for checking that the notes that we expected were all correctly generated by the transaction, and after that tracking them accordingly.
  • This PR also contains a small refactor related to the NoteScreener's use of the Store. It removes the lifetime in favor of Rc.

@igamigo igamigo requested a review from bobbinth May 8, 2024 23:17
@igamigo
Copy link
Collaborator Author

igamigo commented May 9, 2024

@bobbinth don't mind the integration tests failing too much (I think there could be a bug related to tags on miden-base, still investigating), but just want to see if these are about what you had in mind

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

On a quick look this looks pretty much as I've envisioned it. I left a few comments regarding treatment of note headers. I don't think we run into these situations now - so, we could address these comments separately.

src/client/transactions/mod.rs Outdated Show resolved Hide resolved
let mut relevant_notes = vec![];
let output_notes = executed_transaction.output_notes().iter().map(|n| match n {
OutputNote::Full(n) => n,
OutputNote::Header(_) => panic!("ExecutedTransaction should have all note details"),
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 not necessarily true - a transaction could produce a note for which we don't have full details. For example, this is possible when creating a P2ID note when the only thing we know is the recipient digest.

The implication is that while such a note an be inserted into the output_notes table, it cannot be inserted into the input_notes table.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see. But in that case, how do we want it to behave in the context of this code? Neither NoteHeader nor Note allow for the scenario you mentioned. Or do we want to go back to adding rows to the output_notes table based on the expected_notes from the TransactionRequest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah - now that I think about it, the two variants of OutputNote should be Full and something like Reduced (but better name is needed). The Reduced variant would basically be NoteHeader + Assets. I'll create an issue for this in miden-base.

Copy link
Contributor

Choose a reason for hiding this comment

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

For this PR, what you have now is probably fine but I'd change panic!() into todo!() as this is not the final state of how it should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

src/client/transactions/mod.rs Outdated Show resolved Hide resolved
Comment on lines 250 to 259
let tx_note_auth_hashes: BTreeSet<Digest> = executed_transaction
.output_notes()
.iter()
.map(|n| match n {
OutputNote::Full(n) => n.authentication_hash(),
OutputNote::Header(_) => {
panic!("ExecutedTransaction should always have every note's details")
},
})
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment to the ones above re full notes vs. headers.

Also, what is the reason for switching to authentication hashes here (from note IDs)?

Maybe this is related - but I actually think TransactionArgs::add_expected_output_note() should accept NoteDetails rather than Note objects as note metadata is not read from the advice provider but rather is built directly by note scripts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, what is the reason for switching to authentication hashes here (from note IDs)?

It's a stronger check, would avoid problems like these unless I'm missing something

Copy link
Contributor

Choose a reason for hiding this comment

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

ah - makes sense!

Comment on lines +47 to 64
pub fn new<S: Store>(
transaction: ExecutedTransaction,
note_screener: NoteScreener<S>,
) -> Result<Self, ClientError> {
let mut relevant_notes = vec![];

for note in notes_from_output(transaction.output_notes()) {
let account_relevance = note_screener.check_relevance(note)?;

if !account_relevance.is_empty() {
relevant_notes.push(note.clone().into());
}
}
}

pub fn executed_transaction(&self) -> &ExecutedTransaction {
&self.executed_transaction
let tx_result = Self { transaction, relevant_notes };

Ok(tx_result)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also provide a way to create a TransactionResult without filtering by note relevance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Might be a good idea, but since we provide and use this TransactionResult type, I think we should add it if we end up needing it.

OutputNote::Full(n) => n,
// The following todo!() applies until we have a way to support flows where we have
// partial details of the note
OutputNote::Header(_) => todo!("For now, all details should be held in OutputNote::Fulls"),
Copy link
Contributor

Choose a reason for hiding this comment

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

In which case do we get an OutputNote::Header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The OutputNote::Header will contain only partial details of a note. When the transaction has to be proven, it is shrinked. At the point where we are using it though, all details will be held in OutputNote::Full after having been picked up from the advice map (after the transcation execution)

Copy link
Contributor

Choose a reason for hiding this comment

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

don't think it's blocking yet, but for swap flows I think we create an OutputNote::Header when we consume the swap note

// CONVERSIONS
// ================================================================================================

// TODO: Improve conversions by implementing into_parts()
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create an issue for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we probably should. Although I think it would belong in miden-base so that we can do into_parts() with domain types.

Copy link
Collaborator

@tomyrd tomyrd left a comment

Choose a reason for hiding this comment

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

LGTM, left some small comments

Comment on lines 37 to 43
/// It contains an [ExecutedTransaction], a list of [Note] that describe the details of the notes
/// created by the transaction execution, and a list of `usize` `relevant_notes` that contain the
/// indices of `output_notes` that are relevant to the client
/// created by the transaction execution, and a list of `relevant_notes` that contains the
/// `output_notes` that the client has to store as input notes, based on the NoteScreener output
pub struct TransactionResult {
executed_transaction: ExecutedTransaction,
output_notes: Vec<Note>,
relevant_notes: Option<BTreeMap<usize, Vec<(AccountId, NoteRelevance)>>>,
transaction: ExecutedTransaction,
relevant_notes: Vec<InputNoteRecord>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the new doc comment reflects what the struct stores. It talks about a list of [Note] and output_notes but that vec doesn't exist anymore in the struct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, changed.

Comment on lines 176 to 178
pub const P2ID: &str = "0x0007b2229f7c8e3205a485a9879f1906798a2e27abd1706eaf58536e7cc3868b";
pub const P2IDR: &str = "0x418ae31e80b53ddc99179d3cacbc4140c7b36ab04ddb26908b3a6ed2e40061d5";
pub const SWAP: &str = "0x755c5dd2fd8d2aa8c2896e0e366a45bdc59c6d5ab543909db32ccfaf949c5826";
Copy link
Collaborator

Choose a reason for hiding this comment

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

For another PR: Should we find a way to change/calculate these automatically? I guess thanks to the tests we would never forget to update them but it would be a good addition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we might have to. Originally this was a 'temporary' solution until the MAST refactors on the compiler. Additionally I thought that these scripts would not change too much, and even though the tests catch these errors there are a couple of things we can do to avoid having to recalculate them:

  • Provide a const way in miden-base to get these values (since the scripts live there).
  • Alternatively, we could provide a runtime method in miden-base to calculate these easily, because right now the only thing we can do is call create_p2id_note() and get the roots each time which is a bit hacky.

Copy link
Contributor

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

LGTM!

@igamigo igamigo merged commit d7f363f into igamigo-next-0.3 May 13, 2024
6 checks passed
@igamigo igamigo deleted the igamigo-expected-notes branch May 13, 2024 19:16
igamigo added a commit that referenced this pull request May 15, 2024
* feat: Integrate next changes

* fix: Back to next

* Fix conflicts

* Use node next

* fix: Tetss

* refactor: reuse function to create mocked client

* fix: update swap note script root

* fix: Generalize Authenticator

* Merge fixes and refactors

* Lints

* docs: update docs from changes to CLI (#336)

* feat: Utilize expected notes from `ExecutedTransaction` (#329)

* feat: Use expected notes from TransactionResult

* fix: Re-add output note check

* Remove unused code

* Lints

* Fix tests

* fix: Tetss

* Stash

* fix: Address reviews

* fix: Tests

* fix: Lints

* fix: Lints

* Try fix test

* fix: Merge conflicts

* Fix tests

* docs: Address reviews

* Lints

* fix: New script root

* Use 0.3

* fix: Correct genesis toml file

* fix: test fix con cargo make start-node

* fix: temp fix to rename config paths

* fix: Correct miden-node toml

* fix: Ship our own node config files

* Migrate to node 0.3

* feat: Use incoming MMR proof to add block authentications for notes created in past blocks (#337)

* test: Integration tests run with main node

* fix: Remove std::cmp::max

* refactor: git-like usage commands (#338)

* Move new account creation to command

* Flatten account command

* Refactor `default` option

* Separate new account commands

* Refactor `notes` command

* Refactor import comand to infer type

* Remove intermediate sucommand for export

* Flatten tags command

* Separate tx new commands

* Fix documentation

* Join p2id and p2idr to send command

* Remove trait

* Change comment suggestions

* Clarify new account help comments

* Ask for storage path if not specified

* Fixed problem with listing notes with no filter

* Added a message for default account updates

* Change suggestions

* Remove prompt for store path

* Added all NotesFilter

* Fix merge

* feat: enable swap notes (#324)

* feature: add swap tx request and store swap payback note

* feature: insert input note record from payback note details

* feature: show message to user on how to track payback notes

* fix: integration test compilation

* make swap tx send the offered asset

* fix: temporary fix for partial output notes

* test: add skeleton for integration test

* fix: lint issues

* test: add test for onchain swap flow

* test: add test for offchain swap flow

* test: fix note minting for swap tests

* test: fix compilation errors

* fix: use all committed note ids to check transactions to commit

* fix: fix tests checks

* address review comments

* docs: update CHANGELOG

* docs: update CLI reference

* address remaining comment

* fix: clippy issues

* fix: remove wrong check

* refactor: store partial notes in relevant notes of transaction result

* rephrase doc comment

Co-authored-by: igamigo <[email protected]>

* address review comments

* fix: fix offchain swap test

---------

Co-authored-by: igamigo <[email protected]>

* docs: fix doc comments for swap clap command

* feat: update cli-reference with new command structure (#342)

* Update cli-reference with new command structure

* Fix merge

* Fix merge

* Update cli-reference.md

---------

Co-authored-by: igamigo <[email protected]>

* Update README.md

* CLI config.md

---------

Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Tomas Rodriguez Dala <[email protected]>
bobbinth pushed a commit that referenced this pull request May 15, 2024
* feat: Integrate next changes

* fix: Back to next

* Fix conflicts

* Use node next

* fix: Tetss

* refactor: reuse function to create mocked client

* fix: update swap note script root

* fix: Generalize Authenticator

* Merge fixes and refactors

* Lints

* docs: update docs from changes to CLI (#336)

* feat: Utilize expected notes from `ExecutedTransaction` (#329)

* feat: Use expected notes from TransactionResult

* fix: Re-add output note check

* Remove unused code

* Lints

* Fix tests

* fix: Tetss

* Stash

* fix: Address reviews

* fix: Tests

* fix: Lints

* fix: Lints

* Try fix test

* fix: Merge conflicts

* Fix tests

* docs: Address reviews

* Lints

* fix: New script root

* Use 0.3

* fix: Correct genesis toml file

* fix: test fix con cargo make start-node

* fix: temp fix to rename config paths

* fix: Correct miden-node toml

* fix: Ship our own node config files

* Migrate to node 0.3

* feat: Use incoming MMR proof to add block authentications for notes created in past blocks (#337)

* test: Integration tests run with main node

* fix: Remove std::cmp::max

* refactor: git-like usage commands (#338)

* Move new account creation to command

* Flatten account command

* Refactor `default` option

* Separate new account commands

* Refactor `notes` command

* Refactor import comand to infer type

* Remove intermediate sucommand for export

* Flatten tags command

* Separate tx new commands

* Fix documentation

* Join p2id and p2idr to send command

* Remove trait

* Change comment suggestions

* Clarify new account help comments

* Ask for storage path if not specified

* Fixed problem with listing notes with no filter

* Added a message for default account updates

* Change suggestions

* Remove prompt for store path

* Added all NotesFilter

* Fix merge

* feat: enable swap notes (#324)

* feature: add swap tx request and store swap payback note

* feature: insert input note record from payback note details

* feature: show message to user on how to track payback notes

* fix: integration test compilation

* make swap tx send the offered asset

* fix: temporary fix for partial output notes

* test: add skeleton for integration test

* fix: lint issues

* test: add test for onchain swap flow

* test: add test for offchain swap flow

* test: fix note minting for swap tests

* test: fix compilation errors

* fix: use all committed note ids to check transactions to commit

* fix: fix tests checks

* address review comments

* docs: update CHANGELOG

* docs: update CLI reference

* address remaining comment

* fix: clippy issues

* fix: remove wrong check

* refactor: store partial notes in relevant notes of transaction result

* rephrase doc comment

Co-authored-by: igamigo <[email protected]>

* address review comments

* fix: fix offchain swap test

---------

Co-authored-by: igamigo <[email protected]>

* docs: fix doc comments for swap clap command

* feat: update cli-reference with new command structure (#342)

* Update cli-reference with new command structure

* Fix merge

* Fix merge

* Update cli-reference.md

---------

Co-authored-by: igamigo <[email protected]>

* Update README.md

* CLI config.md

---------

Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Tomas Rodriguez Dala <[email protected]>
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.

4 participants