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

Extraction of the FuelBlockSecondaryKeyBlockHeights table to an off-chain worker #1671

Merged
merged 14 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Description of the upcoming release here.

### Added

- [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): Added a new `Merklelized` blueprint that maintains the binary Merkle tree over the storage data. It supports only the insertion of the objects without removing them.
xgreenx marked this conversation as resolved.
Show resolved Hide resolved

### Changed

- [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): The logic related to the `FuelBlockSecondaryKeyBlockHeights` is moved to the off-chain worker.
- [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Removed `Receipts` table. Instead, receipts are part of the `TransactionStatuses` table.
- [#1650](https://github.com/FuelLabs/fuel-core/pull/1650): Add api endpoint for getting estimates for future gas prices
- [#1649](https://github.com/FuelLabs/fuel-core/pull/1649): Add api endpoint for getting latest gas price
Expand All @@ -30,6 +35,7 @@ Description of the upcoming release here.
- [#1636](https://github.com/FuelLabs/fuel-core/pull/1636): Add more docs to GraphQL DAP API.

#### Breaking
- [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): The GraphQL API uses block height instead of the block id where it is possible. The transaction status contains `block_height` instead of the `block_id`.
- [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Receipts are part of the transaction status.
Removed `reason` from the `TransactionExecutionResult::Failed`. It can be calculated based on the program state and receipts.
Also, it is not possible to fetch `receipts` from the `Transaction` directly anymore. Instead, you need to fetch `status` and its receipts.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ input BalanceFilterInput {

type Block {
id: BlockId!
height: U32!
header: Header!
consensus: Consensus!
transactions: [Transaction!]!
Expand Down
7 changes: 5 additions & 2 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,12 @@ impl FuelClient {
Ok(block)
}

pub async fn block_by_height(&self, height: u32) -> io::Result<Option<types::Block>> {
pub async fn block_by_height(
Copy link
Member

Choose a reason for hiding this comment

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

The types on latest_gas_price include a u32 to represent block height. Should we use BlockHeight there?

&self,
height: BlockHeight,
) -> io::Result<Option<types::Block>> {
let query = schema::block::BlockByHeightQuery::build(BlockByHeightArgs {
height: Some(U32(height)),
height: Some(U32(height.into())),
});

let block = self.query(query).await?.block.map(Into::into);
Expand Down
6 changes: 6 additions & 0 deletions crates/client/src/client/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ pub struct BlockIdFragment {
pub id: BlockId,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Block")]
pub struct BlockHeightFragment {
pub height: U32,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct ProduceBlockArgs {
pub start_timestamp: Option<Tai64Timestamp>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ query($id: TransactionId!) {
... on SuccessStatus {
transactionId
block {
id
height
}
time
programState {
Expand Down Expand Up @@ -61,7 +61,7 @@ query($id: TransactionId!) {
... on FailureStatus {
transactionId
block {
id
height
}
time
reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
... on SuccessStatus {
transactionId
block {
id
height
}
time
programState {
Expand Down Expand Up @@ -64,7 +64,7 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
... on FailureStatus {
transactionId
block {
id
height
}
time
reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ query($after: String, $before: String, $first: Int, $last: Int) {
... on SuccessStatus {
transactionId
block {
id
height
}
time
programState {
Expand Down Expand Up @@ -64,7 +64,7 @@ query($after: String, $before: String, $first: Int, $last: Int) {
... on FailureStatus {
transactionId
block {
id
height
}
time
reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ query($id: TransactionId!) {
... on SuccessStatus {
transactionId
block {
id
height
}
time
programState {
Expand Down Expand Up @@ -151,7 +151,7 @@ query($id: TransactionId!) {
... on FailureStatus {
transactionId
block {
id
height
}
time
reason
Expand Down
6 changes: 3 additions & 3 deletions crates/client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::block::BlockIdFragment;
use super::block::BlockHeightFragment;
use crate::client::{
schema::{
schema,
Expand Down Expand Up @@ -178,7 +178,7 @@ pub struct SubmittedStatus {
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct SuccessStatus {
pub transaction_id: TransactionId,
pub block: BlockIdFragment,
pub block: BlockHeightFragment,
pub time: Tai64Timestamp,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe this should be named block_height now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is named block since from the GraphQL perspective you receive the block=) The block_height is ID, but it could be BlockId as well(both works)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed - since this could return a full block, we must use a fragment query here to only return a partial view of the object.

pub program_state: Option<ProgramState>,
pub receipts: Vec<Receipt>,
Expand All @@ -188,7 +188,7 @@ pub struct SuccessStatus {
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct FailureStatus {
pub transaction_id: TransactionId,
pub block: BlockIdFragment,
pub block: BlockHeightFragment,
pub time: Tai64Timestamp,
pub reason: String,
pub program_state: Option<ProgramState>,
Expand Down
13 changes: 8 additions & 5 deletions crates/client/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ use fuel_core_types::{
Receipt,
Transaction,
},
fuel_types::canonical::Deserialize,
fuel_types::{
canonical::Deserialize,
BlockHeight,
},
fuel_vm::ProgramState,
};
use tai64::Tai64;
Expand Down Expand Up @@ -92,7 +95,7 @@ pub enum TransactionStatus {
submitted_at: Tai64,
},
Success {
block_id: String,
block_height: BlockHeight,
time: Tai64,
program_state: Option<ProgramState>,
receipts: Vec<Receipt>,
Expand All @@ -101,7 +104,7 @@ pub enum TransactionStatus {
reason: String,
},
Failure {
block_id: String,
block_height: BlockHeight,
time: Tai64,
reason: String,
program_state: Option<ProgramState>,
Expand All @@ -118,7 +121,7 @@ impl TryFrom<SchemaTxStatus> for TransactionStatus {
submitted_at: s.time.0,
},
SchemaTxStatus::SuccessStatus(s) => TransactionStatus::Success {
block_id: s.block.id.0.to_string(),
block_height: s.block.height.0.into(),
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
time: s.time.0,
program_state: s.program_state.map(TryInto::try_into).transpose()?,
receipts: s
Expand All @@ -128,7 +131,7 @@ impl TryFrom<SchemaTxStatus> for TransactionStatus {
.collect::<Result<Vec<_>, _>>()?,
},
SchemaTxStatus::FailureStatus(s) => TransactionStatus::Failure {
block_id: s.block.id.0.to_string(),
block_height: s.block.height.0.into(),
time: s.time.0,
reason: s.reason,
program_state: s.program_state.map(TryInto::try_into).transpose()?,
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ rand = { workspace = true }
rocksdb = { version = "0.21", default-features = false, features = [
"lz4",
"multi-threaded-cf",
"jemalloc",
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
], optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
Expand Down
Loading
Loading