SAP S/4 HANA –An Introduction to Blockchain 

What is blockchain?

A distributed ledger, formed across a peer-to-peer network of independently controlled nodes. Every participant on this network has a copy of and instant access to all data and – at least in public blockchains – is equal to all other participants. There is no central authority that approves or declines transactions, but consensus about the “one truth” is achieved algorithmically. Once a transaction has been stored on the blockchain and consensus is achieved, it is secured cryptographically, which makes it inherently impossible to tamper with (or at least very, very, very hard).

From a technical point of view, a blockchain is basically a linked list of blocks, with each block containing a number of transactions. Each block contains a hash of the previous block – a cryptographic fingerprint that uniquely identifies a block and all its content. If only one bit of the block changes – for example by tampering with a transaction – the hash value changes as well, which effectively breaks the chain and invalidates all subsequent blocks and transactions. This makes blockchain almost impossible to tamper with. In case of Bitcoin, for example, establishing an alternative transaction history requires control of at least 50% of the computational resources of the network. With a power consumption rivaling countries like Ireland, this can be considered practically impossible.

SAP HANA – yet another Blockchain platform?

Neither SAP Cloud Platform Blockchain nor SAP HANA are a blockchain platform like Bitcoin, Ethereum or Hyperledger fabric. Blockchain is a concept based on collaboration and interoperability. SAPs strategy is not to establish yet another platform and create an SAP-centric blockchain ecosystem, but to integrate into existing enterprise blockchain platforms. SCP Blockchain currently supports Hyperledger fabric (SAP being a premier member of the Linux Foundations Hyperledger project) and MultiChain. With its modular approach, other blockchain platforms can be added easily in the future.

SCP Blockchain connects to any supported blockchain network via a cloud service on SAP Cloud Platform. SAP HANA Blockchain establishes a link between this cloud service and SAP HANA, which results in a representation of on-chain data in SAP HANA as a set of regular column store tables. Technically, this requires two components.

The SAP HANA blockchain adapter subscribes to the HANA blockchain service in the cloud, which in turn communicates with the SAP Blockchain service. The interplay of the different components ensures that transactions submitted to the blockchain are replicated into SAP HANA. This replication works bi-directionally, meaning that transactions inserted in SAP HANA also find their way back to the blockchain, where they can be consumed by other applications.

Easily combine on- and off-chain data

Some of the characteristics of blockchain make it necessary to carefully evaluate what data can and should be stored on the blockchain. Some of the reasons are legal or regulatory. Data protection is a great example, especially in the context of the EUs General Data Protection Regulation (GDPR). Others are performance-related. Storing data on a blockchain is always more expensive than storing it on a central data store. It must be replicated to all participants, verified, hashes must be generated, etc. It’s usually much more economical if you keep the data footprint on the blockchain low.

As a result, a typical business application will most likely store most of the data “off-chain” in a conventional data store, while only necessary data is stored “on-chain” on the actual blockchain. Now, how do we get on- and off-chain data together again?

In a domain dominated by startups, the integration of on-chain data with an enterprise-grade database platform like SAP HANA is unique. With all on-chain data available in SAP HANAs column store through the default SQL interface, combining this data with off-chain data becomes trivial. On-chain data is accessible by all of SAP HANAs advanced analytic engines. This allows simple SQL queries to quickly access a specific excerpt of data, as well as complex scenarios combining local and remote data sources, leveraging SAP HANAs graph, spatial and text search engines and even HANAs machine learning capabilities.

Blockchain: Technical Overview

How SAP HANA blockchain works

My last blog already gave an impression on how SAP HANA blockchain works and which components are involved in getting blockchain data into a SAP HANA database. With this blog, I’d like to provide some more details on these components and their interplay, as well as the features that they enable.

An important fact – and common source of misunderstandings – is that SAP HANA is not acting as a node in a blockchain network all by itself. It is instead leveraging the SCP Blockchain Service as a gateway. The interaction with the network is managed by the SCP blockchain service. The blockchain network itself consists of different nodes that can be hosted on SAP Cloud Platform, any other cloud service provider or even on premise. Additional services like the HANA integration and other application enablement services are only available if the blockchain node is hosted on SCP.

