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

feat: Support block and header versions gql #1848

Merged
merged 25 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dc4d0d9
Add Version to Block and BlockHeader
bvrooman Apr 19, 2024
5b6c8f6
Add Version to Block and BlockHeader client types
bvrooman Apr 19, 2024
0e5cd02
Update snapshots
bvrooman Apr 19, 2024
1146c18
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
Apr 19, 2024
207fc9c
Update CHANGELOG.md
bvrooman Apr 19, 2024
4314ae8
Merge branch 'bvrooman/feat/support-block-and-header-versions-gql' of…
bvrooman Apr 19, 2024
294501f
Update fuel_core_client__client__schema__chain__tests__chain_gql_quer…
bvrooman Apr 19, 2024
4eed205
Remove unneeded derives
bvrooman Apr 20, 2024
e30e81e
Update client types
bvrooman Apr 22, 2024
ecc588a
Use vanilla `Version` types
bvrooman Apr 22, 2024
7448f47
Remove unreachable version
bvrooman Apr 22, 2024
6ef2776
Update insta tests
bvrooman Apr 22, 2024
9852081
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
Dentosal Apr 22, 2024
db530ae
Update CHANGELOG.md
bvrooman Apr 22, 2024
ea6462d
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
Apr 22, 2024
a21c8c5
Use `enum` for `BlockVersion` and `HeaderVersion`
bvrooman Apr 23, 2024
1e42a62
Update snapshots
bvrooman Apr 23, 2024
146c8d0
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
bvrooman Apr 24, 2024
8bc2710
Fix merge
bvrooman Apr 24, 2024
67c118f
Remove unused `Version` server object
bvrooman Apr 25, 2024
90d3829
Test
bvrooman Apr 28, 2024
574b316
Revert "Test"
bvrooman Apr 28, 2024
8c0cca0
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
Apr 29, 2024
c8b2fff
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
Apr 29, 2024
b1764ba
Merge branch 'master' into bvrooman/feat/support-block-and-header-ver…
bvrooman Apr 30, 2024
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: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Description of the upcoming release here.
### 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

### 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`.
bvrooman marked this conversation as resolved.
Show resolved Hide resolved

## [Version 0.25.1]

Expand Down
9 changes: 9 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ input BalanceFilterInput {
}

