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

Move updating of the owned messages and coins to off-chain worker #1635

Merged
merged 116 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
df6e1ae
Move storage traits implementation to the `fuel-core-storage` crate
xgreenx Dec 24, 2023
de82e25
Added comments to all newly added stuff. Made self-review and applied…
xgreenx Dec 26, 2023
7ccc722
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Dec 26, 2023
33661bc
Updated CHANGELOG.md
xgreenx Dec 26, 2023
1b8295a
Merge remote-tracking branch 'origin/feature/move-storage-implementat…
xgreenx Dec 26, 2023
82df7e2
Moved insertion of the blocks into the `BlockImporter` instead of the…
xgreenx Dec 29, 2023
d4a4d0a
Update CHANGELOG.md
xgreenx Dec 29, 2023
5033d8c
Cleanup
xgreenx Dec 29, 2023
ab88c67
Moved insertion of the whole block with transactions
xgreenx Dec 29, 2023
a49d96d
Use `store_block` as a name instead of `block`
xgreenx Dec 30, 2023
c6fb1fe
Merge branch 'master' into feature/move-blocks-to-importer
xgreenx Jan 2, 2024
f5c38f2
Move `ChainId` to `fuel_core_importer::Config`
xgreenx Jan 5, 2024
4c3f18c
Apply suggestions from the PR
xgreenx Jan 5, 2024
0eaab98
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Jan 5, 2024
c1ee5f8
Apply suggestions from the PR
xgreenx Jan 5, 2024
c594d45
Extract off chain logic from the executor
xgreenx Jan 4, 2024
bd60793
Added comments and linked todos
xgreenx Jan 5, 2024
8221443
Updated CHANGELOG.md
xgreenx Jan 5, 2024
810edee
Merge branch 'master' into feature/move-offchain-logic-from-executor
xgreenx Jan 5, 2024
4a580ed
Merge branch 'master' into feature/move-offchain-logic-from-executor
xgreenx Jan 6, 2024
0cea5bb
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Jan 6, 2024
c9977a4
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Jan 6, 2024
b0ed3e9
Fixed compilation
xgreenx Jan 6, 2024
541527e
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Jan 6, 2024
c5a7b71
Merge branch 'master' into feature/move-offchain-logic-from-executor
xgreenx Jan 6, 2024
d2b5504
Use `BlockHeight` as a primary key for the `FuelsBlock` table
xgreenx Jan 6, 2024
1013f0e
Merge branch 'feature/move-storage-implementation-to-own-crate' into …
xgreenx Jan 6, 2024
359192e
Updated CHANGELOG.md
xgreenx Jan 6, 2024
34b5e6a
Merge remote-tracking branch 'origin/feature/block-height-as-primary-…
xgreenx Jan 6, 2024
e27996a
Fix compilation
xgreenx Jan 6, 2024
f3515d8
Merge branch 'master' into feature/move-offchain-logic-from-executor
xgreenx Jan 7, 2024
1be054c
Use `AtomicView` in the `TxPool`
xgreenx Jan 8, 2024
ea69532
Update CHANGELOG.md
xgreenx Jan 8, 2024
452418c
Merge remote-tracking branch 'origin/feature/move-storage-implementat…
xgreenx Jan 19, 2024
1fbc318
Merge branch 'master' into feature/move-storage-implementation-to-own…
xgreenx Jan 19, 2024
c5956a8
Use "blueprint" instead of "structure"
xgreenx Jan 19, 2024
cc9966c
Fix documents
xgreenx Jan 19, 2024
0bbeea1
Merge branch 'feature/move-storage-implementation-to-own-crate' into …
xgreenx Jan 19, 2024
2d3e471
Merge latest modifications from move storage PR
xgreenx Jan 19, 2024
f0df4f0
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx Jan 19, 2024
688a24b
Merge branch 'master' into feature/move-offchain-logic-from-executor
xgreenx Jan 19, 2024
c7bce20
Fix conflicts
xgreenx Jan 19, 2024
0850b03
Merge branch 'feature/move-offchain-logic-from-executor' into feature…
xgreenx Jan 19, 2024
f607007
Merge branch 'feature/move-offchain-logic-from-executor' into feature…
xgreenx Jan 19, 2024
55424cb
Merge remote-tracking branch 'origin/feature/use-view-in-txpool' into…
xgreenx Jan 19, 2024
2b95d4e
Merge branch 'master' into feature/use-view-in-txpool
xgreenx Jan 19, 2024
993aa84
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx Jan 19, 2024
36445b7
Merged master
xgreenx Jan 19, 2024
0e2abad
Merge branch 'master' into feature/block-height-as-primary-key
xgreenx Jan 19, 2024
6a503b9
Apply comments
xgreenx Jan 19, 2024
02a45a8
Merge branch 'master' into feature/use-view-in-txpool
xgreenx Jan 19, 2024
50f2ff0
Merge branch 'feature/block-height-as-primary-key' into feature/use-v…
xgreenx Jan 19, 2024
067792b
Apply comments
xgreenx Jan 19, 2024
6cead2b
Merge branch 'master' into feature/use-view-in-txpool
xgreenx Jan 19, 2024
8369cd5
Move arc wrapper into its own module
xgreenx Jan 19, 2024
4b79c3f
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 21, 2024
c540f4d
Use `AtomicView` in all services
xgreenx Jan 21, 2024
7e7ff6d
Update CHANGELOG.md
xgreenx Jan 21, 2024
fa5d52d
Fix compilation
xgreenx Jan 21, 2024
9c35ab7
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 22, 2024
d75a5c1
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 24, 2024
c8b4da6
Making relayer independent from the executor
xgreenx Jan 24, 2024
31109c7
Update CHANGELOG.md
xgreenx Jan 24, 2024
11cf96f
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 24, 2024
5f65363
Merge branch 'feature/atomic-view-everywhere' into feature/independen…
xgreenx Jan 24, 2024
2af3b6f
Use a separate database for each data domain
xgreenx Jan 25, 2024
76a689d
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 26, 2024
2d63c32
Merged with `master`
xgreenx Jan 26, 2024
08c18e1
Update CHANGELOG.md
xgreenx Jan 26, 2024
43b559b
Merge branch 'feature/atomic-view-everywhere' into feature/independen…
xgreenx Jan 26, 2024
09e5eb3
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 26, 2024
1bffca6
Fix compilation
xgreenx Jan 26, 2024
5300800
Merge branch 'master' into feature/atomic-view-everywhere
xgreenx Jan 26, 2024
555d4e1
Merge with `master`
xgreenx Jan 26, 2024
75d164a
Merge branch 'feature/atomic-view-everywhere' into feature/independen…
xgreenx Jan 26, 2024
4a4f135
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 26, 2024
b50753c
Updated CHANGELOG.md
xgreenx Jan 26, 2024
adbeed6
Fix compilation
xgreenx Jan 26, 2024
ff51296
Apply comments from the PR
xgreenx Jan 26, 2024
843ddf1
Merge branch 'feature/atomic-view-everywhere' into feature/independen…
xgreenx Jan 27, 2024
ec52b27
Merge branch 'master' into feature/independent-relayer-and-fti
xgreenx Jan 27, 2024
d9762f9
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 27, 2024
b0b0df1
Notify services about importing of the genesis block
xgreenx Jan 27, 2024
40c2189
Updated CHANGELOG.md
xgreenx Jan 27, 2024
5f5af6c
Merge branch 'feature/async-genesis-block-import' into feature/separa…
xgreenx Jan 27, 2024
e28f5c1
Merge branch 'master' into feature/independent-relayer-and-fti
xgreenx Jan 29, 2024
d1f0ad4
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 29, 2024
91ca347
Merge `master` branch
xgreenx Jan 29, 2024
2906562
Merge branch 'master' into feature/independent-relayer-and-fti
xgreenx Jan 29, 2024
b6168c6
Patched test
xgreenx Jan 29, 2024
47ac9ea
Forgot to commit the first half of the change=D
xgreenx Jan 29, 2024
c4af13b
The second part of the change that uses events emitted by the executor.
xgreenx Jan 30, 2024
e504b1b
Merge branch 'master' into feature/independent-relayer-and-fti
xgreenx Jan 30, 2024
ed311d0
Fix compilation issue after merge with `master`
xgreenx Jan 30, 2024
6519ab4
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 30, 2024
f3761e6
Applied comments
xgreenx Jan 30, 2024
a077350
Merge branch 'feature/independent-relayer-and-fti' into feature/separ…
xgreenx Jan 30, 2024
dd51818
Merge branch 'feature/separate-databases' into feature/message-owning…
xgreenx Jan 30, 2024
e925bd8
Fixed compilation
xgreenx Jan 30, 2024
c5a4348
Merge branch 'master' into feature/separate-databases
xgreenx Jan 30, 2024
5956015
Merge branch 'feature/separate-databases' into feature/message-owning…
xgreenx Jan 30, 2024
882c6e1
Merge branch 'master' into feature/separate-databases
xgreenx Feb 1, 2024
fb0b2b1
Use diffrent timeout for node B to avoid closign connection from B side.
xgreenx Feb 1, 2024
393dec0
Merge branch 'feature/separate-databases' into feature/message-owning…
xgreenx Feb 2, 2024
1e8b83c
Merge branch 'master' into feature/separate-databases
xgreenx Feb 2, 2024
6631c98
Merge branch 'feature/separate-databases' into feature/message-owning…
xgreenx Feb 2, 2024
9b7617e
Merge branch 'master' into feature/message-owning-indexing-offchain
xgreenx Feb 2, 2024
16b1dc9
Cix compilation
xgreenx Feb 2, 2024
65bbbde
Apply comments
xgreenx Feb 2, 2024
dc6f4c3
Merge branch 'master' into feature/message-owning-indexing-offchain
xgreenx Feb 4, 2024
cfb1280
Merge branch 'master' into feature/message-owning-indexing-offchain
xgreenx Feb 7, 2024
871950f
Update crates/fuel-core/src/coins_query.rs
xgreenx Feb 11, 2024
fe0d157
Merge branch 'master' into feature/message-owning-indexing-offchain
xgreenx Feb 11, 2024
a263be2
Merge remote-tracking branch 'origin/master' into feature/message-own…
xgreenx Feb 14, 2024
facce8a
Update crates/services/executor/src/executor.rs
xgreenx Feb 14, 2024
e2425d6
Merge branch 'master' into feature/message-owning-indexing-offchain
xgreenx Feb 14, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Description of the upcoming release here.
### Changed

