Skip to content

Commit

Permalink
rusk: Restructure execution-core
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Jul 30, 2024
1 parent 2eb868e commit 363ce1b
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 86 deletions.
3 changes: 2 additions & 1 deletion rusk/benches/block_ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use criterion::{
criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion,
};
use execution_core::{
transfer::Transaction as ProtocolTransaction, BlsPublicKey, BlsSecretKey,
signatures::bls::{PublicKey as BlsPublicKey, SecretKey as BlsSecretKey},
transfer::Transaction as ProtocolTransaction,
};
use node_data::ledger::Transaction;
use rand::prelude::StdRng;
Expand Down
13 changes: 8 additions & 5 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ use dusk_consensus::config::{
RATIFICATION_COMMITTEE_CREDITS, VALIDATION_COMMITTEE_CREDITS,
};
use dusk_consensus::operations::{CallParams, VerificationOutput, Voter};
use execution_core::transfer::ContractDeploy;
use execution_core::{
stake::StakeData,
transfer::{AccountData, Transaction as ProtocolTransaction},
BlsPublicKey, BlsScalar, ContractBytecode, ContractError, Dusk, Event,
STAKE_CONTRACT, TRANSFER_CONTRACT,
signatures::bls::PublicKey as BlsPublicKey,
stake::{StakeData, STAKE_CONTRACT},
transfer::{
contract_exec::{ContractBytecode, ContractDeploy},
moonlight::AccountData,
Transaction as ProtocolTransaction, TRANSFER_CONTRACT,
},
BlsScalar, ContractError, Dusk, Event,
};
use node_data::ledger::{Slash, SpentTransaction, Transaction};
use rusk_abi::{CallReceipt, PiecrustError, Session, VM};
Expand Down
4 changes: 2 additions & 2 deletions rusk/src/lib/chain/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use dusk_consensus::operations::{CallParams, VerificationOutput, Voter};
use dusk_consensus::user::provisioners::Provisioners;
use dusk_consensus::user::stake::Stake;
use execution_core::{
stake::StakeData, transfer::Transaction as ProtocolTransaction,
BlsPublicKey,
signatures::bls::PublicKey as BlsPublicKey, stake::StakeData,
transfer::Transaction as ProtocolTransaction,
};
use node::vm::VMExecution;
use node_data::ledger::{Block, Slash, SpentTransaction, Transaction};
Expand Down
5 changes: 4 additions & 1 deletion rusk/src/lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use std::{fmt, io};

use dusk_bytes::Serializable;
use execution_core::{BlsPublicKey, BlsScalar, Dusk, PhoenixError};
use execution_core::{
signatures::bls::PublicKey as BlsPublicKey,
transfer::phoenix::Error as PhoenixError, BlsScalar, Dusk,
};
use rusk_abi::PiecrustError;

#[derive(Debug)]
Expand Down
16 changes: 10 additions & 6 deletions rusk/src/lib/gen_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::hash::Hasher;
use rusk_abi::ContractId;
use blake2b_simd::Params;
use execution_core::{ContractId, CONTRACT_ID_BYTES};

/// Generate a [`ContractId`] address from:
/// - slice of bytes,
Expand All @@ -16,11 +16,15 @@ pub fn gen_contract_id(
nonce: u64,
owner: impl AsRef<[u8]>,
) -> ContractId {
let mut hasher = Hasher::new();
let mut hasher = Params::new().hash_length(CONTRACT_ID_BYTES).to_state();
hasher.update(bytes.as_ref());
hasher.update(nonce.to_le_bytes());
hasher.update(&nonce.to_le_bytes()[..]);
hasher.update(owner.as_ref());
let hash_bytes = hasher.finalize();
let hash_bytes: [u8; CONTRACT_ID_BYTES] = hasher
.finalize()
.as_bytes()
.try_into()
.expect("the hash result is exactly `CONTRACT_ID_BYTES` long");
ContractId::from_bytes(hash_bytes)
}

