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

Make ballast in genesis block pseudo-random rather than filled with zeroes #1620

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 otherwise; qed"),
);
rng.fill(ballast.as_mut_slice());
let digest = Digest {
logs: vec![DigestItem::Other(ballast)],
};
Expand Down