Skip to content

Commit

Permalink
dirty data in extra data is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Sep 21, 2023
1 parent 474debb commit 3917f0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 22 additions & 11 deletions core/consensus/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,28 @@ impl<Adapter: ConsensusAdapter + 'static> Engine<Proposal> for ConsensusEngine<A
}

if let Some(t) = proposal.extra_data.get(0) {
if let Ok(data) = HardforkInfoInner::decode(&t.inner) {
if !self
.node_info
.hardfork_proposals
.read()
.unwrap()
.as_ref()
.map(|v| &data == v)
.unwrap_or_default()
{
return Err(ProtocolError::from(ConsensusError::HardforkDontMatch).into());
match HardforkInfoInner::decode(&t.inner) {
Ok(data) => {
if !self
.node_info
.hardfork_proposals
.read()
.unwrap()
.as_ref()
.map(|v| &data == v)
.unwrap_or_default()
{
return Err(ProtocolError::from(ConsensusError::Hardfork(
"hardfork proposal doesn't match".to_string(),
))
.into());
}
}
Err(_) => {
return Err(ProtocolError::from(ConsensusError::Hardfork(
"hardfork proposal can't decode".to_string(),
))
.into())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ pub enum ConsensusError {
#[display(fmt = "Build trie merkle tree error {}", _0)]
BuildMerkle(String),

#[display(fmt = "Proposal hardfork info don't match")]
HardforkDontMatch,
#[display(fmt = "Proposal hardfork info error {}", _0)]
Hardfork(String),
}

#[derive(Debug, Display)]
Expand Down

0 comments on commit 3917f0c

Please sign in to comment.