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

blockchain/Slot: renamed previous.eta to last_eta

aggstam 3 лет назад
Родитель
Сommit
df5f2a7568

+ 1 - 2
bin/darkfid2/src/tests/harness.rs

@@ -175,7 +175,6 @@ impl Harness {
                 producers,
                 vec![previous_hash],
                 vec![previous.header.previous.clone()],
-                pallas::Base::ZERO,
                 previous_slot.pid.error,
             );
             let (f, error, sigma1, sigma2) = slot_pid_output(&previous_slot, producers);
@@ -183,7 +182,7 @@ impl Harness {
             let total_tokens = previous_slot.total_tokens + previous_slot.reward;
             // Only last slot in the sequence has a reward
             let reward = if i == slots_count - 1 { next_block_reward() } else { 0 };
-            let slot = Slot::new(id, previous, pid, total_tokens, reward);
+            let slot = Slot::new(id, previous, pid, pallas::Base::ZERO, total_tokens, reward);
             slots.push(slot.clone());
             previous_slot = slot;
         }

+ 4 - 5
src/consensus/state.rs

@@ -164,10 +164,9 @@ impl ConsensusState {
         sigma2: pallas::Base,
     ) {
         let id = self.time_keeper.current_slot();
-        let previous =
-            PreviousSlot::new(0, fork_hashes, fork_previous_hashes, self.get_previous_eta(), 0.0);
+        let previous = PreviousSlot::new(0, fork_hashes, fork_previous_hashes, 0.0);
         let pid = PidOutput::new(0.0, 0.0, sigma1, sigma2);
-        let slot = Slot::new(id, previous, pid, 0, 0);
+        let slot = Slot::new(id, previous, pid, self.get_last_eta(), 0, 0);
         info!(target: "consensus::state", "generate_slot: {:?}", slot);
         self.slots.push(slot);
     }
