Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4449 +/- ##
==========================================
+ Coverage 74.48% 74.51% +0.03%
==========================================
Files 339 339
Lines 110643 110865 +222
==========================================
+ Hits 82412 82612 +200
- Misses 28231 28253 +22 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
crates/node/src/protocol.rs
Outdated
| CA: 'static + WasmCacheAccess + Sync, | ||
| { | ||
| for cmt in get_batch_txs_to_execute(tx, &extended_tx_result.masp_tx_refs) { | ||
| let ran_masp_fee_payment = !tx_result.is_empty(); |
There was a problem hiding this comment.
this line seems bug prone. Took me forever to confirm this works
There was a problem hiding this comment.
I think we can check if a masp event is in the values, no?
There was a problem hiding this comment.
We could but there's also another issue #3827 with duplicated events. If we were to ever fix that I believe we won't have those events in here anymore (unless we also implement your suggestion to postpone pushing the events) and we could fail here.
Should we just pass a flag to this function to signal that the first tx already ran to pay fees?
There was a problem hiding this comment.
Got your point, will work on a fix to avoid relying on the tx result
| // Emit the events of the fee-paying inner tx. This tx has | ||
| // just been committed so we need to ensure the relative | ||
| // events are emitted | ||
| let events = tx_result.0.first_key_value().map_or_else( |
There was a problem hiding this comment.
Again, I find this assumption dangerous. Maybe we can soup up the type to keep thses events under a separate field
There was a problem hiding this comment.
We can but we need to handle the case of a failing atomic batch for which the fee paying tx should be committed anyway (and the relative events should be emitted). My reason to emit the events here is that in the line above we commit the storage changes and I wanted to emit the events at the same time.
Also, by emitting the events here, the masp events are already sorted in the block results (without the need to look at the masp fee payment attribute), so that clients don't need to reorder them.
crates/sdk/src/masp/utilities.rs
Outdated
| for MaspEvent { | ||
| tx_index, | ||
| masp_refs, | ||
| kind: _, |
There was a problem hiding this comment.
I cant tell where this field is used
There was a problem hiding this comment.
It is used in the event itself (which could be of type masp/transfer or masp/fee-payment), and after 837d480 it is also used when fetching txs from the indexer since when we cache them we need to be able to sort them correctly (as suggested by @sug0) and we need the tx kind for that since fee payment txs need to be move ahead of the queue
sug0
left a comment
There was a problem hiding this comment.
couple of suggestions. let's not merge this until we thoroughly test integration with the associated masp indexer pr.
| // Stop the execution of an atomic batch at the | ||
| // first failed transaction | ||
| return Err(DispatchError { | ||
| error: Error::FailingAtomicBatch(cmt.get_hash()), | ||
| tx_result: Some(tx_result), |
There was a problem hiding this comment.
Yes we do that in handle_batch_error (exception made for the masp fee paying tx that would be committed even in case of a failing atomic batch)
| // Emit the events of all the inner txs that have been | ||
| // successfully executed when handling the wrapper. These |
There was a problem hiding this comment.
does this imply that we do not emit the events of failing txs? hm. I was thinking what would happen with IBC ack failures, but I guess those are still successful tx executions (despite of the failure semantics).
There was a problem hiding this comment.
That's correct, I asked this question to @yito88 a few days ago, it seemed ok to me but maybe we can discuss it more in depth
crates/sdk/src/masp.rs
Outdated
| // NOTE: It is possible to have two identical references in a same batch: | ||
| // this is because, some types of MASP data packet can be correctly executed | ||
| // more than once (output descriptions). We have to make sure we account for | ||
| // this by using collections that allow for duplicates (both in the args | ||
| // and in the returned type): if the same reference shows up multiple | ||
| // times in the input we must process it the same number of times to | ||
| // ensure we contruct the correct state |
There was a problem hiding this comment.
this comment doesn't make sense anymore, we're returning a single Transaction (rather than a Vec of them)
| // Check if the event is a Masp one | ||
| let Ok(kind) = namada_events::EventType::from_str(&event.kind) | ||
| else { | ||
| return Ok(None); | ||
| }; | ||
|
|
||
| let kind = if kind == namada_tx::event::masp_types::TRANSFER { | ||
| MaspEventKind::Transfer | ||
| } else if kind == namada_tx::event::masp_types::FEE_PAYMENT { | ||
| MaspEventKind::FeePayment | ||
| } else { | ||
| return Ok(None); | ||
| }; | ||
|
|
||
| // Extract the data from the event's attributes, propagate errors if | ||
| // the masp event does not follow the expected format | ||
| let data = | ||
| MaspTxRef::read_from_event_attributes(&event.attributes)?; | ||
| let tx_index = | ||
| IndexedTx::read_from_event_attributes(&event.attributes)?; | ||
|
|
||
| Ok(Some(MaspEvent { | ||
| tx_index, | ||
| kind, | ||
| data, | ||
| })) |
There was a problem hiding this comment.
impl a TryFrom<Event> for MaspEvent
| /// The masp tx kind, fee-payment or transfer | ||
| pub kind: MaspEventKind, |
There was a problem hiding this comment.
I know it feels like code duplication, but it might be better to have a separate type for the kind of masp indexed tx. we might want to introduce other masp event kinds that have nothing to do with the way we intend to sort masp indexed txs.
| use namada_tx::{IndexedTx, IndexedTxRange}; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// An indexed masp tx carrying information on wether it was a fee paying tx or |
There was a problem hiding this comment.
| /// An indexed masp tx carrying information on wether it was a fee paying tx or | |
| /// An indexed masp tx carrying information on whether it was a fee paying tx or |
| .map(|(masp_indexed_tx, transaction)| { | ||
| (masp_indexed_tx.indexed_tx, transaction) | ||
| }) | ||
| .collect::<BTreeMap<_, _>>() |
There was a problem hiding this comment.
Let's not collect a new BTreeMap here. The contains_height method is supposed to be relatively cheap. We can modify IndexedTxRange to refer to a MaspIndexedTxRange instead. Lmk if you need help with this.
There was a problem hiding this comment.
I've created a new MaspIndexedTxRange type for this purpose in 7df026f. I've also left IndexedTxRange untouched as I feel it could come in handy in the future or to current sdk users
|
@tzemanovic, @sug0, @batconjurer, @murisi I'm closing this in favor of #4475 which is the rebased version of this branch of top of main where I've removed the changes brought in by #4442 |
Describe your changes
Partially addresses #3824 (removes
ExtendedTxResult).Partially addresses #3827 as we take events out of
BatchedTxResultin case of masp fee payment.Ensures that events for masp fee payment txs are emitted as soon as the storage changes are committed
Checklist before merging
breaking::labelsnamada-docsreponamada-indexerornamada-masp-indexer, a corresponding PR is opened in that repoUpdate masp events namada-masp-indexer#50->Update masp events adjusted namada-masp-indexer#64