Skip to content

Commit 1a26c82

Browse files
samliokgap-editorStephenButtolphqdm12michaelkaplan13
authored
Add Simplex Messages To p2p.proto (#3976)
Signed-off-by: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Signed-off-by: rodrigo <77309055+RodrigoVillar@users.noreply.github.com> Signed-off-by: Elvis <43846394+Elvis339@users.noreply.github.com> Co-authored-by: Maximilian Hubert <64627729+gap-editor@users.noreply.github.com> Co-authored-by: Stephen Buttolph <stephen@avalabs.org> Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com> Co-authored-by: Michael Kaplan <michael@avalabs.org> Co-authored-by: Rodrigo Villar <rodrigo.villar@avalabs.org> Co-authored-by: rodrigo <77309055+RodrigoVillar@users.noreply.github.com> Co-authored-by: Elvis <43846394+Elvis339@users.noreply.github.com> Co-authored-by: yacovm <yacovm@users.noreply.github.com>
1 parent 664125d commit 1a26c82

File tree

8 files changed

+1536
-336
lines changed

8 files changed

+1536
-336
lines changed

message/fields.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
_ chainIDGetter = (*p2p.AppRequest)(nil)
3333
_ chainIDGetter = (*p2p.AppResponse)(nil)
3434
_ chainIDGetter = (*p2p.AppGossip)(nil)
35+
_ chainIDGetter = (*p2p.Simplex)(nil)
3536

3637
_ requestIDGetter = (*p2p.GetStateSummaryFrontier)(nil)
3738
_ requestIDGetter = (*p2p.StateSummaryFrontier)(nil)

message/inbound_msg_builder.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,19 @@ func InboundAppResponse(
314314
}
315315
}
316316