- [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Removed `Receipts` table. Instead, receipts are part of the `TransactionStatuses` table.
- [#1640](https://github.com/FuelLabs/fuel-core/pull/1640): Upgrade to fuel-vm 0.45.0.
- [#1635](https://github.com/FuelLabs/fuel-core/pull/1635): Move updating of the owned messages and coins to off-chain worker.
- [#1650](https://github.com/FuelLabs/fuel-core/pull/1650): Add api endpoint for getting estimates for future gas prices
- [#1649](https://github.com/FuelLabs/fuel-core/pull/1649): Add api endpoint for getting latest gas price
- [#1600](https://github.com/FuelLabs/fuel-core/pull/1640): Upgrade to fuel-vm 0.45.0
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-config/src/config/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serde_with::{

#[skip_serializing_none]
#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Default, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct CoinConfig {
/// auto-generated if None
#[serde_as(as = "Option<HexType>")]
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-config/src/config/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
// TODO: do streaming deserialization to handle large state configs
#[serde_as]
#[skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
#[derive(Default, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct StateConfig {
/// Spendable coins
pub coins: Option<Vec<CoinConfig>>,
Expand Down
22 changes: 21 additions & 1 deletion crates/fuel-core/src/coins_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,19 @@ mod tests {
SpendQuery,
},
combined_database::CombinedDatabase,
fuel_core_graphql_api::api_service::ReadDatabase as ServiceDatabase,
fuel_core_graphql_api::{
api_service::ReadDatabase as ServiceDatabase,
storage::{
coins::{
owner_coin_id_key,
OwnedCoins,
},
messages::{
OwnedMessageIds,
OwnedMessageKey,
},
},
},
query::asset_query::{
AssetQuery,
AssetSpendTarget,
Expand Down Expand Up @@ -921,6 +933,7 @@ mod tests {
coin_result
}

// TODO: Should use any mock database instead of the `fuel_core::CombinedDatabase`.
pub struct TestDatabase {
database: CombinedDatabase,
last_coin_index: u64,
Expand Down Expand Up @@ -961,6 +974,9 @@ mod tests {

let db = self.database.on_chain_mut();
StorageMutate::<Coins>::insert(db, &id, &coin).unwrap();
let db = self.database.off_chain_mut();
let coin_by_owner = owner_coin_id_key(&owner, &id);
StorageMutate::<OwnedCoins>::insert(db, &coin_by_owner, &()).unwrap();

coin.uncompress(id)
}
Expand All @@ -981,6 +997,10 @@ mod tests {

let db = self.database.on_chain_mut();
StorageMutate::<Messages>::insert(db, message.id(), &message).unwrap();
let db = self.database.off_chain_mut();
let owned_message_key = OwnedMessageKey::new(&owner, &nonce);
StorageMutate::<OwnedMessageIds>::insert(db, &owned_message_key, &())
.unwrap();

message
}
Expand Down
5 changes: 5 additions & 0 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ impl CombinedDatabase {
&self.off_chain
}

#[cfg(any(feature = "test-helpers", test))]
pub fn off_chain_mut(&mut self) -> &mut Database<OffChain> {
&mut self.off_chain
}

pub fn relayer(&self) -> &Database<Relayer> {
&self.relayer
}
Expand Down
115 changes: 10 additions & 105 deletions crates/fuel-core/src/database/coin.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
use crate::database::{
database_description::on_chain::OnChain,
Database,
use crate::{
database::{
database_description::off_chain::OffChain,
Database,
},
fuel_core_graphql_api::storage::coins::{
owner_coin_id_key,
OwnedCoins,
},
};
use fuel_core_chain_config::CoinConfig;
use fuel_core_storage::{
blueprint::plain::Plain,
codec::{
postcard::Postcard,
primitive::utxo_id_to_bytes,
raw::Raw,
},
iter::IterDirection,
not_found,
structured_storage::TableWithBlueprint,
tables::Coins,
Error as StorageError,
Mappable,
Result as StorageResult,
StorageAsMut,
StorageAsRef,
StorageInspect,
StorageMutate,
};
use fuel_core_txpool::types::TxId;
use fuel_core_types::{
Expand All @@ -30,78 +24,8 @@ use fuel_core_types::{
UtxoId,
},
};
use std::borrow::Cow;

// TODO: Reuse `fuel_vm::storage::double_key` macro.
pub fn owner_coin_id_key(owner: &Address, coin_id: &UtxoId) -> OwnedCoinKey {
let mut default = [0u8; Address::LEN + TxId::LEN + 1];
default[0..Address::LEN].copy_from_slice(owner.as_ref());
default[Address::LEN..].copy_from_slice(utxo_id_to_bytes(coin_id).as_ref());
default
}

/// The storage table of owned coin ids. Maps addresses to owned coins.
pub struct OwnedCoins;
/// The storage key for owned coins: `Address ++ UtxoId`
pub type OwnedCoinKey = [u8; Address::LEN + TxId::LEN + 1];

impl Mappable for OwnedCoins {
type Key = Self::OwnedKey;
type OwnedKey = OwnedCoinKey;
type Value = Self::OwnedValue;
type OwnedValue = ();
}

impl TableWithBlueprint for OwnedCoins {
type Blueprint = Plain<Raw, Postcard>;
type Column = fuel_core_storage::column::Column;

fn column() -> Self::Column {
Self::Column::OwnedCoins
}
}

impl StorageInspect<Coins> for Database {
type Error = StorageError;

fn get(&self, key: &UtxoId) -> Result<Option<Cow<CompressedCoin>>, Self::Error> {
self.data.storage::<Coins>().get(key)
}

fn contains_key(&self, key: &UtxoId) -> Result<bool, Self::Error> {
self.data.storage::<Coins>().contains_key(key)
}
}

impl StorageMutate<Coins> for Database {
fn insert(
&mut self,
key: &UtxoId,
value: &CompressedCoin,
) -> Result<Option<CompressedCoin>, Self::Error> {
let coin_by_owner = owner_coin_id_key(value.owner(), key);
// insert primary record
let insert = self.data.storage_as_mut::<Coins>().insert(key, value)?;
// insert secondary index by owner
self.storage_as_mut::<OwnedCoins>()
.insert(&coin_by_owner, &())?;
Ok(insert)
}

fn remove(&mut self, key: &UtxoId) -> Result<Option<CompressedCoin>, Self::Error> {
let coin = self.data.storage_as_mut::<Coins>().remove(key)?;

// cleanup secondary index
if let Some(coin) = &coin {
let key = owner_coin_id_key(coin.owner(), key);
self.storage_as_mut::<OwnedCoins>().remove(&key)?;
}

Ok(coin)
}
}

impl Database<OnChain> {
impl Database<OffChain> {
pub fn owned_coins_ids(
&self,
owner: &Address,
Expand Down Expand Up @@ -158,22 +82,3 @@ impl Database {
Ok(Some(configs))
}
}

#[cfg(test)]
mod test {
use super::*;

fn generate_key(rng: &mut impl rand::Rng) -> <OwnedCoins as Mappable>::Key {
let mut bytes = [0u8; 65];
rng.fill(bytes.as_mut());
bytes
}

fuel_core_storage::basic_storage_tests!(
OwnedCoins,
[0u8; 65],
<OwnedCoins as Mappable>::Value::default(),
<OwnedCoins as Mappable>::Value::default(),
generate_key
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ impl DatabaseDescription for OnChain {

fn prefix(column: &Self::Column) -> Option<usize> {
match column {
Self::Column::OwnedCoins
| Self::Column::OwnedMessageIds
| Self::Column::ContractsAssets
| Self::Column::ContractsState => {
Self::Column::ContractsAssets | Self::Column::ContractsState => {
// prefix is address length
Some(32)
}
Expand Down
Loading
Loading