Forgotten testnet1 cherries (#475)
* Very quick peer banning endpoint, helps with #406 * Ping heights (#407) * add height to ping/ping * reformat output * fix p2p test * Fix orphan handling, not related to current head. Fixes #412 * Check before borrow, fixes #267 * Not finding an output commit in pos is an AlreadySpent * Fix race condition, sending before conn is ready * Explicit error for unknown pos of a forked block * Remove config outdated tests. Fix #333 * Check ref and try before borrow, fix #400 * We do not want to sync with old peers anyway * Hide cargo compiler warning for unused NoopAdapter and unused test code. Add TODOs
This commit is contained in:
committed by
Ignotus Peverell
parent
bffd955c26
commit
17d5898677
+8
-7
@@ -156,9 +156,6 @@ fn check_known(bh: Hash, ctx: &mut BlockContext) -> Result<(), Error> {
|
||||
/// arranged by order of cost to have as little DoS surface as possible.
|
||||
/// TODO require only the block header (with length information)
|
||||
fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), Error> {
|
||||
if header.height > ctx.head.height + 1 {
|
||||
return Err(Error::Orphan);
|
||||
}
|
||||
|
||||
// check version, enforces scheduled hard fork
|
||||
if !consensus::valid_header_version(header.height, header.version) {
|
||||
@@ -188,16 +185,20 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), E
|
||||
}
|
||||
|
||||
// first I/O cost, better as late as possible
|
||||
let prev = try!(ctx.store.get_block_header(&header.previous,).map_err(|e| {
|
||||
Error::StoreErr(e, format!("previous block header {}", header.previous))
|
||||
},));
|
||||
let prev = match ctx.store.get_block_header(&header.previous) {
|
||||
Ok(prev) => Ok(prev),
|
||||
Err(grin_store::Error::NotFoundErr) => Err(Error::Orphan),
|
||||
Err(e) =>{
|
||||
Err(Error::StoreErr(e, format!("previous header {}", header.previous)))
|
||||
}
|
||||
}?;
|
||||
|
||||
if header.height != prev.height + 1 {
|
||||
return Err(Error::InvalidBlockHeight);
|
||||
}
|
||||
if header.timestamp <= prev.timestamp && !global::is_automated_testing_mode() {
|
||||
// prevent time warp attacks and some timestamp manipulations by forcing strict
|
||||
// time progression (but not in CI mode)
|
||||
// time progression (but not in CI mode)
|
||||
return Err(Error::InvalidBlockTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -253,9 +253,7 @@ impl<'a> Extension<'a> {
|
||||
Err(s) => return Err(Error::SumTreeErr(s)),
|
||||
}
|
||||
} else {
|
||||
return Err(Error::SumTreeErr(
|
||||
format!("Missing index for {:?}", input.commitment()),
|
||||
));
|
||||
return Err(Error::AlreadySpent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,12 +344,18 @@ impl<'a> Extension<'a> {
|
||||
);
|
||||
|
||||
let out_pos_rew = match block.outputs.last() {
|
||||
Some(output) => self.commit_index.get_output_pos(&output.commitment())?,
|
||||
Some(output) => self.commit_index.get_output_pos(&output.commitment())
|
||||
.map_err(|e| {
|
||||
Error::StoreErr(e, format!("missing output pos for known block"))
|
||||
})?,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
let kern_pos_rew = match block.kernels.last() {
|
||||
Some(kernel) => self.commit_index.get_kernel_pos(&kernel.excess)?,
|
||||
Some(kernel) => self.commit_index.get_kernel_pos(&kernel.excess)
|
||||
.map_err(|e| {
|
||||
Error::StoreErr(e, format!("missing kernel pos for known block"))
|
||||
})?,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user