// Copyright 2020 The Exonum Team
//
// 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 exonum;

option java_package = "com.exonum.messages.core";

import "exonum/crypto/types.proto";
import "exonum/key_value_sequence.proto";

// Extensible set of additional headers, represented
// as a sequence of key-value pairs.
message AdditionalHeaders {
  KeyValueSequence headers = 1;
}

message Block {
  uint32 proposer_id = 1;
  uint64 height = 2;
  uint32 tx_count = 3;
  exonum.crypto.Hash prev_hash = 4;
  exonum.crypto.Hash tx_hash = 5;
  exonum.crypto.Hash state_hash = 6;
  exonum.crypto.Hash error_hash = 7;
  AdditionalHeaders additional_headers = 8;
}

message TxLocation {
  uint64 block_height = 1;
  uint32 position_in_block = 2;
}

// Location of an isolated call within a block.
message CallInBlock {
  oneof call {
    // Call of a transaction within the block. The value is the zero-based
    // transaction index.
    uint32 transaction = 1;
    // Call of `before_transactions` hook in a service. The value is
    // the service identifier.
    uint32 before_transactions = 2;
    // Call of `after_transactions` hook in a service. The value is
    // the service identifier.
    uint32 after_transactions = 3;
  }
}

// Consensus configuration parameters

// Public keys of a validator.
message ValidatorKeys {
  // Consensus key is used for messages related to the consensus algorithm.
  exonum.crypto.PublicKey consensus_key = 1;
  // Service key is used for services, for example, the configuration
  // updater service, the anchoring service, etc.
  exonum.crypto.PublicKey service_key = 2;
}

// Consensus algorithm parameters.
message Config {
  // List of validators public keys.
  repeated ValidatorKeys validator_keys = 1;
  // Interval between first two rounds.
  uint64 first_round_timeout = 2;
  // Period of sending a Status message.
  uint64 status_timeout = 3;
  // Peer exchange timeout.
  uint64 peers_timeout = 4;
  // Maximum number of transactions per block.
  uint32 txs_block_limit = 5;
  // Maximum message length (in bytes).
  uint32 max_message_len = 6;
  // Minimal propose timeout.
  uint64 min_propose_timeout = 7;
  // Maximal propose timeout.
  uint64 max_propose_timeout = 8;
  // Amount of transactions in pool to start use `min_propose_timeout`.
  uint32 propose_timeout_threshold = 9;
}
