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

contract/money/pow_reward: minor renaming

aggstam 2 лет назад
Родитель
Сommit
f7f8214988

+ 3 - 3
src/contract/money/src/client/pow_reward_v1.rs

@@ -65,8 +65,8 @@ impl PoWRewardRevealed {
 pub struct PoWRewardCallBuilder {
     /// Caller's keypair
     pub keypair: Keypair,
-    /// Rewarded slot(block)
-    pub slot: u64,
+    /// Rewarded block height(slot)
+    pub block_height: u64,
     /// Spend hook for the output
     pub spend_hook: pallas::Base,
     /// User data for the output
@@ -148,7 +148,7 @@ impl PoWRewardCallBuilder {
     }
 
     pub fn build(&self) -> Result<PoWRewardCallDebris> {
-        let reward = expected_reward(self.slot);
+        let reward = expected_reward(self.block_height);
         assert!(reward != 0);
         self._build(reward)
     }

+ 12 - 12
src/contract/money/tests/pow_reward.rs

@@ -37,8 +37,8 @@ fn pow_reward() -> Result<()> {
         // Holders this test will use
         const HOLDERS: [Holder; 3] = [Holder::Faucet, Holder::Alice, Holder::Bob];
 
-        // Slot to verify against
-        let mut current_slot = 0;
+        // Block height(slot) to verify against
+        let mut current_height = 0;
 
         // Initialize harness
         let mut th = TestHarness::new(&["money".to_string()]).await?;
@@ -51,41 +51,41 @@ fn pow_reward() -> Result<()> {
         info!(target: "money", "[Malicious] =======================================");
         info!(target: "money", "[Malicious] Building PoW reward tx for genesis slot");
         info!(target: "money", "[Malicious] =======================================");
-        let (pow_reward_tx, _) = th.pow_reward(&Holder::Alice, current_slot, Some(0))?;
+        let (pow_reward_tx, _) = th.pow_reward(&Holder::Alice, current_height, Some(0))?;
 
         info!(target: "money", "[Malicious] =======================================");
         info!(target: "money", "[Malicious] Checking PoW reward tx for genesis slot");
         info!(target: "money", "[Malicious] =======================================");
-        th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_slot)
+        th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_height)
             .await?;
 
-        current_slot += 1;
-        th.generate_slot(current_slot).await?;
+        current_height += 1;
+        th.generate_slot(current_height).await?;
 
-        let alice_reward = expected_reward(current_slot);
+        let alice_reward = expected_reward(current_height);
         info!(target: "money", "[Malicious] ================================");
         info!(target: "money", "[Malicious] Building erroneous PoW reward tx");
         info!(target: "money", "[Malicious] ================================");
         let (pow_reward_tx, _) =
-            th.pow_reward(&Holder::Alice, current_slot, Some(alice_reward + 1))?;
+            th.pow_reward(&Holder::Alice, current_height, Some(alice_reward + 1))?;
 
         info!(target: "money", "[Malicious] =======================================");
         info!(target: "money", "[Malicious] Checking erroneous amount PoW reward tx");
         info!(target: "money", "[Malicious] =======================================");
-        th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_slot)
+        th.execute_erroneous_pow_reward_tx(&Holder::Alice, &pow_reward_tx.clone(), current_height)
             .await?;
 
         info!(target: "money", "[Alice] ======================");
         info!(target: "money", "[Alice] Building PoW reward tx");
         info!(target: "money", "[Alice] ======================");
         let (pow_reward_tx, pow_reward_params) =
-            th.pow_reward(&Holder::Alice, current_slot, None)?;
+            th.pow_reward(&Holder::Alice, current_height, None)?;
 
         for holder in &HOLDERS {
             info!(target: "money", "[{holder:?}] =============================");
             info!(target: "money", "[{holder:?}] Executing Alice PoW reward tx");
             info!(target: "money", "[{holder:?}] =============================");
-            th.execute_pow_reward_tx(holder, &pow_reward_tx, &pow_reward_params, current_slot)
+            th.execute_pow_reward_tx(holder, &pow_reward_tx, &pow_reward_params, current_height)
                 .await?;
         }
 
@@ -114,7 +114,7 @@ fn pow_reward() -> Result<()> {
             info!(target: "money", "[{holder:?}] ==============================");
             info!(target: "money", "[{holder:?}] Executing Alice2Bob payment tx");
             info!(target: "money", "[{holder:?}] ==============================");
-            th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_slot, true)
+            th.execute_transfer_tx(holder, &transfer_tx, &transfer_params, current_height, true)
                 .await?;
         }
 

