mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Add tests and modify as_vec implementation (#3715)
* Add tests and modify as_vec implementation * Address feedback * fix typo in test
This commit is contained in:
@@ -363,7 +363,7 @@ impl RunningTask {
|
||||
|
||||
fn validate_chunk(&self, validator: &AuthorityDiscoveryId, chunk: &ErasureChunk) -> bool {
|
||||
let anticipated_hash =
|
||||
match branch_hash(&self.erasure_root, &chunk.proof_as_vec(), chunk.index.0 as usize) {
|
||||
match branch_hash(&self.erasure_root, chunk.proof(), chunk.index.0 as usize) {
|
||||
Ok(hash) => hash,
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
|
||||
@@ -363,11 +363,9 @@ impl RequestChunksPhase {
|
||||
|
||||
let validator_index = chunk.index;
|
||||
|
||||
if let Ok(anticipated_hash) = branch_hash(
|
||||
¶ms.erasure_root,
|
||||
&chunk.proof_as_vec(),
|
||||
chunk.index.0 as usize,
|
||||
) {
|
||||
if let Ok(anticipated_hash) =
|
||||
branch_hash(¶ms.erasure_root, chunk.proof(), chunk.index.0 as usize)
|
||||
{
|
||||
let erasure_chunk_hash = BlakeTwo256::hash(&chunk.chunk);
|
||||
|
||||
if erasure_chunk_hash != anticipated_hash {
|
||||
|
||||
@@ -23,3 +23,6 @@ serde = { version = "1.0.130", features = ["derive"] }
|
||||
|
||||
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
||||
zstd = "0.6.0"
|
||||
|
||||
[dev-dependencies]
|
||||
polkadot-erasure-coding = { path = "../../erasure-coding" }
|
||||
|
||||
@@ -301,8 +301,8 @@ pub struct Proof(BoundedVec<BoundedVec<u8, 1, MERKLE_NODE_MAX_SIZE>, 1, MERKLE_P
|
||||
|
||||
impl Proof {
|
||||
/// This function allows to convert back to the standard nested Vec format
|
||||
pub fn as_vec(&self) -> Vec<Vec<u8>> {
|
||||
self.0.as_vec().iter().map(|v| v.as_vec().clone()).collect()
|
||||
pub fn iter(&self) -> impl Iterator<Item = &[u8]> {
|
||||
self.0.iter().map(|v| v.as_slice())
|
||||
}
|
||||
|
||||
/// Construct an invalid dummy proof
|
||||
@@ -365,7 +365,7 @@ impl Encode for Proof {
|
||||
}
|
||||
|
||||
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
|
||||
let temp = self.as_vec();
|
||||
let temp = self.0.iter().map(|v| v.as_vec()).collect::<Vec<_>>();
|
||||
temp.using_encoded(f)
|
||||
}
|
||||
}
|
||||
@@ -404,8 +404,8 @@ pub struct ErasureChunk {
|
||||
|
||||
impl ErasureChunk {
|
||||
/// Convert bounded Vec Proof to regular Vec<Vec<u8>>
|
||||
pub fn proof_as_vec(&self) -> Vec<Vec<u8>> {
|
||||
self.proof.as_vec()
|
||||
pub fn proof(&self) -> &Proof {
|
||||
&self.proof
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user