Skip to content

Commit

Permalink
Client level patch for parent hash (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel authored Feb 7, 2022
1 parent 0b66a77 commit 4cf13fc
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions client/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,30 @@ where
let is_eip1559 = handler.is_eip1559(&id);

match (block, statuses) {
(Some(block), Some(statuses)) => Ok(Some(rich_block_build(
block,
statuses.into_iter().map(|s| Some(s)).collect(),
Some(hash),
full,
base_fee,
is_eip1559,
))),
(Some(block), Some(statuses)) => {
let mut rich_block = rich_block_build(
block,
statuses.into_iter().map(|s| Some(s)).collect(),
Some(hash),
full,
base_fee,
is_eip1559,
);
// Indexers heavily rely on the parent hash.
// Moonbase client-level patch for inconsistent runtime 1200 state.
let number = rich_block.inner.header.number.unwrap_or_default();
if rich_block.inner.header.parent_hash == H256::default()
&& number > U256::zero() {
if let Ok(Some(parent)) = self.block_by_number(
BlockNumber::Num((number - 1).low_u64()),
false
) {
rich_block.inner.header.parent_hash = parent.inner.header.hash.unwrap_or_default();
}
}
Ok(Some(rich_block))

},
_ => Ok(None),
}
}
Expand Down Expand Up @@ -769,14 +785,27 @@ where
let hash =
H256::from_slice(Keccak256::digest(&rlp::encode(&block.header)).as_slice());

Ok(Some(rich_block_build(
let mut rich_block = rich_block_build(
block,
statuses.into_iter().map(|s| Some(s)).collect(),
Some(hash),
full,
base_fee,
is_eip1559,
)))
);
// Indexers heavily rely on the parent hash.
// Moonbase client-level patch for inconsistent runtime 1200 state.
let number = rich_block.inner.header.number.unwrap_or_default();
if rich_block.inner.header.parent_hash == H256::default()
&& number > U256::zero() {
if let Ok(Some(parent)) = self.block_by_number(
BlockNumber::Num((number - 1).low_u64()),
false
) {
rich_block.inner.header.parent_hash = parent.inner.header.hash.unwrap_or_default();
}
}
Ok(Some(rich_block))
}
_ => Ok(None),
}
Expand Down

0 comments on commit 4cf13fc

Please sign in to comment.