Skip to content

Improve tx propagation#4050

Open
vicsn wants to merge 12 commits intostagingfrom
improve_tx_propagation
Open

Improve tx propagation#4050
vicsn wants to merge 12 commits intostagingfrom
improve_tx_propagation

Conversation

@vicsn
Copy link
Collaborator

@vicsn vicsn commented Dec 19, 2025

Motivation

Closes #3962

Test Plan

  • Run stress-testing after review is completed.

Backwards compatibility

  • Review whether nodes which didn't upgrade yet handle the new unknown message gracefully (without closing the connection). This should be done automatically by Upgrade nodes in CI tests #4029

@vicsn vicsn requested a review from kaimast December 19, 2025 20:13
fn get_transmission(&self, transmission_id: TransmissionID<N>) -> Option<Transmission<N>> {
// Try to get the transmission from the cache first.
if let Some((transmission, _)) = self.cache_transmissions.lock().get_mut(&transmission_id) {
if let Some(transmission) = self.cache_transmissions.lock().get(&transmission_id) {
Copy link
Collaborator Author

@vicsn vicsn Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight not sure if this will really have that much impact, the idea is to make the cache more FIFO, because typically older transactions won't be needed in the future anymore.

/// The LRU cache for `aborted transmission ID` to `certificate IDs` entries that are part of the persistent storage.
cache_aborted_transmission_ids: Mutex<LruCache<TransmissionID<N>, IndexSet<Field<N>>>>,
/// The LRU cache for `transmission ID` to `transmission` entries that are part of the persistent storage.
cache_transmissions: Mutex<LruCache<TransmissionID<N>, Transmission<N>>>,
Copy link
Collaborator Author

@vicsn vicsn Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed cache_aborted_transmission_ids because we never read from it.

@vicsn
Copy link
Collaborator Author

vicsn commented Dec 20, 2025

Opened an issue about CI failing: #4052

Err(error) => bail!("[UnconfirmedTransaction] {error}"),
};
// Calculate the transmission checksum.
let checksum = Data::<Transaction<N>>::Buffer(transaction.to_bytes_le()?.into()).to_checksum::<N>()?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this operation involves plenty of redundant work (since we're serializing a transaction that was just deserialized, even if it was in a blob form); it should be possible to optimize it so that the checksum can be calculated based on the event

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

// Broadcast the unconfirmed transaction so other validators can cache it.
self.consensus.bft().primary().gateway().broadcast_unconfirmed_transaction(transaction);
Copy link
Collaborator

@ljedrz ljedrz Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should instead use the serialized transaction here, as it is almost free to clone and write to the socket (as opposed to the deserialized transaction); it could also be used to cheaply construct the transmission id for caching purposes (unless it's already available at the callsite, in which case it would be practical to pass it on to the cache_unconfirmed_transaction call above)

Copy link
Collaborator Author

@vicsn vicsn Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d29ba91

reducing the redundant id computation we do all over the place is out of scope but looking forward to the day we can do it

@kaimast
Copy link
Contributor

kaimast commented Jan 5, 2026

Looks good to me. I merged staging and tested it locally.

@kaimast kaimast self-requested a review January 5, 2026 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Improve transaction propagation

3 participants