Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rewrite block payload (#1499)
* new struct Payload2 * WIP new fns usize_to_bytes, max_from_byte_len with tests * implement NamespaceBuider * WIP begin implementing from_transactions * dead end: const generics not stable in Rust https://stackoverflow.com/a/72467535 * finish impl for from_transactions, use macro_rules to generalize usize_to_bytes * WIP friendly deserializers * generalized friendly deserializer * usize_from_bytes const generic param, add xxx_from_bytes functions * impl namespace_with_proof and some helpers * WIP test infra for namespace proofs * tweak test * Payload2:namespace_with_proof pass tests (yay) * don't double count dupliate namespace ids * tidy * restore block.rs from main, new file block2.rs * move mod tx_table to separate file payload_bytes.rs * rename block2::Payload2 -> Payload * set Payload::ns_iter() Item to NamespaceId * move namespace iterator to a separate file * rename payload2 -> ns_payload_builder * visibility tweaks for ns_iter * new fn verify_namespace_proof, temporary re-use of old parse_ns_payload, enforce maximum ns payload index in ns_iter, rename a few things * move namespace_with_proof and test to ns_proof.rs, use new verify_namespace_proof in test * move Payload::ns_iter, etc to ns_iter.rs * rename ns_payload_builder -> ns_payload * new mod tx_iter, a proper impl for parse_ns_payload * WIP combined iterator for QueryablePayload * move the combined iterator to iter.rs, delete the extra namespace iterator * stub impl of QueryablePayload for Payload * more stubs, tidy, new file tx_proof.rs * fix bug in TxIter, fix test * impl Payload::transaction with test * move tests to new file test.rs * tidy and comments * NsProof do not store VID common data * tidying and stub * new fn tx_table_range with doc * impl transaction_with_proof, still pretty messy tho * WIP tx proof only for num_txs * fix bug in iter, fix test * test: verify transaction proofs * major rework of ns_iter: new struct NsTable, NsIter::Item is now just usize * newtype NsIndex * TxIndex is now a serialized index, newtype NsPayload with awesome helper methods * fix name _max_from_byte_len2 -> _max_from_byte_len * xxx_from_bytes allow small byte lengths * NsIndex in serialized form like TxIndex * move tx_iter mod into ns_payload to enable private data in TxIndex * rename module ns_iter -> ns_table * tweak todo comments * move ns_payload, ns_proof, tx_proof modules inside ns_table * tidy * put TxIndex in a new mod tx_iter, move NsPayload::read_tx_offset into tx_iter, new method NsPayload::read_tx_offset_pref * add tx table range proof to TxProof * NsPayload now a DST, add newtype NsPayloadOwned so that it's to NsPayload as Vec<T> is to [T] * untested: TxProof::verify check tx table proof * dumbest bug ever * TxProof::verify now check tx payload proof (yay) * tidy: new module ns_iter like tx_iter, new method NsTable::read_ns_offset_prev like NsPayload::read_tx_offset_prev * new struct NsPayloadRange with helpers * WIP tweak tx_payload_range[_relative] * make NsPayloadRange a Range<usize> * WIP prep for experiments with NsPayload * add range field to NsPayload, it can no longer be a DST (boo) * revert back to DST for NsPayload * move tx_payload_range method from NsPayload to NsPayloadRange, add args to make it work * move modules ns_proof, tx_proof from ns_table up to block * move module ns_payload_range to its own file * Index fields private * move module ns_iter to its own file * move module tx_iter to its own file * newtype NumTxs * manual serde impl for NumTxs * NsPayloadRange::tx_payload_range arg type change usize -> NumTxs * new struct TxTableEntries * manual serde impl for TxTableEntries * tidy ns_table * move module num_txs into its own file * move module tx_table_entries to its own file * remove pub(crate) from NsPayloadRange newtype field * add TODOs, ugh Rust is killing me * TxIndex newtype from array to usize * NsIndex newtype from array to usize * move module num_txs up to block, experiment with access key design pattern * move module ns_iter up to block * move module tx_table_entries up to block * move module tx_iter up to block * move module ns_payload up to block * move module ns_payload_range up to block * move some NsTable impls into ns_table module * NsTable member private * move some impl Payload to block module * move NsProof construction from Payload to NsProof * move TxProof construction from Payload to TxProof * move struct Payload to a new module payload * visibility restrictions to payload module * oops * delete num_txs_as_bytes from payload_bytes * delete num_txs_from_bytes from payload_bytes * delete tx_offset_as_bytes from payload_bytes * delete tx_offset_from_bytes from payload_bytes * delete num_nss_as_bytes from payload_bytes * delete num_nss_from_bytes from payload_bytes * delete ns_offset_as_bytes from payload_bytes * delete ns_offset_from_bytes from payload_bytes * delete ns_offset_[as|from]_bytes from payload_bytes * tweak: Payload::ns_payload re-use ns_payload_range * move byte len constants to block module * rename module payload_bytes -> uint_bytes * tidy, minor refactor new function usize_fits * replace NsTable::num_nss_with_duplicates -> in_bounds, reflect the change in NsIter, use it in TxProof; also remove NsPayload::find_ns_id and reorder arg list in TxProof::new * check tx index in TxProof::new, new method NsPayload::in_bounds * WIP new model for NsPayload[Range] * WIP read_tx_offset * new traits AsBytes, BytesReader, new test for TxProof2 * PoC TxTableEntries in the new model * tidy, rename * remove const generic param from AsPayloadBytes trait * new structs NumTxs2, TxTableEntries2 using traits AsPayloadBytes * add tx payload range to TxProof2 * error checking in TxProof::new * TxProof::verify: add ns_table arg, remove ns_payload_range from proof, add error checking * derive serde for types in TxProof2 * delete old type TxProof in favor of TxProof2 * NsProofExistence use NsPayloadOwned2 instead of NsPayloadOwned * Iter use TxIter::new2 instead of new (progress toward switching from NsPayload to NsPayload2) * move NamespacePayloadBuilder to module newtypes * delete module ns_payload_range * delete old modules * newtype NsPayloadByteLen * newtype NumTxsChecked * move tx_table_entries_range_relative into TxTableEntriesRange::new * move module tx_iter into newtypes * impl AsPayloadBytes for TxIndex * WIP test fails: AsPayloadBytes new param T * fix test, but AsPayloadBytes trait is now unusable (boo) * fix TxTableEntries deserialization * delete unneeded stuff * rename a bunch of types in module newtypes * make AsPayloadBytes readable and rename it to FromPayloadBytes * tidy and rename * rename ns_payload[_range]2.rx -> without the 2 * tidy and renaming * newtype PayloadByteLen * tidy and docs * tidy ns_table * tidy payload * fix macro bytes_serde_impl * delete ns_iter.rs, move contents to ns_table.rs * restrict visibility of magic constants to a single file (yay) * tidy ns_payload * replace NsPayloadRange::offset with block_payload_range, simplify NsPayloadBytesRange * tidy tx_proof, rename some things * tidy * new method export_tx, in prep for reduced visibility * fix use statements * new module full_payload * WIP new module namespace_payload * move tx_proof, iter to namespace_payload; add helpers to avoid excessive visibility * new helper Payload::ns_payload * doc for bytes_serde_impl macro * move ns_payload_traits module into newtypes * rename module newtypes -> types * fix build after merge main * WIP swap out block for block2 * WIP fix test_namespace_query for block2 * WIP fix nasty_client except for NsIndex serialization issue * fix nasty-client for new block2, appease clippy * fix reference test for new ns table format * fix test demo, tidy * accounting for block byte length limit * temporary hack to pass tests * set forge-std git submodule to correct commit * fix test_message_compat * failing test for large namespace ids * single-character bug fix (damn that feels good) * fix doctest * update reference tests (again) * add test enforce_max_block_size * delete old block module * tidy TODOs, some general tidying * NsTable::read_ns_id check index in bounds * NsTable::ns_range check index in bounds * use read_ns_id_unchecked in NsIter * revert NsTable::ns_range to unchecked and restrict visibility * revert NsTable::read_ns_id to unchecked * re-arrange methods * NsTable::as_bytes_slice restrict visibility * delete NsTable::as_bytes_slice in favor of Encode trait * delete Payload::as_byte_slice in favor of Encode trait * tidy PayloadByteLen * restrict visibility for NsIter * restrict visibility of PayloadByteLen * restrict visibility of NsPayload * restrict visibility of NsPayloadRange * restrict visibility of NsPayloadBuilder * restrict visibility of TxIndex, TxIter * rename module block2 -> block * rename ns_payload_unchecked -> ns_payload * remove obsolete todo * revert #1504 ; this PR supports arbitrary 8-byte namespace IDs * detailed specification rustdoc for Payload, NsTable * detailed specification in rustdoc for namespace payload * rename Payload::payload -> ns_payloads * NsProof do not prove non-existence * Payload::is_consistent return Result instead of bool, eliminate panic * NsProof::new take NsIndex arg instead of NamespaceId * NamespaceProofQueryData::proof is now optional * fix: NsProof::ns_proof for empty payload should be None * address #1499 (comment) * NsTable field for backwards compatibility * set NS_ID_BYTE_LEN to 4 for backwards compatibility * Payload::builder_commitment hack for backwards compatibility * TODOs for NamespaceId, fix tests in block/test.rs * restore data/ files from main branch * remove obsolete comment * fix doc for NsProof::new as per #1499 (comment) * new method NsTable::read_ns_id_unchecked as per #1499 (comment) * NamespaceId manual Deserialize impl enforce u32::MAX * NamespaceId impl From<u32> as per #1499 (comment) * doc: links to github issues in code comments
- Loading branch information