Skip to content

Commit

Permalink
Merge pull request #389 from helium/madninja/unique_entropy
Browse files Browse the repository at this point in the history
Use the solana block hash as source of data
  • Loading branch information
madninja authored Feb 25, 2023
2 parents 59d648e + 212de6c commit 6bd3575
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion poc_entropy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ thiserror = {workspace = true}
serde = {workspace = true}
serde_json = {workspace = true}
base64 = {workspace = true}
sha2 = {workspace = true}
blake3 = {workspace = true}
http = {workspace = true}
tonic = {workspace = true}
hyper = "0"
Expand Down
25 changes: 16 additions & 9 deletions poc_entropy/src/entropy_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,25 @@ impl EntropyGenerator {
&mut self,
file_sink: &file_sink::FileSinkClient,
) -> anyhow::Result<()> {
match Self::get_entropy(&self.client).await {
Ok(data) => self.sender.send_modify(|entry| {
entry.timestamp = Utc::now().timestamp();
entry.data = data;
entry.version = ENTROPY_VERSION;
}),
let source_data = match Self::get_entropy(&self.client).await {
Ok(data) => data,
Err(err) => {
tracing::warn!("failed to get entropy: {err:?}");
self.sender
.send_modify(|entry| entry.timestamp = Utc::now().timestamp());
(*self.receiver.borrow().data).to_vec()
}
}
};
let timestamp = Utc::now().timestamp();

let mut hasher = blake3::Hasher::new();
hasher.update(&timestamp.to_le_bytes());
hasher.update(&source_data);
let data = hasher.finalize().as_bytes().to_vec();

self.sender.send_modify(|entry| {
entry.timestamp = timestamp;
entry.data = data;
});

let entropy = &*self.receiver.borrow();
tracing::info!(
"using entropy: {} at: {}",
Expand Down

0 comments on commit 6bd3575

Please sign in to comment.