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

docs: Updates to Messaging mechanism #1244

Merged
merged 30 commits into from
Jun 6, 2024
Merged

Conversation

stoobie
Copy link
Collaborator

@stoobie stoobie commented May 2, 2024

Description of the Changes

Updates implemented in PR #857, minus questions/comments that are still unanswered or TBD.

PR Preview URL

L1-L2 Messaging mechanism

Check List

  • Changes have been done against main branch, and PR does not conflict
  • PR title follows the convention: <docs/feat/fix/chore>(optional scope): <description>, e.g: fix: minor typos in code

This change is Reviewable

@stoobie stoobie force-pushed the steve/L1_diagram_and_L1_2_L2 branch from d8c15d9 to 7f54e8e Compare May 2, 2024 11:40
@stoobie stoobie requested a review from ArielElp May 2, 2024 11:40
Copy link

github-actions bot commented May 2, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

1 similar comment
Copy link

github-actions bot commented May 2, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 23 at r3 (raw file):

. During the execution of a transaction, a contract on Starknet sends a message from L2 to L1 by calling the `send_message_to_L1` syscall.
. The sequencer attaches the message parameters to the state update that includes the syscall invocation. The message parameters include the address of the recipient contract on L1 and the message data.

Suggestion:

. The sequencer attaches the message parameters to the state update that includes the syscall invocation. The message parameters include the address of the sender on L2, the address of the recipient contract on L1, and the message data.

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 23 at r3 (raw file):

. During the execution of a transaction, a contract on Starknet sends a message from L2 to L1 by calling the `send_message_to_L1` syscall.
. The sequencer attaches the message parameters to the state update that includes the syscall invocation. The message parameters include the address of the recipient contract on L1 and the message data.

Oh wait, do you mean the parameters of the send_message_to_l1_syscall(as in the example below), or the parameters of the message itself as it appears in the block? From the first sentence of this bullet, it seems you mean the block / state update and it does include the sender address as well.

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 23 at r3 (raw file):

Previously, avi-starkware wrote…

Oh wait, do you mean the parameters of the send_message_to_l1_syscall(as in the example below), or the parameters of the message itself as it appears in the block? From the first sentence of this bullet, it seems you mean the block / state update and it does include the sender address as well.

I'm am not sure about your terminology, but to be more exact, only the block contains the L2 -> L1 messages. The state update only contains the root, storage diffs, nonces, and deployed classes. Here's an example for a state update that has messages, and this is the corresponding block. You can see the messages appear in the json of the block in this example, but not in the corresponding state update.
(Use a chrome extension such as JSON Formatting, to see the json in a readable format in the browser.)

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 54 at r3 (raw file):

[#diagram_l2-l1_messaging_mechanism]
.L2->L1 Messaging mechanism
image::l2l1.png[L2->L1 message mechanism]

Should the numbers in red circles refer to the items above? I think they are mismatched.

Code quote:

xref:#diagram_l2-l1_messaging_mechanism[] illustrates this flow:

[#diagram_l2-l1_messaging_mechanism]
.L2->L1 Messaging mechanism
image::l2l1.png[L2->L1 message mechanism]

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 63 at r3 (raw file):

[horizontal,labelwidth="30",role="stripes-odd"]
from_address (`felt252`):: The address of the L2 contract sending the message.

Suggestion:

`from_address` (`felt252`):: The address of the L2 contract sending the message.

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 105 at r3 (raw file):

. The L1 Handler transaction that was created in the previous step is added to a proof.
. The Core Contract receives the state update.
. The message is cleared from the Core Contract's storage. At this point, the message is handled.

This step also incurs a fee that is similar to the fee charged for L2 -> L1 messages (this is mentioned for L2 -> L1 messages in the NOTE above):

  • 5000 gas for clearing the L1 storage to consume the message (instead of the 20000 charged for L2 -> L1 messages).
  • This also emits an L1 event logging this consumption.

I think these costs are not actually being charged, though...
@ArielElp, what exactly happens when charging L1 handler fees?

Code quote:

. The message is cleared from the Core Contract's storage. At this point, the message is handled.

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

1 similar comment
@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@avi-starkware
Copy link

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 23 at r3 (raw file):

Previously, avi-starkware wrote…

I'm am not sure about your terminology, but to be more exact, only the block contains the L2 -> L1 messages. The state update only contains the root, storage diffs, nonces, and deployed classes. Here's an example for a state update that has messages, and this is the corresponding block. You can see the messages appear in the json of the block in this example, but not in the corresponding state update.
(Use a chrome extension such as JSON Formatting, to see the json in a readable format in the browser.)

Sorry, this is the block I meant to refer you to, and this is the corresponding state update.

Look at transaction 0xecd259e52ef5061081559c80c0b5f1560caaca7f198a6bf90a74d866593b1 to find a non-empty message.

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

Copy link

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArielElp and @stoobie)

Copy link
Collaborator Author

@stoobie stoobie left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @ArielElp and @avi-starkware)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 54 at r3 (raw file):

