-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ovm BlockFileCodec
#12247
feat: add ovm BlockFileCodec
#12247
Conversation
First of all I moved the file into I left you a hint about how to approach this. You can import the reth/crates/primitives/src/transaction/mod.rs Lines 1430 to 1459 in 21d911a
and all other of its methods that are called via that. Let me know if it doesn't make sense, then I can finish it off. |
Thanks for the hints, it makes more sense, continuing on it now. |
Thanks for letting me the time to go through this despite it's a blocker for other tasks @emhane @mattsse @JosepBove I have still a couple of questions and observations :
... and while fixing the test |
this issue is part of a bigger whole, eventually we will have a separate import block command for ovm, and make the block
this pr should add unit tests to prove the decoding works as expected. any bugs that may have come into existence from the refactor you describe, should be caught by these tests. it's ok for this specific issue to copy paste the needed code into |
Ok got it, I will remove the integration of the codec - for now, and add units tests for the decoding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the right track
impl Decodable for TransactionSigned { | ||
/// This `Decodable` implementation only supports decoding rlp encoded transactions as it's used | ||
/// by p2p. | ||
/// | ||
/// The p2p encoding format always includes an RLP header, although the type RLP header depends | ||
/// on whether or not the transaction is a legacy transaction. | ||
/// | ||
/// If the transaction is a legacy transaction, it is just encoded as a RLP list: | ||
/// `rlp(tx-data)`. | ||
/// | ||
/// If the transaction is a typed transaction, it is encoded as a RLP string: | ||
/// `rlp(tx-type || rlp(tx-data))` | ||
/// | ||
/// This can be used for decoding all signed transactions in p2p `BlockBodies` responses. | ||
/// | ||
/// This cannot be used for decoding EIP-4844 transactions in p2p `PooledTransactions`, since | ||
/// the EIP-4844 variant of [`TransactionSigned`] does not include the blob sidecar. | ||
/// | ||
/// For a method suitable for decoding pooled transactions, see \[`PooledTransactionsElement`\]. | ||
/// | ||
/// CAUTION: Due to a quirk in [`Header::decode`], this method will succeed even if a typed | ||
/// transaction is encoded in this format, and does not start with a RLP header: | ||
/// `tx-type || rlp(tx-data)`. | ||
/// | ||
/// This is because [`Header::decode`] does not advance the buffer, and returns a length-1 | ||
/// string header if the first byte is less than `0xf7`. | ||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> { | ||
Self::network_decode(buf).map_err(Into::into) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only methods called indirectly by this impl, need to be included, i.e. the methods that are called in the function body of Self::network_decode
, need to stay. the other methods can be removed.
impl Encodable for TransactionSigned { | ||
/// This encodes the transaction _with_ the signature, and an rlp header. | ||
/// | ||
/// For legacy transactions, it encodes the transaction data: | ||
/// `rlp(tx-data)` | ||
/// | ||
/// For EIP-2718 typed transactions, it encodes the transaction type followed by the rlp of the | ||
/// transaction: | ||
/// `rlp(tx-type || rlp(tx-data))` | ||
fn encode(&self, out: &mut dyn BufMut) { | ||
self.network_encode(out); | ||
} | ||
|
||
fn length(&self) -> usize { | ||
let mut payload_length = self.encode_2718_len(); | ||
if !self.is_legacy() { | ||
payload_length += alloy_rlp::Header { list: false, payload_length }.length(); | ||
} | ||
|
||
payload_length | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also certainly not needed since the codec is for decoding blocks from a file of rlp encoded blocks, and will not be used for encoding (in foreseeable future)
need any help to wrap this up @lean-apple ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job!
Thanks, sorry for the late commits, I was a bit absorbed by the Devcon, I've added a last test for eip 1559 type. |
Closes #12184.