Skip to content

Commit

Permalink
node: change block timestamp validation
Browse files Browse the repository at this point in the history
Resolves #1062
  • Loading branch information
herr-seppia committed Jan 8, 2024
1 parent 00e3943 commit 57bb4c5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::database::{self, Ledger, Mempool};
use crate::{vm, Message, Network};
use anyhow::{anyhow, Result};
use dusk_consensus::commons::ConsensusError;
use dusk_consensus::config::CONSENSUS_ROLLING_FINALITY_THRESHOLD;
use dusk_consensus::config::{
CONSENSUS_ROLLING_FINALITY_THRESHOLD, MAX_BLOCK_SECS_DRIFT,
};
use dusk_consensus::user::committee::CommitteeSet;
use dusk_consensus::user::provisioners::{ContextProvisioners, Provisioners};
use node_data::ledger::{
Expand All @@ -19,6 +21,7 @@ use node_data::message::AsyncQueue;
use node_data::message::Payload;
use node_data::StepName;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::sync::RwLock;
use tracing::{info, warn};

Expand Down Expand Up @@ -579,8 +582,15 @@ pub(crate) async fn verify_block_header<DB: database::DB>(
return Err(anyhow!("invalid previous block hash"));
}

if new_blk.timestamp < mrb.timestamp {
//TODO:
// Get the current time as Unix timestamp
let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Great Scott!")
.as_secs();

let max_accepted_ts = current_time + MAX_BLOCK_SECS_DRIFT;

if new_blk.timestamp > max_accepted_ts {
return Err(anyhow!("invalid block timestamp"));
}

Expand Down

0 comments on commit 57bb4c5

Please sign in to comment.