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

consensus: use last blockhash for eta instead of leadproof hash

aggstam 3 лет назад
Родитель
Сommit
56b5a0758e
2 измененных файлов с 7 добавлено и 29 удалено
  1. 1 23
      src/blockchain/mod.rs
  2. 6 6
      src/consensus/state.rs

+ 1 - 23
src/blockchain/mod.rs

@@ -16,13 +16,12 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use darkfi_serial::serialize;
 use log::debug;
 
 use crate::{
     consensus::{Block, BlockInfo, SlotCheckpoint},
     util::time::Timestamp,
-    Error, Result,
+    Result,
 };
 
 pub mod block_store;
@@ -179,27 +178,6 @@ impl Blockchain {
         self.order.get_last()
     }
 
-    /// Retrieve last finalized block leader proof hash.
-    pub fn get_last_proof_hash(&self) -> Result<blake3::Hash> {
-        let (_, hash) = self.last().unwrap();
-        let blocks = self.blocks.get(&[hash], true)?;
-        // Since we used strict get, its safe to unwrap here
-        let block = blocks[0].clone().unwrap();
-        let hash = blake3::hash(&serialize(&block.lead_info.proof));
-        Ok(hash)
-    }
-
-    pub fn get_proof_hash_by_slot(&self, slot: u64) -> Result<blake3::Hash> {
-        let blocks = self.get_blocks_by_slot(&[slot]).unwrap();
-        if blocks.is_empty() {
-            return Err(Error::BlockNotFound("block not found".to_string()))
-        }
-        // Since we used strict get, its safe to unwrap here
-        let block = blocks[0].clone();
-        let hash = blake3::hash(&serialize(&block.lead_info.proof));
-        Ok(hash)
-    }
-
     /// Retrieve the last slot checkpoint.
     pub fn last_slot_checkpoint(&self) -> Result<SlotCheckpoint> {
         self.slot_checkpoints.get_last()

+ 6 - 6
src/consensus/state.rs

@@ -323,8 +323,8 @@ impl ConsensusState {
                 // Temporarily, we compete with fixed stake.
                 // This stake should be based on how many nodes we want to run, and they all
                 // must sum to initial distribution total coins.
-                //let stake = self.initial_distribution;
-                let stake = 200;
+                let stake = self.initial_distribution;
+                //let stake = 200;
                 let c = LeadCoin::new(
                     stake,
                     slot,
@@ -637,11 +637,11 @@ impl ConsensusState {
     }
 
     /// Utility function to extract leader selection lottery randomness(eta),
-    /// defined as the hash of the previous lead proof converted to pallas base.
+    /// defined as the hash of the last block, converted to pallas base.
     pub fn get_eta(&self) -> pallas::Base {
-        let proof_tx_hash = self.blockchain.get_last_proof_hash().unwrap();
-        let mut bytes: [u8; 32] = *proof_tx_hash.as_bytes();
-        // read first 254 bits
+        let (_, hash) = self.blockchain.last().unwrap();
+        let mut bytes: [u8; 32] = *hash.as_bytes();
+        // Read first 254 bits
         bytes[30] = 0;
         bytes[31] = 0;
         pallas::Base::from_repr(bytes).unwrap()