Skip to content

feat(starknet_integration_tests): struct to collect streamed txs #4785

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

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

yair-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

yair-starkware commented Mar 10, 2025

Copy link

graphite-app bot commented Mar 10, 2025

Graphite Automations

"Yair - Auto-assign" took an action on this PR • (03/10/25)

1 assignee was added to this PR based on Yair's automation.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)


crates/starknet_integration_tests/src/utils.rs line 592 at r1 (raw file):

/// Stores tx hashes aggregated by height and round.
#[derive(Debug, Default)]
pub struct AggregatedTransactions(Vec<(BlockNumber, (Round, Vec<TransactionHash>))>);

Create a named struct for this, instead of using .0/.1.

Suggestion:

RoundTransactions

crates/starknet_integration_tests/src/utils.rs line 606 at r1 (raw file):

    }

    pub fn get_latest_block_with_txs(&self) -> Option<BlockNumber> {

What is this for?


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

/// Assumes that rounds are monotonically increasing and that the last round is the chosen one.
#[derive(Debug, Default)]
pub struct AggregatedTransactions(Vec<(BlockNumber, (Round, Vec<TransactionHash>))>);

Do you even need to keep the whole history of blocks and rounds? Why not just store all txs together and track only the current block and round?


crates/starknet_integration_tests/src/utils.rs line 611 at r2 (raw file):

    }

    pub fn get_all_txs_so_far(&self) -> Vec<TransactionHash> {

Looks like here your collecting all the txs from all rounds and not just the last one like you said.


crates/starknet_integration_tests/src/utils.rs line 627 at r2 (raw file):

    }

    fn prepare_entry(&mut self, height: BlockNumber, round: Round) -> &mut Vec<TransactionHash> {

If you store it as a map instead of a vec with the keys being (block, round) you can just get the entry or create a new one. You're already checking these conditions in the validate function.

Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @ArniStarkware and @yair-starkware)


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

/// Assumes that rounds are monotonically increasing and that the last round is the chosen one.
#[derive(Debug, Default)]
pub struct AggregatedTransactions(Vec<(BlockNumber, (Round, Vec<TransactionHash>))>);

why not use a HashMap and store only the most recent round for each block_number.

Code quote:

pub struct AggregatedTransactions(Vec<(BlockNumber, (Round, Vec<TransactionHash>))>);

crates/starknet_integration_tests/src/utils.rs line 624 at r2 (raw file):

        if *last_height == height && *last_round > round {
            panic!("Expected round to be greater or equal to the last round.");
        }

isn't it possible to receive old messages from a previous round?

Code quote:

        if *last_height > height {
            panic!("Expected height to be greater or equal to the last height with transactions.");
        }
        if *last_height == height && *last_round > round {
            panic!("Expected round to be greater or equal to the last round.");
        }

@yair-starkware yair-starkware changed the base branch from yair/copy_listen_to_broadcasted_messages to graphite-base/4785 March 16, 2025 09:41
@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 9770028 to 57a04f7 Compare March 16, 2025 11:57
@yair-starkware yair-starkware changed the base branch from graphite-base/4785 to yair/copy_listen_to_broadcasted_messages March 16, 2025 11:57
@yair-starkware yair-starkware requested a review from alonh5 March 16, 2025 11:58
Copy link
Contributor Author

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 7 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_integration_tests/src/utils.rs line 592 at r1 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Create a named struct for this, instead of using .0/.1.

Done.

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 57a04f7 to 046c35f Compare March 16, 2025 12:37
Copy link
Contributor Author

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 2 files reviewed, 6 unresolved discussions (waiting on @alonh5, @ArniStarkware, and @Yael-Starkware)


crates/starknet_integration_tests/src/utils.rs line 592 at r1 (raw file):

Previously, yair-starkware (Yair) wrote…

Done.

Changed to keep only the last round


crates/starknet_integration_tests/src/utils.rs line 606 at r1 (raw file):

initially I thought about waiting on blocks instead of time

