浏览代码

blockstore: Chain merkle root for slot 0 to genesis hash (#9163)

The function create_new_ledger() is used by solana-genesis to create a
new blockstore with slot 0 full of ticks. The chained merkle root for
the shredder is currently initialized to an array of random bytes. This
means that calling this function two times with the same genesis config
will yield different chained merkle roots.

There is no reason for this to be the case and we can make this
deterministic by seeding the chained merkle root for slot 0 with the
genesis hash
steviez 13 小时之前
父节点
当前提交
108e72547a
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      ledger/src/blockstore.rs

+ 4 - 2
ledger/src/blockstore.rs

@@ -4820,14 +4820,16 @@ pub fn create_new_ledger(
     let entries = create_ticks(ticks_per_slot, hashes_per_tick, genesis_config.hash());
     let last_hash = entries.last().unwrap().hash;
     let version = solana_shred_version::version_from_hash(&last_hash);
+    // Slot 0 has no parent slot so there is nothing to chain to; instead,
+    // initialize the chained merkle root with the genesis hash
+    let chained_merkle_root = genesis_config.hash();
 
     let shredder = Shredder::new(0, 0, 0, version).unwrap();
     let (shreds, _) = shredder.entries_to_merkle_shreds_for_tests(
         &Keypair::new(),
         &entries,
         true, // is_last_in_slot
-        // chained_merkle_root
-        Hash::new_from_array(rand::rng().random()),
+        chained_merkle_root,
         0, // next_shred_index
         0, // next_code_index
         &ReedSolomonCache::default(),