Skip to content

Commit

Permalink
fix: Set position to open if a rollover is rejected
Browse files Browse the repository at this point in the history
Otherwise the position is stuck in `Rollover` and won't get recovered.
  • Loading branch information
holzeis committed May 23, 2024
1 parent 52b57be commit ffd6b56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
23 changes: 0 additions & 23 deletions coordinator/src/db/positions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,6 @@ impl Position {
Ok(crate::position::models::Position::from(position))
}

/// sets the status of the position in state `Closing` to a new state
pub fn update_closing_position(
conn: &mut PgConnection,
trader_pubkey: String,
state: crate::position::models::PositionState,
) -> Result<()> {
let state = PositionState::from(state);
let affected_rows = diesel::update(positions::table)
.filter(positions::trader_pubkey.eq(trader_pubkey.clone()))
.filter(positions::position_state.eq(PositionState::Closing))
.set((
positions::position_state.eq(state),
positions::update_timestamp.eq(OffsetDateTime::now_utc()),
))
.execute(conn)?;

if affected_rows == 0 {
bail!("Could not update position to {state:?} for {trader_pubkey}")
}

Ok(())
}

/// sets the status of all open position to closing (note, we expect that number to be always
/// exactly 1)
pub fn set_open_position_to_closing(
Expand Down
7 changes: 6 additions & 1 deletion coordinator/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,14 @@ impl Node {
"DLC Channel settle offer has been rejected. Setting position to back to open."
);

db::positions::Position::update_closing_position(
db::positions::Position::update_position_state(
&mut connection,
node_id.to_string(),
vec![
// the closing price doesn't matter here.
PositionState::Closing { closing_price: 0.0 },
PositionState::Rollover,
],
PositionState::Open,
)?;
}
Expand Down

0 comments on commit ffd6b56

Please sign in to comment.