-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fix/gateway message processing #1991
base: main
Are you sure you want to change the base?
Changes from all commits
d8216f9
a23ff87
3d7d223
afd2900
0701522
8e9ae25
471f434
bc2cc3a
a3e6f6a
6874cb8
8d27c9e
ef843b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
use cfg_traits::liquidity_pools::{ | ||
InboundMessageHandler, LpMessageBatch, LpMessageHash, LpMessageProof, MessageHash, | ||
MessageQueue, RouterProvider, | ||
InboundMessageHandler, LpMessageHash, LpMessageProof, MessageHash, MessageQueue, RouterProvider, | ||
}; | ||
use cfg_types::domain_address::{Domain, DomainAddress}; | ||
use frame_support::{ | ||
|
@@ -333,7 +332,11 @@ impl<T: Config> Pallet<T> { | |
// we can return. | ||
None => return Ok(()), | ||
Some(stored_inbound_entry) => match stored_inbound_entry { | ||
InboundEntry::Message(message_entry) => message = Some(message_entry.message), | ||
InboundEntry::Message(message_entry) | ||
if message_entry.session_id == session_id => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should not because then it's impossible to replay the message and funds are stuck on the EVM side. Keeping entries for an old session id can be made unstuck via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
message = Some(message_entry.message) | ||
} | ||
InboundEntry::Proof(proof_entry) | ||
if proof_entry.has_valid_vote_for_session(session_id) => | ||
{ | ||
|
@@ -349,10 +352,10 @@ impl<T: Config> Pallet<T> { | |
} | ||
|
||
if let Some(msg) = message { | ||
Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?; | ||
|
||
T::InboundMessageHandler::handle(domain_address.clone(), msg)?; | ||
|
||
Self::execute_post_voting_dispatch(message_hash, router_ids, expected_proof_count)?; | ||
|
||
Self::deposit_event(Event::<T>::InboundMessageExecuted { | ||
domain_address, | ||
message_hash, | ||
|
@@ -401,42 +404,36 @@ impl<T: Config> Pallet<T> { | |
domain_address: DomainAddress, | ||
message: T::Message, | ||
router_id: T::RouterId, | ||
counter: &mut u64, | ||
) -> DispatchResult { | ||
let router_ids = Self::get_router_ids_for_domain(domain_address.domain())?; | ||
let session_id = SessionIdStore::<T>::get(); | ||
let expected_proof_count = Self::get_expected_proof_count(&router_ids)?; | ||
let message_hash = message.get_message_hash(); | ||
let inbound_entry: InboundEntry<T> = InboundEntry::create( | ||
message.clone(), | ||
session_id, | ||
domain_address.clone(), | ||
expected_proof_count, | ||
); | ||
|
||
for submessage in message.submessages() { | ||
counter.ensure_add_assign(1)?; | ||
inbound_entry.validate(&router_ids, &router_id.clone())?; | ||
|
||
let message_hash = submessage.get_message_hash(); | ||
Self::upsert_pending_entry(message_hash, &router_id, inbound_entry)?; | ||
|
||
let inbound_entry: InboundEntry<T> = InboundEntry::create( | ||
submessage.clone(), | ||
session_id, | ||
domain_address.clone(), | ||
expected_proof_count, | ||
); | ||
|
||
inbound_entry.validate(&router_ids, &router_id.clone())?; | ||
Self::upsert_pending_entry(message_hash, &router_id, inbound_entry)?; | ||
|
||
Self::deposit_processing_event( | ||
domain_address.clone(), | ||
submessage, | ||
message_hash, | ||
router_id.clone(), | ||
); | ||
Self::deposit_processing_event( | ||
domain_address.clone(), | ||
message, | ||
message_hash, | ||
router_id.clone(), | ||
); | ||
|
||
Self::execute_if_requirements_are_met( | ||
message_hash, | ||
&router_ids, | ||
session_id, | ||
expected_proof_count, | ||
domain_address.clone(), | ||
)?; | ||
} | ||
Self::execute_if_requirements_are_met( | ||
message_hash, | ||
&router_ids, | ||
session_id, | ||
expected_proof_count, | ||
domain_address.clone(), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
|
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.
Since we are collecting the keys here, it also made sense to me to sort them, just in case. Please let me know if there are any objections to this.
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.
Although this new solution is more simple, I think there is a problem here:
It can collect many keys, making the block impossible to build.
I think we need a complex structure here that allow us to store them already organized
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.
Can you elaborate on this please?
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.
How about limiting the number of keys that we collect via:
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.
When you collect, the iterator will make one read per item, and could be a number of items that overpass the limit for the block weight capacity.
The
take(MAX_MESSAGES_PER_BLOCK)
still does not work because could be left a message in the queue that ideally should be processed first.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.
Not sure if exists some order structure available in substrate for this. If not, we should create some complex/annoying structure to organize the way the messages are stored.
But I'm not able to see a super simple way TBH. We can leave that fix for another PR to unlock this if we see it's not easy
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.
Maybe there's a simpler solution that involves using the latest message nonce. I'll try something on a different branch.
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.
Something similar to - #1992