Removing for now


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

why not use a HashMap and store only the most recent round for each block_number.

Changed, but using vec to keep sorted


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Do you even need to keep the whole history of blocks and rounds? Why not just store all txs together and track only the current block and round?

I guess I could do that, but initially I thought about waiting on blocks instead of time.
I think we might still want this so I prefer to keep the functionality.


crates/starknet_integration_tests/src/utils.rs line 611 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Looks like here your collecting all the txs from all rounds and not just the last one like you said.

Fixed by saving only the last round


crates/starknet_integration_tests/src/utils.rs line 624 at r2 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

isn't it possible to receive old messages from a previous round?

It wasn't possible in the previous implementation


crates/starknet_integration_tests/src/utils.rs line 627 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

If you store it as a map instead of a vec with the keys being (block, round) you can just get the entry or create a new one. You're already checking these conditions in the validate function.

Done

@yair-starkware
Copy link
Contributor Author

crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, yair-starkware (Yair) wrote…

Changed, but using vec to keep sorted

IndexMap

@yair-starkware yair-starkware force-pushed the yair/copy_listen_to_broadcasted_messages branch from 60ea870 to c1a5a6b Compare March 16, 2025 12:58
@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 046c35f to cdcd6c1 Compare March 16, 2025 12:58
Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r3, 1 of 1 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArniStarkware, @Yael-Starkware, and @yair-starkware)


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, yair-starkware (Yair) wrote…

I guess I could do that, but initially I thought about waiting on blocks instead of time.
I think we might still want this so I prefer to keep the functionality.

If you want to wait on blocks you still only need the current block, no?

It will simplify the other functions as well, please consider


crates/starknet_integration_tests/src/utils.rs line 611 at r2 (raw file):

Previously, yair-starkware (Yair) wrote…

Fixed by saving only the last round

Where? I still see add_transactions is called on every round in the next PR, and you're not removing old ones here.
You can maintain staged txs and clean it in the beginning of every round, only if the next txs are from the next block you then add them to the committed txs.

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from cdcd6c1 to 87bfed8 Compare March 16, 2025 13:38
Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 1 of 2 files reviewed, 4 unresolved discussions (waiting on @alonh5, @ArniStarkware, and @yair-starkware)


crates/starknet_integration_tests/src/utils.rs line 624 at r2 (raw file):

Previously, yair-starkware (Yair) wrote…

It wasn't possible in the previous implementation

got it. do we want to verify this?


crates/starknet_integration_tests/src/utils.rs line 615 at r6 (raw file):

        let entry = self.0.entry(height).or_insert(RoundTransactions { round, tx_hashes: vec![] });
        entry.tx_hashes.extend_from_slice(tx_hashes);
        entry.round = round;

Suggestion:

        let entry = self.0.entry(height).or_default();
        entry.tx_hashes.extend_from_slice(tx_hashes);
        entry.round = round;

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 87bfed8 to 650829b Compare March 18, 2025 08:46
Copy link
Contributor Author

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 4 unresolved discussions (waiting on @alonh5, @ArniStarkware, and @Yael-Starkware)


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

If you want to wait on blocks you still only need the current block, no?

It will simplify the other functions as well, please consider

Done.


crates/starknet_integration_tests/src/utils.rs line 611 at r2 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Where? I still see add_transactions is called on every round in the next PR, and you're not removing old ones here.
You can maintain staged txs and clean it in the beginning of every round, only if the next txs are from the next block you then add them to the committed txs.

Not relevant now (it was fixed by using index map with height as key)


crates/starknet_integration_tests/src/utils.rs line 624 at r2 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

got it. do we want to verify this?

Checked


crates/starknet_integration_tests/src/utils.rs line 615 at r6 (raw file):

        let entry = self.0.entry(height).or_insert(RoundTransactions { round, tx_hashes: vec![] });
        entry.tx_hashes.extend_from_slice(tx_hashes);
        entry.round = round;

