Skip to content

Commit

Permalink
x/sync -- Add proto for P2P messages (ava-labs#1472)
Browse files Browse the repository at this point in the history
Co-authored-by: Ron Kuris <ron.kuris@avalabs.org>
Co-authored-by: Dan Laine <daniel.laine@avalabs.org>
  • Loading branch information
3 people committed May 25, 2023
1 parent f7307d5 commit a99a809
Showing 1 changed file with 71 additions and 7 deletions.
78 changes: 71 additions & 7 deletions proto/sync/sync.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,90 @@ package sync;

option go_package = "github.com/ava-labs/avalanchego/proto/pb/sync";

// Request represents a request for information during syncing.
message Request {
oneof message {
RangeProofRequest range_proof_request = 1;
ChangeProofRequest change_proof_request = 2;
}
}

// A RangeProofRequest requests the key-value pairs in a given key range
// at a specific revision.
message RangeProofRequest {
bytes root = 1;
bytes start = 2;
bytes end = 3;
bytes root_hash = 1;
bytes start_key = 2;
bytes end_key = 3;
uint32 key_limit = 4;
uint32 bytes_limit = 5;
}

// A ChangeProofRequest requests the changes between two revisions.
message ChangeProofRequest {
bytes start_root = 1;
bytes end_root = 2;
bytes start = 3;
bytes end = 4;
bytes start_root_hash = 1;
bytes end_root_hash = 2;
bytes start_key = 3;
bytes end_key = 4;
uint32 key_limit = 5;
uint32 bytes_limit = 6;
}

// KeyValue represents a single key and its value.
message KeyValue {
bytes key = 1;
bytes value = 2;
}

// KeyChange is a change for a key from one revision to another.
// If the value is None, the key was deleted.
message KeyChange {
bytes key = 1;
MaybeBytes value = 2;
}

// SerializedPath is the serialized representation of a path.
message SerializedPath {
uint32 nibble_length = 1;
bytes value = 2;
}

// MaybeBytes is an option wrapping bytes.
message MaybeBytes {
bytes value = 1;
// If false, this is None.
bool is_nothing = 2;
}

// ProofNode is a node in a merkle proof.
message ProofNode {
SerializedPath key = 1;
MaybeBytes value_or_hash = 2;
map<uint32, bytes> children = 3;
}

// RangeProof is the response to a RangeProofRequest.
message RangeProof {
repeated ProofNode start = 1;
repeated ProofNode end = 2;
repeated KeyValue key_values = 3;
}

// ChangeProof is a possible response to a ChangeProofRequest.
// It only consists of a proof of the smallest changed key,
// the highest changed key, and the keys that have changed
// between those. Some keys may be deleted (hence
// the use of KeyChange instead of KeyValue).
message ChangeProof {
bool had_roots_in_history = 1; // TODO remove
repeated ProofNode start_proof = 2;
repeated ProofNode end_proof = 3;
repeated KeyChange key_changes = 4;
}

// ChangeProofResponse is the response for a ChangeProofRequest.
message ChangeProofResponse {
oneof response {
ChangeProof change_proof = 1;
RangeProof range_proof = 2;
}
}

0 comments on commit a99a809

Please sign in to comment.