Skip to content

Commit

Permalink
Merge pull request #1244 from dusk-network/rm-ts-check
Browse files Browse the repository at this point in the history
node: remove timestamp validation
  • Loading branch information
herr-seppia authored Jan 9, 2024
2 parents f66e030 + 145afb9 commit cbcf975
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 24 deletions.
6 changes: 0 additions & 6 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct RoundUpdate {

seed: Seed,
hash: [u8; 32],
timestamp: i64,
cert: Certificate,
}

Expand All @@ -53,7 +52,6 @@ impl RoundUpdate {
cert: mrb_block.header().cert,
hash: mrb_block.header().hash,
seed: mrb_block.header().seed,
timestamp: mrb_block.header().timestamp,
round_base_timeout,
}
}
Expand All @@ -66,10 +64,6 @@ impl RoundUpdate {
self.hash
}

pub fn timestamp(&self) -> i64 {
self.timestamp
}

pub fn cert(&self) -> &Certificate {
&self.cert
}
Expand Down
13 changes: 6 additions & 7 deletions consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<T: Operations> Generator<T> {
let blk_header = ledger::Header {
version: 0,
height: ru.round,
timestamp: self.get_timestamp(ru.timestamp()) as i64,
timestamp: self.get_timestamp(),
gas_limit: config::DEFAULT_BLOCK_GAS_LIMIT,
prev_block_hash,
seed,
Expand All @@ -134,11 +134,10 @@ impl<T: Operations> Generator<T> {
Ok(Block::new(blk_header, txs).expect("block should be valid"))
}

fn get_timestamp(&self, _prev_block_timestamp: i64) -> u64 {
// TODO: use config.MaxBlockTime
if let Ok(n) = SystemTime::now().duration_since(UNIX_EPOCH) {
return n.as_secs();
}
0
fn get_timestamp(&self) -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|n| n.as_secs())
.expect("This is heavy.")
}
}
8 changes: 4 additions & 4 deletions node-data/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct Header {
// Hashable fields
pub version: u8,
pub height: u64,
pub timestamp: i64,
pub timestamp: u64,
pub prev_block_hash: Hash,
pub seed: Seed,
pub state_hash: Hash,
Expand All @@ -49,7 +49,7 @@ pub struct Header {
impl std::fmt::Debug for Header {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let timestamp = chrono::NaiveDateTime::from_timestamp_opt(
self.timestamp,
self.timestamp as i64,
0,
)
.map_or_else(
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Header {
) -> io::Result<()> {
w.write_all(&self.version.to_le_bytes())?;
w.write_all(&self.height.to_le_bytes())?;
w.write_all(&(self.timestamp as u64).to_le_bytes())?;
w.write_all(&self.timestamp.to_le_bytes())?;
w.write_all(&self.prev_block_hash[..])?;

if fixed_size_seed {
Expand Down Expand Up @@ -165,7 +165,7 @@ impl Header {

let mut buf = [0u8; 8];
r.read_exact(&mut buf[..])?;
let timestamp = u64::from_le_bytes(buf) as i64;
let timestamp = u64::from_le_bytes(buf);

let mut prev_block_hash = [0u8; 32];
r.read_exact(&mut prev_block_hash[..])?;
Expand Down
5 changes: 0 additions & 5 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,6 @@ pub(crate) async fn verify_block_header<DB: database::DB>(
return Err(anyhow!("invalid previous block hash"));
}

if new_blk.timestamp < mrb.timestamp {
//TODO:
return Err(anyhow!("invalid block timestamp"));
}

// Ensure block is not already in the ledger
db.read().await.view(|v| {
if Ledger::get_block_exists(&v, &new_blk.hash)? {
Expand Down
4 changes: 2 additions & 2 deletions rusk/src/lib/http/chain/graphql/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Header<'_> {
hex::encode(self.0.prev_block_hash)
}

pub async fn timestamp(&self) -> i64 {
pub async fn timestamp(&self) -> u64 {
self.0.timestamp
}

Expand Down Expand Up @@ -202,7 +202,7 @@ impl SpentTransaction {
pub async fn block_timestamp(
&self,
ctx: &async_graphql::Context<'_>,
) -> FieldResult<i64> {
) -> FieldResult<u64> {
let db = ctx.data::<super::DBContext>()?.read().await;
let block_height = self.0.block_height;

Expand Down

0 comments on commit cbcf975

Please sign in to comment.