Преглед изворни кода

blockchain/tx_store: changed location tx_index from u64 to u16

skoupidi пре 2 година
родитељ
комит
0318720cd3
3 измењених фајлова са 9 додато и 9 уклоњено
  1. 4 4
      doc/src/arch/dao.md
  2. 4 4
      src/blockchain/tx_store.rs
  3. 1 1
      src/sdk/src/wasm/util.rs

+ 4 - 4
doc/src/arch/dao.md

@@ -250,7 +250,7 @@ occurred.
 |--------------|--------------|------|----------------------------|
 | k            | Root         | 32   | The current root hash $Rₖ$ |
 | v            | Tx hash      | 32   | Current block height       |
-| v            | Call index   | 2    | Index of contract call     |
+| v            | Call index   | 1    | Index of contract call     |
 
 We call `get_tx_location(tx_hash) -> (block_height, tx_index)`, and
 then use the `(block_height, tx_index)` tuple to figure out all info about
@@ -267,7 +267,7 @@ If they match, then they both exist in the same `update()` call.
 |--------------|--------------|------|----------------------------|
 | k            | Root         | 32   | The current root hash $Sₖ$ |
 | v            | Tx hash      | 32   | Current block height       |
-| v            | Call index   | 2    | Index of contract call     |
+| v            | Call index   | 1    | Index of contract call     |
 
 ## DB Coins (Wallets)
 
@@ -285,9 +285,9 @@ tree so exclusion proofs can be constructed.
 
 | Key or Value | Field Name   | Size | Desc                                  |
 |--------------|--------------|------|---------------------------------------|
-| k            | Block height | 3    | Block height for coin                 |
+| k            | Block height | 4    | Block height for coin                 |
 | k            | Tx index     | 2    | Index in block for tx containing coin |
-| k            | Call index   | 2    | Index of contract call                |
+| k            | Call index   | 1    | Index of contract call                |
 | k            | Val index    | 2    | Index of this coin or nullifier       |
 | v            | Value        | 32   | Coin or nullifier                     |
 | v            | Type         | 1    | Single byte indicating the type       |

+ 4 - 4
src/blockchain/tx_store.rs

@@ -126,7 +126,7 @@ impl TxStore {
         let mut batch = sled::Batch::default();
 
         for (index, tx_hash) in txs_hashes.iter().enumerate() {
-            let serialized = serialize(&(block_height, index as u64));
+            let serialized = serialize(&(block_height, index as u16));
             batch.insert(tx_hash.inner(), serialized);
         }
 
@@ -224,7 +224,7 @@ impl TxStore {
         &self,
         tx_hashes: &[TransactionHash],
         strict: bool,
-    ) -> Result<Vec<Option<(u64, u64)>>> {
+    ) -> Result<Vec<Option<(u64, u16)>>> {
         let mut ret = Vec::with_capacity(tx_hashes.len());
 
         for tx_hash in tx_hashes {
@@ -285,7 +285,7 @@ impl TxStore {
     /// Retrieve all transactions locations from the store's location tree in
     /// the form of a tuple (`tx_hash`, (`block_height`, `index`)).
     /// Be careful as this will try to load everything in memory.
-    pub fn get_all_location(&self) -> Result<Vec<(TransactionHash, (u64, u64))>> {
+    pub fn get_all_location(&self) -> Result<Vec<(TransactionHash, (u64, u16))>> {
         let mut locations = vec![];
 
         for location in self.location.iter() {
@@ -407,7 +407,7 @@ impl TxStoreOverlay {
         let mut lock = self.0.lock().unwrap();
 
         for (index, tx_hash) in txs_hashes.iter().enumerate() {
-            let serialized = serialize(&(block_height, index as u64));
+            let serialized = serialize(&(block_height, index as u16));
             lock.insert(SLED_TX_LOCATION_TREE, tx_hash.inner(), &serialized)?;
         }
 

+ 1 - 1
src/sdk/src/wasm/util.rs

@@ -171,7 +171,7 @@ pub fn get_tx(hash: &TransactionHash) -> GenericResult<Option<Vec<u8>>> {
 /// ```
 /// (block_height, tx_index) = get_tx_location(hash)?;
 /// ```
-pub fn get_tx_location(hash: &TransactionHash) -> GenericResult<(u64, u64)> {
+pub fn get_tx_location(hash: &TransactionHash) -> GenericResult<(u64, u16)> {
     let mut buf = vec![];
     hash.encode(&mut buf)?;