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

feat(rpc): v0.8.0 getMessagesStatus method #388

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

shamsasari
Copy link
Contributor

@shamsasari shamsasari commented Nov 19, 2024

Pull Request type

  • Feature

What is the current behavior?

Resolves: #414

What is the new behavior?

  • Added v0.8.0 starket_getMessagesStatus RPC method
  • L1 transaction hash to L1 handler transaction hash mappings is stored in db in a new column.
  • The L1 -> L2 processing logic was refactored, with the bulk of the event loop extracted out into a separate method
  • This also includes better logging
  • The env variable for the --analytics_collection_endpoint config was also fixed

Does this introduce a breaking change?

New database column added.

Other information

Since there can be multiple handler transactions per L1 transaction, and because the processing of L1 -> L2 messaging is done on a per log event basis, a composite DB key is used so that new entries for the same L1 tx can be added without having to re-serialize and update the same key. Retrieving the handler tx hashes is done by a prefix scan on the L1 transaction hash which is an efficient operation with RocksDB.

Since rejections are currently not supported, the RPC response doesn't populate the failure_reason field.

@shamsasari shamsasari force-pushed the shams-get_msgs_status branch from 9aaeb24 to b69a042 Compare November 19, 2024 16:39
@shamsasari shamsasari changed the title feat(rpc): v0.8.0 getMessagesStatus feat(rpc): v0.8.0 getMessagesStatus method Nov 19, 2024
@jbcaron jbcaron added the rpc-0.8.0 Implementation of the new rpc specs label Nov 19, 2024
@jbcaron
Copy link
Member

jbcaron commented Nov 19, 2024

⚠️ Note: This PR introduces a breaking change due to the addition of a new column in the database

# Conflicts:
#	CHANGELOG.md
#	crates/client/db/src/lib.rs
Copy link
Member

@jbcaron jbcaron left a comment

Choose a reason for hiding this comment

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

Does this implementation account for the entire message history on L1, even if the production sequencer has been inactive for an extended period?

&self,
l1_tx_hash: TxHash,
l1_handler_tx_hash: Felt,
order: u64,
Copy link
Member

Choose a reason for hiding this comment

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

Can the index be a type smaller than u64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason it's u64 is because it's using the log index. Not sure why that needs to be that big, even u32 is more than enough to cover logs in a block I would have thought. I can reduce if you think it's safe.

return Ok(());
}

let l1_handler_transaction = parse_handle_l1_message_transaction(&event)?;
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be better to use our own primitive, mp_transaction::L1HandlerTransaction, even if it requires integrating starknet-api for blocking purposes.

}
let mut message_statuses = vec![];
for l1_handler_tx_hash in l1_handler_tx_hashes {
let finality_status = match get_transaction_status(starknet, l1_handler_tx_hash) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we will need to review the get_transaction_status function in sequencer mode, as we need to handle transactions in both the mempool and the pending state

@antiyro
Copy link
Member

antiyro commented Nov 20, 2024

⚠️ Note: This PR introduces a breaking change due to the addition of a new column in the database

I think that it maybe a good idea to wait for the rolling updates PR from @Trantorian1 to merge this one.

# Conflicts:
#	CHANGELOG.md
#	crates/client/eth/src/l1_messaging.rs
#	crates/client/rpc/src/versions/user/v0_8_0/methods/read/get_messages_status.rs
#	crates/client/rpc/src/versions/user/v0_8_0/methods/read/lib.rs
@shamsasari
Copy link
Contributor Author

Does this implementation account for the entire message history on L1, even if the production sequencer has been inactive for an extended period?

It picks up from the last log event that was processed (which is stored in the db). So yes, I think it does.

Copy link
Collaborator

@Trantorian1 Trantorian1 left a comment

Choose a reason for hiding this comment

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

A few changes related to iteration, otherwise all seems good 👍

crates/client/db/src/l1_db.rs Outdated Show resolved Hide resolved
key[..32].copy_from_slice(l1_tx_hash.as_slice());
key[32..].copy_from_slice(&order.to_be_bytes()); // BE is important for the lexographic sorting
let mut writeopts = WriteOptions::default();
writeopts.disable_wal(true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't WAL be enabled so we don't risk loosing this on a node restart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Storing the mapping is guarded behind messaging_update_last_synced_l1_block_with_event, which also has WAL disabled. The sync will restart from the last stored LastSyncedEventBlock. So I think that should also be enabled? @cchudant

crates/client/eth/src/l1_messaging.rs Outdated Show resolved Hide resolved
@shamsasari
Copy link
Contributor Author

PTAL

Copy link
Collaborator

@Trantorian1 Trantorian1 left a comment

Choose a reason for hiding this comment

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

Seems good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rpc-0.8.0 Implementation of the new rpc specs
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

feat(starknet_getMessageStatus)
4 participants