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

wip: reproduce timing issue #1740

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use tracing::metadata::LevelFilter;
const PROCESS_PROMETHEUS_METRICS: Duration = Duration::from_secs(10);
const PROCESS_INCOMING_DLC_MESSAGES_INTERVAL: Duration = Duration::from_millis(200);
const EXPIRED_POSITION_SYNC_INTERVAL: Duration = Duration::from_secs(5 * 60);
const CLOSED_POSITION_SYNC_INTERVAL: Duration = Duration::from_secs(30);
const CLOSED_POSITION_SYNC_INTERVAL: Duration = Duration::from_secs(1);
const UNREALIZED_PNL_SYNC_INTERVAL: Duration = Duration::from_secs(10 * 60);
const CONNECTION_CHECK_INTERVAL: Duration = Duration::from_secs(30);

Expand Down
9 changes: 7 additions & 2 deletions coordinator/src/node/closed_positions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn sync(node: Node) -> Result<()> {
.context("Failed to load open and closing positions")?;

for position in open_and_closing_positions {
tracing::debug!(position = position.id, "Checking position");
let temporary_contract_id = match position.temporary_contract_id {
None => {
tracing::trace!(position_id=%position.id, "Position does not have temporary contract id, skipping");
Expand All @@ -20,9 +21,13 @@ pub fn sync(node: Node) -> Result<()> {
};

let contract = match node.inner.get_closed_contract(temporary_contract_id) {
Ok(Some(closed_contract)) => closed_contract,
Ok(Some(closed_contract)) => {
tracing::debug!(position = position.id, "Position closed");

closed_contract
}
Ok(None) => {
tracing::trace!(position_id=%position.id, "Position not closed yet, skipping");
tracing::debug!(position_id=%position.id, "Position not closed yet, skipping");
continue;
}
Err(e) => {
Expand Down
12 changes: 11 additions & 1 deletion coordinator/src/node/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ impl Node {
},
)?;

db::positions::Position::set_open_position_to_resizing(conn, position.trader.to_string())?;
let pool = self.pool.clone();
tokio::spawn({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, I wasn't able to reproduce it, although I was using std::thread::spawn instead.

let string = position.trader.to_string();
let pool = pool.clone();
async move {
let mut conn = pool.get()?;
tokio::time::sleep(core::time::Duration::from_secs(10)).await;
db::positions::Position::set_open_position_to_resizing(&mut conn, string)?;
anyhow::Ok(())
}
});

Ok(())
}
Expand Down
Loading