Skip to content

Commit

Permalink
Add missing block header and body fields
Browse files Browse the repository at this point in the history
The block header is updated to allow for the P2P spec to be compatible
with the RPC spec. Before these changes, p2p spec was not enough to
serve to block RPC requests.

Block bodies include Transactions and Receipts because RPC requires the
block to have transactions and receipts. A peer could retrieve them in a
separate request, however, since block bodies are retrieved over
multiple messages I don't see much benefit in requesting them
separately.

Also, note Events were added to Receipt common because `BlockID` is not
enough to determine which event belongs to which receipt. We require the
events for the bloom filter.
  • Loading branch information
IronGauntlets committed Nov 9, 2023
1 parent 9e638e8 commit 3da1088
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
36 changes: 22 additions & 14 deletions p2p/proto/block.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
syntax = "proto3";
import "p2p/proto/common.proto";
import "p2p/proto/state.proto";
import "p2p/proto/transaction.proto";
import "p2p/proto/receipt.proto";
import "google/protobuf/timestamp.proto";

// for now, we assume a small consensus, so this fits in 1M. Else, these will be repeated
Expand All @@ -14,21 +16,25 @@ message Signatures {
// Note: commitments may change to be for the previous blocks like comet/tendermint
// hash of block header sent to L1
message BlockHeader {
Hash parent_header = 1;
uint64 number = 2;
google.protobuf.Timestamp time = 3; // TODO: see if this needs to be Felt252 or can be converted
Address sequencer_address = 4;
Merkle state_diffs = 5; // By order of (contract, key), taking last in case of duplicates.
Hash hash = 1;
Hash parent_hash = 2;
uint64 number = 3;
google.protobuf.Timestamp time = 4; // TODO: see if this needs to be Felt252 or can be converted
Address sequencer_address = 5;
Merkle state_diffs = 6; // By order of (contract, key), taking last in case of duplicates.
// This means the proposer needs to sort after finishing the block (TBD: patricia? )
// State is optional and appears every X blocks for the last block. This is to support
// snapshot sync and also so that light nodes can sync on state without state diffs.
Patricia state = 6; // hash of contract and class patricia tries. Same as in L1. Later more trees will be included
Hash proof_fact = 7; // for Kth block behind. A hash of the output of the proof
Patricia state = 7; // hash of contract and class patricia tries. Same as in L1. Later more trees will be included
Hash proof_fact = 8; // for Kth block behind. A hash of the output of the proof

// The following merkles can be built on the fly while sequencing/validating txs.
Merkle transactions = 8; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff
Merkle events = 9; // By order of issuance. TBD: in receipts?
Merkle receipts = 10; // By order of issuance.
Merkle transactions = 9; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff
Merkle events = 10; // By order of issuance. TBD: in receipts?
Merkle receipts = 11; // By order of issuance.
string protocol_version = 12; // Starknet version
Felt252 extra_data = 13;
Felt252 gas_price = 14;
}

message BlockProof {
Expand Down Expand Up @@ -74,10 +80,12 @@ message BlockBodiesResponse {
optional BlockID id = 1; // may not appear if Fin is sent to end the whole response

oneof body_message {
StateDiff diff = 2;
Classes classes = 3;
BlockProof proof = 4;
Fin fin = 5;
StateDiff diff = 2;
Classes classes = 3;
BlockProof proof = 4;
Transactions transactions = 6;
Receipts receipts = 7;
Fin fin = 8;
}
}

Expand Down
5 changes: 4 additions & 1 deletion p2p/proto/receipt.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";
import "p2p/proto/common.proto";
import "p2p/proto/event.proto";

message MessageToL1 {
Felt252 from_address = 1;
Expand Down Expand Up @@ -29,6 +30,7 @@ message Receipt {
uint32 range_check = 5;
uint32 poseidon = 6;
uint32 keccak = 7;
uint32 output = 8;
}

BuiltinCounter builtins = 1;
Expand All @@ -42,6 +44,7 @@ message Receipt {
repeated MessageToL1 messages_sent = 3;
ExecutionResources execution_resources = 4;
string revert_reason = 5;
Events events = 6;
}


Expand All @@ -68,7 +71,7 @@ message Receipt {
Felt252 contract_address = 2;
}

oneof receipt {
oneof type {
Invoke invoke = 1;
L1Handler l1_handler = 2;
Declare declare = 3;
Expand Down

0 comments on commit 3da1088

Please sign in to comment.