// Copyright 2021 Prysmatic Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";

package ethereum.eth.v2;

import "proto/eth/ext/options.proto";

option csharp_namespace = "Ethereum.Eth.V2";
option go_package = "github.com/prysmaticlabs/prysm/proto/eth/v2;eth";
option java_multiple_files = true;
option java_outer_classname = "SyncCommitteeProto";
option java_package = "org.ethereum.eth.v2";
option php_namespace = "Ethereum\\Eth\\v2";

message SubmitSyncCommitteeSignaturesRequest {
  repeated SyncCommitteeMessage data = 1;
}

// SyncCommittee serves as committees to facilitate light client syncing to beacon chain.
message SyncCommittee {
  repeated bytes pubkeys = 1  [(ethereum.eth.ext.ssz_size) = "sync_committee_bits.size,48"];
  bytes aggregate_pubkey = 2 [(ethereum.eth.ext.ssz_size) = "48"];
}

message SubmitPoolSyncCommitteeSignatures {
  repeated SyncCommitteeMessage data = 1;
}

// Sync committee object to support light client.
message SyncCommitteeMessage {
  // Slot to which this contribution pertains.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Slot"];

  // 32 byte block root for this signature.
  bytes beacon_block_root = 2 [(ethereum.eth.ext.ssz_size) = "32"];

  // Index of the validator that produced this signature.
  uint64 validator_index = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.ValidatorIndex"];

  // Signature by the validator over the block root of `slot`.
  bytes signature = 4 [(ethereum.eth.ext.ssz_size) = "96"];
}

message StateSyncCommitteesRequest {
  // The state id which can be any of: "head" (canonical head in node's view),
  // "genesis", "finalized", "justified", <slot>, <hex encoded stateRoot with 0x prefix>.
  bytes state_id = 1;

  // The epoch to retrieve the committees of.
  optional uint64 epoch = 2 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.Epoch"];
}

message StateSyncCommitteesResponse {
  SyncCommitteeValidators data = 1;
  bool execution_optimistic = 2;
}

message SyncCommitteeValidators {
  // All of the validator indices in the current sync committee.
  repeated uint64 validators = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.ValidatorIndex"];

  repeated SyncSubcommitteeValidators validator_aggregates = 2;
}

message SyncSubcommitteeValidators {
  // Subcommittee slices of the current sync committee.
  repeated uint64 validators = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/eth2-types.ValidatorIndex"];
}
