Просмотр исходного кода

blockchain/tx_store: use empty slice as value in erroneous_txs sled

aggstam 3 лет назад
Родитель
Сommit
4f3105d71d
2 измененных файлов с 10 добавлено и 40 удалено
  1. 3 3
      script/research/nodes-tool/src/main.rs
  2. 7 37
      src/blockchain/tx_store.rs

+ 3 - 3
script/research/nodes-tool/src/main.rs

@@ -266,7 +266,7 @@ impl TxStoreInfo {
 
 
 #[derive(Debug)]
 #[derive(Debug)]
 struct ErroneousTxStoreInfo {
 struct ErroneousTxStoreInfo {
-    _transactions: Vec<TxInfo>,
+    _transactions: Vec<blake3::Hash>,
 }
 }
 
 
 impl ErroneousTxStoreInfo {
 impl ErroneousTxStoreInfo {
@@ -275,8 +275,8 @@ impl ErroneousTxStoreInfo {
         let result = erroneoustxstore.get_all();
         let result = erroneoustxstore.get_all();
         match result {
         match result {
             Ok(iter) => {
             Ok(iter) => {
-                for (hash, tx) in iter.iter() {
-                    _transactions.push(TxInfo::new(hash.clone(), &tx));
+                for hash in iter.iter() {
+                    _transactions.push(hash.clone());
                 }
                 }
             }
             }
             Err(e) => println!("Error: {:?}", e),
             Err(e) => println!("Error: {:?}", e),

+ 7 - 37
src/blockchain/tx_store.rs

@@ -109,7 +109,7 @@ impl TxStore {
 
 
 /// The `ErroneousTxStore` is a `sled` tree storing all the blockchain's
 /// The `ErroneousTxStore` is a `sled` tree storing all the blockchain's
 /// erroneous transactions where the key is the transaction hash, and the value is
 /// erroneous transactions where the key is the transaction hash, and the value is
-/// the serialized transaction.
+/// an empty slice.
 #[derive(Clone)]
 #[derive(Clone)]
 pub struct ErroneousTxStore(sled::Tree);
 pub struct ErroneousTxStore(sled::Tree);
 
 
@@ -123,7 +123,7 @@ impl ErroneousTxStore {
     /// Insert a slice of [`Transaction`] into the erroneoustxstore. With sled, the
     /// Insert a slice of [`Transaction`] into the erroneoustxstore. With sled, the
     /// operation is done as a batch.
     /// operation is done as a batch.
     /// The transactions are hashed with BLAKE3 and this hash is used as
     /// The transactions are hashed with BLAKE3 and this hash is used as
-    /// the key, while the value is the serialized [`Transaction`] itself.
+    /// the key, while the value is an empty slice.
     /// On success, the function returns the transaction hashes in the same
     /// On success, the function returns the transaction hashes in the same
     /// order as the input transactions.
     /// order as the input transactions.
     pub fn insert(&self, transactions: &[Transaction]) -> Result<Vec<blake3::Hash>> {
     pub fn insert(&self, transactions: &[Transaction]) -> Result<Vec<blake3::Hash>> {
@@ -133,7 +133,7 @@ impl ErroneousTxStore {
         for tx in transactions {
         for tx in transactions {
             let serialized = serialize(tx);
             let serialized = serialize(tx);
             let tx_hash = blake3::hash(&serialized);
             let tx_hash = blake3::hash(&serialized);
-            batch.insert(tx_hash.as_bytes(), serialized);
+            batch.insert(tx_hash.as_bytes(), &[]);
             ret.push(tx_hash);
             ret.push(tx_hash);
         }
         }
 
 
@@ -146,45 +146,15 @@ impl ErroneousTxStore {
         Ok(self.0.contains_key(tx_hash.as_bytes())?)
         Ok(self.0.contains_key(tx_hash.as_bytes())?)
     }
     }
 
 
-    /// Fetch given erroneous tx hashes from the erroneoustxstore.
-    /// The resulting vector contains `Option`, which is `Some` if the tx
-    /// was found in the erroneoustxstore, and otherwise it is `None`, if it has not.
-    /// The second parameter is a boolean which tells the function to fail in
-    /// case at least one block was not found.
-    pub fn get(
-        &self,
-        tx_hashes: &[blake3::Hash],
-        strict: bool,
-    ) -> Result<Vec<Option<Transaction>>> {
-        let mut ret = Vec::with_capacity(tx_hashes.len());
-
-        for tx_hash in tx_hashes {
-            if let Some(found) = self.0.get(tx_hash.as_bytes())? {
-                let tx = deserialize(&found)?;
-                ret.push(Some(tx));
-            } else {
-                if strict {
-                    let s = tx_hash.to_hex().as_str().to_string();
-                    return Err(Error::TransactionNotFound(s))
-                }
-                ret.push(None);
-            }
-        }
-
-        Ok(ret)
-    }
-
-    /// Retrieve all erroneous transactions from the erroneoustxstore
-    /// in the form of a tuple (`tx_hash`, `tx`).
+    /// Retrieve all erroneous transaction hashes from the erroneoustxstore.
     /// Be careful as this will try to load everything in memory.
     /// Be careful as this will try to load everything in memory.
-    pub fn get_all(&self) -> Result<Vec<(blake3::Hash, Transaction)>> {
+    pub fn get_all(&self) -> Result<Vec<blake3::Hash>> {
         let mut txs = vec![];
         let mut txs = vec![];
 
 
         for tx in self.0.iter() {
         for tx in self.0.iter() {
-            let (key, value) = tx.unwrap();
+            let (key, _) = tx.unwrap();
             let hash_bytes: [u8; 32] = key.as_ref().try_into().unwrap();
             let hash_bytes: [u8; 32] = key.as_ref().try_into().unwrap();
-            let tx = deserialize(&value)?;
-            txs.push((hash_bytes.into(), tx));
+            txs.push(hash_bytes.into());
         }
         }
 
 
         Ok(txs)
         Ok(txs)