From ff6f4ebe94f44232bb7239d182a4d105389a7593 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 26 Mar 2024 14:54:11 +0000 Subject: [PATCH] up logging --- Cargo.lock | 176 ++++++++++++++++++++++++- Cargo.toml | 23 +++- mantis/node/Cargo.toml | 3 +- mantis/node/src/bin/mantis.rs | 187 +++++++++++++-------------- mantis/node/src/mantis/cosmos/cvm.rs | 10 ++ mantis/node/src/mantis/cosmos/mod.rs | 1 + 6 files changed, 299 insertions(+), 101 deletions(-) create mode 100644 mantis/node/src/mantis/cosmos/cvm.rs diff --git a/Cargo.lock b/Cargo.lock index e282960f..fb16ff7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ "anstyle", "anstyle-parse", @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" @@ -1233,12 +1233,44 @@ dependencies = [ "syn 2.0.52", ] +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b73807008a3c7f171cc40312f37d95ef0396e048b5848d775f54b1a4dd4a0d3" +dependencies = [ + "serde", +] + [[package]] name = "errno" version = "0.3.7" @@ -1570,6 +1602,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.27" @@ -2229,6 +2267,12 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "serde", + "sval", + "sval_ref", + "value-bag", +] [[package]] name = "mantis-node" @@ -2244,6 +2288,7 @@ dependencies = [ "cvm-runtime", "cw-mantis-order", "derive_more", + "env_logger", "fraction", "good_lp", "itertools 0.12.0", @@ -3344,6 +3389,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "serde_fmt" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" +dependencies = [ + "serde", +] + [[package]] name = "serde_json" version = "1.0.108" @@ -3549,6 +3603,84 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" +[[package]] +name = "sval" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82a2386bea23a121e4e72450306b1dd01078b6399af11b93897bf84640a28a59" + +[[package]] +name = "sval_buffer" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16c047898a0e19002005512243bc9ef1c1037aad7d03d6c594e234efec80795" +dependencies = [ + "sval", + "sval_ref", +] + +[[package]] +name = "sval_dynamic" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a74fb116e2ecdcb280b0108aa2ee4434df50606c3208c47ac95432730eaac20c" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_fmt" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10837b4f0feccef271b2b1c03784e08f6d0bb6d23272ec9e8c777bfadbb8f1b8" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_json" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891f5ecdf34ce61a8ab2d10f9cfdc303347b0afec4dad6702757419d2d8312a9" +dependencies = [ + "itoa", + "ryu", + "sval", +] + +[[package]] +name = "sval_nested" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63fcffb4b79c531f38e3090788b64f3f4d54a180aacf02d69c42fa4e4bf284c3" +dependencies = [ + "sval", + "sval_buffer", + "sval_ref", +] + +[[package]] +name = "sval_ref" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af725f9c2aa7cec4ca9c47da2cc90920c4c82d3fa537094c66c77a5459f5809d" +dependencies = [ + "sval", +] + +[[package]] +name = "sval_serde" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7589c649a03d21df40b9a926787d2c64937fa1dccec8d87c6cd82989a2e0a4" +dependencies = [ + "serde", + "sval", + "sval_nested", +] + [[package]] name = "sylvia" version = "0.9.1" @@ -4198,6 +4330,42 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +[[package]] +name = "value-bag" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" +dependencies = [ + "value-bag-serde1", + "value-bag-sval2", +] + +[[package]] +name = "value-bag-serde1" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc35703541cbccb5278ef7b589d79439fc808ff0b5867195a3230f9a47421d39" +dependencies = [ + "erased-serde", + "serde", + "serde_fmt", +] + +[[package]] +name = "value-bag-sval2" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "285b43c29d0b4c0e65aad24561baee67a1b69dc9be9375d4a85138cbf556f7f8" +dependencies = [ + "sval", + "sval_buffer", + "sval_dynamic", + "sval_fmt", + "sval_json", + "sval_ref", + "sval_serde", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 017ce1c3..54d84330 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,10 @@ [workspace] -members = ["crates/*", "contracts/cosmwasm/*", "mantis/node", "mantis/blackbox_rs"] +members = [ + "crates/*", + "contracts/cosmwasm/*", + "mantis/node", + "mantis/blackbox_rs", +] exclude = ["contracts/cosmwasm/node_modules/", "contracts/cosmwasm/dist"] resolver = "2" package.version = "0.3.0" @@ -45,6 +50,21 @@ derive_more = { version = "0.99.17", default-features = false, features = [ "try_into", "unwrap", ] } +log = { version = "0.4.21", default_features = false, features = [ + "std", + "serde", + "kv_std", + "kv_sval", + "kv_serde", +] } +env_logger = { version = "*", default-features = false, features = [ + "default", + "color", + "auto-color", + "humantime", + "regex", + "unstable-kv", +] } hex = { version = "^0.4.3", default-features = false } num = { version = "^0.4.1", default-features = false } enumn = { version = "0.1.12" } @@ -54,7 +74,6 @@ cosmwasm-std = { version = "^1.5.0", features = [ "iterator", ], default-features = false } -log = { version = "0.4.21", default-features = true} parity-scale-codec = { version = "^3.6.5", default-features = false } cw20 = { version = "^1.1.2", default-features = false } cw-controllers = { version = "^1.1.1", default-features = false } diff --git a/mantis/node/Cargo.toml b/mantis/node/Cargo.toml index 13a9a46e..e6eaa68f 100644 --- a/mantis/node/Cargo.toml +++ b/mantis/node/Cargo.toml @@ -23,6 +23,7 @@ cw-mantis-order = { workspace = true, features = [ "json-schema", "std", ] } +log = { workspace = true } derive_more = { workspace = true, features = [] } itertools = { workspace = true, features = []} num-traits = { workspace = true, features = ["std"]} @@ -42,7 +43,7 @@ cvm-runtime = { workspace = true, features = ["std"] } ndarray ={ workspace = true, features = ["std", "serde"]} good_lp = {workspace = true, features = ["coin_cbc", "singlethread-cbc"]} fraction = {workspace = true, features = ["default"]} -log ={ workspace = true} +env_logger = {workspace = true} [dev-dependencies] rustfmt-wrapper = "0.2.1" \ No newline at end of file diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index b168b430..ddfae5e1 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -43,9 +43,81 @@ async fn main() { MantisCommands::Glt(_) => todo!(), } - match args.command { - MantisCommands::Solve(args) => { - let mut wasm_read_client = create_wasm_query_client(&args.grpc_centauri).await; + // match args.command { + // MantisCommands::Solve(args) => { + // let mut wasm_read_client = create_wasm_query_client(&args.grpc_centauri).await; + + // let signer = mantis_node::mantis::cosmos::signer::from_mnemonic( + // args.wallet.as_str(), + // "m/44'/118'/0'/0/0", + // ) + // .expect("mnemonic"); + // let gas = args.gas; + // let mut cosmos_query_client = create_cosmos_query_client(&args.rpc_centauri).await; + // let mut write_client = create_wasm_write_client(&args.rpc_centauri).await; + + + // let start = std::time::Instant::now(); + // loop { + + // if start.elapsed().as_millis() % 10000 == 0 { + // let tip = get_latest_block_and_account_by_key( + // &args.rpc_centauri, + // &args.grpc_centauri, + // &signer, + // ) + // .await; + // autopilot::cleanup( + // &mut write_client, + // &mut cosmos_query_client, + // args.order_contract.clone(), + // &signer, + // &args.rpc_centauri, + // &tip, + // gas, + // ) + // .await; + // }; + + // let tip = get_latest_block_and_account_by_key( + // &args.rpc_centauri, + // &args.grpc_centauri, + // &signer, + // ) + // .await; + + // solve( + // &mut write_client, + // &mut wasm_read_client, + // &args.order_contract, + // &signer, + // &args.rpc_centauri, + // &tip, + // gas, + // ) + // .await; + // } + // } + // MantisCommands::Id(args) => match args.command { + // IdCommands::Asset(args) => match args.command { + // AssetCommands::Gen { + // network_id, + // asset_id, + // } => { + // println!( + // "{}", + // cvm_runtime::generate_asset_id(network_id.into(), 0, asset_id.into()) + // ); + // } + // }, + // }, + // } + +} + +async fn simulate_orders(mantis_args: &MantisArgs, simulate_args: &SimulateArgs) { + + let mut wasm_read_client = create_wasm_query_client(&args.grpc_centauri).await; let signer = mantis_node::mantis::cosmos::signer::from_mnemonic( args.wallet.as_str(), @@ -54,102 +126,29 @@ async fn main() { .expect("mnemonic"); let gas = args.gas; let mut cosmos_query_client = create_cosmos_query_client(&args.rpc_centauri).await; - print!("client 1"); let mut write_client = create_wasm_write_client(&args.rpc_centauri).await; - print!("client 2"); - - let start = std::time::Instant::now(); - loop { - if let Some(assets) = args.simulate.clone() { - if start.elapsed().as_millis() % 100 == 0 { - let tip = get_latest_block_and_account_by_key( - &args.rpc_centauri, - &args.grpc_centauri, - &signer, - ) - .await; - simulate::simulate_order( - &mut write_client, - &mut cosmos_query_client, - args.order_contract.clone(), - assets, - &signer, - &args.rpc_centauri, - &tip, - gas, - ) - .await; - }; - }; - - if start.elapsed().as_millis() % 10000 == 0 { - let tip = get_latest_block_and_account_by_key( - &args.rpc_centauri, - &args.grpc_centauri, - &signer, - ) - .await; - autopilot::cleanup( - &mut write_client, - &mut cosmos_query_client, - args.order_contract.clone(), - &signer, - &args.rpc_centauri, - &tip, - gas, - ) - .await; - }; - - let tip = get_latest_block_and_account_by_key( - &args.rpc_centauri, - &args.grpc_centauri, - &signer, - ) - .await; - - solve( - &mut write_client, - &mut wasm_read_client, - &args.order_contract, - &signer, - &args.rpc_centauri, - &tip, - gas, - ) - .await; - } - } - MantisCommands::Id(args) => match args.command { - IdCommands::Asset(args) => match args.command { - AssetCommands::Gen { - network_id, - asset_id, - } => { - println!( - "{}", - cvm_runtime::generate_asset_id(network_id.into(), 0, asset_id.into()) - ); - } - }, - }, - } -} + log::info!("Simulating orders"); -async fn simulate_orders(args: &MantisArgs, x: &SimulateArgs) -> _ { - todo!() + let tip = get_latest_block_and_account_by_key( + &args.rpc_centauri, + &args.grpc_centauri, + &signer, + ) + .await; + simulate::simulate_order( + &mut write_client, + &mut cosmos_query_client, + args.order_contract.clone(), + assets, + &signer, + &args.rpc_centauri, + &tip, + gas, + ) + .await; } -/// given key and latest block and sequence number, produces binary salt for cross chain block -/// isolating execution of one cross chain transaction from other -fn get_salt(signing_key: &cosmrs::crypto::secp256k1::SigningKey, tip:&Tip) -> Vec { - let mut base = signing_key.public_key().to_bytes().to_vec(); - base.extend(tip.block.value().to_be_bytes().to_vec()); - base.extend(tip.account.sequence.to_be_bytes().to_vec()); - base -} - /// gets orders, groups by pairs /// solves them using algorithm /// if any volume solved, posts solution diff --git a/mantis/node/src/mantis/cosmos/cvm.rs b/mantis/node/src/mantis/cosmos/cvm.rs new file mode 100644 index 00000000..2ea07361 --- /dev/null +++ b/mantis/node/src/mantis/cosmos/cvm.rs @@ -0,0 +1,10 @@ +use super::client::Tip; + +/// given key and latest block and sequence number, produces binary salt for cross chain block +/// isolating execution of one cross chain transaction from other +pub fn get_salt(signing_key: &cosmrs::crypto::secp256k1::SigningKey, tip:&Tip) -> Vec { + let mut base = signing_key.public_key().to_bytes().to_vec(); + base.extend(tip.block.value().to_be_bytes().to_vec()); + base.extend(tip.account.sequence.to_be_bytes().to_vec()); + base +} \ No newline at end of file diff --git a/mantis/node/src/mantis/cosmos/mod.rs b/mantis/node/src/mantis/cosmos/mod.rs index 611f5cbd..a19e2a42 100644 --- a/mantis/node/src/mantis/cosmos/mod.rs +++ b/mantis/node/src/mantis/cosmos/mod.rs @@ -1,3 +1,4 @@ pub mod client; pub mod cosmwasm; pub mod signer; +pub mod cvm;