Skip to content

Commit

Permalink
Avoid possible truncation of higher bits (#1464)
Browse files Browse the repository at this point in the history
Closes FuelLabs/fuel-core#1261

Awaits reelasing of the FuelLabs/fuel-vm#619.

---------

Co-authored-by: Hannes Karppila <[email protected]>
  • Loading branch information
crypto523 and Dentosal committed Oct 31, 2023
1 parent c65080a commit cd17277
Show file tree
Hide file tree
Showing 64 changed files with 166 additions and 186 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Description of the upcoming release here.
- [#1408](https://github.com/FuelLabs/fuel-core/pull/1408): Update gas benchmarks for storage opcodes to use a pre-populated database to get more accurate worst-case costs.

#### Breaking
- [#1464](https://github.com/FuelLabs/fuel-core/pull/1464): Avoid possible truncation of higher bits. It may invalidate the code that truncated higher bits causing different behavior on 32-bit vs. 64-bit systems. The change affects some endpoints that now require lesser integers.
- [#1432](https://github.com/FuelLabs/fuel-core/pull/1432): All subscriptions and requests have a TTL now. So each subscription lifecycle is limited in time. If the subscription is closed because of TTL, it means that you subscribed after your transaction had been dropped by the network.
- [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The recipient is a `ContractId` instead of `Address`. The block producer should deploy its contract to receive the transaction fee. The collected fee is zero until the recipient contract is set.
- [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The `Mint` transaction is reworked with new fields to support the account-base model. It affects serialization and deserialization of the transaction and also affects GraphQL schema.
Expand Down
5 changes: 0 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion benches/src/bin/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn main() {
let mut reader = readers.next().unwrap();
while let Err(TryRecvError::Empty) = rx.try_recv() {
match reader.read_line(&mut line) {
Ok(amount) if amount == 0 => {
Ok(0) => {
reader = match readers.next() {
Some(r) => r,
None => break,
Expand Down
2 changes: 1 addition & 1 deletion benches/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn provision_import_test(
) {
let shared_notify = Arc::new(Notify::new());
let params = Config {
header_batch_size,
header_batch_size: header_batch_size as usize,
block_stream_buffer_size,
};
let p2p = Arc::new(PressurePeerToPeer::new(
Expand Down
2 changes: 1 addition & 1 deletion bin/fuel-core/src/cli/run/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl From<SyncArgs> for fuel_core::sync::Config {
fn from(value: SyncArgs) -> Self {
Self {
block_stream_buffer_size: value.block_stream_buffer_size,
header_batch_size: value.header_batch_size,
header_batch_size: value.header_batch_size as usize,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/chain-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::cast_possible_truncation)]
#![deny(unused_crate_dependencies)]
#![deny(warnings)]

Expand Down
10 changes: 5 additions & 5 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ type Mutation {
`Trigger::Interval { block_time }`, produces blocks with `block_time ` intervals between
them. The `start_timestamp` is the timestamp in seconds.
"""
produceBlocks(startTimestamp: Tai64Timestamp, blocksToProduce: U64!): U32!
produceBlocks(startTimestamp: Tai64Timestamp, blocksToProduce: U32!): U32!
}

type NodeInfo {
Expand Down Expand Up @@ -657,11 +657,11 @@ type ProgramState {
}

type Query {
register(id: ID!, register: U64!): U64!
memory(id: ID!, start: U64!, size: U64!): String!
register(id: ID!, register: U32!): U64!
memory(id: ID!, start: U32!, size: U32!): String!
balance(owner: Address!, assetId: AssetId!): Balance!
balances(filter: BalanceFilterInput!, first: Int, after: String, last: Int, before: String): BalanceConnection!
block(id: BlockId, height: U64): Block
block(id: BlockId, height: U32): Block
blocks(first: Int, after: String, last: Int, before: String): BlockConnection!
chain: ChainInfo!
transaction(id: TransactionId!): Transaction
Expand Down Expand Up @@ -794,7 +794,7 @@ input SpendQueryElementInput {
"""
The maximum number of currencies for selection.
"""
max: U64
max: U32
}

type SqueezedOutStatus {
Expand Down
19 changes: 8 additions & 11 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use cynic::{
use fuel_core_types::{
fuel_asm::{
Instruction,
RegisterId,
Word,
},
fuel_tx::{
Expand Down Expand Up @@ -83,6 +82,7 @@ use schema::{
SetSingleSteppingArgs,
StartTx,
StartTxArgs,
U32,
U64,
};
#[cfg(feature = "subscriptions")]
Expand Down Expand Up @@ -115,6 +115,8 @@ pub mod pagination;
pub mod schema;
pub mod types;

type RegisterId = u32;

#[derive(Debug, Clone)]
pub struct FuelClient {
client: reqwest::Client,
Expand Down Expand Up @@ -473,12 +475,7 @@ impl FuelClient {
Ok(self.query(query).await?.register.0 as Word)
}

pub async fn memory(
&self,
id: &str,
start: usize,
size: usize,
) -> io::Result<Vec<u8>> {
pub async fn memory(&self, id: &str, start: u32, size: u32) -> io::Result<Vec<u8>> {
let query = schema::Memory::build(MemoryArgs {
id: id.into(),
start: start.into(),
Expand Down Expand Up @@ -689,7 +686,7 @@ impl FuelClient {

pub async fn produce_blocks(
&self,
blocks_to_produce: u64,
blocks_to_produce: u32,
start_timestamp: Option<u64>,
) -> io::Result<BlockHeight> {
let query = schema::block::BlockMutation::build(ProduceBlockArgs {
Expand All @@ -713,9 +710,9 @@ impl FuelClient {
Ok(block)
}

pub async fn block_by_height(&self, height: u64) -> io::Result<Option<types::Block>> {
pub async fn block_by_height(&self, height: u32) -> io::Result<Option<types::Block>> {
let query = schema::block::BlockByHeightQuery::build(BlockByHeightArgs {
height: Some(U64(height)),
height: Some(U32(height)),
});

let block = self.query(query).await?.block.map(Into::into);
Expand Down Expand Up @@ -765,7 +762,7 @@ impl FuelClient {
pub async fn coins_to_spend(
&self,
owner: &Address,
spend_query: Vec<(AssetId, u64, Option<u64>)>,
spend_query: Vec<(AssetId, u64, Option<u32>)>,
// (Utxos, Messages Nonce)
excluded_ids: Option<(Vec<UtxoId>, Vec<Nonce>)>,
) -> io::Result<Vec<Vec<types::CoinType>>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/client/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct PaginationRequest<T> {
/// The cursor returned from a previous query to indicate an offset
pub cursor: Option<T>,
/// The number of results to take
pub results: usize,
pub results: i32,
/// The direction of the query (e.g. asc, desc order).
pub direction: PageDirection,
}
Expand Down
10 changes: 5 additions & 5 deletions crates/client/src/client/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct Execute {
#[derive(cynic::QueryVariables)]
pub struct RegisterArgs {
pub id: cynic::Id,
pub register: U64,
pub register: U32,
}

#[derive(cynic::QueryFragment, Debug)]
Expand All @@ -112,8 +112,8 @@ pub struct Register {
#[derive(cynic::QueryVariables)]
pub struct MemoryArgs {
pub id: cynic::Id,
pub start: U64,
pub size: U64,
pub start: U32,
pub size: U32,
}

#[derive(cynic::QueryFragment, Debug)]
Expand Down Expand Up @@ -263,14 +263,14 @@ impl<T: Into<String>> From<PaginationRequest<T>> for ConnectionArgs {
PageDirection::Forward => Self {
after: req.cursor.map(Into::into),
before: None,
first: Some(req.results as i32),
first: Some(req.results),
last: None,
},
PageDirection::Backward => Self {
after: None,
before: req.cursor.map(Into::into),
first: None,
last: Some(req.results as i32),
last: Some(req.results),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/client/schema/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ impl From<(Address, PaginationRequest<String>)> for BalancesConnectionArgs {
filter: BalanceFilterInput { owner: r.0 },
after: r.1.cursor,
before: None,
first: Some(r.1.results as i32),
first: Some(r.1.results),
last: None,
},
PageDirection::Backward => BalancesConnectionArgs {
filter: BalanceFilterInput { owner: r.0 },
after: None,
before: r.1.cursor,
first: None,
last: Some(r.1.results as i32),
last: Some(r.1.results),
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/client/src/client/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct BlockByIdQuery {

#[derive(cynic::QueryVariables, Debug)]
pub struct BlockByHeightArgs {
pub height: Option<U64>,
pub height: Option<U32>,
}

#[derive(cynic::QueryFragment, Debug)]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct BlockIdFragment {
#[derive(cynic::QueryVariables, Debug)]
pub struct ProduceBlockArgs {
pub start_timestamp: Option<Tai64Timestamp>,
pub blocks_to_produce: U64,
pub blocks_to_produce: U32,
}

#[derive(cynic::QueryFragment, Debug)]
Expand Down Expand Up @@ -176,7 +176,7 @@ mod tests {
fn block_by_height_query_gql_output() {
use cynic::QueryBuilder;
let operation = BlockByHeightQuery::build(BlockByHeightArgs {
height: Some(U64(0)),
height: Some(U32(0)),
});
insta::assert_snapshot!(operation.query)
}
Expand All @@ -185,7 +185,7 @@ mod tests {
fn block_mutation_query_gql_output() {
use cynic::MutationBuilder;
let operation = BlockMutation::build(ProduceBlockArgs {
blocks_to_produce: U64(0),
blocks_to_produce: U32(0),
start_timestamp: None,
});
insta::assert_snapshot!(operation.query)
Expand Down
6 changes: 3 additions & 3 deletions crates/client/src/client/schema/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl From<(Address, AssetId, PaginationRequest<String>)> for CoinsConnectionArgs
},
after: r.2.cursor,
before: None,
first: Some(r.2.results as i32),
first: Some(r.2.results),
last: None,
},
PageDirection::Backward => CoinsConnectionArgs {
Expand All @@ -74,7 +74,7 @@ impl From<(Address, AssetId, PaginationRequest<String>)> for CoinsConnectionArgs
after: None,
before: r.2.cursor,
first: None,
last: Some(r.2.results as i32),
last: Some(r.2.results),
},
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ pub struct SpendQueryElementInput {
/// address of the owner
pub amount: U64,
/// the maximum number of coins per asset from the owner to return.
pub max: Option<U64>,
pub max: Option<U32>,
}

#[derive(cynic::QueryFragment, Debug, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/client/schema/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ impl From<(ContractId, PaginationRequest<String>)> for ContractBalancesConnectio
filter: ContractBalanceFilterInput { contract: r.0 },
after: r.1.cursor,
before: None,
first: Some(r.1.results as i32),
first: Some(r.1.results),
last: None,
},
PageDirection::Backward => ContractBalancesConnectionArgs {
filter: ContractBalanceFilterInput { contract: r.0 },
after: None,
before: r.1.cursor,
first: None,
last: Some(r.1.results as i32),
last: Some(r.1.results),
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/client/schema/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ impl From<(Option<Address>, PaginationRequest<String>)> for OwnedMessagesConnect
owner: r.0,
after: r.1.cursor,
before: None,
first: Some(r.1.results as i32),
first: Some(r.1.results),
last: None,
},
PageDirection::Backward => OwnedMessagesConnectionArgs {
owner: r.0,
after: None,
before: r.1.cursor,
first: None,
last: Some(r.1.results as i32),
last: Some(r.1.results),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/client/src/client/schema/block.rs
expression: operation.query
---
query($height: U64) {
query($height: U32) {
block(height: $height) {
id
header {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source: crates/client/src/client/schema/block.rs
expression: operation.query
---
mutation($startTimestamp: Tai64Timestamp, $blocksToProduce: U64!) {
mutation($startTimestamp: Tai64Timestamp, $blocksToProduce: U32!) {
produceBlocks(blocksToProduce: $blocksToProduce, startTimestamp: $startTimestamp)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ impl From<(Address, PaginationRequest<String>)> for TransactionsByOwnerConnectio
owner: r.0,
after: r.1.cursor,
before: None,
first: Some(r.1.results as i32),
first: Some(r.1.results),
last: None,
},
PageDirection::Backward => TransactionsByOwnerConnectionArgs {
owner: r.0,
after: None,
before: r.1.cursor,
first: None,
last: Some(r.1.results as i32),
last: Some(r.1.results),
},
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::cast_possible_truncation)]
#![deny(unused_crate_dependencies)]
#![deny(warnings)]
pub mod client;
Expand Down
1 change: 1 addition & 0 deletions crates/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! defined here are used by services but are flexible enough to customize the
//! logic when the `Database` is known.

#![deny(clippy::cast_possible_truncation)]
#![deny(missing_docs)]
#![deny(unused_crate_dependencies)]
#![deny(warnings)]
Expand Down
Loading

0 comments on commit cd17277

Please sign in to comment.