Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into graceful-shutdown-on-c…
Browse files Browse the repository at this point in the history
…trl-c
  • Loading branch information
shamardy committed Sep 19, 2024
2 parents a3791bd + 3b27172 commit a2643f0
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 44 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

## What is the Komodo DeFi Framework?

The Komodo DeFi Framework is open-source [atomic-swap](https://komodoplatform.com/en/academy/atomic-swaps/) software for seamless, decentralised, peer to peer trading between almost every blockchain asset in existence. This software works with propagation of orderbooks and swap states through the [libp2p](https://libp2p.io/) protocol and uses [Hash Time Lock Contracts (HTLCs)](https://en.bitcoinwiki.org/wiki/Hashed_Timelock_Contracts) for ensuring that the two parties in a swap either mutually complete a trade, or funds return to thier original owner.
The Komodo DeFi Framework is open-source [atomic-swap](https://komodoplatform.com/en/academy/atomic-swaps/) software for seamless, decentralized, peer to peer trading between almost every blockchain asset in existence. This software works with propagation of orderbooks and swap states through the [libp2p](https://libp2p.io/) protocol and uses [Hash Time Lock Contracts (HTLCs)](https://en.bitcoinwiki.org/wiki/Hashed_Timelock_Contracts) for ensuring that the two parties in a swap either mutually complete a trade, or funds return to thier original owner.

There is no 3rd party intermediary, no proxy tokens, and at all times users remain in sole possession of their private keys.

Expand Down Expand Up @@ -172,7 +172,7 @@ Refer to the [Komodo Developer Docs](https://developers.komodoplatform.com/basic

## Project structure

[mm2src](mm2src) - Rust code, contains some parts ported from C `as is` (e.g. `lp_ordermatch`) to reach the most essential/error prone code. Some other modules/crates are reimplemented from scratch.
[mm2src](mm2src) - Rust code, contains some parts ported from C `as is` (e.g. `lp_ordermatch`) to reach the most essential/error-prone code. Some other modules/crates are reimplemented from scratch.


## Additional docs for developers
Expand All @@ -185,8 +185,8 @@ Refer to the [Komodo Developer Docs](https://developers.komodoplatform.com/basic

## Disclaimer

This repository contains the `work in progress` code of the brand new Komodo DeFi Framework (kdf) built mainly on Rust.
The current state can be considered as a alpha version.
This repository contains the `work in progress` code of the brand-new Komodo DeFi Framework (kdf) built mainly on Rust.
The current state can be considered as an alpha version.

**<b>WARNING: Use with test coins only or with assets which value does not exceed an amount you are willing to lose. This is alpha stage software! </b>**

Expand Down
13 changes: 0 additions & 13 deletions mm2src/common/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,19 +518,6 @@ pub fn set_panic_hook() {
}))
}

/// Simulates the panic-in-panic crash.
pub fn double_panic_crash() {
struct Panicker;
impl Drop for Panicker {
fn drop(&mut self) { panic!("panic in drop") }
}
let panicker = Panicker;
if 1 < 2 {
panic!("first panic")
}
drop(panicker) // Delays the drop.
}

/// RPC response, returned by the RPC handlers.
/// NB: By default the future is executed on the shared asynchronous reactor (`CORE`),
/// the handler is responsible for spawning the future on another reactor if it doesn't fit the `CORE` well.
Expand Down
7 changes: 5 additions & 2 deletions mm2src/mm2_core/src/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ impl MmCtx {
})
}

/// Returns the path to the MM databases root.
#[cfg(not(target_arch = "wasm32"))]
pub fn db_root(&self) -> PathBuf { path_to_db_root(self.conf["dbdir"].as_str()) }

#[cfg(not(target_arch = "wasm32"))]
pub fn wallet_file_path(&self, wallet_name: &str) -> PathBuf {
let db_root = path_to_db_root(self.conf["dbdir"].as_str());
db_root.join(wallet_name.to_string() + ".dat")
self.db_root().join(wallet_name.to_string() + ".dat")
}

/// MM database path.
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_libp2p/src/atomicdex_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const ANNOUNCE_INTERVAL: Duration = Duration::from_secs(600);
const ANNOUNCE_INITIAL_DELAY: Duration = Duration::from_secs(60);
const CHANNEL_BUF_SIZE: usize = 1024 * 8;

/// Returns info about connected peers
pub async fn get_peers_info(mut cmd_tx: AdexCmdTx) -> BTreeMap<String, Vec<String>> {
/// Returns info about directly connected peers.
pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> BTreeMap<String, Vec<String>> {
let (result_tx, rx) = oneshot::channel();
let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx };
cmd_tx.send(cmd).await.expect("Rx should be present");
Expand Down
4 changes: 3 additions & 1 deletion mm2src/mm2_main/src/lp_native_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,11 @@ pub async fn lp_init_continue(ctx: MmArc) -> MmInitResult<()> {
pub async fn lp_init(ctx: MmArc, version: String, datetime: String) -> MmInitResult<()> {
info!("Version: {} DT {}", version, datetime);

// Ensure the database root directory exists before initializing the wallet passphrase.
// This is necessary to store the encrypted wallet passphrase if needed.
#[cfg(not(target_arch = "wasm32"))]
{
let dbdir = ctx.dbdir();
let dbdir = ctx.db_root();
fs::create_dir_all(&dbdir).map_to_mm(|e| MmInitError::ErrorCreatingDbDir {
path: dbdir.clone(),
error: e.to_string(),
Expand Down
11 changes: 0 additions & 11 deletions mm2src/mm2_main/src/mm2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

#[cfg(not(target_arch = "wasm32"))] use common::block_on;
use common::crash_reports::init_crash_reports;
use common::double_panic_crash;
use common::log;
use common::log::LogLevel;
use common::password_policy::password_policy;
Expand Down Expand Up @@ -271,16 +270,6 @@ pub fn mm2_main(version: String, datetime: String) {
// we're not checking them for the mode switches in order not to risk [untrusted] data being mistaken for a mode switch.
let first_arg = args_os.get(1).and_then(|arg| arg.to_str());

if first_arg == Some("panic") {
panic!("panic message")
}
if first_arg == Some("crash") {
double_panic_crash()
}
if first_arg == Some("stderr") {
eprintln!("This goes to stderr");
return;
}
if first_arg == Some("update_config") {
match on_update_config(&args_os) {
Ok(_) => println!("Success"),
Expand Down
2 changes: 1 addition & 1 deletion mm2src/mm2_main/src/rpc/dispatcher/dispatcher_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub fn dispatcher(req: Json, ctx: MmArc) -> DispatcherRes {
"electrum" => hyres(electrum(ctx, req)),
"enable" => hyres(enable(ctx, req)),
"get_enabled_coins" => hyres(get_enabled_coins(ctx)),
"get_directly_connected_peers" => hyres(get_directly_connected_peers(ctx)),
"get_gossip_mesh" => hyres(get_gossip_mesh(ctx)),
"get_gossip_peer_topics" => hyres(get_gossip_peer_topics(ctx)),
"get_gossip_topic_peers" => hyres(get_gossip_topic_peers(ctx)),
"get_my_peer_id" => hyres(get_my_peer_id(ctx)),
"get_peers_info" => hyres(get_peers_info(ctx)),
"get_relay_mesh" => hyres(get_relay_mesh(ctx)),
"get_trade_fee" => hyres(get_trade_fee(ctx, req)),
// "fundvalue" => lp_fundvalue (ctx, req, false),
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_main/src/rpc/lp_commands/lp_commands_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ pub fn version(ctx: MmArc) -> HyRes {
}
}

pub async fn get_peers_info(ctx: MmArc) -> Result<Response<Vec<u8>>, String> {
pub async fn get_directly_connected_peers(ctx: MmArc) -> Result<Response<Vec<u8>>, String> {
let ctx = P2PContext::fetch_from_mm_arc(&ctx);
let cmd_tx = ctx.cmd_tx.lock().clone();
let result = mm2_libp2p::get_peers_info(cmd_tx).await;
let result = mm2_libp2p::get_directly_connected_peers(cmd_tx).await;
let result = json!({
"result": result,
});
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_net/src/network_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ impl EventBehaviour for NetworkEvent {
loop {
let p2p_cmd_tx = p2p_ctx.cmd_tx.lock().clone();

let peers_info = atomicdex::get_peers_info(p2p_cmd_tx.clone()).await;
let directly_connected_peers = atomicdex::get_directly_connected_peers(p2p_cmd_tx.clone()).await;
let gossip_mesh = atomicdex::get_gossip_mesh(p2p_cmd_tx.clone()).await;
let gossip_peer_topics = atomicdex::get_gossip_peer_topics(p2p_cmd_tx.clone()).await;
let gossip_topic_peers = atomicdex::get_gossip_topic_peers(p2p_cmd_tx.clone()).await;
let relay_mesh = atomicdex::get_relay_mesh(p2p_cmd_tx).await;

let event_data = json!({
"peers_info": peers_info,
"directly_connected_peers": directly_connected_peers,
"gossip_mesh": gossip_mesh,
"gossip_peer_topics": gossip_peer_topics,
"gossip_topic_peers": gossip_topic_peers,
Expand Down
4 changes: 2 additions & 2 deletions mm2src/mm2_p2p/src/behaviours/atomicdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ pub enum AdexBehaviourCmd {
},
}

/// Returns info about connected peers
pub async fn get_peers_info(mut cmd_tx: AdexCmdTx) -> HashMap<String, Vec<String>> {
/// Returns info about directly connected peers.
pub async fn get_directly_connected_peers(mut cmd_tx: AdexCmdTx) -> HashMap<String, Vec<String>> {
let (result_tx, rx) = oneshot::channel();
let cmd = AdexBehaviourCmd::GetPeersInfo { result_tx };
cmd_tx.send(cmd).await.expect("Rx should be present");
Expand Down
9 changes: 5 additions & 4 deletions mm2src/mm2_p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ use sha2::{Digest, Sha256};
pub use crate::swarm_runtime::SwarmRuntime;

// atomicdex related re-exports
pub use behaviours::atomicdex::{get_gossip_mesh, get_gossip_peer_topics, get_gossip_topic_peers, get_peers_info,
get_relay_mesh, spawn_gossipsub, AdexBehaviourCmd, AdexBehaviourError,
AdexBehaviourEvent, AdexCmdTx, AdexEventRx, AdexResponse, AdexResponseChannel,
GossipsubEvent, GossipsubMessage, MessageId, NodeType, TopicHash, WssCerts};
pub use behaviours::atomicdex::{get_directly_connected_peers, get_gossip_mesh, get_gossip_peer_topics,
get_gossip_topic_peers, get_relay_mesh, spawn_gossipsub, AdexBehaviourCmd,
AdexBehaviourError, AdexBehaviourEvent, AdexCmdTx, AdexEventRx, AdexResponse,
AdexResponseChannel, GossipsubEvent, GossipsubMessage, MessageId, NodeType, TopicHash,
WssCerts};

// peers-exchange re-exports
pub use behaviours::peers_exchange::PeerAddresses;
Expand Down

0 comments on commit a2643f0

Please sign in to comment.