Skip to content

Commit

Permalink
Implement orderbook request (#744)
Browse files Browse the repository at this point in the history
* Impl process_get_orderbook_request(), add green test

* Remove asks_n, bids_n from Ordermatch::GetOrderbook request

* Remove orders_trie_root from GetOrderbookPubkeyItem

* Remove all_orders_trie_root
* Replace orders_trie_root with trie_roots within PubkeyKeepAlive
* Remove SyncPubkeyOrderbookState::[current_orders_trie_root, expected_orders_trie_root]
*

* Remove pair_orders_trie_root from GetOrderbookPubkeyItem

* Implement request_and_fill_orderbook()
* Separate process_orders_keep_alive into itself, process_pubkey_full_trie, process_trie_delta
* Add green test for request_and_fill_orderbook

* Allow mm2_tests::spin_n_nodes be a dead_code

* Refactor process_pubkey_full_trie, process_trie_delta, DeltaOrFullTrie::from_history

* Add clear order history of pair on remove_and_purge_pubkey_pair_orders()
* Change order_pairs_trie_state_history type to HashMap<AlbOrderedOrderbookPair, TrieOrderHistory>

* Set request_orderbook to true

* Rollback alice_can_see_the_active_order_after_connection changes
to ensure that orderbook is received immediately by requesting it from other peers.
Enable TEST MM2 stage on CI back.

* cargo +nightly test on CI.

* Fix alice_can_see_the_active_order_after_connection

* Rollback test changes made for tests to pass without orderbook requests.

* Fix tests.

* Try to turn off the metrics temporary.

* Rollback metrics init turn off for tests to pass. Will test in separate branch.

* Add pair_trie_root and timestamp to maker order related messages.

* Add last_signed_pubkey_payload to GetOrderbookPubkeyItem and SyncPubkeyOrderbookStateRes.

* Pass i_am_relay to process_orders_keep_alive to properly fill trie_roots_to_request.

Co-authored-by: Artem Pikulin <ortgma@gmail.com>
  • Loading branch information
sergeyboyko0791 and artemii235 authored Nov 23, 2020
1 parent f5c4418 commit dc46f4c
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 727 deletions.
3 changes: 1 addition & 2 deletions azure-pipelines-build-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ jobs:
displayName: 'Build MM2 Debug'
# Explicit --test-threads=16 makes testing process slightly faster on agents that have <16 CPU cores.
- bash: |
cargo test --features native --all -- --test-threads=16
cargo +nightly test --features native --all -- --test-threads=16
displayName: 'Test MM2'
timeoutInMinutes: 22
env:
BOB_PASSPHRASE: $(${{ parameters.bob_passphrase }})
BOB_USERPASS: $(${{ parameters.bob_userpass }})
ALICE_PASSPHRASE: $(${{ parameters.alice_passphrase }})
ALICE_USERPASS: $(${{ parameters.alice_userpass }})
enabled: false
- bash: |
cargo +nightly clippy --features native -- -D warnings
displayName: 'Check Clippy warnings'
Expand Down
27 changes: 0 additions & 27 deletions mm2src/docker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,6 @@ mod docker_tests {
log!([block_on(enable_native(&mm_alice, "MYCOIN", vec![]))]);
log!([block_on(enable_native(&mm_alice, "MYCOIN1", vec![]))]);

log!("Get MYCOIN/MYCOIN1 orderbook on Alice side to trigger subscription");
let rc = unwrap!(block_on(mm_alice.rpc(json! ({
"userpass": mm_alice.userpass,
"method": "orderbook",
"base": "MYCOIN",
"rel": "MYCOIN1",
}))));
assert!(rc.0.is_success(), "!orderbook: {}", rc.1);

let rc = unwrap!(block_on(mm_bob.rpc(json! ({
"userpass": mm_bob.userpass,
"method": "setprice",
Expand Down Expand Up @@ -779,15 +770,6 @@ mod docker_tests {
log!([block_on(enable_native(&mm_alice, "MYCOIN", vec![]))]);
log!([block_on(enable_native(&mm_alice, "MYCOIN1", vec![]))]);

log!("Get MYCOIN/MYCOIN1 orderbook on Alice side to trigger subscription");
let rc = unwrap!(block_on(mm_alice.rpc(json! ({
"userpass": mm_alice.userpass,
"method": "orderbook",
"base": "MYCOIN",
"rel": "MYCOIN1",
}))));
assert!(rc.0.is_success(), "!orderbook: {}", rc.1);

let rc = unwrap!(block_on(mm_bob.rpc(json! ({
"userpass": mm_bob.userpass,
"method": "setprice",
Expand Down Expand Up @@ -934,15 +916,6 @@ mod docker_tests {
log!([block_on(enable_native(&mm_bob, "MYCOIN1", vec![]))]);
log!([block_on(enable_native(&mm_alice, "MYCOIN", vec![]))]);
log!([block_on(enable_native(&mm_alice, "MYCOIN1", vec![]))]);
// TODO remove this request when orderbook request is reimplemented using tries
log!("Get MYCOIN/MYCOIN1 orderbook on Alice side to trigger subscription");
let rc = unwrap!(block_on(mm_alice.rpc(json! ({
"userpass": mm_alice.userpass,
"method": "orderbook",
"base": "MYCOIN",
"rel": "MYCOIN1",
}))));
assert!(rc.0.is_success(), "!orderbook: {}", rc.1);

let rc = unwrap!(block_on(mm_bob.rpc(json! ({
"userpass": mm_bob.userpass,
Expand Down
10 changes: 8 additions & 2 deletions mm2src/lp_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ async fn process_p2p_message(
}

if !orderbook_pairs.is_empty() {
let process_fut = lp_ordermatch::process_msg(ctx.clone(), orderbook_pairs, peer_id.to_string(), &message.data);
let process_fut = lp_ordermatch::process_msg(
ctx.clone(),
orderbook_pairs,
peer_id.to_string(),
&message.data,
i_am_relay,
);
if process_fut.await {
to_propagate = true;
}
Expand Down Expand Up @@ -177,7 +183,6 @@ pub async fn subscribe_to_topic(ctx: &MmArc, topic: String) {
}

#[cfg(feature = "native")]
#[allow(dead_code)]
pub async fn request_any_relay<T: de::DeserializeOwned>(
ctx: MmArc,
req: P2PRequest,
Expand Down Expand Up @@ -208,6 +213,7 @@ pub enum PeerDecodedResponse<T> {

#[allow(dead_code)]
#[cfg(feature = "native")]
#[allow(dead_code)]
pub async fn request_relays<T: de::DeserializeOwned>(
ctx: MmArc,
req: P2PRequest,
Expand Down
Loading

0 comments on commit dc46f4c

Please sign in to comment.