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

chore(sealed_blocks): optimize fetching of sealed block header at a given height #2112

Merged
merged 19 commits into from
Aug 21, 2024

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Aug 20, 2024

Linked Issues/PRs

Description

We don't need to fetch the header and the consensus header from the storage if either one of them is None. If consensus evaluates to None, we can early return a None, but if the consensus header exists, we can then fetch the block header.

Performs another optimization in instances where we fetch the SealedBlock and only end up using the entity wrapped within it, and not the consensus headers. Previously, both the consensus headers and the block were fetched from the db and then returned as a SealedBlock, Now, we just check for existence of a given block height in the SealedBlockConsensus table, and avoid the allocation for the consensus headers.

note: also restricts how many blocks worth of transactions can be requested over p2p

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@rymnc rymnc self-assigned this Aug 20, 2024
@rymnc rymnc force-pushed the chore/optimize-get-sealed-block-header branch from 05cf17d to 93fefa5 Compare August 20, 2024 10:03
@rymnc rymnc requested a review from a team August 20, 2024 14:18
@rymnc rymnc marked this pull request as ready for review August 20, 2024 14:18
@rymnc rymnc force-pushed the chore/optimize-get-sealed-block-header branch from 8db2bd7 to 9f3948d Compare August 20, 2024 14:49
@rymnc
Copy link
Member Author

rymnc commented Aug 20, 2024

added block range restriction in 0a7b23a since the CI runners are struggling with all the open PRs

@rymnc
Copy link
Member Author

rymnc commented Aug 20, 2024

p2p metrics issue: #808

@rymnc rymnc force-pushed the chore/optimize-get-sealed-block-header branch from 0a7b23a to 3749d6c Compare August 20, 2024 16:12
&self,
height: &BlockHeight,
) -> StorageResult<Option<Block>> {
if self
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want to do an additional lookup into SealedBlockConsensus table? We can go directly to the self.get_full_block

Copy link
Member Author

@rymnc rymnc Aug 21, 2024

Choose a reason for hiding this comment

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

addressed in 5498c5f and cleaned up in d090523

CHANGELOG.md Outdated
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- [2106](https://github.com/FuelLabs/fuel-core/pull/2106): Remove deadline clock in POA and replace with tokio time functions.
- [2112](https://github.com/FuelLabs/fuel-core/pull/2112): Alter the way the sealed blocks are fetched with a given height.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to move it to ## [Unreleased] section

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in da650f4

@@ -66,6 +66,10 @@ pub struct P2PArgs {
#[clap(long = "max-headers-per-request", default_value = "100", env)]
pub max_headers_per_request: u32,

/// Max number of blocks in a transaction request response
#[clap(long = "max-blocks-per-tx-request", default_value = "100", env)]
pub max_blocks_per_tx_request: u32,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can reuse max_headers_per_request to reduce number of arguments

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 06262b9

@rymnc rymnc requested review from xgreenx and netrome August 21, 2024 08:55
MitchTurner
MitchTurner previously approved these changes Aug 21, 2024
.try_into()
.expect("u32 should always fit into usize");
if range.len() > max_len {
tracing::error!("Requested range of blocks is too big. Requested length: {:?}, Max length: {:?}", range.len(), max_len);
Copy link
Contributor

Choose a reason for hiding this comment

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

The logs become more searchable if we add the information as fields instead of formatting them into the message:

Suggested change
tracing::error!("Requested range of blocks is too big. Requested length: {:?}, Max length: {:?}", range.len(), max_len);
tracing::error!(requested_length = range.len(), max_len, "Requested range of blocks is too big");

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in ebca20d, with the other usage of this as well

netrome
netrome previously approved these changes Aug 21, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Just a few nits and enhancement suggestions from me, otherwise the PR looks good!

@rymnc rymnc dismissed stale reviews from netrome and MitchTurner via ebca20d August 21, 2024 09:05
MitchTurner
MitchTurner previously approved these changes Aug 21, 2024
@rymnc rymnc requested a review from MitchTurner August 21, 2024 13:28
MitchTurner
MitchTurner previously approved these changes Aug 21, 2024
@@ -437,6 +437,24 @@ where
let response_channel = self.request_sender.clone();
match request_message {
RequestMessage::Transactions(range) => {
let max_len = self
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use u32 instead of usize to avoid try_into

@rymnc rymnc enabled auto-merge (squash) August 21, 2024 13:40
@rymnc rymnc merged commit 5871591 into master Aug 21, 2024
31 checks passed
@rymnc rymnc deleted the chore/optimize-get-sealed-block-header branch August 21, 2024 14:00
xgreenx pushed a commit that referenced this pull request Aug 22, 2024
## Linked Issues/PRs
<!-- List of related issues/PRs -->
- #2112

## Description
<!-- List of detailed changes -->
- Addressing
#2112 (comment)

A follow up PR will be made to address #2121

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [x] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?
rymnc added a commit that referenced this pull request Aug 27, 2024
## Linked Issues/PRs
<!-- List of related issues/PRs -->
- #2112
- #2121

## Description
<!-- List of detailed changes -->
Cleans up the impl for `TaskRequest` by breaking the processing into
digestable but extendable functions

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [x] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?

---------

Co-authored-by: Green Baneling <[email protected]>
@xgreenx xgreenx mentioned this pull request Aug 28, 2024
xgreenx added a commit that referenced this pull request Aug 28, 2024
## Version v0.35.0

### Added
- [2122](#2122): Changed the
relayer URI address to be a vector and use a quorum provider. The
`relayer` argument now supports multiple URLs to fetch information from
different sources.
- [2119](#2119): GraphQL query
fields for retrieving information about upgrades.

### Changed
- [2113](#2113): Modify the
way the gas price service and shared algo is initialized to have some
default value based on best guess instead of `None`, and initialize
service before graphql.
- [2112](#2112): Alter the way
the sealed blocks are fetched with a given height.
- [2120](#2120): Added
`submitAndAwaitStatus` subscription endpoint which returns the
`SubmittedStatus` after the transaction is submitted as well as the
`TransactionStatus` subscription.
- [2115](#2115): Add test for
`SignMode` `is_available` method.
- [2124](#2124): Generalize
the way p2p req/res protocol handles requests.

#### Breaking

- [2040](#2040): Added full
`no_std` support state transition related crates. The crates now require
the "alloc" feature to be enabled. Following crates are affected:
  - `fuel-core-types`
  - `fuel-core-storage`
  - `fuel-core-executor`
- [2116](#2116): Replace
`H160` in config and cli options of relayer by `Bytes20` of `fuel-types`

### Fixed
- [2134](#2134): Perform
RecoveryID normalization for AWS KMS -generated signatures.

## What's Changed
* Change TODO clippy to wait for false positive correction by
@AurelienFT in #2110
* Remove option on shared algo, give default algo, reorder service
startup by @MitchTurner in
#2113
* chore(sealed_blocks): optimize fetching of sealed block header at a
given height by @rymnc in
#2112
* chore(p2p_service): remove unnecessary cast to usize by @rymnc in
#2123
* Added a benchmark for the predicate with ed19 verification by @xgreenx
in #2127
* Add test SignMode is_available by @AurelienFT in
#2115
* feat: Add graphql query fields for retreiving information about
upgrades by @netrome in #2119
* Small code optimizations by @MoneyBund in
#2035
* Change relayer URI address to be vector and use quorum provider by
@AurelienFT in #2122
* chore(p2p_service): clean up processing of p2p req/res protocol by
@rymnc in #2124
* feat: add `submitAndAwaitStatus` subscription endpoint by @maschad in
#2120
* Replace H160 in config and cli options of relayer by Bytes20 by
@AurelienFT in #2116
* Secp256k1 RecoveryID correction for KMS-genrated signatures by
@Dentosal in #2134
* Added `no_std` support state transition related crates by @xgreenx in
#2040

## New Contributors
* @MoneyBund made their first contribution in
#2035
* @maschad made their first contribution in
#2120

**Full Changelog**:
v0.34.0...v0.35.0
rymnc added a commit that referenced this pull request Aug 30, 2024
…2p req/res protocol (#2135)

## Linked Issues/PRs
<!-- List of related issues/PRs -->
- #2023
- #2112

## Description
<!-- List of detailed changes -->
We bubble up the usage of a new function `log_metrics` to clean up how
metrics are being logged in the p2p module. additionally, we also
specify a `Gauge` for how many blocks worth of data has been requested,
so we can re-use those numbers in our simulations to find the most
optimal lookup method.

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [ ] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?
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