Ver código fonte

runtime/vm_runtime: rename GAS_LIMIT and add TX_GAS_LIMIT

Rename GAS_LIMIT to CONTRACT_GAS_LIMIT and raise to 800M.

Add TX_GAS_LIMIT = 1B. This supersedes the implicit bound formerly
provided by MAX_TX_CALLS.
darkfi 1 mês atrás
pai
commit
64fa4c2fef
1 arquivos alterados com 14 adições e 11 exclusões
  1. 14 11
      src/runtime/vm_runtime.rs

+ 14 - 11
src/runtime/vm_runtime.rs

@@ -49,8 +49,11 @@ use crate::{blockchain::BlockchainOverlayPtr, Error, Result};
 /// Name of the wasm linear memory in our guest module
 /// Name of the wasm linear memory in our guest module
 const MEMORY: &str = "memory";
 const MEMORY: &str = "memory";
 
 
-/// Gas limit for a single contract call (Single WASM instance)
-pub const GAS_LIMIT: u64 = 400_000_000;
+/// Gas limit for a single contract call (single WASM instance).
+pub const CONTRACT_GAS_LIMIT: u64 = 800_000_000;
+
+/// Gas limit for a single transaction (across all of its calls).
+pub const TX_GAS_LIMIT: u64 = 1_000_000_000;
 
 
 // ANCHOR: contract-section
 // ANCHOR: contract-section
 #[derive(Clone, Copy, PartialEq)]
 #[derive(Clone, Copy, PartialEq)]
@@ -192,7 +195,7 @@ impl Runtime {
         // `Metering` needs to be configured with a limit and a cost function.
         // `Metering` needs to be configured with a limit and a cost function.
         // For each `Operator`, the metering middleware will call the cost
         // For each `Operator`, the metering middleware will call the cost
         // function and subtract the cost from the remaining points.
         // function and subtract the cost from the remaining points.
-        let metering = Arc::new(Metering::new(GAS_LIMIT, cost_function));
+        let metering = Arc::new(Metering::new(CONTRACT_GAS_LIMIT, cost_function));
 
 
         // Define the compiler and middleware, engine, and store
         // Define the compiler and middleware, engine, and store
         let mut compiler_config = Singlepass::new();
         let mut compiler_config = Singlepass::new();
@@ -630,28 +633,28 @@ impl Runtime {
 
 
         match remaining_points {
         match remaining_points {
             MeteringPoints::Remaining(rem) => {
             MeteringPoints::Remaining(rem) => {
-                if rem > GAS_LIMIT {
+                if rem > CONTRACT_GAS_LIMIT {
                     // This should never occur, but catch it explicitly to avoid
                     // This should never occur, but catch it explicitly to avoid
                     // potential underflow issues when calculating `remaining_points`.
                     // potential underflow issues when calculating `remaining_points`.
-                    unreachable!("Remaining wasm points exceed GAS_LIMIT");
+                    unreachable!("Remaining wasm points exceed CONTRACT_GAS_LIMIT");
                 }
                 }
-                GAS_LIMIT - rem
+                CONTRACT_GAS_LIMIT - rem
             }
             }
-            MeteringPoints::Exhausted => GAS_LIMIT + 1,
+            MeteringPoints::Exhausted => CONTRACT_GAS_LIMIT + 1,
         }
         }
     }
     }
 
 
     // Return a message informing the user whether there is any
     // Return a message informing the user whether there is any
-    // gas remaining. Values equal to GAS_LIMIT are not considered
+    // gas remaining. Values equal to CONTRACT_GAS_LIMIT are not considered
     // to be exhausted. e.g. Using 100/100 gas should not give a
     // to be exhausted. e.g. Using 100/100 gas should not give a
     // 'gas exhausted' message.
     // 'gas exhausted' message.
     fn gas_info(&mut self) -> String {
     fn gas_info(&mut self) -> String {
         let gas_used = self.gas_used();
         let gas_used = self.gas_used();
 
 
-        if gas_used > GAS_LIMIT {
-            format!("Gas fully exhausted: {gas_used}/{GAS_LIMIT}")
+        if gas_used > CONTRACT_GAS_LIMIT {
+            format!("Gas fully exhausted: {gas_used}/{CONTRACT_GAS_LIMIT}")
         } else {
         } else {
-            format!("Gas used: {gas_used}/{GAS_LIMIT}")
+            format!("Gas used: {gas_used}/{CONTRACT_GAS_LIMIT}")
         }
         }
     }
     }