github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/validator/src/scheduler/mod.rs (about)

     1  /*
     2   * Copyright 2018 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   * ------------------------------------------------------------------------------
    16   */
    17  
    18  use proto::events::Event;
    19  use proto::transaction_receipt::StateChange;
    20  
    21  mod execution_result_ffi;
    22  use batch::Batch;
    23  
    24  pub mod py_scheduler;
    25  
    26  pub trait Scheduler: Sync + Send {
    27      /// Add a batch to the scheduler, optionally specifying that the transactions
    28      /// in this batch and each of the batches in order up to this one should produce a
    29      /// Merkle root specified by expected_state_hash. If the two roots are equal, the results of
    30      /// the block are written to the database, otherwise not.
    31      fn add_batch(
    32          &mut self,
    33          batch: Batch,
    34          expected_state_hash: Option<&str>,
    35          required: bool,
    36      ) -> Result<(), SchedulerError>;
    37  
    38      /// Signal to the scheduler that it can finish it's work and no
    39      /// more batches will be handed to it.
    40      fn finalize(&mut self, unschedule_incomplete: bool) -> Result<(), SchedulerError>;
    41  
    42      /// Cancel the scheduling of the supplied transactions as they are no longer needed.
    43      fn cancel(&mut self) -> Result<(), SchedulerError>;
    44  
    45      /// Ask if the ExecutionResults are ready, optionally blocking until they become available.
    46      fn complete(&mut self, block: bool) -> Result<Option<ExecutionResults>, SchedulerError>;
    47  }
    48  
    49  pub use self::execution_result_ffi::{BatchResult, TransactionResult};
    50  
    51  pub struct ExecutionResults {
    52      pub beginning_state_hash: Option<String>,
    53      pub ending_state_hash: Option<String>,
    54      pub batch_results: Vec<BatchExecutionResult>,
    55  }
    56  
    57  pub type BatchExecutionResult = (String, Option<Vec<TxnExecutionResult>>);
    58  
    59  #[derive(Clone, Debug)]
    60  pub struct TxnExecutionResult {
    61      pub signature: String,
    62      pub is_valid: bool,
    63      pub state_changes: Vec<StateChange>,
    64      pub events: Vec<Event>,
    65      pub data: Vec<(String, Vec<u8>)>,
    66      pub error_message: String,
    67      pub error_data: Vec<u8>,
    68  }
    69  
    70  #[derive(Debug)]
    71  pub enum SchedulerError {
    72      /// The scheduler transition is not allowed by the Finite State Machine.
    73      FSMError(String),
    74      Other(String),
    75  }