transact/
lib.rs

1/*
2 * Copyright 2018 Bitwise IO, Inc.
3 * Copyright 2019-2021 Cargill Incorporated
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * -----------------------------------------------------------------------------
17 */
18
19//! # Transact
20//!
21//! Transact makes writing distributed ledger software easier by providing a shared software
22//! library that handles the execution of smart contracts, including all aspects of scheduling,
23//! transaction dispatch, and state management.
24//!
25//! Framework-level projects and custom distributed ledgers can use Transact's advanced transaction
26//! execution and state management to simplify the transaction execution code in their projects and
27//! to take advantage of Transact’s additional features.
28//!
29//! More specifically, Transact provides an extensible approach to implementing new smart contract
30//! languages called “smart contract engines.” Each smart contract engine implements a virtual
31//! machine or interpreter that processes smart contracts.
32//!
33//! ## Diving Deeper
34//!
35//! Transact is fundamentally a transaction processing system for state transitions. State data is
36//! generally stored in a Merkle-Radix tree a key-value database, or an SQL database. Given an
37//! initial state and a transaction, Transact executes the transaction to produce a new state.
38//! These state transitions are considered “pure” because only the initial state and the
39//! transaction are used as input. (In contrast, other systems such as Ethereum combine state and
40//! block information to produce the new state.) As a result, Transact is agnostic about framework
41//! features other than transaction execution and state. Awesome, right?
42//!
43//! Transact deliberately omits other features such as consensus, blocks, chaining, and peering.
44//! These features are the responsibility of the frameworks and other distributed ledger
45//! implementations. The focus on smart contract execution means that Transact can be used for
46//! smart contract execution without conflicting with other platform-level architectural design
47//! elements.
48//!
49//! Transact includes the following components:
50//!
51//! * State. The Transact state implementation provides get, set, and delete operations against a
52//!   database. For the Merkle-Radix tree state implementation, the tree structure is implemented on
53//!   top of LMDB or an in-memory database.
54//! * Context manager. In Transact, state reads and writes are scoped (sandboxed) to a specific
55//!   "context" that contains a reference to a state ID (such as a Merkle-Radix state root hash) and
56//!   one or more previous contexts. The context manager implements the context lifecycle and
57//!   services the calls that read, write, and delete data from state.
58//! * Scheduler. This component controls the order of transactions to be executed. Concrete
59//!   implementations include a serial scheduler and a parallel scheduler. Parallel transaction
60//!   execution is an important innovation for increasing network throughput.
61//! * Executor. The Transact executor obtains transactions from the scheduler and executes them
62//!   against a specific context. Execution is handled by sending the transaction to specific
63//!   execution adapters (such as ZMQ or a static in-process adapter) which, in turn, send the
64//!   transaction to a specific smart contract.
65//! * Smart Contract Engines. These components provide the virtual machine implementations and
66//!   interpreters that run the smart contracts. Examples of engines include WebAssembly, Ethereum
67//!   Virtual Machine, Sawtooth Transactions Processors, and Fabric Chain Code.
68//!
69//! ## Sawtooth Compatibility Layer
70//!
71//! Transact provides optional support for smart contract engines implemented for Sawtooth through
72//! the `sawtooth-compat` feature.
73
74// This must be allowed until diesel is upgraded to 2.0
75#![allow(clippy::extra_unused_lifetimes)]
76#![cfg_attr(feature = "nightly", feature(test))]
77
78#[cfg(feature = "diesel")]
79#[macro_use]
80extern crate diesel;
81#[cfg(feature = "diesel_migrations")]
82#[macro_use]
83extern crate diesel_migrations;
84
85#[cfg(feature = "context")]
86mod collections;
87#[cfg(feature = "context")]
88pub mod context;
89#[cfg(feature = "contract")]
90pub mod contract;
91pub mod database;
92pub mod error;
93#[cfg(feature = "execution")]
94pub mod execution;
95pub mod families;
96#[cfg(feature = "handler")]
97pub mod handler;
98pub mod protocol;
99#[allow(renamed_and_removed_lints)]
100pub mod protos;
101#[cfg(feature = "sawtooth-compat")]
102pub mod sawtooth;
103#[cfg(feature = "scheduler")]
104pub mod scheduler;
105pub mod state;
106#[cfg(feature = "workload")]
107pub mod workload;
108
109// #[macro_use]` on the `sabre-sdk` enables the sabre log macros, this however cannot be
110// enabled at the same time as the `log` crate's macros due to linker conflicts
111#[cfg(all(feature = "sabre-compat", feature = "log"))]
112compile_error!("Incompatible features enabled: 'sabre-compat' and 'log'");
113
114#[cfg(feature = "log")]
115#[macro_use]
116extern crate log;
117#[cfg(feature = "sabre-compat")]
118#[macro_use]
119extern crate sabre_sdk;
120#[cfg(feature = "serde_derive")]
121#[macro_use]
122extern crate serde_derive;