Skip to content
Merged
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
22 changes: 11 additions & 11 deletions src/speedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
&self,
) -> Result<Vec<CoordinatedSpeedUpTransaction>, BitcoinCoordinatorStoreError> {
let key = SpeedupStoreKey::PendingSpeedUpList.get_key();
let speedups = self.store.get::<&str, Vec<Txid>>(&key)?.unwrap_or_default();
let speedups = self.store.get::<&str, Vec<Txid>>(&key, None)?.unwrap_or_default();

let mut pending_speedups = Vec::new();

Expand All @@ -256,7 +256,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
&self,
) -> Result<Vec<CoordinatedSpeedUpTransaction>, BitcoinCoordinatorStoreError> {
let key = SpeedupStoreKey::PendingSpeedUpList.get_key();
let speedups = self.store.get::<&str, Vec<Txid>>(&key)?.unwrap_or_default();
let speedups = self.store.get::<&str, Vec<Txid>>(&key, None)?.unwrap_or_default();

let mut pending_speedups = Vec::new();

Expand All @@ -280,7 +280,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
&self,
) -> Result<Vec<CoordinatedSpeedUpTransaction>, BitcoinCoordinatorStoreError> {
let key = SpeedupStoreKey::PendingSpeedUpList.get_key();
let speedup_ids = self.store.get::<&str, Vec<Txid>>(&key)?.unwrap_or_default();
let speedup_ids = self.store.get::<&str, Vec<Txid>>(&key, None)?.unwrap_or_default();

let mut pending_speedups = Vec::new();

Expand Down Expand Up @@ -327,7 +327,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
// Also speedup should be saved at the end of the list. Because is gonna be the new way to fund next speedups.

let key = SpeedupStoreKey::PendingSpeedUpList.get_key();
let mut speedups = self.store.get::<&str, Vec<Txid>>(&key)?.unwrap_or_default();
let mut speedups = self.store.get::<&str, Vec<Txid>>(&key, None)?.unwrap_or_default();
speedups.push(speedup.tx_id);

self.store.set(&key, speedups, None)?;
Expand All @@ -346,7 +346,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::SpeedUpTransaction(*txid).get_key();
let speedup = self
.store
.get::<&str, CoordinatedSpeedUpTransaction>(&key)?
.get::<&str, CoordinatedSpeedUpTransaction>(&key, None)?
.ok_or(BitcoinCoordinatorStoreError::SpeedupNotFound)?;

Ok(speedup)
Expand Down Expand Up @@ -380,7 +380,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::PendingSpeedUpList.get_key();
let mut speedups = self
.store
.get::<&str, Vec<Txid>>(&key)?
.get::<&str, Vec<Txid>>(&key, None)?
.ok_or(BitcoinCoordinatorStoreError::SpeedupNotFound)?;

let index = speedups
Expand All @@ -406,7 +406,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {

let mut speedup = self
.store
.get::<&str, CoordinatedSpeedUpTransaction>(&key)?
.get::<&str, CoordinatedSpeedUpTransaction>(&key, None)?
.ok_or(BitcoinCoordinatorStoreError::SpeedupNotFound)?;

speedup.state = state;
Expand Down Expand Up @@ -457,7 +457,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::RetrySpeedUpTransactionList.get_key();
let speedups: Vec<CoordinatedSpeedUpTransaction> = self
.store
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key)?
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key, None)?
.unwrap_or_default();

let mut eligible_speedups = Vec::new();
Expand Down Expand Up @@ -493,7 +493,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::RetrySpeedUpTransactionList.get_key();
let mut speedups = self
.store
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key)?
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key, None)?
.unwrap_or_default();

speedup.retry_info = Some(RetryInfo::new(0, Utc::now().timestamp_millis() as u64));
Expand All @@ -508,7 +508,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::RetrySpeedUpTransactionList.get_key();
let mut speedups = self
.store
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key)?
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key, None)?
.unwrap_or_default();
speedups.retain(|s| s.tx_id != txid);
self.store.set(&key, &speedups, None)?;
Expand All @@ -523,7 +523,7 @@ impl SpeedupStore for BitcoinCoordinatorStore {
let key = SpeedupStoreKey::RetrySpeedUpTransactionList.get_key();
let mut speedups = self
.store
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key)?
.get::<&str, Vec<CoordinatedSpeedUpTransaction>>(&key, None)?
.unwrap_or_default();