+ 6 - 6
src/contract/test-harness/src/money_pow_reward.rs

@@ -37,7 +37,7 @@ impl TestHarness {
     pub fn pow_reward(
         &mut self,
         holder: &Holder,
-        slot: u64,
+        block_height: u64,
         reward: Option<u64>,
     ) -> Result<(Transaction, MoneyTokenMintParamsV1)> {
         let wallet = self.holders.get(holder).unwrap();
@@ -56,7 +56,7 @@ impl TestHarness {
 
         let builder = PoWRewardCallBuilder {
             keypair: wallet.keypair,
-            slot,
+            block_height,
             spend_hook,
             user_data,
             mint_zkbin: mint_zkbin.clone(),
@@ -93,14 +93,14 @@ impl TestHarness {
         holder: &Holder,
         tx: &Transaction,
         params: &MoneyTokenMintParamsV1,
-        slot: u64,
+        block_height: u64,
     ) -> Result<()> {
         let wallet = self.holders.get_mut(holder).unwrap();
         let tx_action_benchmark =
             self.tx_action_benchmarks.get_mut(&TxAction::MoneyPoWReward).unwrap();
         let timer = Instant::now();
 
-        wallet.validator.read().await.add_test_producer_transaction(tx, slot, true).await?;
+        wallet.validator.read().await.add_test_producer_transaction(tx, block_height, true).await?;
         wallet.money_merkle_tree.append(MerkleNode::from(params.output.coin.inner()));
         tx_action_benchmark.verify_times.push(timer.elapsed());
 
@@ -111,7 +111,7 @@ impl TestHarness {
         &mut self,
         holder: &Holder,
         tx: &Transaction,
-        slot: u64,
+        block_height: u64,
     ) -> Result<()> {
         let wallet = self.holders.get_mut(holder).unwrap();
         let tx_action_benchmark =
@@ -122,7 +122,7 @@ impl TestHarness {
             .validator
             .read()
             .await
-            .add_test_producer_transaction(tx, slot, true)
+            .add_test_producer_transaction(tx, block_height, true)
             .await
             .is_err());
         tx_action_benchmark.verify_times.push(timer.elapsed());

+ 4 - 4
src/sdk/src/blockchain.rs

@@ -121,13 +121,13 @@ impl Default for Slot {
 // TODO: This values are experimental, should be replaced with the proper ones once defined
 pub const POW_CUTOFF: u64 = 1000000;
 pub const POS_START: u64 = 1000001;
-/// Auxiliary function to calculate provided slot(block height) expected reward value.
+/// Auxiliary function to calculate provided block height(slot) expected reward value.
 /// Genesis slot(0) always returns reward value 0.
-/// We use PoW bootstrap, configured to reduce rewards at fixed slot numbers, until a cutoff.
+/// We use PoW bootstrap, configured to reduce rewards at fixed height numbers, until a cutoff.
 /// Once cut-off is reached, signalling PoS start, reward value is based on DARK token-economics.
-pub fn expected_reward(slot: u64) -> u64 {
+pub fn expected_reward(height: u64) -> u64 {
     // Configured block rewards (1 DRK == 1 * 10^8)
-    match slot {
+    match height {
         0 => 0,
         1..=1000 => 2_000_000_000,         // 20 DRK
         1001..=2000 => 1_800_000_000,      // 18 DRK