type Block {
version: BlockVersion!
id: BlockId!
height: U32!
header: Header!
Expand Down Expand Up @@ -83,6 +84,8 @@ type BlockEdge {

scalar BlockId

union BlockVersion = Version


"""
Breakpoint, defined as a tuple of contract ID and relative PC offset inside it
Expand Down Expand Up @@ -467,6 +470,10 @@ type Genesis {
}

type Header {
"""
Version of the header
"""
version: HeaderVersion!
"""
Hash of the header
"""
Expand Down Expand Up @@ -521,6 +528,8 @@ type Header {
applicationHash: Bytes32!
}

union HeaderVersion = Version

type HeavyOperation {
base: U64!
gasPerUnit: U64!
Expand Down
6 changes: 6 additions & 0 deletions crates/client/src/client/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,9 @@ impl From<TryFromSliceError> for ConversionError {
ConversionError::BytesLength
}
}

#[derive(cynic::QueryFragment, Clone, Debug, Eq, PartialEq)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Version {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this out of chain.rs and into the parent level schema.rs for reuse in other submodules.

pub value: U8,
}
19 changes: 19 additions & 0 deletions crates/client/src/client/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::client::schema::{
PageInfo,
Signature,
Tai64Timestamp,
Version,
U32,
U64,
};
Expand Down Expand Up @@ -75,10 +76,19 @@ pub struct BlockEdge {
pub node: Block,
}

#[derive(cynic::InlineFragments, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum BlockVersion {
V1(Version),
#[cynic(fallback)]
Unknown,
}

/// Block with transactiuon 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,
Expand Down Expand Up @@ -114,9 +124,18 @@ pub struct BlockMutation {
pub produce_blocks: U32,
}

#[derive(cynic::InlineFragments, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum HeaderVersion {
V1(Version),
#[cynic(fallback)]
Unknown,
}

#[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,
Expand Down
8 changes: 1 addition & 7 deletions crates/client/src/client/schema/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ use crate::client::schema::{
Address,
AssetId,
ConversionError,
Version,
U16,
U32,
U64,
U8,
};

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Version {
pub value: U8,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct ConsensusParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ expression: operation.query
---
query($height: U32) {
block(height: $height) {
version {
__typename
... on Version {
value
}
}
id
header {
version {
__typename
... on Version {
value
}
}
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ expression: operation.query
---
query($id: BlockId) {
block(id: $id) {
version {
__typename
... on Version {
value
}
}
id
header {
version {
__typename
... on Version {
value
}
}
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ query($after: String, $before: String, $first: Int, $last: Int) {
edges {
cursor
node {
version {
__typename
... on Version {
value
}
}
id
header {
version {
__typename
... on Version {
value
}
}
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ query {
daHeight
name
latestBlock {
version {
__typename
... on Version {
value
}
}
id
header {
version {
__typename
... on Version {
value
}
}
id
daHeight
consensusParametersVersion
Expand Down
10 changes: 10 additions & 0 deletions crates/fuel-core/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use async_graphql::{
},
MergedObject,
MergedSubscription,
Object,
OutputType,
Schema,
SchemaBuilder,
Expand All @@ -35,6 +36,15 @@ pub mod tx;

pub mod relayed_tx;

pub struct Version(u8);

#[Object]
impl Version {
async fn value(&self) -> scalars::U8 {
self.0.into()
}
}
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 remove this one=)


#[derive(MergedObject, Default)]
pub struct Query(
dap::DapQuery,
Expand Down
24 changes: 24 additions & 0 deletions crates/fuel-core/src/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
U64,
},
tx::types::Transaction,
Version,
},
};
use anyhow::anyhow;
Expand Down Expand Up @@ -86,8 +87,19 @@ pub struct PoAConsensus {
signature: Signature,
}

#[derive(Union)]
pub enum BlockVersion {
V1(Version),
}

#[Object]
impl Block {
async fn version(&self) -> BlockVersion {
match self.0 {
CompressedBlock::V1(_) => BlockVersion::V1(Version(1)),
}
}

async fn id(&self) -> BlockId {
let bytes: fuel_types::Bytes32 = self.0.header().id().into();
bytes.into()
Expand Down Expand Up @@ -131,8 +143,20 @@ impl Block {
}
}

#[derive(Union)]
pub enum HeaderVersion {
V1(Version),
}

#[Object]
impl Header {
/// Version of the header
async fn version(&self) -> HeaderVersion {
match self.0 {
BlockHeader::V1(_) => HeaderVersion::V1(Version(1)),
}
}

/// Hash of the header
async fn id(&self) -> BlockId {
let bytes: fuel_core_types::fuel_types::Bytes32 = self.0.id().into();
Expand Down
11 changes: 1 addition & 10 deletions crates/fuel-core/src/schema/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
U16,
U32,
U64,
U8,
},
Version,
},
};
use async_graphql::{
Expand All @@ -44,8 +44,6 @@ pub struct FeeParameters(fuel_tx::FeeParameters);

pub struct GasCosts(fuel_tx::GasCosts);

pub struct Version(u8);

#[derive(Union)]
pub enum GasCostsVersion {
V1(Version),
Expand Down Expand Up @@ -114,13 +112,6 @@ impl From<fuel_tx::DependentCost> for DependentCost {
}
}

#[Object]
impl Version {
async fn value(&self) -> U8 {
self.0.into()
}
}

#[Object]
impl ConsensusParameters {
async fn version(&self) -> ConsensusParametersVersion {
Expand Down
1 change: 0 additions & 1 deletion crates/types/src/blockchain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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<TransactionRepresentation = Transaction> {
/// V1 Block
V1(BlockV1<TransactionRepresentation>),
Expand Down
3 changes: 1 addition & 2 deletions crates/types/src/blockchain/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
Loading