Not relevant now

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 650829b to d41f1e7 Compare March 18, 2025 09:09
Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @alonh5 and @ArniStarkware)


crates/starknet_integration_tests/src/utils.rs line 600 at r7 (raw file):

    // To remove from tx_hashes when a new round replaces the last round.
    last_round_tx_hashes: Vec<TransactionHash>,
}

consider changing the names.
you are adding transactions to the "last_round_tx_hashes" during the current round, so I think it is more clear to look at it as the current round.

Suggestion:

pub struct AggregatedTransactions {
    pub latest_block_number: BlockNumber,
    pub round: u32,
    pub accumulated_tx_hashes: Vec<TransactionHash>,
    // To remove from tx_hashes when a new round replaces the current round.
    current_round_tx_hashes: Vec<TransactionHash>,
}

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from d41f1e7 to faf5927 Compare March 18, 2025 11:40
Copy link
Contributor Author

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @alonh5, @ArniStarkware, and @Yael-Starkware)


crates/starknet_integration_tests/src/utils.rs line 600 at r7 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

consider changing the names.
you are adding transactions to the "last_round_tx_hashes" during the current round, so I think it is more clear to look at it as the current round.

Done.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7, 1 of 1 files at r8, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @Yael-Starkware)


crates/starknet_integration_tests/src/utils.rs line 593 at r2 (raw file):

Previously, yair-starkware (Yair) wrote…

Done.

Nice, thanks


crates/starknet_integration_tests/src/utils.rs line 611 at r7 (raw file):

        self.validate_coherent_height_and_round(height, round);
        if self.latest_block_number == height && self.round < round {
            self.tx_hashes.retain(|tx_hash| !self.last_round_tx_hashes.contains(tx_hash));

Can you store the current round tx and only add them to self.tx_hashes if you advance to the next height?
The way it is now, if the last round is sent but not accepted the test could still pass.
Also it will make this code more explicit and readable, there should be explicit logic for these cases:

  1. Same round - accumulate round txs
  2. Same height new round - discard last round and restart accumulation
  3. New height - add round txs to tx hashes

Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @yair-starkware)


crates/starknet_integration_tests/src/utils.rs line 600 at r7 (raw file):

Previously, yair-starkware (Yair) wrote…

Done.

I also suggested to rename the tx_hashes to accumulated_tx_hashes. non blocking.

@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from faf5927 to 03d0914 Compare March 18, 2025 14:02
@yair-starkware yair-starkware requested a review from alonh5 March 18, 2025 14:02
Copy link
Contributor Author

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @alonh5 and @ArniStarkware)


crates/starknet_integration_tests/src/utils.rs line 600 at r7 (raw file):

Previously, Yael-Starkware (YaelD) wrote…

I also suggested to rename the tx_hashes to accumulated_tx_hashes. non blocking.

Done


crates/starknet_integration_tests/src/utils.rs line 611 at r7 (raw file):

Previously, alonh5 (Alon Haramati) wrote…

Can you store the current round tx and only add them to self.tx_hashes if you advance to the next height?
The way it is now, if the last round is sent but not accepted the test could still pass.
Also it will make this code more explicit and readable, there should be explicit logic for these cases:

  1. Same round - accumulate round txs
  2. Same height new round - discard last round and restart accumulation
  3. New height - add round txs to tx hashes

Done.

Copy link
Collaborator

@alonh5 alonh5 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Nice!

Reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@yair-starkware yair-starkware changed the base branch from yair/copy_listen_to_broadcasted_messages to main March 19, 2025 08:54
@yair-starkware yair-starkware force-pushed the yair/aggregatet_txs_struct branch from 03d0914 to 9dc29ce Compare March 19, 2025 09:28
Copy link
Contributor

@Yael-Starkware Yael-Starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r10, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArniStarkware)

@yair-starkware yair-starkware added this pull request to the merge queue Mar 19, 2025
Merged via the queue into main with commit a0415f3 Mar 19, 2025
9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants