Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payout curve short liquidation interval start payout can be incorrect #2288

Closed
bonomat opened this issue Mar 21, 2024 · 2 comments · Fixed by #2352
Closed

Payout curve short liquidation interval start payout can be incorrect #2288

bonomat opened this issue Mar 21, 2024 · 2 comments · Fixed by #2352
Assignees
Labels
bug Something isn't working

Comments

@bonomat
Copy link
Contributor

bonomat commented Mar 21, 2024

2024-03-21 04:53:06  INFO coordinator::trade: Executing match trader_id=03023bd502865822c47356883ac5c79981b6f3f857464054b41e69bc83d22c0d57 order_id=afaccc50-c064-40e2-8e91-301ff63324fa
2024-03-21 04:53:06  INFO coordinator::trade: Opening DLC channel and position peer_id=03023bd502865822c47356883ac5c79981b6f3f857464054b41e69bc83d22c0d57 order_id=afaccc50-c064-40e2-8e91-301ff63324fa trade_params=TradeParams { pubkey: PublicKey(570d2cd283bc691eb454404657f8f3b68199c7c53a885673c422588602d53b022b50c17b9f2d5e263a551375a56aab067643a022c92c01feada077b3743f3622), contract_symbol: BtcUsd, leverage: 2.0, quantity: 500.0, direction: Long, filled_with: FilledWith { order_id: afaccc50-c064-40e2-8e91-301ff63324fa, expiry_timestamp: 2024-03-22 0:00:00.0 +00:00:00, oracle_pk: XOnlyPublicKey(c071e1fd881a55831cc38c85986c6c72193b4e3a98bcbc460f6c1ed2f78cf8167458a18010faf718756c69de33ee9e38a0d3f0ad48befa58e23a4b1f843e08be), matches: [Match { id: 7f1717cf-3336-42ce-892c-52e49d0ae5fb, order_id: b9ef1c2e-c18c-41e9-8598-2eadfa4ffac2, quantity: 500, pubkey: PublicKey(d446917fae8d65f81a9598bcfb62d8e5049c88b7599d421731249a022a58aef82d1b0819d45e54899ef8f8f4067120ae6e0f1d44f53a0a7f2a04dd2bcb072d6b), execution_price: 65354.65 }] } } leverage_coordinator=2.0 margin_coordinator_sat=382528 margin_trader_sat=382528 order_matching_fee_sat=2295 collateral_reserve_with_fee_coordinator=2295 collateral_reserve_trader=0
2024-03-21 04:53:06  INFO build_contract_descriptor{initial_price=65354.65 coordinator_margin=382528 trader_margin=382528 leverage_coordinator=2.0 leverage_trader=2.0 coordinator_direction=Short coordinator_collateral_reserve=2295 trader_collateral_reserve=0 quantity=500.0 symbol=BtcUsd}: coordinator::payout_curve: Building contract descriptor
2024-03-21 04:53:06 ERROR build_contract_descriptor{initial_price=65354.65 coordinator_margin=382528 trader_margin=382528 leverage_coordinator=2.0 leverage_trader=2.0 coordinator_direction=Short coordinator_collateral_reserve=2295 trader_collateral_reserve=0 quantity=500.0 symbol=BtcUsd}: coordinator: Aborting after panic in task info=panicked at crates/payout_curve/src/lib.rs:389:13:
assertion failed: outcome_payout >= interval_start.outcome_payout
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/backtrace.rs:331:13
   3: coordinator::main::{{closure}}::{{closure}}
             at ./coordinator/src/bin/coordinator.rs:66:29
   4: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2029:9
   5: std::panicking::rust_panic_with_hook
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:783:13
   6: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:649:13
   7: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:171:18
   8: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   9: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
  10: core::panicking::panic
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:144:5
  11: payout_curve::calculate_short_liquidation_interval_payouts
             at ./crates/payout_curve/src/lib.rs:389:13
  12: payout_curve::build_inverse_payout_function
             at ./crates/payout_curve/src/lib.rs:186:47
  13: coordinator::payout_curve::build_inverse_payout_function
             at ./coordinator/src/payout_curve.rs:118:25
  14: coordinator::payout_curve::build_contract_descriptor
             at ./coordinator/src/payout_curve.rs:48:49
  15: coordinator::trade::TradeExecutor::open_dlc_channel::{{closure}}
             at ./coordinator/src/trade/mod.rs:251:35
  16: coordinator::trade::TradeExecutor::execute_internal::{{closure}}
             at ./coordinator/src/trade/mod.rs:171:18
  17: coordinator::trade::TradeExecutor::execute::{{closure}}
             at ./coordinator/src/trade/mod.rs:83:45
  18: coordinator::orderbook::trading::process_new_market_order::{{closure}}
             at ./coordinator/src/orderbook/trading.rs:337:14
  19: coordinator::orderbook::trading::start::{{closure}}::{{closure}}
             at ./coordinator/src/orderbook/trading.rs:107:30
  20: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/future/future.rs:124:9
  21: <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.40/src/instrument.rs:321:9
  22: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/core.rs:334:17
  23: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/loom/std/unsafe_cell.rs:16:9
  24: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/core.rs:323:13
  25: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:485:19
  26: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panic/unwind_safe.rs:272:9
  27: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  28: ___rust_try
  29: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  30: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  31: tokio::runtime::task::harness::poll_future
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:473:18
  32: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:208:27
  33: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:153:15
  34: tokio::runtime::task::raw::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/raw.rs:276:5
  35: tokio::runtime::task::raw::RawTask::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/raw.rs:200:18
  36: tokio::runtime::task::LocalNotified<S>::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/mod.rs:400:9
  37: tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:576:13
  38: tokio::runtime::coop::with_budget
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/coop.rs:107:5
  39: tokio::runtime::coop::budget
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/coop.rs:73:5
  40: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:575:9
  41: tokio::runtime::scheduler::multi_thread::worker::Context::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:526:24
  42: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:491:21
  43: tokio::runtime::context::scoped::Scoped<T>::set
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/context/scoped.rs:40:9
  44: tokio::runtime::context::set_scheduler::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/context.rs:176:26
  45: std::thread::local::LocalKey<T>::try_with
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/local.rs:270:16
  46: std::thread::local::LocalKey<T>::with
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/local.rs:246:9
  47: tokio::runtime::context::set_scheduler
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/context.rs:176:9
  48: tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:486:9
  49: tokio::runtime::context::runtime::enter_runtime
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/context/runtime.rs:65:16
  50: tokio::runtime::scheduler::multi_thread::worker::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:478:5
  51: tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/scheduler/multi_thread/worker.rs:447:45
  52: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/blocking/task.rs:42:21
  53: <tracing::instrument::Instrumented<T> as core::future::future::Future>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.40/src/instrument.rs:321:9
  54: tokio::runtime::task::core::Core<T,S>::poll::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/core.rs:334:17
  55: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/loom/std/unsafe_cell.rs:16:9
  56: tokio::runtime::task::core::Core<T,S>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/core.rs:323:13
  57: tokio::runtime::task::harness::poll_future::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:485:19
  58: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panic/unwind_safe.rs:272:9
  59: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  60: ___rust_try
  61: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  62: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  63: tokio::runtime::task::harness::poll_future
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:473:18
  64: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:208:27
  65: tokio::runtime::task::harness::Harness<T,S>::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/harness.rs:153:15
  66: tokio::runtime::task::raw::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/raw.rs:276:5
  67: tokio::runtime::task::raw::RawTask::poll
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/raw.rs:200:18
  68: tokio::runtime::task::UnownedTask<S>::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/task/mod.rs:437:9
  69: tokio::runtime::blocking::pool::Task::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/blocking/pool.rs:159:9
  70: tokio::runtime::blocking::pool::Inner::run
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/blocking/pool.rs:513:17
  71: tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}
             at /Users/bonomat/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.1/src/runtime/blocking/pool.rs:471:13
  72: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  73: std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:529:17
  74: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panic/unwind_safe.rs:272:9
  75: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  76: ___rust_try
  77: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  78: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  79: std::thread::Builder::spawn_unchecked_::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:528:30
  80: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
  81: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  82: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2015:9
  83: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys/unix/thread.rs:108:17
@bonomat bonomat added the bug Something isn't working label Mar 21, 2024
@bonomat
Copy link
Contributor Author

bonomat commented Mar 21, 2024

Just happened again:

2024-03-21 08:24:09  INFO coordinator::trade: Opening position peer_id=03023bd502865822c47356883ac5c79981b6f3f857464054b41e69bc83d22c0d57 order_id=7dba9366-511c-4f22-9143-c21d07954a38 channel_id=6b08bc5cd1a62d8e952d0ab98d8d8ffaa760b587f46e8b2aaf0bbaafb7e796b1 trade_params=TradeParams { pubkey: PublicKey(570d2cd283bc691eb454404657f8f3b68199c7c53a885673c422588602d53b022b50c17b9f2d5e263a551375a56aab067643a022c92c01feada077b3743f3622), contract_symbol: BtcUsd, leverage: 2.0, quantity: 100.0, direction: Long, filled_with: FilledWith { order_id: 7dba9366-511c-4f22-9143-c21d07954a38, expiry_timestamp: 2024-03-22 0:00:00.0 +00:00:00, oracle_pk: XOnlyPublicKey(c071e1fd881a55831cc38c85986c6c72193b4e3a98bcbc460f6c1ed2f78cf8167458a18010faf718756c69de33ee9e38a0d3f0ad48befa58e23a4b1f843e08be), matches: [Match { id: 2386c183-7436-451b-8dc2-bb541103f015, order_id: e79f18c3-25d4-4e04-a19d-3a250132a57e, quantity: 100, pubkey: PublicKey(5874e28f749ee92d53e95fc0e675e51393fb47159ada8cb1771155f1bfae5dad3a1c6a68bf0f837d3e6035df8cfd788a45b4b0f1951c69db1c81b1d41a84ed85), execution_price: 67079.99 }] } }
2024-03-21 08:24:09 DEBUG coordinator::trade: DLC channel update parameters peer_id=03023bd502865822c47356883ac5c79981b6f3f857464054b41e69bc83d22c0d57 order_id=7dba9366-511c-4f22-9143-c21d07954a38 leverage_coordinator=2.0 margin_coordinator_sat=74538 margin_trader_sat=74538 coordinator_collateral_reserve_sat=361381 trader_collateral_reserve_sat=237743 order_matching_fee_sat=447
2024-03-21 08:24:09  INFO build_contract_descriptor{initial_price=67079.99 coordinator_margin=74538 trader_margin=74538 leverage_coordinator=2.0 leverage_trader=2.0 coordinator_direction=Short coordinator_collateral_reserve=361381 trader_collateral_reserve=237743 quantity=100.0 symbol=BtcUsd}: coordinator::payout_curve: Building contract descriptor
2024-03-21 08:24:09 ERROR build_contract_descriptor{initial_price=67079.99 coordinator_margin=74538 trader_margin=74538 leverage_coordinator=2.0 leverage_trader=2.0 coordinator_direction=Short coordinator_collateral_reserve=361381 trader_collateral_reserve=237743 quantity=100.0 symbol=BtcUsd}: coordinator: Aborting after panic in task info=panicked at crates/payout_curve/src/lib.rs:389:13:
assertion failed: outcome_payout >= interval_start.outcome_payout

@holzeis
Copy link
Contributor

holzeis commented Mar 21, 2024

This is now also happening in our CI pipeline https://github.com/get10101/10101/actions/runs/8376774883/job/22937914343?pr=2293

Did we change there something recently?

@luckysori luckysori self-assigned this Mar 22, 2024
@luckysori luckysori self-assigned this Apr 2, 2024
@luckysori luckysori changed the title Coordinator panic Payout curve short liquidation interval start payout can be incorrect Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants