Skip to content

Commit

Permalink
Upgraded fuel-vm to 0.55.0 (#2012)
Browse files Browse the repository at this point in the history
Bumped the `fuel-vm` to `0.55.0` release. More about the change
[here](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.55.0).

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog

### Before requesting review
- [x] I have reviewed the code myself
  • Loading branch information
xgreenx authored Jul 5, 2024
1 parent eb9c44b commit 916b9cb
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 93 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#1980](https://github.com/FuelLabs/fuel-core/pull/1980): Add `Transaction` to relayer 's event filter

#### Breaking
- [#2012](https://github.com/FuelLabs/fuel-core/pull/2012): Bumped the `fuel-vm` to `0.55.0` release. More about the change [here](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.55.0).
- [#2001](https://github.com/FuelLabs/fuel-core/pull/2001): Prevent GraphQL query body to be huge and cause OOM. The default body size is `1MB`. The limit can be changed by the `graphql-request-body-bytes-limit` CLI argument.
- [#1991](https://github.com/FuelLabs/fuel-core/pull/1991): Prepare the database to use different types than `Database` for atomic view.
- [#1989](https://github.com/FuelLabs/fuel-core/pull/1989): Extract `HistoricalView` trait from the `AtomicView`.
Expand Down
32 changes: 16 additions & 16 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fuel-core-xtask = { version = "0.0.0", path = "./xtask" }
fuel-gas-price-algorithm = { version = "0.30.0", path = "crates/fuel-gas-price-algorithm" }

# Fuel dependencies
fuel-vm-private = { version = "0.54.1", package = "fuel-vm", default-features = false }
fuel-vm-private = { version = "0.55.0", package = "fuel-vm", default-features = false }

# Common dependencies
anyhow = "1.0"
Expand Down
Binary file not shown.
20 changes: 10 additions & 10 deletions crates/fuel-core/src/database/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
StructuredStorage<Storage>: StorageInspect<M, Error = StorageError>,
for<'a> StorageTransaction<&'a Storage>: StorageMutate<M, Error = StorageError>,
{
fn insert(
fn replace(
&mut self,
key: &M::Key,
value: &M::Value,
Expand All @@ -33,18 +33,18 @@ where
ConflictPolicy::Overwrite,
Default::default(),
);
let prev = transaction.storage_as_mut::<M>().insert(key, value)?;
let prev = transaction.storage_as_mut::<M>().replace(key, value)?;
self.commit_changes(transaction.into_changes())?;
Ok(prev)
}

fn remove(&mut self, key: &M::Key) -> Result<Option<M::OwnedValue>, Self::Error> {
fn take(&mut self, key: &M::Key) -> Result<Option<M::OwnedValue>, Self::Error> {
let mut transaction = StorageTransaction::transaction(
self.as_ref(),
ConflictPolicy::Overwrite,
Default::default(),
);
let prev = transaction.storage_as_mut::<M>().remove(key)?;
let prev = transaction.storage_as_mut::<M>().take(key)?;
self.commit_changes(transaction.into_changes())?;
Ok(prev)
}
Expand All @@ -57,18 +57,18 @@ where
for<'a> StorageTransaction<&'a Storage>: StorageWrite<M, Error = StorageError>,
Self: Modifiable,
{
fn write(&mut self, key: &M::Key, buf: &[u8]) -> Result<usize, Self::Error> {
fn write_bytes(&mut self, key: &M::Key, buf: &[u8]) -> Result<usize, Self::Error> {
let mut transaction = StorageTransaction::transaction(
self.as_ref(),
ConflictPolicy::Overwrite,
Default::default(),
);
let prev = <_ as StorageWrite<M>>::write(&mut transaction, key, buf)?;
let prev = <_ as StorageWrite<M>>::write_bytes(&mut transaction, key, buf)?;
self.commit_changes(transaction.into_changes())?;
Ok(prev)
}

fn replace(
fn replace_bytes(
&mut self,
key: &M::Key,
buf: &[u8],
Expand All @@ -78,18 +78,18 @@ where
ConflictPolicy::Overwrite,
Default::default(),
);
let prev = <_ as StorageWrite<M>>::replace(&mut transaction, key, buf)?;
let prev = <_ as StorageWrite<M>>::replace_bytes(&mut transaction, key, buf)?;
self.commit_changes(transaction.into_changes())?;
Ok(prev)
}

fn take(&mut self, key: &M::Key) -> Result<Option<Vec<u8>>, Self::Error> {
fn take_bytes(&mut self, key: &M::Key) -> Result<Option<Vec<u8>>, Self::Error> {
let mut transaction = StorageTransaction::transaction(
self.as_ref(),
ConflictPolicy::Overwrite,
Default::default(),
);
let prev = <_ as StorageWrite<M>>::take(&mut transaction, key)?;
let prev = <_ as StorageWrite<M>>::take_bytes(&mut transaction, key)?;
self.commit_changes(transaction.into_changes())?;
Ok(prev)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/graphql_api/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub mod worker {
block_height: BlockHeight,
tx_idx: u16,
tx_id: &Bytes32,
) -> StorageResult<Option<Bytes32>>;
) -> StorageResult<()>;

fn update_tx_status(
&mut self,
Expand Down
4 changes: 2 additions & 2 deletions crates/fuel-core/src/graphql_api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
block_height: BlockHeight,
tx_idx: u16,
tx_id: &Bytes32,
) -> StorageResult<Option<Bytes32>> {
) -> StorageResult<()> {
self.storage::<OwnedTransactions>().insert(
&OwnedTransactionIndexKey::new(owner, block_height, tx_idx),
tx_id,
Expand All @@ -141,7 +141,7 @@ where
id: &Bytes32,
status: TransactionStatus,
) -> StorageResult<Option<TransactionStatus>> {
self.storage::<TransactionStatuses>().insert(id, &status)
self.storage::<TransactionStatuses>().replace(id, &status)
}

fn increase_tx_count(&mut self, new_txs_count: u64) -> StorageResult<u64> {
Expand Down
8 changes: 4 additions & 4 deletions crates/fuel-core/src/service/genesis/importer/on_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn init_coin(

if transaction
.storage::<Coins>()
.insert(&utxo_id, &compressed_coin)?
.replace(&utxo_id, &compressed_coin)?
.is_some()
{
return Err(anyhow!("Coin should not exist"));
Expand All @@ -244,7 +244,7 @@ fn init_contract_latest_utxo(

if transaction
.storage::<ContractsLatestUtxo>()
.insert(&contract_id, &entry.value)?
.replace(&contract_id, &entry.value)?
.is_some()
{
return Err(anyhow!("Contract utxo should not exist"));
Expand All @@ -263,7 +263,7 @@ fn init_contract_raw_code(
// insert contract code
if transaction
.storage::<ContractsRawCode>()
.insert(&contract_id, contract)?
.replace(&contract_id, contract)?
.is_some()
{
return Err(anyhow!("Contract code should not exist"));
Expand All @@ -287,7 +287,7 @@ fn init_da_message(

if transaction
.storage::<Messages>()
.insert(message.id(), &message)?
.replace(message.id(), &message)?
.is_some()
{
return Err(anyhow!("Message should not exist"));
Expand Down
6 changes: 3 additions & 3 deletions crates/fuel-core/src/state/historical_rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ where

let old_changes = storage_transaction
.storage_as_mut::<ModificationsHistory<Description>>()
.insert(&height_u64, &reverse_changes)?;
.replace(&height_u64, &reverse_changes)?;

if let Some(old_changes) = old_changes {
tracing::warn!(
Expand Down Expand Up @@ -269,7 +269,7 @@ where

let last_changes = storage_transaction
.storage_as_mut::<ModificationsHistory<Description>>()
.remove(&latest_height)?
.take(&latest_height)?
.ok_or(not_found!(ModificationsHistory<Description>))?;

remove_historical_modifications(
Expand Down Expand Up @@ -312,7 +312,7 @@ where

let old_changes = storage_transaction
.storage_as_mut::<ModificationsHistory<Description>>()
.remove(&old_height)?;
.take(&old_height)?;

if let Some(old_changes) = old_changes {
remove_historical_modifications(
Expand Down
8 changes: 4 additions & 4 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ where

if storage_tx
.storage::<ProcessedTransactions>()
.insert(&coinbase_id, &())?
.replace(&coinbase_id, &())?
.is_some()
{
return Err(ExecutorError::TransactionIdCollision(coinbase_id))
Expand Down Expand Up @@ -1637,7 +1637,7 @@ where
// prune utxo from db
let coin = db
.storage::<Coins>()
.remove(utxo_id)
.take(utxo_id)
.map_err(Into::into)
.transpose()
.unwrap_or_else(|| {
Expand Down Expand Up @@ -1666,7 +1666,7 @@ where
// and cleanup message contents
let message = db
.storage::<Messages>()
.remove(nonce)?
.take(nonce)?
.ok_or(ExecutorError::MessageDoesNotExist(*nonce))?;
execution_data
.events
Expand Down Expand Up @@ -1981,7 +1981,7 @@ where
}
.into();

if db.storage::<Coins>().insert(&utxo_id, &coin)?.is_some() {
if db.storage::<Coins>().replace(&utxo_id, &coin)?.is_some() {
return Err(ExecutorError::OutputAlreadyExists)
}
execution_data
Expand Down
6 changes: 3 additions & 3 deletions crates/services/importer/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ where
let height = block.entity.header().height();
let mut found = storage
.storage_as_mut::<FuelBlocks>()
.insert(height, &block.entity.compress(chain_id))?
.replace(height, &block.entity.compress(chain_id))?
.is_some();
found |= storage
.storage_as_mut::<SealedBlockConsensus>()
.insert(height, &block.consensus)?
.replace(height, &block.consensus)?
.is_some();

// TODO: Use `batch_insert` from https://github.com/FuelLabs/fuel-core/pull/1576
for tx in block.entity.transactions() {
found |= storage
.storage_as_mut::<Transactions>()
.insert(&tx.id(chain_id), tx)?
.replace(&tx.id(chain_id), tx)?
.is_some();
}
storage.commit()?;
Expand Down
15 changes: 7 additions & 8 deletions crates/storage/src/blueprint/merklized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ where
let key_encoder = KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes();
let encoded_value = ValueCodec::encode_as_value(value);
let prev = storage
.replace(key_bytes.as_ref(), column, encoded_value)?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
.transpose()?;
let prev =
KeyValueMutate::replace(storage, key_bytes.as_ref(), column, encoded_value)?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
.transpose()?;

if prev.is_some() {
Self::remove(storage, key_bytes.as_ref(), column)?;
Expand All @@ -198,8 +198,7 @@ where
let key_encoder = KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes();
Self::remove(storage, key_bytes.as_ref(), column)?;
let prev = storage
.take(key_bytes.as_ref(), column)?
let prev = KeyValueMutate::take(storage, key_bytes.as_ref(), column)?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
Expand Down
17 changes: 8 additions & 9 deletions crates/storage/src/blueprint/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ where
let key_encoder = KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes();
let value = ValueCodec::encode_as_value(value);
let prev = storage
.replace(key_bytes.as_ref(), column, value.clone())?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
.transpose()?;
let prev =
KeyValueMutate::replace(storage, key_bytes.as_ref(), column, value.clone())?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
.transpose()?;

Self::insert_into_tree(storage, key, key_bytes.as_ref(), value.as_ref())?;
Ok(prev)
Expand All @@ -230,8 +230,7 @@ where
) -> StorageResult<Option<M::OwnedValue>> {
let key_encoder = KeyCodec::encode(key);
let key_bytes = key_encoder.as_bytes();
let prev = storage
.take(key_bytes.as_ref(), column)?
let prev = KeyValueMutate::take(storage, key_bytes.as_ref(), column)?
.map(|value| {
ValueCodec::decode_from_value(value).map_err(StorageError::Codec)
})
Expand Down Expand Up @@ -641,7 +640,7 @@ macro_rules! root_storage_tests {
// Then
let result = storage_transaction
.storage_as_mut::<$table>()
.insert(&given_key, &state_value)
.replace(&given_key, &state_value)
.unwrap();

assert!(result.is_some());
Expand Down
Loading

0 comments on commit 916b9cb

Please sign in to comment.