// 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.v1;

import "google/protobuf/descriptor.proto";
import "proto/eth/ext/options.proto";
import "proto/engine/v1/execution_engine.proto";

option csharp_namespace = "Ethereum.Eth.V1";
option go_package = "github.com/prysmaticlabs/prysm/v4/proto/eth/v1";
option java_multiple_files = true;
option java_outer_classname = "BeaconEventsProto";
option java_package = "org.ethereum.eth.v1";
option php_namespace = "Ethereum\\Eth\\v1";

message StreamEventsRequest {
  // List of topics to request for event streaming items. Allowed request topics are
  // head, attestation, block, voluntary_exit, finalized_checkpoint, chain_reorg.
  repeated string topics = 1;
}

message EventHead {
  // Slot of the new chain head.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];

  // Block root of the new chain head.
  bytes block = 2 [(ethereum.eth.ext.ssz_size) = "32"];

  // State root of the new chain head.
  bytes state = 3 [(ethereum.eth.ext.ssz_size) = "32"];

  // Whether or not the new chain head is at an epoch transition.
  bool epoch_transition = 4;

  // The previous dependent root.
  bytes previous_duty_dependent_root = 5 [(ethereum.eth.ext.ssz_size) = "32"];

  // The current dependent root.
  bytes current_duty_dependent_root = 6 [(ethereum.eth.ext.ssz_size) = "32"];

  // Information about optimistic sync.
  bool execution_optimistic = 7;
}

message EventBlock {
  // The slot of the observed block.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];

  // The root of the observed block.
  bytes block = 2 [(ethereum.eth.ext.ssz_size) = "32"];

  // Information about optimistic sync.
  bool execution_optimistic = 3;
}

message EventChainReorg {
  // The slot of the observed reorg.
  uint64 slot = 1 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];

  // Depth of the reorg in slots.
  uint64 depth = 2;

  // Block root of the old head.
  bytes old_head_block = 3 [(ethereum.eth.ext.ssz_size) = "32"];

  // Block root of the new head.
  bytes new_head_block = 4 [(ethereum.eth.ext.ssz_size) = "32"];

  // State root of the old state.
  bytes old_head_state = 5 [(ethereum.eth.ext.ssz_size) = "32"];

  // State root of the new state.
  bytes new_head_state = 6 [(ethereum.eth.ext.ssz_size) = "32"];

  // Epoch of the observed reorg.
  uint64 epoch = 7 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Epoch"];

  // Information about optimistic sync.
  bool execution_optimistic = 8;
}

message EventFinalizedCheckpoint {
  // Block root of the finalized checkpoint.
  bytes block = 1 [(ethereum.eth.ext.ssz_size) = "32"];

  // State root of the finalized checkpoint.
  bytes state = 2 [(ethereum.eth.ext.ssz_size) = "32"];

  // Epoch the checkpoint references.
  uint64 epoch = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Epoch"];

  // Information about optimistic sync.
  bool execution_optimistic = 4;
}

message EventPayloadAttributeV1 {
  // the identifier of the beacon hard fork at `proposal_slot`, e.g.`"bellatrix"`.
  string version = 1;
  BasePayloadAttribute data = 2;
  message BasePayloadAttribute {
     // The slot at which a block using these payload attributes may be built.
        uint64 proposal_slot = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];

        // The execution block number of the parent block.
        uint64 parent_block_number = 4;

        // The beacon block root of the parent block to be built upon.
        bytes parent_block_root = 5 [(ethereum.eth.ext.ssz_size) = "32"];

        // The execution block hash of the parent block.
        bytes parent_block_hash = 6 [(ethereum.eth.ext.ssz_size) = "32"];

        // The validator index of the proposer at proposal_slot on the chain identified by parent_block_root.
        uint64 proposer_index = 7 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.ValidatorIndex"];

        // payload_attributes: beacon API encoding of PayloadAttributesV<N> as defined by the execution-apis specification.
        // The version N must match the payload attributes for the hard fork matching version.
        // The beacon API encoded object must have equivalent fields to its counterpart in execution-apis with two differences:
        // 1) snake_case identifiers must be used rather than camelCase; 2) integers must be encoded as quoted decimals rather than big-endian hex.
        engine.v1.PayloadAttributes payload_attributes = 8;
  }
}


message EventPayloadAttributeV2 {
  // the identifier of the beacon hard fork at `proposal_slot`, e.g.`"bellatrix"`.
  string version = 1;
  BasePayloadAttribute data = 2;
  message BasePayloadAttribute {
     // The slot at which a block using these payload attributes may be built.
        uint64 proposal_slot = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];

        // The execution block number of the parent block.
        uint64 parent_block_number = 4;

        // The beacon block root of the parent block to be built upon.
        bytes parent_block_root = 5 [(ethereum.eth.ext.ssz_size) = "32"];

        // The execution block hash of the parent block.
        bytes parent_block_hash = 6 [(ethereum.eth.ext.ssz_size) = "32"];

        // The validator index of the proposer at proposal_slot on the chain identified by parent_block_root.
        uint64 proposer_index = 7 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.ValidatorIndex"];

        // payload_attributes: beacon API encoding of PayloadAttributesV<N> as defined by the execution-apis specification.
        // The version N must match the payload attributes for the hard fork matching version.
        // The beacon API encoded object must have equivalent fields to its counterpart in execution-apis with two differences:
        // 1) snake_case identifiers must be used rather than camelCase; 2) integers must be encoded as quoted decimals rather than big-endian hex.
        engine.v1.PayloadAttributesV2 payload_attributes = 8;
  }
}

message EventBlobSidecar {
  bytes block_root = 1 [(ethereum.eth.ext.ssz_size) = "32"];
  uint64 index = 2;
  uint64 slot = 3 [(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives.Slot"];
  // calculated from the kzg commitment
  bytes versioned_hash = 4 [(ethereum.eth.ext.ssz_size) = "32"];
  bytes kzg_commitment = 5 [(ethereum.eth.ext.ssz_size) = "48"];
}