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

Return the list of committed transactions in state sync endpoint #377

Merged
merged 17 commits into from
Jun 10, 2024

Conversation

polydez
Copy link
Contributor

@polydez polydez commented Jun 6, 2024

Resolves: #371
Related issue: 0xPolygonMiden/miden-base#722

@polydez polydez requested review from igamigo and bobbinth June 6, 2024 04:43
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.

code looks good! I left some minor questions. I'll test this against the client to have another layer of validation

.iter()
.flat_map(|(&account_id, update)| {
update.transactions.iter().flat_map(move |&tx| {
let mut result = vec![Felt::ZERO, Felt::ZERO, Felt::ZERO, account_id.into()];
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to add the account id to the elements to hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please look into this issue for clarifications: 0xPolygonMiden/miden-base#722

Comment on lines +702 to +703
ORDER BY
transaction_id ASC
Copy link
Contributor

Choose a reason for hiding this comment

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

does the order by transaction id add anything? was it supposed to be ordered by block number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to have reproducible results. If for client it's matter to have ordering by block number, I can change it.

Copy link
Collaborator

@igamigo igamigo Jun 7, 2024

Choose a reason for hiding this comment

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

I don't think any ordering would matter for the client, but it makes sense for reproducible results.

Comment on lines 107 to 122
#[test]
fn test_sql_select_transactions() {
fn query_transactions(conn: &mut Connection) -> Vec<RpoDigest> {
sql::select_transactions_by_accounts_and_block_range(conn, 1, 2, &[1]).unwrap()
}

let mut conn = create_db();

let transactions = query_transactions(&mut conn);

assert!(transactions.is_empty(), "No elements must be initially in the DB");

let count = insert_transactions(&mut conn);

assert_eq!(count, 2, "Two elements must have been inserted");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also query after inserting the transactions and make sure it's also 2?

Copy link
Contributor Author

@polydez polydez Jun 7, 2024

Choose a reason for hiding this comment

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

Good catch, thank you! I moved query code to separated function in this matter, but forgot to query for a second time. :(

Cargo.toml Outdated Show resolved Hide resolved
crates/store/src/state.rs Outdated Show resolved Hide resolved
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.

Looks good! Thank you! I left a couple of small comments inline.

Also, I think one thing that is missing is verifying that tx_hash is consistent with transaction info in the block during apply_block (we check that all other data in the block is consistent with the header, would be good to check that transaction data is consistent as well).

Lastly, what do you think of moving transaction IDs into AccountSummary (something along the lines what is suggested in #371 (comment)). I don't think we should do it in this PR, but curious how much work it would be.

crates/proto/proto/responses.proto Outdated Show resolved Hide resolved
crates/block-producer/src/block_builder/prover/mod.rs Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

bobbinth commented Jun 7, 2024

Oh - also, let's resolve merge conflicts and update the changelog.

@polydez polydez force-pushed the polydez-tx-ids-in-sync branch from f5cf27a to c904c9f Compare June 7, 2024 12:04
@polydez
Copy link
Contributor Author

polydez commented Jun 7, 2024

@bobbinth

Lastly, what do you think of moving transaction IDs into AccountSummary (something along the lines what is suggested in #371 (comment)). I don't think we should do it in this PR, but curious how much work it would be.

I looked into the code and it seems to be pretty easy to implement this.

@polydez polydez requested a review from bobbinth June 7, 2024 12:24
Copy link
Collaborator

@igamigo igamigo 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 a couple of comments (also, I wasn't sure if the AccountSummary updates are meant to be included in this PR or a follow-up).

Comment on lines +702 to +703
ORDER BY
transaction_id ASC
Copy link
Collaborator

@igamigo igamigo Jun 7, 2024

Choose a reason for hiding this comment

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

I don't think any ordering would matter for the client, but it makes sense for reproducible results.

crates/block-producer/src/block_builder/prover/mod.rs Outdated Show resolved Hide resolved
crates/store/src/state.rs Outdated Show resolved Hide resolved
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.

One thing I noticed we might still have problems with in the client is that we're still not getting the info of when the transaction was included in a block. This is due to the fact that we return a sync state response with all nullifiers and transaction ids in the range (request.block_header, next_block_header) where block header is the block of the first note matching any of the requests' tags or account ids. So, if many TXs that only consume notes are sent and then we sync after a while, we'll still receive the TXs ids but won't know which got included in which block. A similar thing happens with nullifiers as well.

@bobbinth
Copy link
Contributor

bobbinth commented Jun 7, 2024

One thing I noticed we might still have problems with in the client is that we're still not getting the info of when the transaction was included in a block. This is due to the fact that we return a sync state response with all nullifiers and transaction ids in the range (request.block_header, next_block_header) where block header is the block of the first note matching any of the requests' tags or account ids. So, if many TXs that only consume notes are sent and then we sync after a while, we'll still receive the TXs ids but won't know which got included in which block. A similar thing happens with nullifiers as well.

Ah - good point! We could return (TransactionId, block_num) and (Nullifier, block_num) tuples. But that's separate from this PR. Could you create a new issue for this?

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.

Looks good! Thank you!

Before merging this, let's do the changes I mentioned here (will require a PR in miden-base).

In a follow-up PR we can update the structure of returned data (i.e., move transaction IDs into account summaries, return block numbers for nullifiers and transaction IDs).

@mFragaBA
Copy link
Contributor

mFragaBA commented Jun 7, 2024

also, I think after 0xPolygonMiden/miden-base#732 got merged in base it's breaking compilation, idk if we should fix it here or should I open a new PR (I still need these changes to compile the node)

@bobbinth
Copy link
Contributor

bobbinth commented Jun 8, 2024

also, I think after 0xPolygonMiden/miden-base#732 got merged in base it's breaking compilation, idk if we should fix it here or should I open a new PR (I still need these changes to compile the node)

Ah, yes! @polydez could you update this PR to make sure it works with latest next from miden-base? For example, the format_input_notes() function could look something like this:

pub fn format_input_notes(notes: &InputNotes<InputNoteCommitment>) -> String {
    format_array(notes.iter().map(|c| match c.note_id() {
        Some(note_id) => format!("({}, {})", c.nullifier().to_hex(), note_id.to_hex()),
        None => format!("({})", c.nullifier().to_hex()),
    }))
}

After this, we'll merge this PR and can address my comments from #377 (comment) in a separate PR.

@mFragaBA
Copy link
Contributor

mFragaBA commented Jun 10, 2024

One thing I noticed we might still have problems with in the client is that we're still not getting the info of when the transaction was included in a block. This is due to the fact that we return a sync state response with all nullifiers and transaction ids in the range (request.block_header, next_block_header) where block header is the block of the first note matching any of the requests' tags or account ids. So, if many TXs that only consume notes are sent and then we sync after a while, we'll still receive the TXs ids but won't know which got included in which block. A similar thing happens with nullifiers as well.

Ah - good point! We could return (TransactionId, block_num) and (Nullifier, block_num) tuples. But that's separate from this PR. Could you create a new issue for this?

created #380. I'm open to taking it

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.

Looks good! Thank you! I've pushed a couple of small commits to point this back at next in miden-base and also did some minor refactoring.

@bobbinth bobbinth merged commit 6e0689c into next Jun 10, 2024
6 checks passed
@bobbinth bobbinth deleted the polydez-tx-ids-in-sync branch June 10, 2024 23:05
@bobbinth
Copy link
Contributor

created #380. I'm open to taking it

Thank you! I'll assign it to you.

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