Skip to content
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

Ignore messages with duplicated nonces #2375

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Fixed
- [2375](https://github.com/FuelLabs/fuel-core/pull/2375): Modify executor to ignore messages from the relayer that have a duplicate nonce
- [2366](https://github.com/FuelLabs/fuel-core/pull/2366): The `importer_gas_price_for_block` metric is properly collected.

### Added
Expand Down
64 changes: 64 additions & 0 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,70 @@ mod tests {
Ok(())
}

fn on_chain_db_containing_message(
message: &Message,
da_block_height: u64,
) -> Database<OnChain> {
let mut db = add_consensus_parameters(
Database::default(),
&ConsensusParameters::default(),
);
db.storage_as_mut::<Messages>()
.insert(message.id(), message)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.insert(message.id(), message)
.insert(message.nonce(), message)

May I ask you to rename this method please?=D message.id() for me means MessageId return type, while it is not true.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is already a nonce method that returns the same thing as id. Very silly.

.unwrap();

let mut block = Block::default();
block.header_mut().set_da_height(da_block_height.into());
block.header_mut().recalculate_metadata();

db.storage_as_mut::<FuelBlocks>()
.insert(&0.into(), &block)
.expect("Should insert genesis block without any problems");
db
}

fn relayer_db_containing_message(message: &Message) -> Database<Relayer> {
let mut relayer_db = Database::<Relayer>::default();
add_message_to_relayer(&mut relayer_db, message.clone());
relayer_db
}

#[test]
fn produce_without_commit__messages_with_duplicate_nonces_are_ignored() {
// given
let previous_da_height = 1;
let shared_nonce = 1234.into();
let mut message = Message::default();
message.set_amount(10);
message.set_da_height(previous_da_height.into());
message.set_nonce(shared_nonce);
let on_chain_db =
on_chain_db_containing_message(&message, previous_da_height);

let mut message_with_matching_nonce = message.clone();
message_with_matching_nonce.set_amount(20);
let new_da_height = previous_da_height + 1;
message_with_matching_nonce.set_da_height(new_da_height.into());
let relayer_db = relayer_db_containing_message(&message_with_matching_nonce);

let producer = create_relayer_executor(on_chain_db, relayer_db);
let block_height = 1;
let block = test_block(block_height.into(), new_da_height.into(), 0);

// when
let changes = producer
.produce_without_commit(block.into())
.unwrap()
.into_changes();

// then
let no_messages_in_changes = ChangesIterator::<Column>::new(&changes)
.iter_all::<Messages>(None)
.count()
== 0;
assert!(no_messages_in_changes);
}

#[test]
fn execute_without_commit__block_producer_includes_correct_inbox_event_merkle_root(
) {
Expand Down
16 changes: 11 additions & 5 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ where
D: KeyValueInspect<Column = Column>,
{
let forced_transactions = if self.relayer.enabled() {
self.process_da(
self.process_l1_events(
block_height,
da_block_height,
data,
Expand Down Expand Up @@ -875,7 +875,7 @@ where
}
}

fn process_da<D>(
fn process_l1_events<D>(
&mut self,
block_height: BlockHeight,
da_block_height: DaBlockHeight,
Expand Down Expand Up @@ -916,9 +916,15 @@ where
if message.da_height() != da_height {
return Err(ExecutorError::RelayerGivesIncorrectMessages)
}
block_storage_tx
.storage_as_mut::<Messages>()
.insert(message.nonce(), &message)?;
let message_nonce = message.nonce();
if !block_storage_tx
.storage_as_ref::<Messages>()
.contains_key(message_nonce)?
{
block_storage_tx
.storage_as_mut::<Messages>()
.insert(message_nonce, &message)?;
}
execution_data
.events
.push(ExecutorEvent::MessageImported(message));
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also be conditional to the message_nonce not being already present in the block storage?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I've moved it.

This makes me wonder if we should be including an event in the case that a message is skipped. Or add it to a list of skipped messages, similar to the skipped tx.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have the info somewhere that we manage a message with this nonce at this height and ignored this can be important to debug, index...

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

Expand Down
Loading