for speedup in speedups.iter_mut() {
Expand Down
55 changes: 29 additions & 26 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl BitcoinCoordinatorStore {
fn get_txs(&self) -> Result<Vec<Txid>, BitcoinCoordinatorStoreError> {
let key = self.get_key(StoreKey::PendingTransactionList);

let all_txs = self.store.get::<&str, Vec<Txid>>(&key)?;
let all_txs = self.store.get::<&str, Vec<Txid>>(&key, None)?;

match all_txs {
Some(txs) => Ok(txs),
Expand All @@ -132,7 +132,7 @@ impl BitcoinCoordinatorStore {
impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
fn get_tx(&self, tx_id: &Txid) -> Result<CoordinatedTransaction, BitcoinCoordinatorStoreError> {
let key = self.get_key(StoreKey::Transaction(*tx_id));
let tx = self.store.get::<&str, CoordinatedTransaction>(&key)?;
let tx = self.store.get::<&str, CoordinatedTransaction>(&key, None)?;

if let Some(tx) = tx {
Ok(tx)
Expand Down Expand Up @@ -211,7 +211,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let txs_key = self.get_key(StoreKey::PendingTransactionList);
let mut txs = self
.store
.get::<&str, Vec<Txid>>(&txs_key)?
.get::<&str, Vec<Txid>>(&txs_key, None)?
.unwrap_or_default();
txs.push(tx.compute_txid());
self.store.set(&txs_key, &txs, None)?;
Expand All @@ -226,7 +226,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let txs_key = self.get_key(StoreKey::PendingTransactionList);
let mut txs = self
.store
.get::<&str, Vec<Txid>>(&txs_key)?
.get::<&str, Vec<Txid>>(&txs_key, None)?
.unwrap_or_default();

txs.retain(|id| *id != tx_id);
Expand Down Expand Up @@ -294,7 +294,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let txs_key = self.get_key(StoreKey::PendingTransactionList);
let mut txs = self
.store
.get::<&str, Vec<Txid>>(&txs_key)?
.get::<&str, Vec<Txid>>(&txs_key, None)?
.unwrap_or_default();
txs.retain(|id| *id != tx_id);
self.store.set(&txs_key, &txs, None)?;
Expand All @@ -313,7 +313,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::InsufficientFundsNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list.iter().position(|(id, _, _, _)| id == &tx_id);
Expand All @@ -338,7 +338,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::DispatchTransactionErrorNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list.iter().position(|(id, _, _, _)| id == &tx_id);
Expand All @@ -363,6 +363,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
.store
.get::<&str, Vec<(Vec<Txid>, Vec<String>, Txid, String, (BlockHash, bool))>>(
&key,
None
)?
.unwrap_or_default();

Expand All @@ -389,7 +390,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
}
CoordinatorNews::FundingNotFound => {
let key = self.get_key(StoreKey::FundingNotFoundNews);
let news = self.store.get::<&str, (BlockHash, bool)>(&key)?;
let news = self.store.get::<&str, (BlockHash, bool)>(&key, None)?;

if let Some((last_block_hash, _)) = news {
// If there is existing news, check if the block hash differs
Expand All @@ -405,7 +406,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::EstimateFeerateTooHighNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list
Expand All @@ -430,7 +431,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::TransactionAlreadyInMempoolNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list.iter().position(|(id, _, _)| id == &tx_id);
Expand All @@ -451,7 +452,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::MempoolRejectionNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list.iter().position(|(id, _, _, _)| id == &tx_id);
Expand All @@ -472,7 +473,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::NetworkErrorNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

let is_new_news = news_list.iter().position(|(id, _, _, _)| id == &tx_id);
Expand All @@ -498,7 +499,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::InsufficientFundsNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list.iter().position(|(id, _, _, _)| *id == tx_id) {
Expand All @@ -511,7 +512,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::DispatchTransactionErrorNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list.iter().position(|(id, _, _, _)| *id == tx_id) {
Expand All @@ -526,6 +527,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
.store
.get::<&str, Vec<(Vec<Txid>, Vec<String>, Txid, String, (BlockHash, bool))>>(
&key,
None
)?
.unwrap_or_default();

Expand All @@ -542,7 +544,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::EstimateFeerateTooHighNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list
Expand All @@ -556,7 +558,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
}
AckCoordinatorNews::FundingNotFound => {
let key = self.get_key(StoreKey::FundingNotFoundNews);
let mut news = self.store.get::<&str, (BlockHash, bool)>(&key)?;
let mut news = self.store.get::<&str, (BlockHash, bool)>(&key, None)?;

if let Some((block_hash, _)) = news {
news = Some((block_hash, true));
Expand All @@ -567,7 +569,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::TransactionAlreadyInMempoolNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list.iter().position(|(id, _, _)| *id == tx_id) {
Expand All @@ -580,7 +582,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::MempoolRejectionNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list.iter().position(|(id, _, _, _)| *id == tx_id) {
Expand All @@ -593,7 +595,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let key = self.get_key(StoreKey::NetworkErrorNewsList);
let mut news_list = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&key, None)?
.unwrap_or_default();

if let Some(pos) = news_list.iter().position(|(id, _, _, _)| *id == tx_id) {
Expand All @@ -613,7 +615,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let insufficient_funds_key = self.get_key(StoreKey::InsufficientFundsNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&insufficient_funds_key)?
.get::<&str, Vec<(Txid, u64, u64, (BlockHash, bool))>>(&insufficient_funds_key, None)?
{
for (txid, amount, required, (_, acked)) in news_list {
if !acked {
Expand All @@ -626,7 +628,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let dispatch_error_key = self.get_key(StoreKey::DispatchTransactionErrorNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&dispatch_error_key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&dispatch_error_key, None)?
{
for (tx_id, context, error, (_, acked)) in news_list {
if !acked {
Expand All @@ -643,6 +645,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
self.store
.get::<&str, Vec<(Vec<Txid>, Vec<String>, Txid, String, (BlockHash, bool))>>(
&speed_up_error_key,
None
)?
{
for (tx_ids, contexts, txid, error, (_, acked)) in news_list {
Expand All @@ -658,7 +661,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let funding_not_found_key = self.get_key(StoreKey::FundingNotFoundNews);
if let Some((_, acked)) = self
.store
.get::<&str, (BlockHash, bool)>(&funding_not_found_key)?
.get::<&str, (BlockHash, bool)>(&funding_not_found_key, None)?
{
if !acked {
all_news.push(CoordinatorNews::FundingNotFound);
Expand All @@ -669,7 +672,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let estimate_feerate_too_high_key = self.get_key(StoreKey::EstimateFeerateTooHighNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&estimate_feerate_too_high_key)?
.get::<&str, Vec<(u64, u64, (BlockHash, bool))>>(&estimate_feerate_too_high_key, None)?
{
for (estimate_fee, max_allowed, (_, acked)) in news_list {
if !acked {
Expand All @@ -685,7 +688,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let already_in_mempool_key = self.get_key(StoreKey::TransactionAlreadyInMempoolNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&already_in_mempool_key)?
.get::<&str, Vec<(Txid, String, (BlockHash, bool))>>(&already_in_mempool_key, None)?
{
for (tx_id, context, (_, acked)) in news_list {
if !acked {
Expand All @@ -698,7 +701,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let mempool_rejection_key = self.get_key(StoreKey::MempoolRejectionNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&mempool_rejection_key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&mempool_rejection_key, None)?
{
for (tx_id, context, error, (_, acked)) in news_list {
if !acked {
Expand All @@ -711,7 +714,7 @@ impl BitcoinCoordinatorStoreApi for BitcoinCoordinatorStore {
let network_error_key = self.get_key(StoreKey::NetworkErrorNewsList);
if let Some(news_list) = self
.store
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&network_error_key)?
.get::<&str, Vec<(Txid, String, String, (BlockHash, bool))>>(&network_error_key, None)?
{
for (tx_id, context, error, (_, acked)) in news_list {
if !acked {
Expand Down