Skip to content

Commit

Permalink
Async Block verification in ChainSync (#409)
Browse files Browse the repository at this point in the history
* bump base64 from 1.12.0 to 1.12.1

* bump rocksdb from 1.13 to 1.14

* asyncronize block validation
  • Loading branch information
ec2 authored May 12, 2020
1 parent 0bba0ec commit ef7aafd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions blockchain/chain_sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
b.secp_msg_includes,
)?;
// validate tipset and messages
self.validate_tipsets(fts)?;
self.validate_tipsets(fts).await?;
// store messages
self.chain_store.put_messages(&b.bls_msgs)?;
self.chain_store.put_messages(&b.secp_msgs)?;
Expand All @@ -277,7 +277,7 @@ where
}
};
// full tipset found in storage; validate and continue
self.validate_tipsets(fts)?;
self.validate_tipsets(fts).await?;
i -= 1;
continue;
}
Expand Down Expand Up @@ -616,7 +616,7 @@ where
}

/// Validates block semantically according to https://github.com/filecoin-project/specs/blob/6ab401c0b92efb6420c6e198ec387cf56dc86057/validation.md
fn validate(&self, block: &Block) -> Result<(), Error> {
async fn validate(&self, block: &Block) -> Result<(), Error> {
let header = block.header();

// check if block has been signed
Expand Down Expand Up @@ -662,13 +662,13 @@ where
Ok(())
}
/// validates tipsets and adds header data to tipset tracker
fn validate_tipsets(&mut self, fts: FullTipset) -> Result<(), Error> {
async fn validate_tipsets(&mut self, fts: FullTipset) -> Result<(), Error> {
if fts.to_tipset()? == self.genesis {
return Ok(());
}

for b in fts.blocks() {
if let Err(e) = self.validate(b) {
if let Err(e) = self.validate(b).await {
self.bad_blocks.put(b.cid().clone(), e.to_string());
return Err(Error::Other("Invalid blocks detected".to_string()));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/serialization_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde_tests = ["serde", "crypto", "base64"]
[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true }
crypto = { path = "../../crypto", optional = true }
base64 = { version = "0.12.0", optional = true }
base64 = { version = "0.12.1", optional = true }

[dev-dependencies]
cid = { package = "forest_cid", path = "../../ipld/cid", features = ["cbor", "json"] }
Expand Down

0 comments on commit ef7aafd

Please sign in to comment.