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

runtime/merkle: return early with SUCCESS (but give a warning) if the coins list for changing the tree is empty. We also don't do any gas calc since nothing on disk was modified.

zero 2 лет назад
Родитель
Сommit
309157e0ba
1 измененных файлов с 11 добавлено и 6 удалено
  1. 11 6
      src/runtime/import/merkle.rs

+ 11 - 6
src/runtime/import/merkle.rs

@@ -20,7 +20,7 @@ use std::io::Cursor;
 
 
 use darkfi_sdk::crypto::{MerkleNode, MerkleTree};
 use darkfi_sdk::crypto::{MerkleNode, MerkleTree};
 use darkfi_serial::{serialize, Decodable, Encodable, WriteExt};
 use darkfi_serial::{serialize, Decodable, Encodable, WriteExt};
-use log::{debug, error};
+use log::{debug, error, warn};
 use wasmer::{FunctionEnvMut, WasmPtr};
 use wasmer::{FunctionEnvMut, WasmPtr};
 
 
 use super::acl::acl_allow;
 use super::acl::acl_allow;
@@ -131,7 +131,7 @@ pub(crate) fn merkle_add(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u3
         }
         }
     };
     };
 
 
-    // This `key` represents the sled database tree name
+    // This `key` represents the sled key in info where the Merkle tree is
     let tree_key: Vec<u8> = match Decodable::decode(&mut buf_reader) {
     let tree_key: Vec<u8> = match Decodable::decode(&mut buf_reader) {
         Ok(v) => v,
         Ok(v) => v,
         Err(e) => {
         Err(e) => {
@@ -155,6 +155,15 @@ pub(crate) fn merkle_add(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u3
         }
         }
     };
     };
 
 
+    // Nothing to do so just return here
+    if coins.is_empty() {
+        warn!(
+            target: "runtime::merkle::merkle_add",
+            "[WASM] [{}] merkle_add(): Nothing to add! Returning.", cid,
+        );
+        return darkfi_sdk::entrypoint::SUCCESS
+    }
+
     // Make sure we've read the entire buffer
     // Make sure we've read the entire buffer
     if buf_reader.position() != (len as u64) {
     if buf_reader.position() != (len as u64) {
         error!(
         error!(
@@ -258,11 +267,7 @@ pub(crate) fn merkle_add(mut ctx: FunctionEnvMut<Env>, ptr: WasmPtr<u8>, len: u3
     }
     }
 
 
     // Here we add the Merkle root to our set of roots
     // Here we add the Merkle root to our set of roots
-    // TODO: We should probably make sure that this root isn't in the set
     for root in new_roots.iter() {
     for root in new_roots.iter() {
-        // FIXME: Why were we writing the set size here?
-        //let root_index: Vec<u8> = serialize(&(set_size as u32));
-        //assert_eq!(root_index.len(), 4);
         debug!(
         debug!(
             target: "runtime::merkle::merkle_add",
             target: "runtime::merkle::merkle_add",
             "[WASM] [{}] merkle_add(): Appending Merkle root to db: {:?}", cid, root,
             "[WASM] [{}] merkle_add(): Appending Merkle root to db: {:?}", cid, root,