Previously, avi-starkware wrote…

Should the numbers in red circles refer to the items above? I think they are mismatched.

Yeah, I have to update the diagram. I'm going to do that in a separate PR.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 63 at r3 (raw file):

[horizontal,labelwidth="30",role="stripes-odd"]
from_address (`felt252`):: The address of the L2 contract sending the message.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 105 at r3 (raw file):

Previously, avi-starkware wrote…

This step also incurs a fee that is similar to the fee charged for L2 -> L1 messages (this is mentioned for L2 -> L1 messages in the NOTE above):

  • 5000 gas for clearing the L1 storage to consume the message (instead of the 20000 charged for L2 -> L1 messages).
  • This also emits an L1 event logging this consumption.

I think these costs are not actually being charged, though...
@ArielElp, what exactly happens when charging L1 handler fees?

@avi-starkware Is this not covered already in https://starknet-io.github.io/starknet-docs/pr-1244/documentation/architecture_and_concepts/Network_Architecture/messaging-mechanism/#l1_l2_message_structure?

Copy link

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @ArielElp and @stoobie)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 105 at r3 (raw file):
I don't see it there. All it says is

The fee itself is calculated in the same manner as "regular" L2 transactions. You can use the CLI to get an estimate of an L1 → L2 message fee.

But as I said above, I know that additional L1 costs are added to the calculation, and it's not just the normal fee calculation for "regular" transactions.

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

6 similar comments
@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

Copy link
Collaborator Author

@stoobie stoobie left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @ArielElp and @avi-starkware)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 23 at r3 (raw file):
@avi-starkware So is this correct:

The sequencer attaches the message parameters to the block that includes the syscall invocation.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc line 105 at r3 (raw file):
@avi-starkware I changed this line as follows:

. The message is cleared from the Core Contract's storage to consume the message. Clearing the Core Contract's storage does the following:

  • incurs a fixed cost of 5,000 gas
  • emits an L1 event logging the message consumption

I'm checking on whether we actually charge the fee.

@starknet-bot
Copy link
Collaborator

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1244/documentation/ .

Copy link

@avi-starkware avi-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ArielElp)

@stoobie stoobie removed the request for review from ArielElp June 6, 2024 14:23
@stoobie stoobie merged commit 2adb157 into main Jun 6, 2024
2 checks passed
@stoobie stoobie deleted the steve/L1_diagram_and_L1_2_L2 branch June 6, 2024 14:23
stoobie added a commit that referenced this pull request Jul 8, 2024
* Clarifying messaging-mechanism.adoc.

* Merge branch 'dev' into steve/L1-L2_messaging

* Removed extraneous space.

* Use Cairo for source block label.

* Added messaging-reference.adoc

* Merge branch 'dev' into steve/L1-L2_messaging

* Merge branch 'dev' into steve/L1-L2_messaging

* Merge branch 'dev' into steve/L1-L2_messaging

* More questions.

* Minor edits.

* Merge branch 'dev' into steve/L1-L2_messaging

* Close some open questions.

* Merge branch 'steve/L1-L2_messaging' of github.com:starknet-io/starknet-docs into steve/L1-L2_messaging

* Clarification edits.

* Clarification edits.

* Merge branch 'master' into steve/L1-L2_messaging

* Edits.

* Edits.

* Edits.

* Edits.

* Merge branch 'main' into steve/L1-L2_messaging

* Update components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/messaging-mechanism.adoc

* Merge branch 'main' into steve/L1-L2_messaging

* More edits.

* Merge branch 'main' into steve/L1-L2_messaging

* Updates implemented in PR #857, minus questions/comments that are still unanswered or TBD.

* Added intro content from the Cairo Book topic on messaging.

* Added intro content from the Cairo Book topic on messaging.

* SME comments

* Added fixed 5,000 gas fee for clearing Core Contract storage after L1->L2 message is handled.

Co-Authored-By: JameStark <[email protected]>
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.

4 participants