Skip to content

Commit

Permalink
Merge pull request #25 from starknet-io/matan/consensus
Browse files Browse the repository at this point in the history
Initial draft of consensus messages.
  • Loading branch information
matan-starkware authored May 22, 2024
2 parents 9e4c3a4 + c0199af commit 050f07d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 27 deletions.
84 changes: 57 additions & 27 deletions p2p/proto/consensus.proto
Original file line number Diff line number Diff line change
@@ -1,42 +1,72 @@
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;
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 {
uint64 block_number = 2;
uint64 fork_id = 3;
uint32 proposal_round = 4;
}

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:
// 1. height
// 2. fork_id
// 3. proposal_round
// 4. valid_round
// 5. block_hash - the validator calculates the block_hash on its own from the content stream and
// confirms the signature with that value.
message ProposalFin {
optional uint32 valid_round = 1;
}

// 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 050f07d

Please sign in to comment.