-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Modify Relayer service to order Events from L1 by block index #1779
Changes from all commits
02ec8cd
d68bd4b
2120be1
b200848
c39961f
307cf7c
65491a2
fe2c0f0
bb33d12
5d9f37a
a977697
cfc9939
3db8add
3ceacf7
2f82803
8427203
e831dd0
954607c
46bba1c
502a1f8
f0a8297
daabb9d
b249ebb
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 |
---|---|---|
|
@@ -68,24 +68,24 @@ where | |
while let Some((last_height, events)) = logs.try_next().await? { | ||
let last_height = last_height.into(); | ||
let mut ordered_events = BTreeMap::<DaBlockHeight, Vec<Event>>::new(); | ||
let fuel_events = | ||
events | ||
.into_iter() | ||
.filter_map(|event| match EthEventLog::try_from(&event) { | ||
Ok(event) => { | ||
match event { | ||
EthEventLog::Message(m) => { | ||
Some(Ok(Event::Message(Message::from(&m)))) | ||
} | ||
EthEventLog::Transaction(tx) => { | ||
Some(Ok(Event::Transaction(RelayedTransaction::from(tx)))) | ||
} | ||
// TODO: Log out ignored messages. | ||
EthEventLog::Ignored => None, | ||
let sorted_events = sort_events_by_log_index(events)?; | ||
let fuel_events = sorted_events.into_iter().filter_map(|event| { | ||
match EthEventLog::try_from(&event) { | ||
Ok(event) => { | ||
match event { | ||
EthEventLog::Message(m) => { | ||
Some(Ok(Event::Message(Message::from(&m)))) | ||
} | ||
EthEventLog::Transaction(tx) => { | ||
Some(Ok(Event::Transaction(RelayedTransaction::from(tx)))) | ||
} | ||
// TODO: Log out ignored messages. | ||
EthEventLog::Ignored => None, | ||
} | ||
Err(e) => Some(Err(e)), | ||
}); | ||
} | ||
Err(e) => Some(Err(e)), | ||
} | ||
}); | ||
|
||
for event in fuel_events { | ||
let event = event?; | ||
|
@@ -109,3 +109,18 @@ where | |
} | ||
Ok(()) | ||
} | ||
|
||
fn sort_events_by_log_index(events: Vec<Log>) -> anyhow::Result<Vec<Log>> { | ||
let mut with_indexes = events | ||
.into_iter() | ||
.map(|e| { | ||
let log_index = e | ||
.log_index | ||
.ok_or(anyhow::anyhow!("Log missing `log_index`: {e:?}"))?; | ||
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. The alternative here would be set to I think I prefer the error, but there are still ways for this to be non-deterministic, e.g. if there are more than one log with the same index. So, maybe we need to have additional checks that there are no duplicates? And do we want to accept batches with missing log indices? If we don't want to worry about all the edge cases, then we could just do 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. Talked to the team about this offline. It sounds like we are okay with throwing an error here and not including the batch. In practice, this value should always be In a similar vein, we can probably assume they will always be in order and all unique. 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. Are all events coming through this sort helper 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. They get sorted into blocks after they are sorted by index. So it will maintain order once sorted by block. |
||
Ok((log_index, e)) | ||
}) | ||
.collect::<anyhow::Result<Vec<_>>>()?; | ||
with_indexes.sort_by(|(index_a, _a), (index_b, _b)| index_a.cmp(index_b)); | ||
let new_events = with_indexes.into_iter().map(|(_, e)| e).collect(); | ||
Ok(new_events) | ||
} |
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.
We need to return an error if
retry_on_error == true