Skip to content

Commit

Permalink
chore: reset version for reset (#4914)
Browse files Browse the repository at this point in the history
Description
---
The resets all versioning for the reset. 
It also removes all redundant versioning code. 

How Has This Been Tested?
---
pass all unit tests
  • Loading branch information
SWvheerden authored Nov 14, 2022
1 parent bd72d03 commit 5d1d25d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 55 deletions.
28 changes: 1 addition & 27 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,6 @@ impl ConsensusConstants {
target_time: 200,
});
let (input_version_range, output_version_range, kernel_version_range) = version_zero();
let output_version_2_range = OutputVersionRange {
outputs: TransactionOutputVersion::V0..=TransactionOutputVersion::V0,
features: OutputFeaturesVersion::V0..=OutputFeaturesVersion::V0,
opcode: OpcodeVersion::V0..=OpcodeVersion::V1,
};
let consensus_constants_1 = ConsensusConstants {
effective_from_height: 0,
coinbase_lock_height: 6,
Expand All @@ -534,29 +529,8 @@ impl ConsensusConstants {
kernel_version_range,
permitted_output_types: Self::current_permitted_output_types(),
};
let consensus_constants_2 = ConsensusConstants {
effective_from_height: 23000,
blockchain_version: 1,
valid_blockchain_version_range: 0..=1,
..consensus_constants_1.clone()
};
let consensus_constants_3 = ConsensusConstants {
effective_from_height: 25000,
output_version_range: output_version_2_range,
..consensus_constants_2.clone()
};
let consensus_constants_4 = ConsensusConstants {
effective_from_height: 33000,
blockchain_version: 2,
..consensus_constants_3.clone()
};

vec![
consensus_constants_1,
consensus_constants_2,
consensus_constants_3,
consensus_constants_4,
]
vec![consensus_constants_1]
}

pub fn mainnet() -> Vec<Self> {
Expand Down
31 changes: 7 additions & 24 deletions base_layer/core/src/proof_of_work/sha3_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,16 @@ use crate::{
/// Mining using this CPU version of the algorithm is unlikely to be profitable, but is included for reference and
/// can be used to mine tXTR on testnets.
pub fn sha3x_difficulty(header: &BlockHeader) -> Difficulty {
match header.version {
2 => sha3x_difficulty_with_hash(header).0,
_ => old_sha3_difficulty_with_hash(header).0,
}
sha3x_difficulty_with_hash(header).0
}

pub fn sha3_hash(header: &BlockHeader) -> Vec<u8> {
let sha = Sha3_256::new();
match header.version {
0 => sha
.chain(header.mining_hash())
.chain(header.nonce.to_le_bytes())
.chain(header.pow.to_bytes()),
_ => sha
.chain(header.nonce.to_le_bytes())
.chain(header.mining_hash())
.chain(header.pow.to_bytes()),
}
.finalize()
.to_vec()
Sha3_256::new()
.chain(header.nonce.to_le_bytes())
.chain(header.mining_hash())
.chain(header.pow.to_bytes())
.finalize()
.to_vec()
}

fn sha3x_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec<u8>) {
Expand All @@ -64,13 +54,6 @@ fn sha3x_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec<u8>) {
(difficulty, hash.to_vec())
}

fn old_sha3_difficulty_with_hash(header: &BlockHeader) -> (Difficulty, Vec<u8>) {
let hash = sha3_hash(header);
let hash = Sha3_256::digest(&hash);
let difficulty = big_endian_difficulty(&hash);
(difficulty, hash.to_vec())
}

#[cfg(test)]
pub mod test {
use chrono::{DateTime, NaiveDate, Utc};
Expand Down
4 changes: 2 additions & 2 deletions base_layer/tari_mining_helper_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ mod tests {

#[test]
fn detect_change_in_consensus_encoding() {
const NONCE: u64 = 1368783905506569398;
const DIFFICULTY: Difficulty = Difficulty::from_u64(3549);
const NONCE: u64 = 18006431465547767508;
const DIFFICULTY: Difficulty = Difficulty::from_u64(13879);
unsafe {
let mut error = -1;
let error_ptr = &mut error as *mut c_int;
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/tari_script/src/op_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ impl Opcode {
Opcode::CheckSigVerify(..) |
Opcode::CheckMultiSig(..) |
Opcode::CheckMultiSigVerify(..) |
Opcode::CheckMultiSigVerifyAggregatePubKey(..) |
Opcode::ToRistrettoPoint |
Opcode::Return |
Opcode::IfThen |
Opcode::Else |
Opcode::EndIf => OpcodeVersion::V0,
Opcode::CheckMultiSigVerifyAggregatePubKey(..) => OpcodeVersion::V1,
}
}

Expand Down Expand Up @@ -636,7 +636,6 @@ impl fmt::Display for Opcode {
#[repr(u8)]
pub enum OpcodeVersion {
V0 = 0,
V1 = 1,
}

#[cfg(test)]
Expand Down

0 comments on commit 5d1d25d

Please sign in to comment.