Skip to content

Call To*InboundLaneApi::message_details() with batched messages#1545

Merged
svyatonik merged 6 commits into
paritytech:masterfrom
serban300:refactoring
Aug 10, 2022
Merged

Call To*InboundLaneApi::message_details() with batched messages#1545
svyatonik merged 6 commits into
paritytech:masterfrom
serban300:refactoring

Conversation

@serban300
Copy link
Copy Markdown
Collaborator

Closes #1538

- avoid using a HashMap for `messages_to_refine`. It seems that a vec is
  enough
- minimize the number of conversions between `OutboundMessageDetails` and
  `MessageDetails`
- use references where possible in order to minimize the number of
  intermediary Vecs
- simplify `make_message_details_map()` logic, reduce its scope and rename
  it to `validate_out_msgs_details()`

Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
Copy link
Copy Markdown
Contributor

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

Just couple of questions, then it is good to merge

out_msg_details.dispatch_weight = in_msg_details.dispatch_weight;
}

current_msgs_batch = next_msgs_batch;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I may be missing something, but aren't you dropping remaining current_msgs_batch values here? I mean if e.g. current_msgs_batch has 5 entries initially and let's say only first entry is below P::TargetChain::max_extrinsic_size() limit, then you're pushing 2rd entry to the next_msgs_batch and then just drop remaining 3 entries here? Sorry - I may be missing something here, just checking :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually imo would be cool if we could have a function that can be easily tested (i.e. without RPC calls). The function shall just split single vector (msgs_to_refine) to a vector of vectors. t is optional, but WDYT?

Copy link
Copy Markdown
Collaborator Author

@serban300 serban300 Aug 9, 2022

Choose a reason for hiding this comment

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

I may be missing something, but aren't you dropping remaining current_msgs_batch values here? I mean if e.g. current_msgs_batch has 5 entries initially and let's say only first entry is below P::TargetChain::max_extrinsic_size() limit, then you're pushing 2rd entry to the next_msgs_batch and then just drop remaining 3 entries here? Sorry - I may be missing something here, just checking :)

In this case all the 4 entries that don't fit in P::TargetChain::max_extrinsic_size() should be moved to next_msgs_batch in the while above:

			while (self.lane_id, &current_msgs_batch).encoded_size() >
				P::TargetChain::max_extrinsic_size() as usize
			{
                             ...
			}

I hope I didn't miss anything there.

Actually imo would be cool if we could have a function that can be easily tested (i.e. without RPC calls). The function shall just split single vector (msgs_to_refine) to a vector of vectors. t is optional, but WDYT?

Yes, that's a very good idea. I'll try to move this logic to a separate function.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

weights.last().map(|details| details.nonce != *nonces.end()).unwrap_or(true);
if last_nonce_is_missing {
// Check if last nonce is missing. The loop above is not checking this.
if !nonces.is_empty() && nonces_iter.peek() == Some(nonces.end()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please verify me here: nonces_iter is noces.rev(), so we're moving from end to begin and here we are comparing with the end() here. Is that intended?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, if nonces_iter.peek() == Some(nonces.end()) at this point, it means that the last nonce was not found in the messages list (and that the messages list is empty actually), and we need to return an error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, can we then check "that the messages list is empty"? :) Imo it should be simpler :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think it should work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Also added another check for the case where there are more messages than nonces.

Copy link
Copy Markdown
Contributor

@svyatonik svyatonik left a comment

Choose a reason for hiding this comment

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

Thank you!

@svyatonik svyatonik merged commit 544a3ba into paritytech:master Aug 10, 2022
svyatonik pushed a commit that referenced this pull request Jul 17, 2023
Bumps [clap](https://github.com/clap-rs/clap) from 3.2.16 to 3.2.17.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/v3.2.17/CHANGELOG.md)
- [Commits](clap-rs/clap@v3.2.16...v3.2.17)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
serban300 added a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
…tytech#1545)

* generated_message_details() -> Simplifications

- avoid using a HashMap for `messages_to_refine`. It seems that a vec is
  enough
- minimize the number of conversions between `OutboundMessageDetails` and
  `MessageDetails`
- use references where possible in order to minimize the number of
  intermediary Vecs
- simplify `make_message_details_map()` logic, reduce its scope and rename
  it to `validate_out_msgs_details()`

Signed-off-by: Serban Iorga <serban@parity.io>

* Define typed_state_call()

Signed-off-by: Serban Iorga <serban@parity.io>

* Call To*InboundLaneApi::message_details() with single messages

Signed-off-by: Serban Iorga <serban@parity.io>

* Call To*InboundLaneApi::message_details() with batched messages

Signed-off-by: Serban Iorga <serban@parity.io>

* validate_out_msgs_details() -> change check

* Define split_msgs_to_refine()

Signed-off-by: Serban Iorga <serban@parity.io>

Signed-off-by: Serban Iorga <serban@parity.io>
serban300 added a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
…tytech#1545)

* generated_message_details() -> Simplifications

- avoid using a HashMap for `messages_to_refine`. It seems that a vec is
  enough
- minimize the number of conversions between `OutboundMessageDetails` and
  `MessageDetails`
- use references where possible in order to minimize the number of
  intermediary Vecs
- simplify `make_message_details_map()` logic, reduce its scope and rename
  it to `validate_out_msgs_details()`

Signed-off-by: Serban Iorga <serban@parity.io>

* Define typed_state_call()

Signed-off-by: Serban Iorga <serban@parity.io>

* Call To*InboundLaneApi::message_details() with single messages

Signed-off-by: Serban Iorga <serban@parity.io>

* Call To*InboundLaneApi::message_details() with batched messages

Signed-off-by: Serban Iorga <serban@parity.io>

* validate_out_msgs_details() -> change check

* Define split_msgs_to_refine()

Signed-off-by: Serban Iorga <serban@parity.io>

Signed-off-by: Serban Iorga <serban@parity.io>
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.

Change To*InboundLaneApi::message_details to accept single messages

2 participants