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

Retrayable messages fuel-core part #1067

Merged
merged 17 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 16 additions & 15 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 @@ -75,7 +75,7 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" }
fuel-core-xtask = { version = "0.0.0", path = "./xtask" }

# Fuel dependencies
fuel-vm-private = { version = "0.27", package = "fuel-vm" }
fuel-vm-private = { version = "0.28", package = "fuel-vm" }

# Common dependencies
anyhow = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use criterion::{
Throughput,
};
use fuel_core_benches::*;
use fuel_core_storage::ContractsAssetsStorage;
use fuel_core_types::{
fuel_asm::*,
fuel_tx::{
Expand Down Expand Up @@ -424,7 +425,6 @@ pub fn run(c: &mut Criterion) {
for i in linear.clone() {
let mut input = VmBench::contract(rng, op::smo(0x15, 0x16, 0x17, 0x18))
.expect("failed to prepare contract");
input.outputs.push(Output::message(Address::zeroed(), 1));
let index = input.outputs.len() - 1;
input.post_call.extend(vec![
op::gtf_args(0x15, 0x00, GTFArgs::ScriptData),
Expand Down
1 change: 1 addition & 0 deletions benches/src/bin/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ mod tests {
.arg(&manifest_path)
.output()
.unwrap();
println!("{}", String::from_utf8(output.stderr).unwrap());
assert!(output.status.success());
}

Expand Down
18 changes: 9 additions & 9 deletions bin/e2e-test-client/src/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{
Context,
};
use fuel_core_client::client::{
schema::resource::Resource,
schema::coins::CoinType,
types::TransactionStatus,
FuelClient,
PageDirection,
Expand Down Expand Up @@ -142,9 +142,9 @@ impl Wallet {
let asset_id_str = asset_id_string.as_str();
let total_amount = transfer_amount + BASE_AMOUNT;
// select coins
let resources = &self
let coins = &self
.client
.resources_to_spend(
.coins_to_spend(
self.address.to_string().as_str(),
vec![(asset_id_str, total_amount, None)],
None,
Expand All @@ -156,8 +156,8 @@ impl Wallet {
tx.gas_price(1);
tx.gas_limit(BASE_AMOUNT);

for resource in resources {
if let Resource::Coin(coin) = resource {
for coin in coins {
if let CoinType::Coin(coin) = coin {
tx.add_unsigned_coin_input(
self.secret,
coin.utxo_id.clone().into(),
Expand Down Expand Up @@ -204,9 +204,9 @@ impl Wallet {
let asset_id_str = asset_id_string.as_str();
let total_amount = BASE_AMOUNT;
// select coins
let resources = &self
let coins = &self
.client
.resources_to_spend(
.coins_to_spend(
self.address.to_string().as_str(),
vec![(asset_id_str, total_amount, None)],
None,
Expand All @@ -222,8 +222,8 @@ impl Wallet {
tx.gas_price(1);
tx.gas_limit(BASE_AMOUNT);

for resource in resources {
if let Resource::Coin(coin) = resource {
for coin in coins {
if let CoinType::Coin(coin) = coin {
tx.add_unsigned_coin_input(
self.secret,
coin.utxo_id.clone().into(),
Expand Down
22 changes: 15 additions & 7 deletions crates/chain-config/src/config/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use fuel_core_storage::MerkleRoot;
use fuel_core_types::{
blockchain::primitives::BlockHeight,
entities::coin::CompressedCoin,
entities::coins::coin::CompressedCoin,
fuel_crypto::Hasher,
fuel_types::{
Address,
Expand Down Expand Up @@ -58,13 +58,21 @@ pub struct CoinConfig {

impl GenesisCommitment for CompressedCoin {
fn root(&self) -> anyhow::Result<MerkleRoot> {
let Self {
owner,
amount,
asset_id,
maturity,
tx_pointer,
} = self;

let coin_hash = *Hasher::default()
.chain(self.owner)
.chain(self.amount.to_be_bytes())
.chain(self.asset_id)
.chain((*self.maturity).to_be_bytes())
.chain(self.tx_pointer.block_height().to_be_bytes())
.chain(self.tx_pointer.tx_index().to_be_bytes())
.chain(owner)
.chain(amount.to_be_bytes())
.chain(asset_id)
.chain((*maturity).to_be_bytes())
.chain(tx_pointer.block_height().to_be_bytes())
.chain(tx_pointer.tx_index().to_be_bytes())
.finalize();

Ok(coin_hash)
Expand Down
35 changes: 26 additions & 9 deletions crates/chain-config/src/config/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ use fuel_core_types::{
blockchain::primitives::DaBlockHeight,
entities::message::Message,
fuel_asm::Word,
fuel_types::Address,
fuel_crypto::Hasher,
fuel_types::{
Address,
Nonce,
},
};
use serde::{
Deserialize,
Serialize,
};
use serde_with::{
serde_as,
skip_serializing_none,
};
use serde_with::serde_as;

#[skip_serializing_none]
#[serde_as]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
pub struct MessageConfig {
#[serde_as(as = "HexType")]
pub sender: Address,
#[serde_as(as = "HexType")]
pub recipient: Address,
#[serde_as(as = "HexNumber")]
pub nonce: Word,
#[serde_as(as = "HexType")]
pub nonce: Nonce,
#[serde_as(as = "HexNumber")]
pub amount: Word,
#[serde_as(as = "HexType")]
Expand All @@ -55,6 +55,23 @@ impl From<MessageConfig> for Message {

impl GenesisCommitment for Message {
fn root(&self) -> anyhow::Result<MerkleRoot> {
Ok(self.id().into())
let Self {
sender,
recipient,
nonce,
amount,
data,
da_height,
} = self;

let message_hash = *Hasher::default()
.chain(sender)
.chain(recipient)
.chain(nonce)
.chain(amount.to_be_bytes())
.chain(data.as_slice())
.chain(da_height.to_be_bytes())
.finalize();
Ok(message_hash)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ expression: json
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"k256": 19,
"lb": 1,
"log": 40,
Expand Down
Loading