Skip to content

Commit

Permalink
fix: Revert block builder (#2)
Browse files Browse the repository at this point in the history
Fixed unmatched uncles count error

```
Verification(Uncles(MissMatchCount { expected: 2, actual: 1 }))
```
  • Loading branch information
quake authored and doitian committed Nov 20, 2018
1 parent 0db50a4 commit a42b2fa
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
8 changes: 0 additions & 8 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ impl Block {
&self.header
}

pub fn mut_header(&mut self) -> &mut Header {
&mut self.header
}

pub fn is_genesis(&self) -> bool {
self.header.is_genesis()
}
Expand Down Expand Up @@ -102,15 +98,11 @@ impl BlockBuilder {
}

pub fn uncle(mut self, uncle: UncleBlock) -> Self {
*self.inner.mut_header().mut_raw().mut_uncles_count() =
self.inner.header().raw().uncles_count() + 1;
self.inner.uncles.push(uncle);
self
}

pub fn uncles(mut self, uncles: Vec<UncleBlock>) -> Self {
*self.inner.mut_header().mut_raw().mut_uncles_count() =
self.inner.header().raw().uncles_count() + uncles.len() as u32;
self.inner.uncles.extend(uncles);
self
}
Expand Down
8 changes: 0 additions & 8 deletions core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,10 @@ impl Header {
self.raw.uncles_hash
}

pub fn raw(&self) -> &RawHeader {
&self.raw
}

pub fn into_raw(self) -> RawHeader {
self.raw
}

pub fn mut_raw(&mut self) -> &mut RawHeader {
&mut self.raw
}

pub fn uncles_count(&self) -> u32 {
self.raw.uncles_count
}
Expand Down
6 changes: 3 additions & 3 deletions verification/src/tests/uncle_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ fn test_uncle_verifier() {

let verifier = UnclesVerifier::new(shared.clone());

let mut block = BlockBuilder::default()
let block = BlockBuilder::default()
.block(chain1.last().cloned().unwrap())
.uncle(chain2.last().cloned().unwrap().into())
.build();

*block.mut_header().mut_raw().mut_uncles_count() = 0;
// Uncles not match uncles_hash
// Uncles not match uncles_count
assert_eq!(
verifier.verify(&block),
Err(Error::Uncles(UnclesError::MissMatchCount {
Expand All @@ -113,6 +112,7 @@ fn test_uncle_verifier() {

let block = BlockBuilder::default()
.block(chain1.last().cloned().unwrap())
.header(HeaderBuilder::default().uncles_count(1).build())
.uncle(chain2.last().cloned().unwrap().into())
.build();
// Uncles not match uncles_hash
Expand Down

0 comments on commit a42b2fa

Please sign in to comment.