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 19 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 @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### 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`.

### Fixed

- [#1856](https://github.com/FuelLabs/fuel-core/pull/1856): Replaced instances of `Union` with `Enum` for GraphQL definitions of `ConsensusParametersVersion` and related types. This is needed because `Union` does not support multiple `Version`s inside discriminants or empty variants.
Expand All @@ -20,7 +24,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

### Changed

Expand Down
13 changes: 13 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,10 @@ type BlockEdge {

scalar BlockId

enum BlockVersion {
V1
}


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

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

enum HeaderVersion {
V1
}

type HeavyOperation {
base: U64!
gasPerUnit: U64!
Expand Down
23 changes: 19 additions & 4 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -771,7 +781,7 @@ impl FuelClient {
) -> io::Result<PaginatedResult<types::Block, String>> {
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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 15 additions & 1 deletion crates/client/src/client/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,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,
Expand Down Expand Up @@ -114,9 +121,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ expression: operation.query
---
query($height: U32) {
block(height: $height) {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ expression: operation.query
---
query($id: BlockId) {
block(id: $id) {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ query($after: String, $before: String, $first: Int, $last: Int) {
edges {
cursor
node {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ query {
daHeight
name
latestBlock {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
98 changes: 60 additions & 38 deletions crates/client/src/client/types/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::client::{
schema,
schema::ConversionError,
types::primitives::{
BlockId,
Hash,
Expand All @@ -10,6 +11,11 @@ use crate::client::{
},
PaginatedResult,
};

use crate::client::schema::block::{
BlockVersion,
HeaderVersion,
};
use tai64::Tai64;

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -67,24 +73,28 @@ pub struct PoAConsensus {

// GraphQL Translation

impl From<schema::block::Header> 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<schema::block::Header> for Header {
type Error = ConversionError;

fn try_from(value: schema::block::Header) -> Result<Self, Self::Error> {
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(),
}),
}
}
}
Expand Down Expand Up @@ -124,32 +134,44 @@ impl From<schema::block::PoAConsensus> for PoAConsensus {
}
}

impl From<schema::block::Block> for Block {
fn from(value: schema::block::Block) -> Self {
let transactions = value
.transactions
.iter()
.map(|tx| tx.id.clone())
.map(Into::into)
.collect::<Vec<TransactionId>>();
let block_producer = value.block_producer();
Self {
id: value.id.into(),
header: value.header.into(),
consensus: value.consensus.into(),
transactions,
block_producer,
impl TryFrom<schema::block::Block> for Block {
type Error = ConversionError;

fn try_from(value: schema::block::Block) -> Result<Self, Self::Error> {
match value.version {
BlockVersion::V1 => {
let transactions = value
.transactions
.iter()
.map(|tx| tx.id.clone())
.map(Into::into)
.collect::<Vec<TransactionId>>();
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<schema::block::BlockConnection> for PaginatedResult<Block, String> {
fn from(conn: schema::block::BlockConnection) -> Self {
PaginatedResult {
impl TryFrom<schema::block::BlockConnection> for PaginatedResult<Block, String> {
type Error = ConversionError;

fn try_from(conn: schema::block::BlockConnection) -> Result<Self, Self::Error> {
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::<Result<_, _>>()?,
})
}
}
2 changes: 1 addition & 1 deletion crates/client/src/client/types/chain_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl TryFrom<schema::chain::ChainInfo> 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()?,
})
}
Expand Down
15 changes: 9 additions & 6 deletions crates/client/src/client/types/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::client::{
schema,
schema::ConversionError,
types::{
block::Header,
primitives::{
Expand Down Expand Up @@ -89,18 +90,20 @@ impl From<schema::message::MessageConnection> for PaginatedResult<Message, Strin
}
}

impl From<schema::message::MessageProof> for MessageProof {
fn from(value: schema::message::MessageProof) -> Self {
Self {
impl TryFrom<schema::message::MessageProof> for MessageProof {
type Error = ConversionError;

fn try_from(value: schema::message::MessageProof) -> Result<Self, Self::Error> {
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(),
}
})
}
}
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
Loading
Loading