From 9e638e826a3c6505046b87b889132e168ef96254 Mon Sep 17 00:00:00 2001 From: IronGauntlets Date: Thu, 9 Nov 2023 21:06:05 +0000 Subject: [PATCH 1/3] Add `CurrentBlockHeaderRequest{}` The response to `CurrentBlockHeaderRequest{}` is the peer's local current header. This can be used to get a rough idea of what the latest block is as viewed by other peers on the network. The header can be compared with a subset of peers to determine an efficient way of pulling blocks from the network while syncing. Initially, we modified the iteration message to include a `latest` option, however, since the iteration message is shared by multiple requests it didn't make sense for each of the messages to have access to it. --- p2p/proto/block.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/proto/block.proto b/p2p/proto/block.proto index d8e30dd..ef521dd 100644 --- a/p2p/proto/block.proto +++ b/p2p/proto/block.proto @@ -45,6 +45,8 @@ message NewBlock { } } +// Requests a peer's CurrentBlockHeader +message CurrentBlockHeaderRequest {} // result is (BlockHeader, Signature?)* in order of creation (incr/dec) message BlockHeadersRequest { From 3da1088ba741dce3d52c3a67b7ffe163674437c1 Mon Sep 17 00:00:00 2001 From: IronGauntlets Date: Thu, 9 Nov 2023 21:32:11 +0000 Subject: [PATCH 2/3] Add missing block header and body fields 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. --- p2p/proto/block.proto | 36 ++++++++++++++++++++++-------------- p2p/proto/receipt.proto | 5 ++++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/p2p/proto/block.proto b/p2p/proto/block.proto index ef521dd..684c65c 100644 --- a/p2p/proto/block.proto +++ b/p2p/proto/block.proto @@ -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 @@ -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 { @@ -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; } } diff --git a/p2p/proto/receipt.proto b/p2p/proto/receipt.proto index f22ff09..03ad711 100644 --- a/p2p/proto/receipt.proto +++ b/p2p/proto/receipt.proto @@ -1,5 +1,6 @@ syntax = "proto3"; import "p2p/proto/common.proto"; +import "p2p/proto/event.proto"; message MessageToL1 { Felt252 from_address = 1; @@ -29,6 +30,7 @@ message Receipt { uint32 range_check = 5; uint32 poseidon = 6; uint32 keccak = 7; + uint32 output = 8; } BuiltinCounter builtins = 1; @@ -42,6 +44,7 @@ message Receipt { repeated MessageToL1 messages_sent = 3; ExecutionResources execution_resources = 4; string revert_reason = 5; + Events events = 6; } @@ -68,7 +71,7 @@ message Receipt { Felt252 contract_address = 2; } - oneof receipt { + oneof type { Invoke invoke = 1; L1Handler l1_handler = 2; Declare declare = 3; From 1692596cc219b053bfa66799f6af6bdd87d9ad5e Mon Sep 17 00:00:00 2001 From: IronGauntlets Date: Fri, 17 Nov 2023 16:06:32 +0300 Subject: [PATCH 3/3] Remove extra_data and hash from BlockHeader --- p2p/proto/block.proto | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/p2p/proto/block.proto b/p2p/proto/block.proto index 684c65c..aa822f9 100644 --- a/p2p/proto/block.proto +++ b/p2p/proto/block.proto @@ -16,25 +16,23 @@ 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 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. + Hash parent_hash = 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. // 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 = 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 + 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 // The following merkles can be built on the fly while sequencing/validating txs. - 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; + 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. + string protocol_version = 11; // Starknet version + Felt252 gas_price = 12; } message BlockProof { @@ -83,9 +81,9 @@ message BlockBodiesResponse { StateDiff diff = 2; Classes classes = 3; BlockProof proof = 4; - Transactions transactions = 6; - Receipts receipts = 7; - Fin fin = 8; + Transactions transactions = 5; + Receipts receipts = 6; + Fin fin = 7; } }