diff --git a/CHANGELOG.md b/CHANGELOG.md index 235df7a571..5d944fc94e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [#1876](https://github.com/FuelLabs/fuel-core/pull/1876): Updated benchmark to include the worst scenario for `CROO` opcode. Also include consensus parameters in bench output. +### Added + +- [#1848](https://github.com/FuelLabs/fuel-core/pull/1848): Added `version` field to the `Block` and `BlockHeader` GraphQL entities. Added corresponding `version` field to the `Block` and `BlockHeader` client types in `fuel-core-client`. + ## [Version 0.26.0] ### Fixed @@ -39,7 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - [#1844](https://github.com/FuelLabs/fuel-core/pull/1844): Fixed the publishing of the `fuel-core 0.25.1` release. -- [1842](https://github.com/FuelLabs/fuel-core/pull/1842): Ignore RUSTSEC-2024-0336: `rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network +- [#1842](https://github.com/FuelLabs/fuel-core/pull/1842): Ignore RUSTSEC-2024-0336: `rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network ## [Version 0.25.1] diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 04ec35c394..46283dca4f 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -45,6 +45,7 @@ input BalanceFilterInput { } type Block { + version: BlockVersion! id: BlockId! height: U32! header: Header! @@ -83,6 +84,10 @@ type BlockEdge { scalar BlockId +enum BlockVersion { + V1 +} + """ Breakpoint, defined as a tuple of contract ID and relative PC offset inside it @@ -475,6 +480,10 @@ type Genesis { } type Header { + """ + Version of the header + """ + version: HeaderVersion! """ Hash of the header """ @@ -529,6 +538,10 @@ type Header { applicationHash: Bytes32! } +enum HeaderVersion { + V1 +} + type HeavyOperation { base: U64! gasPerUnit: U64! diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 2ff901afce..954a8a992b 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -746,7 +746,12 @@ impl FuelClient { id: Some((*id).into()), }); - let block = self.query(query).await?.block.map(Into::into); + let block = self + .query(query) + .await? + .block + .map(TryInto::try_into) + .transpose()?; Ok(block) } @@ -759,7 +764,12 @@ impl FuelClient { height: Some(U32(height.into())), }); - let block = self.query(query).await?.block.map(Into::into); + let block = self + .query(query) + .await? + .block + .map(TryInto::try_into) + .transpose()?; Ok(block) } @@ -771,7 +781,7 @@ impl FuelClient { ) -> io::Result> { let query = schema::block::BlocksQuery::build(request.into()); - let blocks = self.query(query).await?.blocks.into(); + let blocks = self.query(query).await?.blocks.try_into()?; Ok(blocks) } @@ -967,7 +977,12 @@ impl FuelClient { commit_block_height, }); - let proof = self.query(query).await?.message_proof.map(Into::into); + let proof = self + .query(query) + .await? + .message_proof + .map(TryInto::try_into) + .transpose()?; Ok(proof) } diff --git a/crates/client/src/client/schema/block.rs b/crates/client/src/client/schema/block.rs index 4be2d54e08..f00392321d 100644 --- a/crates/client/src/client/schema/block.rs +++ b/crates/client/src/client/schema/block.rs @@ -76,10 +76,17 @@ pub struct BlockEdge { pub node: Block, } -/// Block with transactiuon ids +#[derive(cynic::Enum, Clone, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub enum BlockVersion { + V1, +} + +/// Block with transaction ids #[derive(cynic::QueryFragment, Clone, Debug)] #[cynic(schema_path = "./assets/schema.sdl")] pub struct Block { + pub version: BlockVersion, pub id: BlockId, pub header: Header, pub consensus: Consensus, @@ -115,9 +122,16 @@ pub struct BlockMutation { pub produce_blocks: U32, } +#[derive(cynic::Enum, Clone, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub enum HeaderVersion { + V1, +} + #[derive(cynic::QueryFragment, Clone, Debug)] #[cynic(schema_path = "./assets/schema.sdl")] pub struct Header { + pub version: HeaderVersion, pub id: BlockId, pub da_height: U64, pub consensus_parameters_version: U32, diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_height_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_height_query_gql_output.snap index e707ee4521..6cd3efe8c2 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_height_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_height_query_gql_output.snap @@ -4,8 +4,10 @@ expression: operation.query --- query($height: U32) { block(height: $height) { + version id header { + version id daHeight consensusParametersVersion diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_id_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_id_query_gql_output.snap index 38f86c4356..fc24235694 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_id_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__block_by_id_query_gql_output.snap @@ -4,8 +4,10 @@ expression: operation.query --- query($id: BlockId) { block(id: $id) { + version id header { + version id daHeight consensusParametersVersion diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__blocks_connection_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__blocks_connection_query_gql_output.snap index 42b672009f..f46f2ac29a 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__blocks_connection_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__block__tests__blocks_connection_query_gql_output.snap @@ -7,8 +7,10 @@ query($after: String, $before: String, $first: Int, $last: Int) { edges { cursor node { + version id header { + version id daHeight consensusParametersVersion diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap index d722675a9d..d0c6f77b7d 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap @@ -7,8 +7,10 @@ query { daHeight name latestBlock { + version id header { + version id daHeight consensusParametersVersion diff --git a/crates/client/src/client/types/block.rs b/crates/client/src/client/types/block.rs index 66ee5e2370..a953f3ffaa 100644 --- a/crates/client/src/client/types/block.rs +++ b/crates/client/src/client/types/block.rs @@ -1,5 +1,6 @@ use crate::client::{ schema, + schema::ConversionError, types::primitives::{ BlockId, Hash, @@ -10,6 +11,11 @@ use crate::client::{ }, PaginatedResult, }; + +use crate::client::schema::block::{ + BlockVersion, + HeaderVersion, +}; use tai64::Tai64; #[derive(Clone, Debug, PartialEq, Eq)] @@ -67,24 +73,28 @@ pub struct PoAConsensus { // GraphQL Translation -impl From for Header { - fn from(value: schema::block::Header) -> Self { - Self { - id: value.id.into(), - da_height: value.da_height.into(), - consensus_parameters_version: value.consensus_parameters_version.into(), - state_transition_bytecode_version: value - .state_transition_bytecode_version - .into(), - transactions_count: value.transactions_count.into(), - message_receipt_count: value.message_receipt_count.into(), - transactions_root: value.transactions_root.into(), - message_outbox_root: value.message_outbox_root.into(), - event_inbox_root: value.event_inbox_root.into(), - height: value.height.into(), - prev_root: value.prev_root.into(), - time: value.time.0, - application_hash: value.application_hash.into(), +impl TryFrom for Header { + type Error = ConversionError; + + fn try_from(value: schema::block::Header) -> Result { + match value.version { + HeaderVersion::V1 => Ok(Self { + id: value.id.into(), + da_height: value.da_height.into(), + consensus_parameters_version: value.consensus_parameters_version.into(), + state_transition_bytecode_version: value + .state_transition_bytecode_version + .into(), + transactions_count: value.transactions_count.into(), + message_receipt_count: value.message_receipt_count.into(), + transactions_root: value.transactions_root.into(), + message_outbox_root: value.message_outbox_root.into(), + event_inbox_root: value.event_inbox_root.into(), + height: value.height.into(), + prev_root: value.prev_root.into(), + time: value.time.0, + application_hash: value.application_hash.into(), + }), } } } @@ -124,32 +134,44 @@ impl From for PoAConsensus { } } -impl From for Block { - fn from(value: schema::block::Block) -> Self { - let transactions = value - .transactions - .iter() - .map(|tx| tx.id.clone()) - .map(Into::into) - .collect::>(); - let block_producer = value.block_producer(); - Self { - id: value.id.into(), - header: value.header.into(), - consensus: value.consensus.into(), - transactions, - block_producer, +impl TryFrom for Block { + type Error = ConversionError; + + fn try_from(value: schema::block::Block) -> Result { + match value.version { + BlockVersion::V1 => { + let transactions = value + .transactions + .iter() + .map(|tx| tx.id.clone()) + .map(Into::into) + .collect::>(); + let block_producer = value.block_producer(); + Ok(Self { + id: value.id.into(), + header: value.header.try_into()?, + consensus: value.consensus.into(), + transactions, + block_producer, + }) + } } } } -impl From for PaginatedResult { - fn from(conn: schema::block::BlockConnection) -> Self { - PaginatedResult { +impl TryFrom for PaginatedResult { + type Error = ConversionError; + + fn try_from(conn: schema::block::BlockConnection) -> Result { + Ok(PaginatedResult { cursor: conn.page_info.end_cursor, has_next_page: conn.page_info.has_next_page, has_previous_page: conn.page_info.has_previous_page, - results: conn.edges.into_iter().map(|e| e.node.into()).collect(), - } + results: conn + .edges + .into_iter() + .map(|e| e.node.try_into()) + .collect::>()?, + }) } } diff --git a/crates/client/src/client/types/chain_info.rs b/crates/client/src/client/types/chain_info.rs index 76b1d1ecf4..c4f7debbfd 100644 --- a/crates/client/src/client/types/chain_info.rs +++ b/crates/client/src/client/types/chain_info.rs @@ -25,7 +25,7 @@ impl TryFrom for ChainInfo { Ok(Self { da_height: value.da_height.into(), name: value.name, - latest_block: value.latest_block.into(), + latest_block: value.latest_block.try_into()?, consensus_parameters: value.consensus_parameters.try_into()?, }) } diff --git a/crates/client/src/client/types/message.rs b/crates/client/src/client/types/message.rs index 97ddfb33be..d5332dbaf7 100644 --- a/crates/client/src/client/types/message.rs +++ b/crates/client/src/client/types/message.rs @@ -1,5 +1,6 @@ use crate::client::{ schema, + schema::ConversionError, types::{ block::Header, primitives::{ @@ -89,18 +90,20 @@ impl From for PaginatedResult for MessageProof { - fn from(value: schema::message::MessageProof) -> Self { - Self { +impl TryFrom for MessageProof { + type Error = ConversionError; + + fn try_from(value: schema::message::MessageProof) -> Result { + Ok(Self { message_proof: value.message_proof.into(), block_proof: value.block_proof.into(), - message_block_header: value.message_block_header.into(), - commit_block_header: value.commit_block_header.into(), + message_block_header: value.message_block_header.try_into()?, + commit_block_header: value.commit_block_header.try_into()?, sender: value.sender.into(), recipient: value.recipient.into(), nonce: value.nonce.into(), amount: value.amount.into(), data: value.data.into(), - } + }) } } diff --git a/crates/fuel-core/src/schema/block.rs b/crates/fuel-core/src/schema/block.rs index a455b1c363..8e50e6a7ec 100644 --- a/crates/fuel-core/src/schema/block.rs +++ b/crates/fuel-core/src/schema/block.rs @@ -33,6 +33,7 @@ use async_graphql::{ EmptyFields, }, Context, + Enum, Object, SimpleObject, Union, @@ -87,8 +88,19 @@ pub struct PoAConsensus { signature: Signature, } +#[derive(Clone, Copy, Debug, Enum, Eq, PartialEq)] +pub enum BlockVersion { + V1, +} + #[Object] impl Block { + async fn version(&self) -> BlockVersion { + match self.0 { + CompressedBlock::V1(_) => BlockVersion::V1, + } + } + async fn id(&self) -> BlockId { let bytes: fuel_types::Bytes32 = self.0.header().id().into(); bytes.into() @@ -125,8 +137,20 @@ impl Block { } } +#[derive(Clone, Copy, Debug, Enum, Eq, PartialEq)] +pub enum HeaderVersion { + V1, +} + #[Object] impl Header { + /// Version of the header + async fn version(&self) -> HeaderVersion { + match self.0 { + BlockHeader::V1(_) => HeaderVersion::V1, + } + } + /// Hash of the header async fn id(&self) -> BlockId { let bytes: fuel_core_types::fuel_types::Bytes32 = self.0.id().into(); diff --git a/crates/types/src/blockchain/block.rs b/crates/types/src/blockchain/block.rs index 54d8fb4e74..b104eaa85f 100644 --- a/crates/types/src/blockchain/block.rs +++ b/crates/types/src/blockchain/block.rs @@ -33,7 +33,6 @@ use crate::{ /// Version-able block type #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[non_exhaustive] pub enum Block { /// V1 Block V1(BlockV1), diff --git a/crates/types/src/blockchain/header.rs b/crates/types/src/blockchain/header.rs index b0245d8b7e..8ac4373329 100644 --- a/crates/types/src/blockchain/header.rs +++ b/crates/types/src/blockchain/header.rs @@ -25,7 +25,6 @@ use tai64::Tai64; #[derive(Clone, Debug, derivative::Derivative)] #[derivative(PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[non_exhaustive] pub enum BlockHeader { /// V1 BlockHeader V1(BlockHeaderV1), @@ -149,7 +148,7 @@ impl BlockHeader { #[derive(Copy, Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(any(test, feature = "test-helpers"), derive(Default))] -/// A partially complete fuel block header that doesn't not +/// A partially complete fuel block header that does not /// have any generated fields because it has not been executed yet. pub struct PartialBlockHeader { /// The application header.