/**
 * # Block Stream Info
 * Information stored in consensus state at the beginning of each block to
 * record the status of the immediately prior block.
 *
 * ### Keywords
 * The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
 * "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
 * document are to be interpreted as described in
 * [RFC2119](https://www.ietf.org/rfc/rfc2119) and clarified in
 * [RFC8174](https://www.ietf.org/rfc/rfc8174).
 */
syntax = "proto3";

package com.hedera.hapi.node.state.blockstream;

// SPDX-License-Identifier: Apache-2.0
import "services_timestamp.proto";
import "services_basic_types.proto";

option java_package = "com.hederahashgraph.api.proto.java";
// <<<pbj.java_package = "com.hedera.hapi.node.state.blockstream">>> This comment is special code for setting PBJ Compiler java package
option java_multiple_files = true;

/**
 * A message stored in state to maintain block stream parameters.<br/>
 * Nodes use this information for three purposes.
 * 1. To maintain hash chain continuity at restart and reconnect boundaries.
 * 2. To store historical hashes for implementation of the EVM `BLOCKHASH`
 *    and `PREVRANDAO` opcodes.
 * 3. To track the amount of consensus time that has passed between blocks.
 *
 * This value MUST be updated for every block.<br/>
 * This value MUST be transmitted in the "state changes" section of
 * _each_ block, but MUST be updated at the beginning of the _next_ block.<br/>
 * This value SHALL contain the block hash up to, and including, the
 * immediately prior completed block.<br/>
 * The state change to update this singleton MUST be the last
 * block item in this block.
 */
message BlockStreamInfo {
    /**
     * A block number.<br/>
     * This is the current block number.
     */
    uint64 block_number = 1;

    /**
     * A consensus time for the current block.<br/>
     * This is the consensus time of the first round in the current block,
     * which equates to the first contained transaction's consensus time.
     * It is used to determine if this block was the first across an
     * important boundary in consensus time, such as UTC midnight.
     * This may also be used to purge entities expiring between the last
     * block time and this time.
     */
    proto.Timestamp block_time = 2;

    /**
     * A concatenation of hash values.<br/>
     * This combines several trailing output block item hashes and
     * is used as a seed value for a pseudo-random number generator.<br/>
     * This is also required to implement the EVM `PREVRANDAO` opcode.<br/>
     * This MUST contain at least 256 bits of entropy.
     */
    bytes trailing_output_hashes = 3;

    /**
     * A concatenation of hash values.<br/>
     * This field combines up to 256 trailing block hashes.
     * <p>
     * If this message is for block number N, then the earliest available
     * hash SHALL be for block number N-256.<br/>
     * The latest available hash SHALL be for block N-1.<br/>
     * This is REQUIRED to implement the EVM `BLOCKHASH` opcode.
     * <p>
     * ### Field Length
     * Each hash value SHALL be the trailing 265 bits of a SHA2-384 hash.<br/>
     * The length of this field SHALL be an integer multiple of 32 bytes.<br/>
     * This field SHALL be at least 32 bytes.<br/>
     * The maximum length of this field SHALL be 8192 bytes.
     */
    bytes trailing_block_hashes = 4;

    /**
     * A SHA2-384 hash value.<br/>
     * This is the final hash of the "input" subtree for this block.
     */
    bytes input_tree_root_hash = 5;

    /**
     * A SHA2-384 hash value.<br/>
     * This is the hash of consensus state at the _start_ of this block.
     */
    bytes start_of_block_state_hash = 6;

    /**
     * A count of "output" block items in this block.
     * <p>
     * This SHALL count the number of output block items that _precede_
     * the state change that updates this singleton.
     */
    uint32 num_preceding_state_changes_items = 7;

    /**
     * A concatenation of SHA2-384 hash values.<br/>
     * This is the "rightmost" values of the "output" subtree.
     * <p>
     * The subtree containing these hashes SHALL be constructed from all "output"
     * `BlockItem`s in this block that _precede_ the update to this singleton.
     */
    repeated bytes rightmost_preceding_state_changes_tree_hashes = 8;

    /**
     * A block-end consensus time stamp.
     * <p>
     * This field SHALL hold the last-used consensus time for
     * the current block.
     */
    proto.Timestamp block_end_time = 9;

    /**
     * Whether the post-upgrade work has been done.
     * <p>
     * This MUST be false if and only if the network just restarted
     * after an upgrade and has not yet done the post-upgrade work.
     */
    bool post_upgrade_work_done = 10;

    /**
     * A version describing the version of application software.
     * <p>
     * This SHALL be the software version that created this block.
     */
    proto.SemanticVersion creation_software_version = 11;

    /**
     * The time stamp at which the last interval process was done.
     * <p>
     * This field SHALL hold the consensus time for the last time
     * at which an interval of time-dependent events were processed.
     */
    proto.Timestamp last_interval_process_time = 12;

    /**
     * The time stamp at which the last user transaction was handled.
     * <p>
     * This field SHALL hold the consensus time for the last time
     * at which a user transaction was handled.
     */
    proto.Timestamp last_handle_time = 13;

    /**
     * A SHA2-384 hash value.<br/>
     * This is the final hash of the "consensus headers" subtree for this block.
     */
    bytes consensus_header_root_hash = 14;

    /**
     * A SHA2-384 hash value.<br/>
       * This is the final hash of the "output" subtree for this block.
     */
    bytes output_item_root_hash = 15;

    /**
     * A SHA2-384 hash value.<br/>
     * This is the final hash of the "trace data" subtree for this block.
     */
    bytes trace_data_root_hash = 16;

    /**
     * The intermediate hashes needed for subroot 2 in the block merkle
     * tree structure. These hashes SHALL include the minimum required
     * block root hashes needed to construct subroot 2's final state at
     * the end of the previous block.
     */
    repeated bytes intermediate_previous_block_root_hashes = 17;

    /**
     * The number of leaves in the intermediate block roots subtree.
     */
    uint64 intermediate_block_roots_leaf_count = 18;
}
