Skip to content

Commit

Permalink
Make ballast in genesis block pseudo-random rather than filled with z…
Browse files Browse the repository at this point in the history
…eroes
  • Loading branch information
nazar-pc committed Jun 29, 2023
1 parent 25ae19b commit 6d46af6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/subspace-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jsonrpsee = { version = "0.16.2", features = ["server"] }
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
parity-scale-codec = "3.6.1"
parking_lot = "0.12.1"
rand = "0.8.5"
rand_chacha = "0.3.1"
sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
sc-chain-spec = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "28e33f78a3aa8ac4c6753108bc0471273ff6bf6f" }
Expand Down
13 changes: 11 additions & 2 deletions crates/subspace-service/src/genesis_block_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
use sc_client_api::backend::Backend;
use sc_client_api::BlockImportOperation;
use sc_executor::RuntimeVersionOf;
Expand Down Expand Up @@ -67,7 +69,7 @@ impl<Block: BlockT, B: Backend<Block>, E: RuntimeVersionOf> BuildGenesisBlock<Bl

/// Create a custom Subspace genesis block, given the initial storage.
///
/// We have a non-empty digest in comparision to the default Substrate genesis block.
/// We have a non-empty digest in comparison to the default Substrate genesis block.
fn construct_genesis_block<Block: BlockT>(
state_root: Block::Hash,
state_version: StateVersion,
Expand All @@ -79,7 +81,14 @@ fn construct_genesis_block<Block: BlockT>(

// We fill genesis block with extra data such that the very first archived
// segment can be produced right away, bootstrapping the farming process.
let ballast = vec![0; RecordedHistorySegment::SIZE];
let mut ballast = vec![0; RecordedHistorySegment::SIZE];
let mut rng = ChaCha8Rng::from_seed(
state_root
.as_ref()
.try_into()
.expect("State root in Subspace must be 32 bytes, panic itherwise; qed"),
);
rng.fill(ballast.as_mut_slice());
let digest = Digest {
logs: vec![DigestItem::Other(ballast)],
};
Expand Down

0 comments on commit 6d46af6

Please sign in to comment.