Skip to content

Commit

Permalink
Cleanup. added VMConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Dec 2, 2021
1 parent 5d6493c commit db48aad
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
5 changes: 2 additions & 3 deletions fuel-core/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::chain_config::GlobalConfig;
use crate::service::{Config, DbType};
use crate::service::{Config, DbType,VMConfig};
use std::{env, io, net, path::PathBuf, string::ToString};
use structopt::StructOpt;
use tracing_subscriber::filter::EnvFilter;
Expand Down Expand Up @@ -64,7 +63,7 @@ impl Opt {
database_path,
database_type,
chain_conf: chain_config.as_str().parse()?,
global_conf: GlobalConfig { vm_backtrace },
vm: VMConfig { backtrace: vm_backtrace },
})
}
}
6 changes: 0 additions & 6 deletions fuel-core/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ impl FromStr for ChainConfig {
}
}

#[skip_serializing_none]
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct GlobalConfig {
pub vm_backtrace: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub enum ProductionStrategy {
Instant,
Expand Down
10 changes: 5 additions & 5 deletions fuel-core/src/schema/tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::chain_config::GlobalConfig;
use crate::service::Config;
use crate::database::{transaction::OwnedTransactionIndexCursor, Database, KvStoreError};
use crate::schema::scalars::{HexString, HexString256};
use crate::state::IterDirection;
Expand Down Expand Up @@ -213,11 +213,11 @@ impl TxMutation {
tx: HexString,
) -> async_graphql::Result<Vec<receipt::Receipt>> {
let transaction = ctx.data_unchecked::<Database>().transaction();
let cfg = ctx.data_unchecked::<GlobalConfig>();
let cfg = ctx.data_unchecked::<Config>();
let tx = FuelTx::from_bytes(&tx.0)?;
// make virtual txpool from transactional view
let tx_pool = TxPool::new(transaction.deref().clone());
let receipts = tx_pool.run_tx(tx, cfg.vm_backtrace).await?;
let receipts = tx_pool.run_tx(tx, cfg.vm.backtrace).await?;
Ok(receipts.into_iter().map(receipt::Receipt).collect())
}

Expand All @@ -228,9 +228,9 @@ impl TxMutation {
tx: HexString,
) -> async_graphql::Result<HexString256> {
let tx_pool = ctx.data::<Arc<TxPool>>().unwrap();
let cfg = ctx.data_unchecked::<GlobalConfig>();
let cfg = ctx.data_unchecked::<Config>();
let tx = FuelTx::from_bytes(&tx.0)?;
let id = tx_pool.submit_tx(tx, cfg.vm_backtrace).await?;
let id = tx_pool.submit_tx(tx, cfg.vm.backtrace).await?;

Ok(id.into())
}
Expand Down
11 changes: 8 additions & 3 deletions fuel-core/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::chain_config::{ChainConfig, ContractConfig, GlobalConfig, StateConfig};
use crate::chain_config::{ChainConfig, ContractConfig, StateConfig};
use crate::database::Database;
use crate::model::coin::{Coin, CoinStatus, UtxoId};
use crate::tx_pool::TxPool;
Expand Down Expand Up @@ -26,7 +26,7 @@ pub struct Config {
pub database_path: PathBuf,
pub database_type: DbType,
pub chain_conf: ChainConfig,
pub global_conf: GlobalConfig,
pub vm: VMConfig,
}

impl Config {
Expand All @@ -36,11 +36,16 @@ impl Config {
database_path: Default::default(),
database_type: DbType::InMemory,
chain_conf: ChainConfig::local_testnet(),
global_conf: Default::default(),
vm: Default::default(),
}
}
}

#[derive(Clone, Debug,Default)]
pub struct VMConfig {
pub backtrace: bool,
}

#[derive(Clone, Debug, PartialEq, EnumString, Display)]
pub enum DbType {
InMemory,
Expand Down
5 changes: 3 additions & 2 deletions fuel-core/src/service/graph_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ pub async fn start_server(
db: Database,
tx_pool: Arc<TxPool>,
) -> Result<(SocketAddr, JoinHandle<Result<(), crate::service::Error>>), std::io::Error> {
let network_addr = config.addr;
let schema = build_schema()
.data(db)
.data(tx_pool)
.data(config.global_conf);
.data(config);
let schema = dap::init(schema).finish();

let router = Router::new()
Expand All @@ -58,7 +59,7 @@ pub async fn start_server(
.boxed();

let (tx, rx) = tokio::sync::oneshot::channel();
let listener = TcpListener::bind(&config.addr)?;
let listener = TcpListener::bind(&network_addr)?;
let bound_addr = listener.local_addr().unwrap();

info!("Binding GraphQL provider to {}", bound_addr);
Expand Down

0 comments on commit db48aad

Please sign in to comment.