Skip to content

Commit

Permalink
Merge branch 'master' into 2466-bug-cargo-test-fails-on-newer-toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
netrome authored Nov 29, 2024
2 parents 349f75c + ffb7644 commit f0f3671
Show file tree
Hide file tree
Showing 34 changed files with 1,484 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

#### Breaking
- [2389](https://github.com/FuelLabs/fuel-core/pull/2258): Updated the `messageProof` GraphQL schema to return a non-nullable `MessageProof`.
- [2383](https://github.com/FuelLabs/fuel-core/pull/2383): Asset balance queries now return U128 instead of U64.
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Transaction graphql endpoints use `TransactionType` instead of `fuel_tx::Transaction`.
- [2446](https://github.com/FuelLabs/fuel-core/pull/2446): Use graphiql instead of graphql-playground due to known vulnerability and stale development.
- [2379](https://github.com/FuelLabs/fuel-core/issues/2379): Change `kv_store::Value` to be `Arc<[u8]>` instead of `Arc<Vec<u8>>`.
Expand Down
2 changes: 1 addition & 1 deletion bin/e2e-test-client/src/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Wallet {
}

/// returns the balance associated with a wallet
pub async fn balance(&self, asset_id: Option<AssetId>) -> anyhow::Result<u64> {
pub async fn balance(&self, asset_id: Option<AssetId>) -> anyhow::Result<u128> {
self.client
.balance(&self.address, Some(&asset_id.unwrap_or_default()))
.await
Expand Down
4 changes: 3 additions & 1 deletion crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ scalar AssetId

type Balance {
owner: Address!
amount: U64!
amount: U128!
assetId: AssetId!
}

Expand Down Expand Up @@ -1259,6 +1259,8 @@ enum TxParametersVersion {

scalar TxPointer

scalar U128

scalar U16

scalar U32
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ impl FuelClient {
&self,
owner: &Address,
asset_id: Option<&AssetId>,
) -> io::Result<u64> {
) -> io::Result<u128> {
let owner: schema::Address = (*owner).into();
let asset_id: schema::AssetId = match asset_id {
Some(asset_id) => (*asset_id).into(),
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 @@ -4,7 +4,7 @@ use crate::client::{
Address,
AssetId,
PageInfo,
U64,
U128,
},
PageDirection,
PaginationRequest,
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct BalanceEdge {
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Balance {
pub owner: Address,
pub amount: U64,
pub amount: U128,
pub asset_id: AssetId,
}

Expand Down
1 change: 1 addition & 0 deletions crates/client/src/client/schema/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ macro_rules! number_scalar {
};
}

number_scalar!(U128, u128);
number_scalar!(U64, u64);
number_scalar!(U32, u32);
number_scalar!(U16, u16);
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/client/types/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::client::{
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Balance {
pub owner: Address,
pub amount: u64,
pub amount: u128,
pub asset_id: AssetId,
}

Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/src/coins_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ mod tests {
let on_chain = self.database.on_chain().clone();
let off_chain = self.database.off_chain().clone();
ServiceDatabase::new(100, 0u32.into(), on_chain, off_chain)
.expect("should create service database")
}
}

Expand Down
196 changes: 184 additions & 12 deletions crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use fuel_core_types::{
};
use itertools::Itertools;
use std::{
borrow::Cow,
fmt::Debug,
sync::Arc,
};
Expand All @@ -66,7 +67,10 @@ pub use fuel_core_database::Error;
pub type Result<T> = core::result::Result<T, Error>;

// TODO: Extract `Database` and all belongs into `fuel-core-database`.
use crate::database::database_description::gas_price::GasPriceDatabase;
use crate::database::database_description::{
gas_price::GasPriceDatabase,
indexation_availability,
};
#[cfg(feature = "rocksdb")]
use crate::state::{
historical_rocksdb::{
Expand Down Expand Up @@ -482,15 +486,13 @@ where
ConflictPolicy::Overwrite,
changes,
);
let maybe_current_metadata = transaction
.storage_as_mut::<MetadataTable<Description>>()
.get(&())?;
let metadata = update_metadata::<Description>(maybe_current_metadata, new_height);
transaction
.storage_as_mut::<MetadataTable<Description>>()
.insert(
&(),
&DatabaseMetadata::V1 {
version: Description::version(),
height: new_height,
},
)?;
.insert(&(), &metadata)?;

transaction.into_changes()
} else {
Expand All @@ -509,6 +511,39 @@ where
Ok(())
}

fn update_metadata<Description>(
maybe_current_metadata: Option<
Cow<DatabaseMetadata<<Description as DatabaseDescription>::Height>>,
>,
new_height: <Description as DatabaseDescription>::Height,
) -> DatabaseMetadata<<Description as DatabaseDescription>::Height>
where
Description: DatabaseDescription,
{
let updated_metadata = match maybe_current_metadata.as_ref() {
Some(metadata) => match metadata.as_ref() {
DatabaseMetadata::V1 { .. } => DatabaseMetadata::V1 {
version: Description::version(),
height: new_height,
},
DatabaseMetadata::V2 {
indexation_availability,
..
} => DatabaseMetadata::V2 {
version: Description::version(),
height: new_height,
indexation_availability: indexation_availability.clone(),
},
},
None => DatabaseMetadata::V2 {
version: Description::version(),
height: new_height,
indexation_availability: indexation_availability::<Description>(None),
},
};
updated_metadata
}

#[cfg(feature = "rocksdb")]
pub fn convert_to_rocksdb_direction(direction: IterDirection) -> rocksdb::Direction {
match direction {
Expand All @@ -524,10 +559,6 @@ mod tests {
database_description::DatabaseDescription,
Database,
};
use fuel_core_storage::{
tables::FuelBlocks,
StorageAsMut,
};

fn column_keys_not_exceed_count<Description>()
where
Expand Down Expand Up @@ -1084,4 +1115,145 @@ mod tests {
// rocks db fails
test(db);
}

mod metadata {
use crate::database::database_description::IndexationKind;
use fuel_core_storage::kv_store::StorageColumn;
use std::{
borrow::Cow,
collections::HashSet,
};
use strum::EnumCount;

use super::{
database_description::DatabaseDescription,
update_metadata,
DatabaseHeight,
DatabaseMetadata,
};

#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
struct HeightMock(u64);
impl DatabaseHeight for HeightMock {
fn as_u64(&self) -> u64 {
1
}

fn advance_height(&self) -> Option<Self> {
None
}

fn rollback_height(&self) -> Option<Self> {
None
}
}

const MOCK_VERSION: u32 = 0;

#[derive(EnumCount, enum_iterator::Sequence, Debug, Clone, Copy)]
enum ColumnMock {
Column1,
}

impl StorageColumn for ColumnMock {
fn name(&self) -> String {
"column".to_string()
}

fn id(&self) -> u32 {
42
}
}

#[derive(Debug, Clone, Copy)]
struct DatabaseDescriptionMock;
impl DatabaseDescription for DatabaseDescriptionMock {
type Column = ColumnMock;

type Height = HeightMock;

fn version() -> u32 {
MOCK_VERSION
}

fn name() -> String {
"mock".to_string()
}

fn metadata_column() -> Self::Column {
Self::Column::Column1
}

fn prefix(_: &Self::Column) -> Option<usize> {
None
}
}

#[test]
fn update_metadata_preserves_v1() {
let current_metadata: DatabaseMetadata<HeightMock> = DatabaseMetadata::V1 {
version: MOCK_VERSION,
height: HeightMock(1),
};
let new_metadata = update_metadata::<DatabaseDescriptionMock>(
Some(Cow::Borrowed(&current_metadata)),
HeightMock(2),
);

match new_metadata {
DatabaseMetadata::V1 { version, height } => {
assert_eq!(version, current_metadata.version());
assert_eq!(height, HeightMock(2));
}
DatabaseMetadata::V2 { .. } => panic!("should be V1"),
}
}

#[test]
fn update_metadata_preserves_v2() {
let available_indexation = HashSet::new();

let current_metadata: DatabaseMetadata<HeightMock> = DatabaseMetadata::V2 {
version: MOCK_VERSION,
height: HeightMock(1),
indexation_availability: available_indexation.clone(),
};
let new_metadata = update_metadata::<DatabaseDescriptionMock>(
Some(Cow::Borrowed(&current_metadata)),
HeightMock(2),
);

match new_metadata {
DatabaseMetadata::V1 { .. } => panic!("should be V2"),
DatabaseMetadata::V2 {
version,
height,
indexation_availability,
} => {
assert_eq!(version, current_metadata.version());
assert_eq!(height, HeightMock(2));
assert_eq!(indexation_availability, available_indexation);
}
}
}

#[test]
fn update_metadata_none_becomes_v2() {
let new_metadata =
update_metadata::<DatabaseDescriptionMock>(None, HeightMock(2));

match new_metadata {
DatabaseMetadata::V1 { .. } => panic!("should be V2"),
DatabaseMetadata::V2 {
version,
height,
indexation_availability,
} => {
assert_eq!(version, MOCK_VERSION);
assert_eq!(height, HeightMock(2));
assert_eq!(indexation_availability, IndexationKind::all().collect());
}
}
}
}
}
Loading

0 comments on commit f0f3671

Please sign in to comment.