317+
// NewInboundSimplexMessage creates a new InboundMessage for simplex messages.
318+
func InboundSimplexMessage(
319+
nodeID ids.NodeID,
320+
msg *p2p.Simplex,
321+
) InboundMessage {
322+
return &inboundMessage{
323+
nodeID: nodeID,
324+
op: SimplexOp,
325+
message: msg,
326+
expiration: mockable.MaxTime,
327+
}
328+
}
329+
317330
func encodeIDs(ids []ids.ID, result [][]byte) {
318331
for i, id := range ids {
319332
result[i] = id[:]

message/messages_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,26 @@ func TestMessage(t *testing.T) {
629629
bypassThrottling: true,
630630
bytesSaved: true,
631631
},
632+
{
633+
desc: "simplex message with no compression",
634+
op: SimplexOp,
635+
msg: &p2p.Message{
636+
Message: &p2p.Message_Simplex{
637+
Simplex: &p2p.Simplex{
638+
ChainId: testID[:],
639+
Message: &p2p.Simplex_ReplicationRequest{
640+
ReplicationRequest: &p2p.ReplicationRequest{
641+
Seqs: []uint64{1, 2, 3},
642+
LatestRound: 1,
643+
},
644+
},
645+
},
646+
},
647+
},
648+
compressionType: compression.TypeNone,
649+
bypassThrottling: true,
650+
bytesSaved: false,
651+
},
632652
}
633653

634654
for _, tv := range tests {

message/ops.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const (
5959
DisconnectedOp
6060
NotifyOp
6161
GossipRequestOp
62+
// Simplex
63+
SimplexOp
6264
)
6365

6466
var (
@@ -76,6 +78,7 @@ var (
7678
AppGossipOp,
7779
GetStateSummaryFrontierOp,
7880
GetAcceptedStateSummaryOp,
81+
SimplexOp,
7982
)
8083
// FailedToResponseOps maps response failure messages to their successful
8184
// counterparts.
@@ -171,6 +174,9 @@ func (op Op) String() string {
171174
return "notify"
172175
case GossipRequestOp:
173176
return "gossip_request"
177+
// Simplex
178+
case SimplexOp:
179+
return "simplex"
174180
default:
175181
return "unknown"
176182
}
@@ -231,6 +237,9 @@ func Unwrap(m *p2p.Message) (fmt.Stringer, error) {
231237
return msg.AppError, nil
232238
case *p2p.Message_AppGossip:
233239
return msg.AppGossip, nil
240+
// Simplex
241+
case *p2p.Message_Simplex:
242+
return msg.Simplex, nil
234243
default:
235244
return nil, fmt.Errorf("%w: %T", errUnknownMessageType, msg)
236245
}
@@ -286,6 +295,8 @@ func ToOp(m *p2p.Message) (Op, error) {
286295
return AppErrorOp, nil
287296
case *p2p.Message_AppGossip:
288297
return AppGossipOp, nil
298+
case *p2p.Message_Simplex:
299+
return SimplexOp, nil
289300
default:
290301
return 0, fmt.Errorf("%w: %T", errUnknownMessageType, msg)
291302
}

proto/p2p/p2p.proto

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ option go_package = "github.com/ava-labs/avalanchego/proto/pb/p2p";
99
// Only one type can be non-null.
1010
message Message {
1111
reserved 1; // Until E upgrade is activated.
12-
reserved 36; // Next unused field number.
12+
reserved 37; // Next unused field number.
1313
// NOTES
1414
// Use "oneof" for each message type and set rest to null if not used.
1515
// That is because when the compression is enabled, we don't want to include uncompressed fields.
@@ -55,6 +55,9 @@ message Message {
5555
AppResponse app_response = 31;
5656
AppGossip app_gossip = 32;
5757
AppError app_error = 34;
58+
59+
// Simplex messages:
60+
Simplex simplex = 36;
5861
}
5962
}
6063

@@ -419,3 +422,91 @@ message AppGossip {
419422
// Message body
420423
bytes app_bytes = 2;
421424
}
425+
426+
message Simplex {
427+
bytes chain_id = 1;
428+
429+
oneof message {
430+
BlockProposal block_proposal = 2;
431+
Vote vote = 3;
432+
EmptyVote empty_vote = 4;
433+
Vote finalize_vote = 5;
434+
QuorumCertificate notarization = 6;
435+
EmptyNotarization empty_notarization = 7;
436+
QuorumCertificate finalization = 8;
437+
ReplicationRequest replication_request = 9;
438+
ReplicationResponse replication_response = 10;
439+
}
440+
}
441+
442+
message BlockProposal {
443+
bytes block = 1;
444+
Vote vote = 2;
445+
}
446+
447+
message ProtocolMetadata {
448+
// Version defines the version of the protocol this block was created with.
449+
uint32 version = 1;
450+
// Epoch returns the epoch in which the block was proposed
451+
uint64 epoch = 2;
452+
// Round returns the round number in which the block was proposed.
453+
// Can also be an empty block.
454+
uint64 round = 3;
455+
// Seq is the order of the block among all blocks in the blockchain.
456+
// Cannot correspond to an empty block.
457+
uint64 seq = 4;
458+
// Prev returns the digest of the previous data block
459+
bytes prev = 5;
460+
}
461+
462+
message BlockHeader {
463+
ProtocolMetadata metadata = 1;
464+
// digest is the short representation of the inner block's bytes
465+
bytes digest = 2;
466+
}
467+
468+
message Signature {
469+
// Signer identifies who the signature came from.
470+
bytes signer = 1;
471+
// Value is the actual cryptographic signature.
472+
bytes value = 2;
473+
}
474+
475+
message Vote {
476+
BlockHeader vote = 1;
477+
Signature signature = 2;
478+
}
479+
480+
message EmptyVote {
481+
ProtocolMetadata vote = 1;
482+
Signature signature = 2;
483+
}
484+
485+
message QuorumCertificate {
486+
BlockHeader finalization = 1;
487+
bytes quorum_certificate = 2;
488+
}
489+
490+
message EmptyNotarization {
491+
ProtocolMetadata empty_vote = 1;
492+
bytes quorum_certificate = 2;
493+
}
494+
495+
message ReplicationRequest {
496+
repeated uint64 seqs = 1; // sequences we are requesting
497+
uint64 latest_round = 2; // latest round that we are aware of
498+
}
499+
500+
message ReplicationResponse {
501+
repeated QuorumRound data = 1; // requested seqs. not required to be in particular order
502+
QuorumRound latest_round = 2; // latest round the responding node is aware of
503+
}
504+
505+
// QuorumRound represents a round that has acheived quorum on either
506+
// (empty notarization), (block & notarization), or (block, finalization certificate)
507+
message QuorumRound {
508+
bytes block = 1;
509+
QuorumCertificate notarization = 2;
510+
EmptyNotarization empty_notarization = 3;
511+
QuorumCertificate finalization = 4;
512+
}

0 commit comments

Comments
 (0)