The SAP HANA Integration Service connects the SCP Blockchain service to SAP HANA. It is also used to configure the connection properties on SCP side. This includes the mapping of blockchain messages to the columns of a database table, read/write or read-only access and table types. There are three types of tables.

Raw data: Information about blocks and transactions.

Ledger: Individual messages; allow access to the whole history of transactions that were committed to the blockchain.

World state: Only the latest valid tuples that are known to the blockchain. A world state table looks and behaves in many ways just like a regular database table.

Ledger and worldstate tables contain transaction-specific information as well, like the timestamp and block number.

The connection between SAP HANA and the integration service is established via Smart Data Integration (SDI). The result is a remote source in SAP HANA that can be mapped into a database schema via virtual tables.

Synchronizing SAP HANA and SCP Blockchain service

SAP HANA uses Smart Data Integration (SDI) to retrieve data from and send data to the SCP Blockchain service. Three components are involved in this.

  • The data provisioning server is part of SAP HANA.
  • Data provisioning adapters are specific to each type of data source. SDI is delivered with a set of predefined adapters for various remote sources, but also provides an SDK for custom built adapters.
  • Data provisioning agents host data provisioning adapters. Agents can be deployed on any server that has a network connection to SAP HANA and the remote source – in this case your Blockchain in SCP. Deploying it on the same server as SAP HANA is possible as well, although it is recommended to deploy it as close to the data source as possible.

Accessing data from the blockchain

Mapping the remote source into a database schema via virtual tables is already the first step to enable SAP HANA to access data on the blockchain. Virtual tables provide a symbolic link to the data on the blockchain. This means that data is retrieved on-demand with every single query. Especially for large blockchains or performance-critical applications, this is most likely not an ideal solution.

The big benefit of SAP HANA blockchain is its ability to persist blockchain data locally in the database. This is done via a remote subscription, which reads the data from the blockchain, writes it to a physical database table in SAP HANAs column store and keeps this table and the blockchain in sync by regularly polling the blockchain. Once this is set up, you can leverage the full feature set of SAP HANAs column store with your blockchain data. This includes SAP HANAs advanced analytic engines for graph and geospatial data, as well as machine learning algorithms and text search. Plus, of course, data modelling options with calculation views, etc.

Writing data to the blockchain

The virtual worldstate table supports DML statements like INSERT, UPDATE, and DELETE and feels very much like a regular database table in that regard. The statement will, of course, not actually update or delete anything that was written to the blockchain. This would violate one of the most fundamental blockchain paradigms: The immutability of transactions. Instead, it inserts a new record to the ledger that effectively invalidates the previous one from an application perspective. The big benefit is that an application developer doesn’t need to be aware of this process at all. It is completely transparent, just as if it was a regular database table, while the blockchain magic happens in the background. The only noticeable difference is that the transaction is not committed until a new block has been created that contains the transaction.

Configuring the SAP HANA Integration Service

Before you can work with SAP HANA blockchain, you will need to perform a few configuration steps on SAP Cloud Platform (SCP) side. Let’s assume you already have an account on SCP with an instance of Hyperledger fabric. This account has a subaccount with one Hyperledger fabric channel and an instance of the SAP HANA integration service. The SAP HANA integration service is part of the Application Enablement Services.

The channel provides an isolated communication line on the blockchain for you and other authorized parties, but with safe isolation from everyone that is not authorized. The SAP HANA integration service connects your channel to a SAP HANA database and is used to configure this connection. The configuration screen is displayed in the screenshot above. As mentioned earlier, you can define whether to have a connection read-only or read/write, you can configure the table types that will be available in the remote source on SAP HANA and – finally – set the mapping of messages on the blockchain to a two-dimensional database table.

The example in the screenshot defines a very simple table layout to track personal information via a blockchain. On SAP HANA, this will then look and behave very much like a normal relational database table.

The connection details that are displayed above are required later when configuring the remote source on SAP HANA. As we remember, SAP HANA doesn’t connect directly to the SCP Blockchain service, but to the HANA integration service. The following details must be extracted from the service key of your SAP HANA integration service: