Skip to content

Commit

Permalink
Stop banning on NegotiateFailed. Stop processing messages from banned…
Browse files Browse the repository at this point in the history
… pub. (#896)

#886

* WIP. Added ban_pubkey_rpc for testing convenience.

* WIP.

* WIP.

* Don't ban on NegotiateFailed.
Skip all messages from banned pubkey in lp_ordermatch::process_msg.

* Refactor tests.

* Move MM_VERSION and MM_DATETIME to mm2
To avoid rebuilding common crate every time

* Fix root() in build.rs after movement.
  • Loading branch information
artemii235 authored Apr 9, 2021
1 parent d3e81c3 commit 7cb5800
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 647 deletions.
135 changes: 1 addition & 134 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ rand4 = { version = "0.4", package = "rand" }
testcontainers = { git = "https://github.com/artemii235/testcontainers-rs.git" }
winapi = "0.3"

[build-dependencies]
chrono = "0.4"
gstuff = { version = "0.6", features = ["nightly", "term"] }
regex = "1"

[workspace]
members = [
"mm2src/coins",
Expand Down
124 changes: 124 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use chrono::DateTime;
use gstuff::slurp;
use regex::Regex;
use std::fs;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::from_utf8;

/// Absolute path taken from SuperNET's root + `path`.
fn rabs(rrel: &str) -> PathBuf { root().join(rrel) }

fn path2s(path: PathBuf) -> String {
path.to_str()
.unwrap_or_else(|| panic!("Non-stringy path {:?}", path))
.into()
}

/// SuperNET's root.
fn root() -> PathBuf {
let super_net = Path::new(env!("CARGO_MANIFEST_DIR"));
let super_net = match super_net.canonicalize() {
Ok(p) => p,
Err(err) => panic!("Can't canonicalize {:?}: {}", super_net, err),
};
// On Windows we're getting these "\\?\" paths from canonicalize but they aren't any good for CMake.
if cfg!(windows) {
let s = path2s(super_net);
let stripped = match s.strip_prefix(r"\\?\") {
Some(stripped) => stripped,
None => &s,
};
Path::new(stripped).into()
} else {
super_net
}
}

/// This function ensures that we have the “MM_VERSION” and “MM_DATETIME” variables during the build.
///
/// The build script will usually help us by putting the MarketMaker version into the “MM_VERSION” file
/// and the corresponding ISO 8601 time into the “MM_DATETIME” file
/// (environment variable isn't as useful because we can't `rerun-if-changed` on it).
///
/// For the nightly builds the version contains the short commit hash.
///
/// We're also trying to get the hash and the time from Git.
///
/// Git information isn't always available during the build (for instance, when a build server is used,
/// we might skip synchronizing the Git repository there),
/// but if it is, then we're going to check if the “MM_DATETIME” and the Git data match.
fn mm_version() -> String {
// Try to load the variable from the file.
let mm_version_p = root().join("MM_VERSION");
let mut buf;
let version = if let Ok(mut mm_version_f) = fs::File::open(&mm_version_p) {
buf = String::new();
mm_version_f
.read_to_string(&mut buf)
.expect("Can't read from MM_VERSION");
buf.trim().to_string()
} else {
// If the “MM_VERSION” file is absent then we should create it
// in order for the Cargo dependency management to see it,
// because Cargo will keep rebuilding the `common` crate otherwise.
//
// We should probably fetch the actual git version here,
// with something like `git log '--pretty=format:%h' -n 1` for the nightlies,
// and a release tag when building from some kind of a stable branch,
// though we should keep the ability for the tooling to provide the “MM_VERSION”
// externally, because moving the entire ".git" around is not always practical.

let mut version = "UNKNOWN".to_string();
let mut command = Command::new("git");
command.arg("log").arg("--pretty=format:%h").arg("-n1");
if let Ok(go) = command.output() {
if go.status.success() {
version = from_utf8(&go.stdout).unwrap().trim().to_string();
if !Regex::new(r"^\w+$").unwrap().is_match(&version) {
panic!("{}", version)
}
}
}

if let Ok(mut mm_version_f) = fs::File::create(&mm_version_p) {
mm_version_f.write_all(version.as_bytes()).unwrap();
}
version
};
println!("cargo:rustc-env=MM_VERSION={}", version);

let mut dt_git = None;
let mut command = Command::new("git");
command.arg("log").arg("--pretty=format:%cI").arg("-n1"); // ISO 8601
if let Ok(go) = command.output() {
if go.status.success() {
let got = from_utf8(&go.stdout).unwrap().trim();
let _dt_check = DateTime::parse_from_rfc3339(got).unwrap();
dt_git = Some(got.to_string());
}
}

let mm_datetime_p = root().join("MM_DATETIME");
let dt_file = String::from_utf8(slurp(&mm_datetime_p)).unwrap();
let mut dt_file = dt_file.trim().to_string();
if let Some(ref dt_git) = dt_git {
if dt_git[..] != dt_file[..] {
// Create or update the “MM_DATETIME” file in order to appease the Cargo dependency management.
let mut mm_datetime_f = fs::File::create(&mm_datetime_p).unwrap();
mm_datetime_f.write_all(dt_git.as_bytes()).unwrap();
dt_file = dt_git.clone();
}
}

println!("cargo:rustc-env=MM_DATETIME={}", dt_file);

version
}

fn main() {
println!("cargo:rerun-if-changed={}", path2s(rabs("MM_VERSION")));
println!("cargo:rerun-if-changed={}", path2s(rabs("MM_DATETIME")));
mm_version();
}
4 changes: 2 additions & 2 deletions mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use common::first_char_to_upper;
use common::jsonrpc_client::JsonRpcError;
use common::mm_ctx::MmArc;
use common::mm_metrics::MetricsArc;
use common::{small_rng, MM_VERSION};
use common::small_rng;
#[cfg(not(target_arch = "wasm32"))] use dirs::home_dir;
use futures::channel::mpsc;
use futures::compat::Future01CompatExt;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ pub trait UtxoCoinBuilder {
let client = Arc::new(client);

let weak_client = Arc::downgrade(&client);
let client_name = format!("{} GUI/MM2 {}", ctx.gui().unwrap_or("UNKNOWN"), MM_VERSION);
let client_name = format!("{} GUI/MM2 {}", ctx.gui().unwrap_or("UNKNOWN"), ctx.mm_version());
spawn_electrum_version_loop(weak_client, on_connect_rx, client_name);

try_s!(wait_for_protocol_version_checked(&client).await);
Expand Down
Loading

0 comments on commit 7cb5800

Please sign in to comment.