From 27a837da5b0f4cf6c334a3551865f991b2e8504c Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 22 Jul 2019 12:25:17 +0300 Subject: [PATCH] improve redis keys naming --- .../src/engines/ethereum_ledger/eth_engine.rs | 4 +++- .../src/stores/redis_ethereum_ledger/store.rs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/interledger-settlement-engines/src/engines/ethereum_ledger/eth_engine.rs b/crates/interledger-settlement-engines/src/engines/ethereum_ledger/eth_engine.rs index 6643bb557..b0a0ce111 100644 --- a/crates/interledger-settlement-engines/src/engines/ethereum_ledger/eth_engine.rs +++ b/crates/interledger-settlement-engines/src/engines/ethereum_ledger/eth_engine.rs @@ -334,7 +334,7 @@ where let self_clone = self.clone(); // Skip transactions which have already been credited to the connector store.check_tx_credited(tx_hash) - .map_err(move |_| error!("Transaction {} has already been credited!", tx_hash)) + .map_err(move |_| error!("Error when querying store about transaction: {:?}", tx_hash)) .and_then(move |credited| { if !credited { Either::A( @@ -362,6 +362,8 @@ where self_clone.notify_connector(id.to_string(), amount.low_u64()) }) .and_then(move |_| { + // only save the transaction hash if the connector + // was successfully notified store.credit_tx(tx_hash) })) } else { diff --git a/crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger/store.rs b/crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger/store.rs index c0e41dd44..a3cb4151f 100644 --- a/crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger/store.rs +++ b/crates/interledger-settlement-engines/src/stores/redis_ethereum_ledger/store.rs @@ -18,6 +18,7 @@ use crate::stores::redis_store::{EngineRedisStore, EngineRedisStoreBuilder}; // avoid double crediting transactions which have already been processed, and in // order to resume watching from the last observed point. static RECENTLY_OBSERVED_DATA_KEY: &str = "recently_observed_data"; +static SAVED_TRANSACTIONS_KEY: &str = "transactions"; static SETTLEMENT_ENGINES_KEY: &str = "settlement"; static LEDGER_KEY: &str = "ledger"; static ETHEREUM_KEY: &str = "eth"; @@ -37,10 +38,18 @@ impl AccountTrait for Account { } } +fn ethereum_transactions_key(tx_hash: H256) -> String { + format!( + "{}:{}:{}:{}", + ETHEREUM_KEY, LEDGER_KEY, SAVED_TRANSACTIONS_KEY, tx_hash, + ) +} + + fn ethereum_ledger_key(account_id: u64) -> String { format!( "{}:{}:{}:{}", - SETTLEMENT_ENGINES_KEY, LEDGER_KEY, ETHEREUM_KEY, account_id + ETHEREUM_KEY, LEDGER_KEY, SETTLEMENT_ENGINES_KEY, account_id ) } @@ -226,7 +235,7 @@ impl EthereumStore for EthereumLedgerRedisStore { fn check_tx_credited(&self, tx_hash: H256) -> Box + Send> { Box::new( cmd("EXISTS") - .arg(tx_hash.to_string()) + .arg(ethereum_transactions_key(tx_hash)) .arg(true) .query_async(self.connection.clone()) .map_err(move |err| error!("Error loading account data: {:?}", err)) @@ -245,7 +254,7 @@ impl EthereumStore for EthereumLedgerRedisStore { fn credit_tx(&self, tx_hash: H256) -> Box + Send> { Box::new( cmd("SETNX") - .arg(tx_hash.to_string()) + .arg(ethereum_transactions_key(tx_hash)) .arg(true) .query_async(self.connection.clone()) .map_err(move |err| error!("Error loading account data: {:?}", err))