# Trusted Electronic Contract for Enabling Peer-to-Peer HPC Resource Sharing
## 3 Proposed Design
### Smart Contract Design and Communication Flow
To ensure HPC activities are automatically synced with blockchain, an interface module (Figure 6) is implemented to facilitate the exchange of states between blockchain and HPC service. To enable portability and isolation from underlying infrastructure (environment on host machines), this module is operated within its own container separated from the rest of the system. Two major components of the module comprise the following:

1. _Blockchain Gateway Service_--is a service that facilitates data exchange between HPC and blockchain. Its key functionalities are composing, signing, and submitting transactions to the blockchain on behalf of the HPC cluster. It also subscribes to blockchain's event hub to listen for smart contract events. Upon a new event arrival, it will send a request to the system monitoring service to perform system actions corresponding to the event types. It uses a network connection profile* for discovering peers in the network and uses cryptographic materials* for presenting eligibility in performing on-chained actions. (* these files are available in a mounted directory). 2. _System Monitoring Service_--helps monitor changes in system states by spawning threads to monitor attentive processes. It also opens a port for listening to the incoming requests. There are two types of operations performed in this module. The first is an asynchronous operation that will execute once there is an incoming request from the blockchain gateway service. For example, blockchain gateway service has received an event notifying new job submission from blockchain, it will then call _/addJobMonitoring_ endpoint on the port listening by system monitoring service. The service then executes the command from bash scripts* to perform system action and return the result back correspondingly. The second type is scheduling operation. For example, for all jobs that are submitted to the system, the service will periodically perform checking if the states of jobs are changed (illustrated in Figure 7). If there are, the changes will be packed and sent to the Blockchain Gateway Service to update the job's states on the blockchain. As the interface module is operated in an isolated container, to ensure operation on the host machine can be carried out, the container needs permission access to local files via the volume mount path. Three types of files are stored in this mounted directory. 1. _Action Scripts_--These are the scripts that are called by System Monitoring Service. It helps perform querying on the scheduler to attain the overall status of HPC components as well as job and queue state. Regardless of the differences in scheduler commands that vary according to scheduler brands, we define a standard structure format for output (i.e, stdout) produced by scripts to ensure the results are understandable by other dependent services. 2. _Blockchain's Crypto Materials_--Used by Blockchain Gateway Service, crypto materials (e.g., public key, private key, and certificates) are files that were used to represent HPC identity in blockchain space. Any transaction generated by the cluster must be digitally signed before being published out to the network. As mentioned earlier, these credentials are registered to a specific role according to RBAC policy to prohibit an entity from performing irrelevant or unauthorized on-chained actions. 3. _Network Connection Profile_--contains network topology, allows the cluster to discover and be discovered by other peers in the blockchain network. ## 4 Implementation

### Blockchain Network Setup

Hyperledger Fabric (HLF) [30] version 1.4 was used for setting up a permissioned blockchain network. To ensure the network can tolerate node crashes, a multi-node Ordering service [31] with Raft protocol [32] was used. The network was deployed on two settings: single-host setting and multi-host setting. For a single host setting, the system was operated on Ubuntu 16.04 LTS machine with 2 CPU cores 2.80 GHz, and 12 GB of RAM.