From c2a942336cfc3cca88eae101574e4bc3dbea1af5 Mon Sep 17 00:00:00 2001 From: Riordan Panayides Date: Wed, 4 Jan 2023 00:04:35 +0000 Subject: [PATCH] Set up fly deployments, upgrade mango-v4 --- Cargo.lock | 39 +++++++++++++++++------------ Cargo.toml | 6 ++--- Dockerfile | 17 +++++++------ fly.toml | 25 +++++++++++++++--- lib/Cargo.toml | 2 +- lib/src/fill_event_filter.rs | 7 +++--- lib/src/orderbook_filter.rs | 7 +----- service-mango-fills/Cargo.toml | 4 +-- service-mango-fills/src/main.rs | 13 +++++----- service-mango-orderbook/Cargo.toml | 4 +-- service-mango-orderbook/src/main.rs | 5 ++-- service-mango-pnl/Cargo.toml | 4 +-- service-mango-pnl/src/main.rs | 2 +- 13 files changed, 76 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ac66b0..7241da3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,7 +104,7 @@ checksum = "6b2d54853319fd101b8dd81de382bcbf3e03410a64d8928bbee85a3e7dcde483" [[package]] name = "anchor-attribute-access-control" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -117,7 +117,7 @@ dependencies = [ [[package]] name = "anchor-attribute-account" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -131,7 +131,7 @@ dependencies = [ [[package]] name = "anchor-attribute-constant" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "proc-macro2 1.0.47", @@ -141,7 +141,7 @@ dependencies = [ [[package]] name = "anchor-attribute-error" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "proc-macro2 1.0.47", @@ -152,7 +152,7 @@ dependencies = [ [[package]] name = "anchor-attribute-event" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -164,7 +164,7 @@ dependencies = [ [[package]] name = "anchor-attribute-interface" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -177,7 +177,7 @@ dependencies = [ [[package]] name = "anchor-attribute-program" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -189,7 +189,7 @@ dependencies = [ [[package]] name = "anchor-attribute-state" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -201,7 +201,7 @@ dependencies = [ [[package]] name = "anchor-client" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-lang", "anyhow", @@ -217,7 +217,7 @@ dependencies = [ [[package]] name = "anchor-derive-accounts" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-syn", "anyhow", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "anchor-lang" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", @@ -252,7 +252,7 @@ dependencies = [ [[package]] name = "anchor-spl" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-lang", "solana-program", @@ -263,7 +263,7 @@ dependencies = [ [[package]] name = "anchor-syn" version = "0.25.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anyhow", "bs58 0.3.1", @@ -411,6 +411,12 @@ dependencies = [ "event-listener", ] +[[package]] +name = "async-once-cell" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f61305cacf1d0c5c9d3ee283d22f8f1f8c743a18ceb44a1b102bd53476c141de" + [[package]] name = "async-stream" version = "0.2.1" @@ -966,7 +972,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "checked_math" version = "0.1.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "proc-macro-error", "proc-macro2 1.0.47", @@ -1072,12 +1078,13 @@ dependencies = [ [[package]] name = "client" version = "0.1.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-client", "anchor-lang", "anchor-spl", "anyhow", + "async-once-cell", "async-trait", "base64 0.13.1", "bincode", @@ -3005,7 +3012,7 @@ dependencies = [ [[package]] name = "mango-v4" version = "0.1.0" -source = "git+https://github.com/blockworks-foundation/mango-v4?branch=dev#7a8f31c6118b0577aa6375af4643e41efe85e057" +source = "git+https://github.com/blockworks-foundation/mango-v4?branch=ckamm/accountfetcher-send#0bad232315b6c5ddf420d728dfcb13c18a0fb50f" dependencies = [ "anchor-lang", "anchor-spl", diff --git a/Cargo.toml b/Cargo.toml index 392599a..d6a6bc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = [ # for gzip encoded responses jsonrpc-core-client = { git = "https://github.com/ckamm/jsonrpc.git", branch = "ckamm/http-with-gzip" } # force usage of mango-v4 submodules with 1.14.9 support -anchor-spl = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } -anchor-lang = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } -anchor-client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } +anchor-spl = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } +anchor-lang = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } +anchor-client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } switchboard-v2 = { git = "https://github.com/blockworks-foundation/sbv2-solana", branch = "mango-v4" } diff --git a/Dockerfile b/Dockerfile index 4d397dc..4fb782a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,25 @@ # syntax = docker/dockerfile:1.2 # Base image containing all binaries, deployed to gcr.io/mango-markets/mango-geyser-services:latest -FROM rust:1.59.0 as base -RUN cargo install cargo-chef +FROM rust:1.65.0 as base +# RUN cargo install cargo-chef RUN rustup component add rustfmt -RUN apt-get update && apt-get install -y clang cmake +RUN apt-get update && apt-get install -y clang cmake ssh WORKDIR /app FROM base AS plan COPY . . WORKDIR /app -RUN cargo chef prepare --recipe-path recipe.json +# RUN cargo chef prepare --recipe-path recipe.json FROM base as build -COPY --from=plan /app/recipe.json recipe.json -RUN cargo chef cook --release --recipe-path recipe.json +# COPY --from=plan /app/recipe.json recipe.json +# RUN cargo chef cook --release --recipe-path recipe.json COPY . . -RUN cargo build --release --bin service-mango-fills --bin service-mango-pnl +RUN cargo build --release --bin service-mango-fills --bin service-mango-pnl --bin service-mango-orderbook FROM debian:bullseye-slim as run RUN apt-get update && apt-get -y install ca-certificates libc6 COPY --from=build /app/target/release/service-mango-* /usr/local/bin/ COPY --from=build /app/service-mango-pnl/template-config.toml ./pnl-config.toml -COPY --from=build /app/service-mango-fills/template-config.toml ./fills-config.toml \ No newline at end of file +COPY --from=build /app/service-mango-fills/template-config.toml ./fills-config.toml +COPY --from=build /app/service-mango-orderbook/template-config.toml ./orderbook-config.toml \ No newline at end of file diff --git a/fly.toml b/fly.toml index 6c8b65e..0c7ed13 100644 --- a/fly.toml +++ b/fly.toml @@ -3,12 +3,13 @@ app = "mango-geyser-services" kill_signal = "SIGINT" kill_timeout = 5 -[build] - image = "us-docker.pkg.dev/mango-markets/gcr.io/mango-geyser-services:latest" +# [build] +# image = "us-docker.pkg.dev/mango-markets/gcr.io/mango-geyser-services:latest" [processes] fills = "service-mango-fills fills-config.toml" pnl = "service-mango-pnl pnl-config.toml" + orderbook = "service-mango-orderbook orderbook-config.toml" [[services]] processes = ["fills"] @@ -16,6 +17,7 @@ kill_timeout = 5 protocol = "tcp" [[services.ports]] + handlers = ["tls", "http"] port = "8080" [services.concurrency] @@ -25,11 +27,26 @@ kill_timeout = 5 [[services]] processes = ["pnl"] - internal_port = 2052 + internal_port = 8081 protocol = "tcp" [[services.ports]] - port = "2052" + handlers = ["tls", "http"] + port = 8081 + + [services.concurrency] + type = "connections" + hard_limit = 1024 + soft_limit = 1024 + +[[services]] + processes = ["orderbook"] + internal_port = 8082 + protocol = "tcp" + + [[services.ports]] + handlers = ["tls", "http"] + port = "8082" [services.concurrency] type = "connections" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index db3bac2..82f7e9c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -16,7 +16,7 @@ solana-client = "~1.14.9" solana-account-decoder = "~1.14.9" solana-sdk = "~1.14.9" -mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } +mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } arrayref = "*" bytemuck = "*" fixed = { version = "*", features = ["serde"] } diff --git a/lib/src/fill_event_filter.rs b/lib/src/fill_event_filter.rs index 9ce6095..8aaec2e 100644 --- a/lib/src/fill_event_filter.rs +++ b/lib/src/fill_event_filter.rs @@ -326,7 +326,7 @@ fn publish_changes_serum( let mkt_pk_string = mkt.0.to_string(); let evq_pk_string = mkt.1.to_string(); let header_seq_num = header.seq_num; - info!("start seq {} header seq {}", start_seq_num, header_seq_num); + debug!("start seq {} header seq {}", start_seq_num, header_seq_num); for seq_num in start_seq_num..header_seq_num { let idx = (seq_num % MAX_NUM_EVENTS as u64) as usize; let event_view = events[idx].as_view().unwrap(); @@ -340,7 +340,7 @@ fn publish_changes_serum( // 3) all other events are matching the old event queue // the order of these checks is important so they are exhaustive if seq_num >= old_seq_num { - info!("found new serum fill {} idx {}", mkt_pk_string, idx,); + debug!("found new serum fill {} idx {}", mkt_pk_string, idx,); metric_events_new.increment(); fill_update_sender @@ -359,12 +359,11 @@ fn publish_changes_serum( match old_event_view { EventView::Fill { .. } => { - info!("already got all fills???"); // every already published event is recorded in checkpoint checkpoint.push(events[idx]); } EventView::Out { .. } => { - info!( + debug!( "found changed event {} idx {} seq_num {} header seq num {} old seq num {}", mkt_pk_string, idx, seq_num, header_seq_num, old_seq_num ); diff --git a/lib/src/orderbook_filter.rs b/lib/src/orderbook_filter.rs index 67b5cfe..aa9a5c3 100644 --- a/lib/src/orderbook_filter.rs +++ b/lib/src/orderbook_filter.rs @@ -147,7 +147,6 @@ fn publish_changes( match peer { None => { - info!("level removed {}", previous_order.price); update.push(OrderbookLevel { price: previous_order.price, size: 0f64, @@ -203,7 +202,7 @@ fn publish_changes( if update.len() == 0 { return; } - info!("diff {} {:?}", mkt.1.name, update); + orderbook_update_sender .try_send(OrderbookFilterMessage::Update(OrderbookUpdate { market: mkt.0.to_string(), @@ -237,7 +236,6 @@ fn publish_changes_serum( match peer { None => { - info!("level removed {}", previous_order.price); update.push(OrderbookLevel { price: previous_order.price, size: 0f64, @@ -290,7 +288,6 @@ fn publish_changes_serum( None => info!("other bookside not in cache"), } - info!("diff {} {:?}", mkt.1.name, update); if update.len() > 0 { orderbook_update_sender .try_send(OrderbookFilterMessage::Update(OrderbookUpdate { @@ -352,7 +349,6 @@ pub async fn init( if !relevant_pubkeys.contains(&account_write.pubkey) { continue; } - info!("updating account {}", &account_write.pubkey); chain_cache.update_account( account_write.pubkey, AccountData { @@ -470,7 +466,6 @@ pub async fn init( let account = &mut account_info.account.clone(); let data = account.data_as_mut_slice(); let len = data.len(); - info!("side pk {} side {}", side_pk, side); let inner = &mut data[5..len - 7]; let slab = Slab::new(&mut inner[size_of::()..]); diff --git a/service-mango-fills/Cargo.toml b/service-mango-fills/Cargo.toml index 2e94ff9..b56c273 100644 --- a/service-mango-fills/Cargo.toml +++ b/service-mango-fills/Cargo.toml @@ -24,8 +24,8 @@ tokio = { version = "1", features = ["full"] } tokio-tungstenite = "0.17" bytemuck = "1.7.2" -mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } -client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } +mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } +client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } serum_dex = { git = "https://github.com/jup-ag/openbook-program", branch = "feat/expose-things" } anchor-lang = "0.25.0" anchor-client = "0.25.0" diff --git a/service-mango-fills/src/main.rs b/service-mango-fills/src/main.rs index 53d7863..f6e6d4c 100644 --- a/service-mango-fills/src/main.rs +++ b/service-mango-fills/src/main.rs @@ -275,10 +275,9 @@ async fn main() -> anyhow::Result<()> { Some(rpc_timeout), ); let group_context = Arc::new(MangoGroupContext::new_from_rpc( + &client.rpc_async(), Pubkey::from_str(&config.mango_group).unwrap(), - client.cluster.clone(), - client.commitment, - )?); + ).await?); let perp_queue_pks: Vec<(Pubkey, Pubkey)> = group_context .perp_markets @@ -293,8 +292,8 @@ async fn main() -> anyhow::Result<()> { .collect(); let serum_market_ais = client - .rpc() - .get_multiple_accounts(serum_market_pks.as_slice())?; + .rpc_async() + .get_multiple_accounts(serum_market_pks.as_slice()).await?; let serum_market_ais: Vec<&Account> = serum_market_ais .iter() .filter_map(|maybe_ai| match maybe_ai { @@ -317,11 +316,11 @@ async fn main() -> anyhow::Result<()> { let a: Vec<(String, String)> = group_context .serum3_markets .iter() - .map(|(_, context)| (context.market.name().to_owned(), context.market.serum_market_external.to_string())).collect(); + .map(|(_, context)| (context.market.serum_market_external.to_string(), context.market.name().to_owned())).collect(); let b: Vec<(String, String)> = group_context .perp_markets .iter() - .map(|(_, context)| (context.market.name().to_owned(), context.address.to_string())).collect(); + .map(|(_, context)| (context.address.to_string(), context.market.name().to_owned())).collect(); let market_pubkey_strings: HashMap = [a, b] .concat() .into_iter() diff --git a/service-mango-orderbook/Cargo.toml b/service-mango-orderbook/Cargo.toml index cad41db..88467a1 100644 --- a/service-mango-orderbook/Cargo.toml +++ b/service-mango-orderbook/Cargo.toml @@ -24,8 +24,8 @@ tokio = { version = "1", features = ["full"] } tokio-tungstenite = "0.17" bytemuck = "1.7.2" -mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } -client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } +mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } +client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } serum_dex = { git = "https://github.com/openbook-dex/program", branch = "master" } anchor-lang = "0.25.0" anchor-client = "0.25.0" diff --git a/service-mango-orderbook/src/main.rs b/service-mango-orderbook/src/main.rs index 5102bff..4a9bf93 100644 --- a/service-mango-orderbook/src/main.rs +++ b/service-mango-orderbook/src/main.rs @@ -286,10 +286,9 @@ async fn main() -> anyhow::Result<()> { Some(rpc_timeout), ); let group_context = Arc::new(MangoGroupContext::new_from_rpc( + &client.rpc_async(), Pubkey::from_str(&config.mango_group).unwrap(), - client.cluster.clone(), - client.commitment, - )?); + ).await?); // todo: reload markets at intervals let market_configs: Vec<(Pubkey, MarketConfig)> = group_context diff --git a/service-mango-pnl/Cargo.toml b/service-mango-pnl/Cargo.toml index a3f9558..e958aea 100644 --- a/service-mango-pnl/Cargo.toml +++ b/service-mango-pnl/Cargo.toml @@ -21,7 +21,7 @@ tokio = { version = "1", features = ["full"] } serde = "1.0.130" serde_derive = "1.0.130" -mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } -client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "dev" } +mango-v4 = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } +client = { git = "https://github.com/blockworks-foundation/mango-v4", branch = "ckamm/accountfetcher-send" } anchor-lang = "0.25.0" anchor-client = "0.25.0" diff --git a/service-mango-pnl/src/main.rs b/service-mango-pnl/src/main.rs index 87bcb44..1e36db6 100644 --- a/service-mango-pnl/src/main.rs +++ b/service-mango-pnl/src/main.rs @@ -119,7 +119,7 @@ fn start_pnl_updater( } let pnl_vals = - compute_pnl(context.clone(), account_fetcher.clone(), &mango_account.clone()).await.unwrap(); + compute_pnl(context.clone(), account_fetcher.clone(), &mango_account).await.unwrap(); // Alternatively, we could prepare the sorted and limited lists for each // market here. That would be faster and cause less contention on the pnl_data