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: Versionable CompressedCoin #1628

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Use explicit v1 over default
  • Loading branch information
bvrooman committed Jan 26, 2024
commit 2968ae0d347d2917bab7905787c5eb91b7e28197
25 changes: 15 additions & 10 deletions crates/fuel-core/src/service/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 39,10 @@ use fuel_core_types::{
SealedBlock,
},
entities::{
coins::coin::CompressedCoin,
coins::coin::{
CompressedCoin,
CompressedCoinV1,
},
contract::ContractUtxoInfo,
message::Message,
},
Expand Down Expand Up @@ -181,15 184,17 @@ fn init_coin_state(
}),
);

let mut compressed_coin = CompressedCoin::default();
compressed_coin.set_owner(coin.owner);
compressed_coin.set_amount(coin.amount);
compressed_coin.set_asset_id(coin.asset_id);
compressed_coin.set_maturity(coin.maturity.unwrap_or_default());
compressed_coin.set_tx_pointer(TxPointer::new(
coin.tx_pointer_block_height.unwrap_or_default(),
coin.tx_pointer_tx_idx.unwrap_or_default(),
));
let compressed_coin: CompressedCoin = CompressedCoinV1 {
owner: coin.owner,
amount: coin.amount,
asset_id: coin.asset_id,
maturity: coin.maturity.unwrap_or_default(),
tx_pointer: TxPointer::new(
coin.tx_pointer_block_height.unwrap_or_default(),
coin.tx_pointer_tx_idx.unwrap_or_default(),
),
}
.into();

// ensure coin can't point to blocks in the future
if compressed_coin.tx_pointer().block_height()
Expand Down
32 changes: 20 additions & 12 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,10 @@ use fuel_core_types::{
primitives::DaBlockHeight,
},
entities::{
coins::coin::CompressedCoin,
coins::coin::{
CompressedCoin,
CompressedCoinV1,
},
contract::ContractUtxoInfo,
},
fuel_asm::{
Expand Down Expand Up @@ -1371,11 1374,14 @@ where
.map(Cow::into_owned)
} else {
// if utxo validation is disabled, just assign this new input to the original block
let mut coin = CompressedCoin::default();
coin.set_owner(owner);
coin.set_amount(amount);
coin.set_asset_id(asset_id);
coin.set_maturity(maturity);
let coin = CompressedCoinV1 {
owner,
amount,
asset_id,
maturity,
tx_pointer: Default::default(),
}
.into();
Ok(coin)
}
}
Expand Down Expand Up @@ -1507,12 1513,14 @@ where
// This is because variable or transfer outputs won't have any value
// if there's a revert or panic and shouldn't be added to the utxo set.
if *amount > Word::MIN {
let mut coin = CompressedCoin::default();
coin.set_owner(*to);
coin.set_amount(*amount);
coin.set_asset_id(*asset_id);
coin.set_maturity(0u32.into());
coin.set_tx_pointer(TxPointer::new(block_height, tx_idx));
let coin = CompressedCoinV1 {
owner: *to,
amount: *amount,
asset_id: *asset_id,
maturity: 0u32.into(),
tx_pointer: TxPointer::new(block_height, tx_idx),
}
.into();

if db.storage::<Coins>().insert(&utxo_id, &coin)?.is_some() {
return Err(ExecutorError::OutputAlreadyExists)
Expand Down
6 changes: 6 additions & 0 deletions crates/types/src/entities/coins/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 84,12 @@ pub struct CompressedCoinV1 {
pub tx_pointer: TxPointer,
}

impl From<CompressedCoinV1> for CompressedCoin {
fn from(value: CompressedCoinV1) -> Self {
Self::V1(value)
}
}

impl CompressedCoin {
/// Uncompress the coin.
pub fn uncompress(self, utxo_id: UtxoId) -> Coin {
Expand Down
Loading