Expand All @@ -47,7 +51,7 @@ mod tests {

assert_eq!(
hex::encode(contract_id.as_bytes()),
"a138d3b9c87235dac6f62d1d30b75cffbb94601d9cbe5bd540b3e1e5842c8a7d"
"2da8b6277789a88c7215789e227ef4dd97486db252e554805c7b874a17e07785"
);
}
}
44 changes: 0 additions & 44 deletions rusk/src/lib/hash.rs

This file was deleted.

2 changes: 1 addition & 1 deletion rusk/src/lib/http/chain/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use data::*;
use tx::*;

use async_graphql::{Context, FieldError, FieldResult, Object};
use execution_core::{ContractId, TRANSFER_CONTRACT};
use execution_core::{transfer::TRANSFER_CONTRACT, ContractId};
use node::database::rocksdb::Backend;
use node::database::{Ledger, DB};

Expand Down
1 change: 0 additions & 1 deletion rusk/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
pub mod chain;
mod error;
pub mod gen_id;
mod hash;
pub mod http;
pub mod verifier;
mod version;
Expand Down
13 changes: 8 additions & 5 deletions rusk/src/lib/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ use futures::Stream;
use tokio::spawn;
use tracing::{error, info};

use execution_core::stake::StakeData;
use execution_core::transfer::{TreeLeaf, TRANSFER_TREE_DEPTH};
use execution_core::{
BlsPublicKey, BlsScalar, ContractId, Note, ViewKey, STAKE_CONTRACT,
TRANSFER_CONTRACT,
signatures::bls::PublicKey as BlsPublicKey,
stake::{StakeData, STAKE_CONTRACT},
transfer::{
phoenix::{Note, TreeLeaf, ViewKey, NOTES_TREE_DEPTH},
TRANSFER_CONTRACT,
},
BlsScalar, ContractId,
};
use parking_lot::RwLockWriteGuard;
use poseidon_merkle::Opening as PoseidonOpening;
Expand Down Expand Up @@ -62,7 +65,7 @@ impl Rusk {
pub fn tree_opening(
&self,
pos: u64,
) -> Result<Option<PoseidonOpening<(), TRANSFER_TREE_DEPTH>>> {
) -> Result<Option<PoseidonOpening<(), NOTES_TREE_DEPTH>>> {
self.query(TRANSFER_CONTRACT, "opening", &pos)
}

Expand Down
5 changes: 4 additions & 1 deletion rusk/src/lib/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use crate::error::Error;
use crate::Result;

use execution_core::transfer::{MoonlightTransaction, PhoenixTransaction};
use execution_core::transfer::{
moonlight::Transaction as MoonlightTransaction,
phoenix::Transaction as PhoenixTransaction,
};
use rusk_profile::Circuit as CircuitProfile;

use std::sync::LazyLock;
Expand Down
2 changes: 1 addition & 1 deletion rusk/tests/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rand::prelude::*;
use rand::rngs::StdRng;
use tracing::info;

use execution_core::BlsSecretKey;
use execution_core::signatures::bls::SecretKey as BlsSecretKey;

#[allow(dead_code)]
pub static STAKE_SK: LazyLock<BlsSecretKey> = LazyLock::new(|| {
Expand Down
4 changes: 3 additions & 1 deletion rusk/tests/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use rusk::{Result, Rusk};
use rusk_recovery_tools::state::{self, Snapshot};

use dusk_consensus::operations::CallParams;
use execution_core::{transfer::Transaction, BlsPublicKey};
use execution_core::{
signatures::bls::PublicKey as BlsPublicKey, transfer::Transaction,
};
use node_data::{
bls::PublicKeyBytes,
ledger::{
Expand Down
11 changes: 8 additions & 3 deletions rusk/tests/common/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ use crate::common::block::Block as BlockAwait;
use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_plonk::prelude::Proof;
use execution_core::{
signatures::bls::PublicKey as BlsPublicKey,
stake::StakeData,
transfer::{AccountData, Transaction, TRANSFER_TREE_DEPTH},
BlsPublicKey, BlsScalar, Note, ViewKey,
transfer::{
moonlight::AccountData,
phoenix::{Note, ViewKey, NOTES_TREE_DEPTH},
Transaction,
},
BlsScalar,
};
use futures::StreamExt;
use poseidon_merkle::Opening as PoseidonOpening;
Expand Down Expand Up @@ -101,7 +106,7 @@ impl wallet::StateClient for TestStateClient {
fn fetch_opening(
&self,
note: &Note,
) -> Result<PoseidonOpening<(), TRANSFER_TREE_DEPTH>, Self::Error> {
) -> Result<PoseidonOpening<(), NOTES_TREE_DEPTH>, Self::Error> {
self.rusk
.tree_opening(*note.pos())?
.ok_or(Error::OpeningPositionNotFound(*note.pos()))
Expand Down
17 changes: 12 additions & 5 deletions rusk/tests/rusk-state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ use std::path::Path;
use std::sync::{mpsc, Arc};

use execution_core::{
transfer::TreeLeaf, JubJubScalar, Note, PublicKey, SecretKey, LUX,
TRANSFER_CONTRACT,
transfer::{
phoenix::{
Note, PublicKey as PhoenixPublicKey, SecretKey as PhoenixSecretKey,
TreeLeaf,
},
TRANSFER_CONTRACT,
},
JubJubScalar, LUX,
};
use ff::Field;
use parking_lot::RwLockWriteGuard;
Expand Down Expand Up @@ -55,9 +61,10 @@ where
info!("Generating a note");
let mut rng = StdRng::seed_from_u64(0xdead);

let sender_sk = SecretKey::random(&mut rng);
let sender_pk = PublicKey::from(&sender_sk);
let receiver_pk = PublicKey::from(&SecretKey::random(&mut rng));
let sender_sk = PhoenixSecretKey::random(&mut rng);
let sender_pk = PhoenixPublicKey::from(&sender_sk);
let receiver_pk =
PhoenixPublicKey::from(&PhoenixSecretKey::random(&mut rng));

let sender_blinder = [
JubJubScalar::random(&mut rng),
Expand Down
6 changes: 3 additions & 3 deletions rusk/tests/services/contract_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};

use execution_core::{
transfer::{ContractDeploy, ContractExec},
ContractBytecode, ContractId,
transfer::contract_exec::{ContractBytecode, ContractDeploy, ContractExec},
ContractId,
};
use rand::prelude::*;
use rand::rngs::StdRng;
Expand Down Expand Up @@ -88,7 +88,7 @@ fn initial_state<P: AsRef<Path>>(dir: P, deploy_bob: bool) -> Result<Rusk> {
)),
POINT_LIMIT,
)
.expect("Deploying the alice contract should succeed");
.expect("Deploying the bob contract should succeed");
}
})
.expect("Deploying initial state should succeed");
Expand Down
6 changes: 4 additions & 2 deletions rusk/tests/services/gas_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use std::collections::HashMap;
use std::path::Path;
use std::sync::{Arc, RwLock};

use execution_core::transfer::{ContractCall, ContractExec};
use execution_core::TRANSFER_CONTRACT;
use execution_core::transfer::{
contract_exec::{ContractCall, ContractExec},
TRANSFER_CONTRACT,
};
use rand::prelude::*;
use rand::rngs::StdRng;
use rusk::{Result, Rusk};
Expand Down
6 changes: 4 additions & 2 deletions rusk/tests/services/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use std::path::Path;
use std::sync::{Arc, RwLock};

use execution_core::{
dusk, stake::StakeAmount, transfer::ContractCall, BlsPublicKey,
STAKE_CONTRACT,
dusk,
signatures::bls::PublicKey as BlsPublicKey,
stake::{StakeAmount, STAKE_CONTRACT},
transfer::contract_exec::ContractCall,
};
use rand::prelude::*;
use rand::rngs::StdRng;
Expand Down
4 changes: 2 additions & 2 deletions rusk/tests/services/unspendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::collections::HashMap;
use std::path::Path;
use std::sync::{Arc, RwLock};

use execution_core::{
transfer::{ContractCall, ContractExec},
use execution_core::transfer::{
contract_exec::{ContractCall, ContractExec},
TRANSFER_CONTRACT,
};
use rand::prelude::*;
Expand Down

0 comments on commit 363ce1b

Please sign in to comment.