Skip to content

Commit b55a48c

Browse files
[storage/qmdb/current] have current proof types implement codec (#3717)
1 parent dec68db commit b55a48c

4 files changed

Lines changed: 635 additions & 6 deletions

File tree

storage/conformance.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,50 @@ hash = "311e78baa8209313a49f2d788d96aa880ba4b3c1c5c88f3151b665f25160fad8"
262262
n_cases = 200
263263
hash = "d6b0f89534be60d85f5754c16574536d84899fce930dfc182ef973475d3078e4"
264264

265+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<ExclusionProof<mmb::Family,U64,FixedEncoding<U64>\n,Sha256Digest,32>>"]
266+
n_cases = 65536
267+
hash = "3be28a20c912b32bc94dacedbee177f371dedae0374788062283a09198bbe8a1"
268+
269+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<ExclusionProof<mmb::Family,U64,VariableEncoding<Vec\n<u8>>,Sha256Digest,32>>"]
270+
n_cases = 65536
271+
hash = "dec32d46d821f96fcf6795e79316dd120acbfa80c579aede1e3e1b12fa5d529b"
272+
273+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<ExclusionProof<mmr::Family,U64,FixedEncoding<U64>\n,Sha256Digest,32>>"]
274+
n_cases = 65536
275+
hash = "ab38295608a9725a7e3ae3066d0908271f049f373beee1a266f823b8e4aa0e19"
276+
277+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<ExclusionProof<mmr::Family,U64,VariableEncoding<Vec\n<u8>>,Sha256Digest,32>>"]
278+
n_cases = 65536
279+
hash = "8127a8b087d13a867eb02343e90b40dcc7ac1abaf1f49f205d932a7772944f94"
280+
281+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<KeyValueProof<mmb::Family,U64,Sha256Digest,32>>"]
282+
n_cases = 65536
283+
hash = "bb7c2e0914c06a3cd0b64540c022cadc32ee1eafcf319a9d4fe744edf0e43428"
284+
285+
["commonware_storage::qmdb::current::ordered::tests::conformance::CodecConformance<KeyValueProof<mmr::Family,U64,Sha256Digest,32>>"]
286+
n_cases = 65536
287+
hash = "a9d1bd40b8bf177389e77a4d33c9561ba5e96b12220de506bd4ce0817311d09a"
288+
289+
["commonware_storage::qmdb::current::proof::tests::conformance::CodecConformance<OperationProof<mmb::Family,Sha256Digest,32>>"]
290+
n_cases = 65536
291+
hash = "755bf9cd2a1d3e27c44472094e0b9f509b0c5f977dd63fd8df334adf860fd9b2"
292+
293+
["commonware_storage::qmdb::current::proof::tests::conformance::CodecConformance<OperationProof<mmr::Family,Sha256Digest,32>>"]
294+
n_cases = 65536
295+
hash = "d1035bc4913d84385ed906f0a44a28be3dbd0a91a3cdbf475f8a8427bd7276c8"
296+
297+
["commonware_storage::qmdb::current::proof::tests::conformance::CodecConformance<OpsRootWitness<Sha256Digest>>"]
298+
n_cases = 65536
299+
hash = "10f6ff08377d0fa64e3802d5b7e14b314699a16fbd1a080d4487288a3c6048e4"
300+
301+
["commonware_storage::qmdb::current::proof::tests::conformance::CodecConformance<RangeProof<mmb::Family,Sha256Digest>>"]
302+
n_cases = 65536
303+
hash = "b5e8e12fe4cefcc5cd0ba81e0bf1dabd816b6af63a2c939ad2e38c3bf2eea508"
304+
305+
["commonware_storage::qmdb::current::proof::tests::conformance::CodecConformance<RangeProof<mmr::Family,Sha256Digest>>"]
306+
n_cases = 65536
307+
hash = "1385f5d8ad72ee20548a3154223208ef83b83ce34769871957c631caaf2d56f1"
308+
265309
["commonware_storage::qmdb::immutable::operation::fixed::tests::conformance::CodecConformance<FixedOp>"]
266310
n_cases = 65536
267311
hash = "1737c49c112fc9dfdc4dde3626d8ab08a9df8353b9a702e488d3a1fd8e9428dc"

storage/src/qmdb/current/ordered/db.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use crate::{
1818
},
1919
Context,
2020
};
21-
use commonware_codec::Codec;
21+
use bytes::{Buf, BufMut};
22+
use commonware_codec::{Codec, EncodeSize, Read, Write};
2223
use commonware_cryptography::{Digest, Hasher};
2324
use commonware_parallel::{Sequential, Strategy};
2425
use futures::stream::Stream;
@@ -30,6 +31,51 @@ pub struct KeyValueProof<F: merkle::Family, K: Key, D: Digest, const N: usize> {
3031
pub next_key: K,
3132
}
3233

34+
impl<F: merkle::Family, K: Key, D: Digest, const N: usize> Write for KeyValueProof<F, K, D, N> {
35+
fn write(&self, buf: &mut impl BufMut) {
36+
self.proof.write(buf);
37+
self.next_key.write(buf);
38+
}
39+
}
40+
41+
impl<F: merkle::Family, K: Key, D: Digest, const N: usize> EncodeSize
42+
for KeyValueProof<F, K, D, N>
43+
{
44+
fn encode_size(&self) -> usize {
45+
self.proof.encode_size() + self.next_key.encode_size()
46+
}
47+
}
48+
49+
impl<F: merkle::Family, K: Key, D: Digest, const N: usize> Read for KeyValueProof<F, K, D, N> {
50+
/// `(max_digests, key_cfg)`: the total digest cap for the embedded operation proof and the
51+
/// read configuration for the key type.
52+
type Cfg = (usize, <K as Read>::Cfg);
53+
54+
fn read_cfg(
55+
buf: &mut impl Buf,
56+
(max_digests, key_cfg): &Self::Cfg,
57+
) -> Result<Self, commonware_codec::Error> {
58+
let proof = OperationProof::<F, D, N>::read_cfg(buf, max_digests)?;
59+
let next_key = K::read_cfg(buf, key_cfg)?;
60+
Ok(Self { proof, next_key })
61+
}
62+
}
63+
64+
#[cfg(feature = "arbitrary")]
65+
impl<F: merkle::Family, K: Key, D: Digest, const N: usize> arbitrary::Arbitrary<'_>
66+
for KeyValueProof<F, K, D, N>
67+
where
68+
K: for<'a> arbitrary::Arbitrary<'a>,
69+
D: for<'a> arbitrary::Arbitrary<'a>,
70+
{
71+
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
72+
Ok(Self {
73+
proof: u.arbitrary()?,
74+
next_key: u.arbitrary()?,
75+
})
76+
}
77+
}
78+
3379
/// The generic Db type for ordered Current QMDB variants.
3480
///
3581
/// This type is generic over the index type `I`, allowing it to be used with both regular

0 commit comments

Comments
 (0)