Skip to content

Commit

Permalink
Add traces to PoA builtin (paritytech#258)
Browse files Browse the repository at this point in the history
* replace debug printlns with traces

* cargo fmt --all

* fixed traces

* update RUST_LOG in docker-compose

* only print hex data if error has occured

* updated OE hash
  • Loading branch information
svyatonik authored and serban300 committed Apr 8, 2024
1 parent 2f44745 commit 64fa450
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bridges/modules/ethereum-contract/builtin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
codec = { package = "parity-scale-codec", version = "1.3.1" }
ethereum-types = "0.9.2"
finality-grandpa = "0.12.3"
hex = "0.4"
log = "0.4.11"

# Runtime/chain specific dependencies

Expand Down
63 changes: 56 additions & 7 deletions bridges/modules/ethereum-contract/builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ pub struct ValidatorsSetSignal {
/// Convert from U256 to BlockNumber. Fails if `U256` value isn't fitting within `BlockNumber`
/// limits (the runtime referenced by this module uses u32 as `BlockNumber`).
pub fn to_substrate_block_number(number: U256) -> Result<BlockNumber, Error> {
match number == number.low_u32().into() {
let substrate_block_number = match number == number.low_u32().into() {
true => Ok(number.low_u32()),
false => Err(Error::BlockNumberDecode),
}
};

log::trace!(
target: "bridge-builtin",
"Parsed Substrate block number from {}: {:?}",
number,
substrate_block_number,
);

substrate_block_number
}

/// Convert from BlockNumber to U256.
Expand All @@ -76,7 +85,7 @@ pub fn from_substrate_block_number(number: BlockNumber) -> Result<U256, Error> {

/// Parse Substrate header.
pub fn parse_substrate_header(raw_header: &[u8]) -> Result<Header, Error> {
RuntimeHeader::decode(&mut &raw_header[..])
let substrate_header = RuntimeHeader::decode(&mut &raw_header[..])
.map(|header| Header {
hash: header.hash(),
parent_hash: header.parent_hash,
Expand All @@ -100,7 +109,20 @@ pub fn parse_substrate_header(raw_header: &[u8]) -> Result<Header, Error> {
_ => None,
}),
})
.map_err(Error::HeaderDecode)
.map_err(Error::HeaderDecode);

log::debug!(
target: "bridge-builtin",
"Parsed Substrate header {}: {:?}",
if substrate_header.is_ok() {
format!("<{}-bytes-blob>", raw_header.len())
} else {
hex::encode(raw_header)
},
substrate_header,
);

substrate_header
}

/// Verify GRANDPA finality proof.
Expand All @@ -113,16 +135,43 @@ pub fn verify_substrate_finality_proof(
) -> Result<(), Error> {
let best_set = AuthorityList::decode(&mut &raw_best_set[..])
.map_err(Error::BestSetDecode)
.and_then(|authorities| VoterSet::new(authorities.into_iter()).ok_or(Error::InvalidBestSet))?;
sc_finality_grandpa::GrandpaJustification::<Block>::decode_and_verify_finalizes(
.and_then(|authorities| VoterSet::new(authorities.into_iter()).ok_or(Error::InvalidBestSet));

log::debug!(
target: "bridge-builtin",
"Parsed Substrate authorities set {}: {:?}",
if best_set.is_ok() {
format!("<{}-bytes-blob>", raw_best_set.len())
} else {
hex::encode(raw_best_set)
},
best_set,
);

let best_set = best_set?;

let verify_result = sc_finality_grandpa::GrandpaJustification::<Block>::decode_and_verify_finalizes(
&raw_finality_proof,
(finality_target_hash, finality_target_number),
best_set_id,
&best_set,
)
.map_err(Box::new)
.map_err(Error::JustificationVerify)
.map(|_| ())
.map(|_| ());

log::debug!(
target: "bridge-builtin",
"Verified Substrate finality proof {}: {:?}",
if verify_result.is_ok() {
format!("<{}-bytes-blob>", raw_finality_proof.len())
} else {
hex::encode(raw_finality_proof)
},
verify_result,
);

verify_result
}

#[cfg(test)]
Expand Down

0 comments on commit 64fa450

Please sign in to comment.