Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add issuing_time check #1821

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions sdk/src/client/api/block_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod transaction;

pub use self::transaction::verify_semantic;
use crate::{
client::{ClientInner, Result},
client::{constants::FIVE_MINUTES_IN_NANOSECONDS, ClientInner, Error, Result},
types::block::{
core::{BlockHeader, UnsignedBlock},
output::AccountId,
Expand All @@ -19,7 +19,6 @@ impl ClientInner {
pub async fn build_basic_block(&self, issuer_id: AccountId, payload: Option<Payload>) -> Result<UnsignedBlock> {
let issuance = self.get_issuance().await?;

// TODO https://github.com/iotaledger/iota-sdk/issues/1753
let issuing_time = {
#[cfg(feature = "std")]
let issuing_time = std::time::SystemTime::now()
Expand All @@ -30,7 +29,20 @@ impl ClientInner {
// https://github.com/iotaledger/iota-sdk/issues/647
#[cfg(not(feature = "std"))]
let issuing_time = 0;
issuing_time

// Check that the issuing_time is in the range of +-5 minutes of the node to prevent potential issues
if !(issuance.latest_parent_block_issuing_time - FIVE_MINUTES_IN_NANOSECONDS
..issuance.latest_parent_block_issuing_time + FIVE_MINUTES_IN_NANOSECONDS)
.contains(&issuing_time)
{
return Err(Error::TimeNotSynced {
current_time: issuing_time,
tangle_time: issuance.latest_parent_block_issuing_time,
});
}
// If timestamp is below latest_parent_block_issuing_time, just increase it to that +1 so the block doesn't
// get rejected
issuing_time.max(issuance.latest_parent_block_issuing_time + 1)
};

let protocol_params = self.get_protocol_parameters().await?;
Expand Down