Closed oleganza closed 4 years ago
Reader/Writer traits: #427, #429
- Crate blockchain depends on readerwriter, but not on p2p.
But CustomMessage trait placed in p2p, so p2p will be in blockchain dependencies. Moving this trait into another place seems illogical to me.
But CustomMessage trait placed in p2p, so p2p will be in blockchain dependencies. Moving this trait into another place seems illogical to me.
How about this:
blockchain
implements encoding via Reader/Writer traits.demo
) that provides concrete storage and I/O, implements p2p::CustomMessage for blockchain::protocol::Message
(via a newtype wrapper) and wires all things together.Final results:
Encodable
/Decodable
in readerwriter
crate. Implement trait Codable
for T where T both implement Encodable
+ Decodable
.Codable
instead of CustomMessage
.Encodable
/Decodable
to blockchain::Message
.
We currently have multiple uses for encoding throughout
zkvm
,blockchain
andp2p
crates:Downsides of the current approach:
zkvm::Contract::id()
andblockchain::BlockTx::witness_hash()
).bytes::BytesMut
/BufMut
), but keep the rest of the system independent from Tokio or any I/O framework.Requirements
We need a pair of traits
Reader/Writer
akin to Buf/BufMut, but with several modifications:&'static str
that can be used with the Transcript (or JSON ;-)) Binary buffers will simply ignore the label._le
explicit in the naming, though.)Organization
readerwriter
crate.bytes
(for interop with Bytes/Buf), with corresponding modulebytes_impls.rs
enabled on#[cfg(feature="bytes")]
.merlin
(for interop with Transcript), with corresponding modulemerlin_impls.rs
enabled on#[cfg(feature="merlin")]
.zkvm
depends onreaderwriter
, SliceReader is removed.zkvm
andblockchain
: encoding/decoding methods are changed to use Reader/Writer API. Hashing is redefined in the spec to write data to transcript field-by-field.blockchain
depends onreaderwriter
, but not onp2p
.p2p
uses samereaderwriter
API for its encoding needs.