Skip to content

Commit

Permalink
Initial draft of consensus messages.
Browse files Browse the repository at this point in the history
This is set up for Proposal streaming and voting. Certificates for a quorum are part of the sync protocol, not consensus. Peer state sharing is considered a future optimization.
  • Loading branch information
matan-starkware committed May 22, 2024
1 parent 9e4c3a4 commit 6954e1c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
85 changes: 58 additions & 27 deletions p2p/proto/consensus.proto
Original file line number Diff line number Diff line change
@@ -1,42 +1,73 @@
syntax = "proto3";

import "p2p/proto/common.proto";
import "p2p/proto/header.proto";
import "p2p/proto/transaction.proto";
import "p2p/proto/state.proto";
import "google/protobuf/timestamp.proto";


// WIP - will change

message Proposal {
uint64 block_number = 1;
uint32 round = 2;
uint32 pol = 3; // proof of lock
Hash block_header_hash = 4;
google protobuf Timestamp timestamp = 5;
ConsensusSignature signature = 6;
}

// A block proposal is a series of (Transactions+, StateDiff)* BlockHeader

message Vote {
enum Type {
UNKNOWN = 0;
Proposal = 1;
Prevote = 2;
Precommit = 3;
enum VoteType {
Prevote = 0;
Precommit = 1;
};

Proposal proposal = 1;
Address validator_address = 2;
int32 validator_index = 3; // ???
ConsensusSignature signature = 4;
// We use a type field to distinguish between prevotes and precommits instead of different
// messages, to make sure the data, and therefore the signatures, are unambiguous between
// Prevote and Precommit.
VoteType vote_type = 1;
Hash parent_hash = 2;
uint64 block_number = 3;
uint64 fork_id = 4;
uint32 round = 5;
// This is optional since a vote can be NIL.
optional Hash block_hash = 6;
// Identifies the voter.
Address voter = 7;
}

message ProposalInit {
Hash parent_hash = 1;
uint64 block_number = 2;
uint64 fork_id = 3;
uint32 proposal_round = 4;
Address proposer = 5;
}

message CreateBlock {
// Finalize the Tendermint Proposal. When a validator receives this message it will presume that no
// more content for the proposal should be sent.
// - The signature supplied with ProposalFin should be for the full Tendermint proposal, meaning it
// it includes the the fields present here as well as those in `ProposalInit` (with the exception
// of `ProposalInit::proposer`).
message ProposalFin {
optional uint32 valid_round = 1;
// Validators must verify this matches the block_hash they calculated from the content.
Hash block_hash = 2;
}

// The timestamp of a proposal can impact consensus, specifically the lower bound applied. If nodes
// apply a lower bound validation based on their local time, then we risk a scenario where in round
// `R` proposal P is locked. Then in a later round the timestamp in P has gone stale. Therefore the
// lower bound should be "greater than the previous timestamp". Upper bounds don't suffer from this
// problem.
message Proposal {
oneof messages {
Transactions transactions = 1;
StateDiff state_diff = 2;
Proposal proposal = 3;
ProposalInit init = 1;
ProposalFin fin = 2;
// Once block `H` is decided there remains a question; which set of validators receive a
// reward? More specifically, what is the canonical set of precommits for block `H`? Our
// current plan is for the proposer to set the first transaction in `H+1` to be writing the
// list of precommits for `H` to the staking contract in startknet.
Transactions transactions = 3;
BlockProof proof = 4;
}
}

message ConsensusMessage {
oneof messages {
Vote vote = 1;
Proposal proposal = 2;
}
// Signature by the initial sender (e.g. proposer, voter) of the message.
ConsensusSignature signature = 3;
}
4 changes: 4 additions & 0 deletions p2p/proto/header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ message BlockHeadersResponse {
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its header.
}
}

message BlockProof {
repeated bytes proof = 1;
}
4 changes: 4 additions & 0 deletions p2p/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ message TransactionsResponse {
Fin fin = 2; // Fin is sent after the peer sent all the data or when it encountered a block that it doesn't have its transactions.
}
}

message Transactions {
repeated Transaction transactions = 1;
}

0 comments on commit 6954e1c

Please sign in to comment.