@@ -438,7 +437,7 @@ impl ConsensusState {
             let first_winning = coin.is_leader(
                 sigma1,
                 sigma2,
-                self.get_previous_eta(),
+                self.get_last_eta(),
                 pallas::Base::from(self.time_keeper.current_slot()),
             );
 
@@ -549,7 +548,7 @@ impl ConsensusState {
 
     /// Utility function to extract leader selection lottery randomness(eta),
     /// defined as the hash of the last block, converted to pallas base.
-    pub fn get_previous_eta(&self) -> pallas::Base {
+    pub fn get_last_eta(&self) -> pallas::Base {
         let (_, hash) = self.blockchain.last().unwrap();
         let mut bytes: [u8; 32] = *hash.as_bytes();
         // Read first 254 bits

+ 2 - 2
src/consensus/validator.rs

@@ -364,7 +364,7 @@ impl ValidatorState {
         sigma1: pallas::Base,
         sigma2: pallas::Base,
     ) -> Result<Option<(BlockProposal, LeadCoin, pallas::Scalar)>> {
-        let eta = self.consensus.get_previous_eta();
+        let eta = self.consensus.get_last_eta();
         // Check if node can produce proposals
         if !self.consensus.proposing {
             return Ok(None)
@@ -578,7 +578,7 @@ impl ValidatorState {
 
             // Validate proposal public value against coin creation slot
             let (mu_y, mu_rho) = LeadCoin::election_seeds_u64(
-                self.consensus.get_previous_eta(),
+                self.consensus.get_last_eta(),
                 self.consensus.time_keeper.current_slot(),
             );
             // y

+ 1 - 1
src/contract/consensus/src/client/proposal_v1.rs

@@ -175,7 +175,7 @@ impl ConsensusProposalCallBuilder {
 
         info!("Building Consensus::ProposalV1 VRF proof");
         let mut vrf_input = Vec::with_capacity(32 + blake3::OUT_LEN + 32);
-        vrf_input.extend_from_slice(&self.slot.previous.eta.to_repr());
+        vrf_input.extend_from_slice(&self.slot.last_eta.to_repr());
         vrf_input.extend_from_slice(self.fork_previous_hash.as_bytes());
         vrf_input.extend_from_slice(&pallas::Base::from(self.slot.id).to_repr());
         let vrf_proof = VrfProof::prove(input.secret, &vrf_input, &mut OsRng);

+ 1 - 1
src/contract/consensus/src/entrypoint/proposal_v1.rs

@@ -94,7 +94,7 @@ pub(crate) fn consensus_proposal_get_metadata_v1(
 
     // Construct VRF input
     let mut vrf_input = Vec::with_capacity(32 + blake3::OUT_LEN + 32);
-    vrf_input.extend_from_slice(&slot.previous.eta.to_repr());
+    vrf_input.extend_from_slice(&slot.last_eta.to_repr());
     vrf_input.extend_from_slice(params.fork_previous_hash.as_bytes());
     vrf_input.extend_from_slice(&slot_fp.to_repr());
 

+ 2 - 8
src/contract/test-harness/src/lib.rs

@@ -456,15 +456,9 @@ impl TestHarness {
         // using same consensus parameters
         let genesis_block = self.genesis_block;
         let genesis_slot = self.get_slot_by_slot(0).await?;
-        let previous = PreviousSlot::new(
-            0,
-            vec![genesis_block],
-            vec![genesis_block],
-            genesis_slot.previous.eta,
-            0.0,
-        );
+        let previous = PreviousSlot::new(0, vec![genesis_block], vec![genesis_block], 0.0);
         let pid = PidOutput::new(0.0, 0.0, genesis_slot.pid.sigma1, genesis_slot.pid.sigma2);
-        let slot = Slot::new(id, previous, pid, 0, 0);
+        let slot = Slot::new(id, previous, pid, genesis_slot.last_eta, 0, 0);
 
         // Store generated slot
         for wallet in self.holders.values() {

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

@@ -31,8 +31,6 @@ pub struct PreviousSlot {
     /// Existing forks second to last proposal/block hashes,
     /// as observed by the validator
     pub second_to_last_hashes: Vec<blake3::Hash>,
-    /// Slot eta
-    pub eta: pallas::Base,
     /// Feedback error
     pub error: f64,
 }
@@ -42,17 +40,16 @@ impl PreviousSlot {
         producers: u64,
         last_hashes: Vec<blake3::Hash>,
         second_to_last_hashes: Vec<blake3::Hash>,
-        eta: pallas::Base,
         error: f64,
     ) -> Self {
-        Self { producers, last_hashes, second_to_last_hashes, eta, error }
+        Self { producers, last_hashes, second_to_last_hashes, error }
     }
 }
 
 impl Default for PreviousSlot {
     /// Represents the genesis slot previous slot on current timestamp
     fn default() -> Self {
-        Self::new(0, vec![], vec![], pallas::Base::ZERO, 0.0)
+        Self::new(0, vec![], vec![], 0.0)
     }
 }
 
@@ -91,6 +88,8 @@ pub struct Slot {
     pub previous: PreviousSlot,
     /// Slot PID output
     pub pid: PidOutput,
+    /// Last block/proposal eta
+    pub last_eta: pallas::Base,
     /// Total tokens up until this slot
     pub total_tokens: u64,
     /// Slot reward
@@ -102,16 +101,17 @@ impl Slot {
         id: u64,
         previous: PreviousSlot,
         pid: PidOutput,
+        last_eta: pallas::Base,
         total_tokens: u64,
         reward: u64,
     ) -> Self {
-        Self { id, previous, pid, total_tokens, reward }
+        Self { id, previous, pid, last_eta, total_tokens, reward }
     }
 }
 
 impl Default for Slot {
     /// Represents the genesis slot on current timestamp
     fn default() -> Self {
-        Self::new(0, PreviousSlot::default(), PidOutput::default(), 0, 0)
+        Self::new(0, PreviousSlot::default(), PidOutput::default(), pallas::Base::ZERO, 0, 0)
     }
 }

+ 1 - 1
src/validator/consensus/mod.rs

@@ -113,7 +113,7 @@ impl Consensus {
         }
 
         // Check if proposal extends any existing forks
-        let (mut fork, index) = self.find_extended_fork(&proposal).await?;
+        let (mut fork, index) = self.find_extended_fork(proposal).await?;
 
         // Grab overlay last block
         let previous = fork.overlay.lock().unwrap().last_block()?;

+ 1 - 1
src/validator/verification.rs

@@ -123,7 +123,7 @@ pub async fn verify_block(
     // Validate proposal transaction if not in testing mode
     if !testing_mode {
         verify_proposal_transaction(overlay, time_keeper, &block.producer.proposal).await?;
-        verify_producer_signature(&block)?;
+        verify_producer_signature(block)?;
     }
 
     // Verify transactions