فهرست منبع

contract/money/entrypoint: return clean error when height fees accumulator is missing

skoupidi 2 ماه پیش
والد
کامیت
06b245416c

+ 5 - 2
src/contract/money/src/entrypoint/fee_v1.rs

@@ -199,8 +199,11 @@ pub(crate) fn money_fee_process_instruction_v1(
 
     // Accumulate the height paid fee
     let verifying_block_height = wasm::util::get_verifying_block_height()?;
-    let mut paid_fee: u64 =
-        deserialize(&db_get(fees_db, &serialize(&verifying_block_height))?.unwrap())?;
+    let Some(paid_fee) = db_get(fees_db, &serialize(&verifying_block_height))? else {
+        msg!("[FeeV1] Error: Block height fees accumulator not found");
+        return Err(MoneyError::PoWRewardCallMissingFeesAccumulator.into())
+    };
+    let mut paid_fee: u64 = deserialize(&paid_fee)?;
     paid_fee += fee;
 
     // At this point the state transition has passed, so we create a state update.

+ 5 - 2
src/contract/money/src/entrypoint/pow_reward_v1.rs

@@ -110,8 +110,11 @@ pub(crate) fn money_pow_reward_process_instruction_v1(
 
     // Grab the currect height accumulated fees
     let fees_db = wasm::db::db_lookup(cid, MONEY_CONTRACT_FEES_TREE)?;
-    let paid_fee: u64 =
-        deserialize(&wasm::db::db_get(fees_db, &serialize(&verifying_block_height))?.unwrap())?;
+    let Some(paid_fee) = wasm::db::db_get(fees_db, &serialize(&verifying_block_height))? else {
+        msg!("[PoWRewardV1] Error: Block height fees accumulator not found");
+        return Err(MoneyError::PoWRewardCallMissingFeesAccumulator.into())
+    };
+    let paid_fee: u64 = deserialize(&paid_fee)?;
 
     // Verify reward value matches the expected one for this block height,
     // including the paid fees.

+ 10 - 6
src/contract/money/src/error.rs

@@ -94,6 +94,9 @@ pub enum MoneyError {
     #[error("Call is not executed on next block height")]
     PoWRewardCallNotOnNextBlockHeight,
 
+    #[error("Block height fees accumulator not found")]
+    PoWRewardCallMissingFeesAccumulator,
+
     #[error("No inputs in fee call")]
     FeeMissingInputs,
 
@@ -141,12 +144,13 @@ impl From<MoneyError> for ContractError {
             MoneyError::PoWRewardCallOnGenesisBlock => Self::Custom(22),
             MoneyError::PoWRewardRetrieveLastBlockHeightError => Self::Custom(23),
             MoneyError::PoWRewardCallNotOnNextBlockHeight => Self::Custom(24),
-            MoneyError::FeeMissingInputs => Self::Custom(25),
-            MoneyError::InsufficientFee => Self::Custom(26),
-            MoneyError::CoinMerkleRootNotFound => Self::Custom(27),
-            MoneyError::RootsValueDataMismatch => Self::Custom(28),
-            MoneyError::ChildrenIndexesLengthMismatch => Self::Custom(29),
-            MoneyError::BurnMissingInputs => Self::Custom(30),
+            MoneyError::PoWRewardCallMissingFeesAccumulator => Self::Custom(25),
+            MoneyError::FeeMissingInputs => Self::Custom(26),
+            MoneyError::InsufficientFee => Self::Custom(27),
+            MoneyError::CoinMerkleRootNotFound => Self::Custom(28),
+            MoneyError::RootsValueDataMismatch => Self::Custom(29),
+            MoneyError::ChildrenIndexesLengthMismatch => Self::Custom(30),
+            MoneyError::BurnMissingInputs => Self::Custom(31),
         }
     }
 }