Skip to content

Commit a42b2fa

Browse files
quakedoitian
authored andcommitted
fix: Revert block builder (#2)
Fixed unmatched uncles count error ``` Verification(Uncles(MissMatchCount { expected: 2, actual: 1 })) ```
1 parent 0db50a4 commit a42b2fa

3 files changed

Lines changed: 3 additions & 19 deletions

File tree

core/src/block.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ impl Block {
3232
&self.header
3333
}
3434

35-
pub fn mut_header(&mut self) -> &mut Header {
36-
&mut self.header
37-
}
38-
3935
pub fn is_genesis(&self) -> bool {
4036
self.header.is_genesis()
4137
}
@@ -102,15 +98,11 @@ impl BlockBuilder {
10298
}
10399

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

111105
pub fn uncles(mut self, uncles: Vec<UncleBlock>) -> Self {
112-
*self.inner.mut_header().mut_raw().mut_uncles_count() =
113-
self.inner.header().raw().uncles_count() + uncles.len() as u32;
114106
self.inner.uncles.extend(uncles);
115107
self
116108
}

core/src/header.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,10 @@ impl Header {
138138
self.raw.uncles_hash
139139
}
140140

141-
pub fn raw(&self) -> &RawHeader {
142-
&self.raw
143-
}
144-
145141
pub fn into_raw(self) -> RawHeader {
146142
self.raw
147143
}
148144

149-
pub fn mut_raw(&mut self) -> &mut RawHeader {
150-
&mut self.raw
151-
}
152-
153145
pub fn uncles_count(&self) -> u32 {
154146
self.raw.uncles_count
155147
}

verification/src/tests/uncle_verifier.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ fn test_uncle_verifier() {
9494

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

97-
let mut block = BlockBuilder::default()
97+
let block = BlockBuilder::default()
9898
.block(chain1.last().cloned().unwrap())
9999
.uncle(chain2.last().cloned().unwrap().into())
100100
.build();
101101

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

114113
let block = BlockBuilder::default()
115114
.block(chain1.last().cloned().unwrap())
115+
.header(HeaderBuilder::default().uncles_count(1).build())
116116
.uncle(chain2.last().cloned().unwrap().into())
117117
.build();
118118
// Uncles not match uncles_hash

0 commit comments

Comments
 (0)