From fc2c1d6a64ae5ee04436ffcbb8ac935d10a234e5 Mon Sep 17 00:00:00 2001 From: serejkaaa512 <5125402@mail.ru> Date: Thu, 12 Sep 2024 12:01:33 +0300 Subject: [PATCH] feat(collator): add seqno to rand seed --- collator/src/collator/do_collate.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/collator/src/collator/do_collate.rs b/collator/src/collator/do_collate.rs index 1f196a95d..dba0496ec 100644 --- a/collator/src/collator/do_collate.rs +++ b/collator/src/collator/do_collate.rs @@ -73,11 +73,15 @@ impl CollatorStdImpl { .get_last_imported_anchor_ct_and_author() .unwrap(); - // TODO: need to generate unique for each block - // generate seed from the chain_time from the anchor + // Generate unique rand seed from the anchor chain_time and the next block seqno let hash_bytes = sha2::Sha256::digest(next_chain_time.to_be_bytes()); - let rand_seed = HashBytes::from_slice(hash_bytes.as_slice()); - tracing::trace!(target: tracing_targets::COLLATOR, "rand_seed from chain time: {}", rand_seed); + let seqno = working_state.next_block_id_short.seqno.to_be_bytes(); + let rand_seed = HashBytes::from_slice( + [&hash_bytes.as_slice()[..32 - 4], &seqno[..]] + .concat() + .as_slice(), + ); + tracing::trace!(target: tracing_targets::COLLATOR, "rand_seed from chain time and block seqno: {}", rand_seed); let is_masterchain = self.shard_id.is_masterchain();