Implement optimistic locking for read-update-write swap operations (#652)

* Implement optimistic locking for read-update-write swap operations

* Fail on stale swap update and add tests
This commit is contained in:
Daniel Granhão
2025-01-12 22:44:15 +00:00
committed by GitHub
parent 50cb8be18c
commit 95bbd0e49b
10 changed files with 205 additions and 25 deletions

View File

@@ -137,6 +137,7 @@ pub(crate) fn new_chain_swap(
}
}"#
.to_string(),
version: 0
};
}
match direction {
@@ -223,6 +224,7 @@ pub(crate) fn new_chain_swap(
}
}
}"#.to_string(),
version: 0,
},
Direction::Outgoing => ChainSwap {
id: generate_random_string(4),
@@ -306,6 +308,7 @@ pub(crate) fn new_chain_swap(
}
}
}"#.to_string(),
version: 0
}
}
}

View File

@@ -86,6 +86,7 @@ pub(crate) fn new_send_swap(payment_state: Option<PaymentState>) -> SendSwap {
created_at: utils::now(),
state: payment_state.unwrap_or(PaymentState::Created),
refund_private_key: "945affeef55f12227f1d4a3f80a17062a05b229ddc5a01591eb5ddf882df92e3".to_string(),
version: 0,
}
}
@@ -140,6 +141,7 @@ pub(crate) fn new_receive_swap(payment_state: Option<PaymentState>) -> ReceiveSw
mrh_tx_id: None,
created_at: utils::now(),
state: payment_state.unwrap_or(PaymentState::Created),
version: 0,
}
}