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

Change complexity block API #2276

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2204](https://github.com/FuelLabs/fuel-core/pull/2204): Added `dnsaddr` resolution for TLD without suffixes.

### Changed
- [2276](https://github.com/FuelLabs/fuel-core/pull/2276): Change complexity block query to allow fetching of 10 blocks

#### Breaking
- [2199](https://github.com/FuelLabs/fuel-core/pull/2199): Applying several breaking changes to the WASM interface from backlog:
Expand Down
14 changes: 14 additions & 0 deletions crates/fuel-core/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ pub struct Costs {
pub status_change: usize,
pub raw_payload: usize,
pub storage_read: usize,
pub tx_get: usize,
pub tx_status_read: usize,
pub tx_raw_payload: usize,
pub block_header: usize,
pub block_transactions: usize,
pub block_transactions_ids: usize,
pub storage_iterator: usize,
pub bytecode_read: usize,
pub state_transition_bytecode_read: usize,
}

pub const QUERY_COSTS: Costs = Costs {
Expand All @@ -57,8 +64,15 @@ pub const QUERY_COSTS: Costs = Costs {
status_change: 10001,
raw_payload: 10,
storage_read: 10,
tx_get: 50,
tx_status_read: 50,
tx_raw_payload: 150,
block_header: 150,
block_transactions: 1500,
block_transactions_ids: 50,
storage_iterator: 100,
bytecode_read: 2000,
state_transition_bytecode_read: 19_000,
};

#[derive(Clone, Debug)]
Expand Down
21 changes: 10 additions & 11 deletions crates/fuel-core/src/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl Block {
Ok(query.consensus(height)?.try_into()?)
}

#[graphql(complexity = "QUERY_COSTS.block_transactions_ids")]
async fn transaction_ids(&self) -> Vec<TransactionId> {
self.0
.transactions()
Expand All @@ -134,8 +135,7 @@ impl Block {
}

// Assume that in average we have 32 transactions per block.
#[graphql(complexity = "QUERY_COSTS.storage_iterator\
+ (QUERY_COSTS.storage_read + child_complexity) * 32")]
#[graphql(complexity = "QUERY_COSTS.block_transactions + child_complexity")]
async fn transactions(
&self,
ctx: &Context<'_>,
Expand Down Expand Up @@ -246,7 +246,7 @@ pub struct BlockQuery;

#[Object]
impl BlockQuery {
#[graphql(complexity = "2 * QUERY_COSTS.storage_read + child_complexity")]
#[graphql(complexity = "QUERY_COSTS.block_header + child_complexity")]
async fn block(
&self,
ctx: &Context<'_>,
Expand Down Expand Up @@ -276,9 +276,8 @@ impl BlockQuery {
}

#[graphql(complexity = "{\
QUERY_COSTS.storage_iterator\
+ (QUERY_COSTS.storage_read + first.unwrap_or_default() as usize) * child_complexity \
+ (QUERY_COSTS.storage_read + last.unwrap_or_default() as usize) * child_complexity\
(QUERY_COSTS.block_header + child_complexity) \
* (first.unwrap_or_default() as usize + last.unwrap_or_default() as usize) \
}")]
async fn blocks(
&self,
Expand All @@ -305,7 +304,7 @@ pub struct HeaderQuery;

#[Object]
impl HeaderQuery {
#[graphql(complexity = "QUERY_COSTS.storage_read + child_complexity")]
#[graphql(complexity = "QUERY_COSTS.block_header + child_complexity")]
async fn header(
&self,
ctx: &Context<'_>,
Expand All @@ -319,9 +318,8 @@ impl HeaderQuery {
}

#[graphql(complexity = "{\
QUERY_COSTS.storage_iterator\
+ (QUERY_COSTS.storage_read + first.unwrap_or_default() as usize) * child_complexity \
+ (QUERY_COSTS.storage_read + last.unwrap_or_default() as usize) * child_complexity\
(QUERY_COSTS.block_header + child_complexity) \
* (first.unwrap_or_default() as usize + last.unwrap_or_default() as usize) \
}")]
async fn headers(
&self,
Expand Down Expand Up @@ -374,13 +372,14 @@ impl BlockMutation {
start_timestamp: Option<Tai64Timestamp>,
blocks_to_produce: U32,
) -> async_graphql::Result<U32> {
let consensus_module = ctx.data_unchecked::<ConsensusModule>();
let config = ctx.data_unchecked::<GraphQLConfig>().clone();

if !config.debug {
return Err(anyhow!("`debug` must be enabled to use this endpoint").into())
}

let consensus_module = ctx.data_unchecked::<ConsensusModule>();

let start_time = start_timestamp.map(|timestamp| timestamp.0);
let blocks_to_produce: u32 = blocks_to_produce.into();
consensus_module
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/schema/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct LatestGasPriceQuery {}

#[Object]
impl LatestGasPriceQuery {
#[graphql(complexity = "2 * QUERY_COSTS.storage_read")]
#[graphql(complexity = "QUERY_COSTS.block_header")]
async fn latest_gas_price(
&self,
ctx: &Context<'_>,
Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ impl TxQuery {
}
}

// We assume that each block has 100 transactions.
#[graphql(complexity = "{\
QUERY_COSTS.storage_iterator\
+ (QUERY_COSTS.storage_read + first.unwrap_or_default() as usize) * child_complexity \
+ (QUERY_COSTS.storage_read + last.unwrap_or_default() as usize) * child_complexity\
(QUERY_COSTS.tx_get + child_complexity) \
* (first.unwrap_or_default() as usize + last.unwrap_or_default() as usize)
}")]
async fn transactions(
&self,
Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/schema/tx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl SuccessStatus {
self.block_height.into()
}

#[graphql(complexity = "QUERY_COSTS.storage_read + child_complexity")]
#[graphql(complexity = "QUERY_COSTS.block_header + child_complexity")]
async fn block(&self, ctx: &Context<'_>) -> async_graphql::Result<Block> {
let query = ctx.read_view()?;
let block = query.block(&self.block_height)?;
Expand Down Expand Up @@ -238,7 +238,7 @@ impl FailureStatus {
self.block_height.into()
}

#[graphql(complexity = "QUERY_COSTS.storage_read + child_complexity")]
#[graphql(complexity = "QUERY_COSTS.block_header + child_complexity")]
async fn block(&self, ctx: &Context<'_>) -> async_graphql::Result<Block> {
let query = ctx.read_view()?;
let block = query.block(&self.block_height)?;
Expand Down Expand Up @@ -693,7 +693,7 @@ impl Transaction {
}
}

#[graphql(complexity = "QUERY_COSTS.storage_read + child_complexity")]
#[graphql(complexity = "QUERY_COSTS.tx_status_read + child_complexity")]
async fn status(
&self,
ctx: &Context<'_>,
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/src/schema/upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl StateTransitionBytecode {
HexString(self.root.to_vec())
}

#[graphql(complexity = "QUERY_COSTS.state_transition_bytecode_read")]
async fn bytecode(
&self,
ctx: &Context<'_>,
Expand Down
Loading
Loading