Ontology Sharding TestNet Released

The Ontology Team
OntologyNetwork
Published in
5 min readJun 30, 2019

Read the full Ontology Sharding TestNet Developer Manual on GitHub here.

On December 27th, 2018, we published the Ontology sharding design as an early open-source new year gift for the Ontology developer community.

Over the past 6 months, the Ontology team has completed developing and testing the Ontology Sharding. To celebrate the first anniversary of the Ontology MainNet launch, we are now releasing the Ontology Sharding TestNet. We welcome developers to give it a go and offer your suggestions or feedback to help us improve.

Ontology Sharding

Ontology is committed to creating a componentized, freely configurable, cross-chain supporting, high performance, and scalable blockchain infrastructure, making deploying and calling decentralized applications much easier.

The Ontology Sharding supports the following features:

  • Multi-layer sharding network structure
  • Sharding solution based on smart contract
  • Cross-shard message communication between smart contracts
  • Cross-shard atomic call

TestNet Environment

The Ontology Sharding TestNet includes three shards, which can achieve cross-chain interaction.

We can see from the table above that the sharding network has 21 nodes as shown in the figure below:

Multi-layer Sharding Network Structure

As can be seen from the above figure, all 21 nodes participate in the root shard. Amongst them, 7 nodes in green form Shard-A, and 7 nodes in orange form Shard-B.

The entire sharding network forms a two-layer structure with 7 nodes participating only in the Root Shard at the top. The second layer consists of two sharding subnetworks.

How to get Test Tokens

Apply for test tokens here.

The site allows one address to apply for 1,000 ONT and 10 ONG as test tokens once.

How to Activate Sharding Nodes

The complete process of activating a shard is as follows:

  1. Create a shard: Apply for a shard ID in the Root Shard
  2. Configure the shard: Configure parameters of the new shard, including consensus and related parameters of the Gas
  3. The nodes join the sharding network: the nodes in the Root Shard join the new sharding network through staking
  4. Activate the shard

Sharding Smart Contract Development

The Ontology Sharding adopts a sharding strategy for smart contracts, assigning smart contracts in the root shard to sharding, while assets can be kept in the root shard, thus simultaneously improving the performance of smart contracts and ensuring the security of blockchain assets.

In the Ontology Sharding Network, all smart contracts are deployed in the root shard and smart contracts can run as follows:

  • All-Shard: Smart contracts can run on all shards simultaneously.
  • One-Shard: Smart contracts can only run on a single shard at one time.

The state of the smart contract running on All-Shard will be saved in all the shards it runs on, so the state of the All-Shard smart contract will have to be saved as an account. In the current Ontology Sharding network, smart contracts based on shardAsset contracts can implement smart contract state management in the form of accounts. For details, please refer to OEP-9.

Cross-Shard Smart Contract Development

Developing cross-shard smart contract development is basically the same as developing Ontology smart contracts, except that two interfaces are added to the sharding network for calling cross-shard smart contracts. Ontology provides two interfaces for cross-shard communication: NotifyRemoteShard and InvokeRemoteShard used for asynchronous and synchronous call. Since cross-shard communication relies on network transmission, Parameters transmitted during cross-shard communication should be serialized into byte array.

  • NotifyRemoteShard
  • InvokeRemoteShard

NotifyRemoteShard is used for asynchronous cross-shard call. However, the caller cannot get the call result of the callee, nor does it know when callee executes on the target shard or whether callee executes successfully or not.

InvokeRemoteShard is used for synchronous cross-shard call. The caller can get the call result of the callee and can see it as delayed execution of cross-contract call. Since the call result is returned via network transmission, the return result of the callee should be the serialized byte array.

Call Sharding Smart Contract

You can call the sharding contract using two methods: Ontology-Cli and Ontology-Go-SDK.

Ontology-Cli

The method of calling smart contract using Ontology-Cli is the same as existing Cli, except that you need to add one more parameter - -ShardID. The new --ShardID parameter is used to indicate the contract on which shard is called. If not specified, the default is 0. There are two limitations to using Ontology-Cli to call a sharding smart contract:

  1. Ontology-Cli needs to be compiled with the code in the Ontology sharding branch;
  2. Only the synchronous nodes which activate the Sharding TestNet can use Ontology-Cli. You need to synchronize the blocks on the shard whose contract you are going to call.

Call Smart Contract with Ontology-Go-SDK

Unlike Ontology-Cli, using Ontology-Go-SDK does not have the same limitations. For example, the sample codes for calling the cross-shard transfer of the smart contract example xshardassetdemo.py are as follows:

Deploy Sharding Smart Contract

New smart contract features are supported in the sharding environment. The two most important features are presented in the form of OEP. See OEP-9 and OEP-11 for more details.

To support these new features, the smart contract compiler has also been upgraded and has added Runtime API specifically for the new sharding network. At the moment, only the compiler for Python has been upgraded. See Ontology Sharding Compiler for the upgraded compiler. The method is the same as before.

Likewise, in order to support these new features in the sharding environment, the transaction structure has changed. Currently, only Ontology-Go-SDK supports sharding transactions.

Read the full Ontology Sharding TestNet Developer Manual on GitHub here.

Please feel free to try the Ontology Sharding TestNet and let us know your suggestions and feedback. If you have any questions, please ask us on Discord.

Are you a developer? Make sure you have joined our tech community on Discord. Also, take a look at the Developer Center on our website, there you can find developer tools, documentation, and more.

--

--