Git Product home page Git Product logo

chronicle-decentred's Introduction

Chronicle-Decentred

XCL Banner

Chronicle Decentred is a framework for building a peer to peer Secure Scalable Microservices on Distributed Ledger Technology.

The purpose of this library is to make it easy to create many high throughput microservices which can be run in a decentralised manner.

Versions supported

Currently only Java 8, OpenJDK or Oracle JVMs are supported.

What features will be supported in the open source version

The open source version will

  • peer to peer chains running concurrently

  • a near unlimited number of chains. The theoretical limit is one bllion chains for every person in the world.

  • 25K - 500K transactions per second per chain depending on hardware.

  • latencies down to single digit milli-seconds (depending on network connectivity)

  • testing tools for creating new transaction types

  • simple decentralised consensus strategy (PoIP - Proof Of IP)

  • simple exchange of value

  • supports digital and fiat currencies including XCL (Chronicle Accelerate’s token)

What features will the Enterprise version have

The Enterprise version is designed to add features a commercial operator would like

  • supports bursts of millions of messages per second.

  • tighter latencies (sub-milli-second for Proof of Receipt)

  • more options for exchange of value including continuous auctions.

  • more pluggable consensus strategies

  • doesn’t require a digital currency to run.

Lifecycle of a chain

There is one registry chain for finding the nodes providing any individual chain. This is required for peer chains to find each other but not to run.

  • A private/public key pair for an address is created. The address includes the IPv4 address and port of the first node and is the last 6 bytes of the public key.

  • This address must be verified by a majority of nodes running the registry chain.

  • Once verified, the address can delegate authorirty to run the chain the initial nodes. After that a majority of nodes need to agree a transaction occurred for them to be considered to have happened.

  • This chain can create any number of tokens for use in transactions on this chain. Each token has a home chain which created it.

  • Peer chains can also hold value and perform transaction on these tokens.

  • A chain can set the costs, comsumption rate and reward rate for any token.

Single pass transaction lifecycle

A transaction which only needs the authority of one address can be confirmed in a single pass of the blockchain.

  • The holder of a private key creates a Request with an always increasing micro-second timestamp and signs the message using it’s private key.

  • The Request is passed to one or more nodes in the cluster running the chain.

  • Any transaction which has the same (or earlier timestamp) is ignored.

  • The Request is validated by the gateway of the nodes receiving the request, and possibly rejected with a Response to the sender.

  • If valid, the Request is passed to the chainer to be added to the block created by that node.

  • The blocks created by each node are socialised throughout the cluster and through a consensus model agreed as to the order of those blocks.

  • Once the order of blocks has been agreed by a majority of nodes, every node processes those blocks in the same order and publishes any results.

Double pass transaction lifecycle

A transaction which requires the authority of the majority of nodes running in the cluster requires two passes.

  • A Request is created which follows the single pass lifecycle above, however

  • The results of the transactions on each node are socialised to every other node.

  • The outcome is only confirmed by a majority of nodes chosing the same result, this is published as another event with the events from each node attached as proof.

Examples of single and multi-pass transactions

Transaction

Passes

Transfer within a chain using a single address

Single pass

Transfer between a peer chain and the home chain of a token

Two passes on the peer chain and a single pass on the home chain

Transfer between a peer chain and another peer chain for a token which is homed by a third chain

Two passes on the source peer chain, two passes on the home chain and one pass on the destination chain

How does the chaining work?

XCL Chain
Figure 1. Workflow for transactions on the blockchain
  • A client connects to a server over TCP.

  • The gateway receives the transaction and verifies its signature

  • The gateway can process the request or query and send a reply, or it can pass the request onto the blockchain.

  • Transactions passed to the blockchain are batched into blocks. Each node creates a block concurrently (as needed)

  • Blocks are replicated across nodes via TCP.

  • Each node gossips about the blocks it has.

  • Each node votes on which blocks to include in the next round.

  • Once a majority of node vote the same way, those blocks are included in the next round.

  • Transaction in the next round are processed in order.

  • The results of those transactions are published on all nodes.

  • Events to pass back to the client are returned over TCP.

Getting started

Under examples/appreciation there is a module containing tests for transaction.

A more complex example is examples/exchange for transfer and exchange of value.

In detail

There are a number of key concepts need to understand how this works.

Addresses

Information is associated with an address. You need the private key for the public key registered to an address to alter that data.

Addresses are registered allowing them to be limited in size. Decentred uses 64-bit addresses. Addresses can be

  • Base32 encoded string (top 3 bits are all set)

  • IPv4:port:id (top 3 bits are not all set)

The IPv4:port:id is shorten to IPv4:port if the id is 0.

See DecentredUtils for more details.

Java Server Components and Messages

Chronicle Decentred Java Server Components and Messages are typically handled as described hereunder:

Server Components

Gateway

Receives SignedMessage application messages, validates signatures, responds to query messages that do not change any perceived state of the chain members and sends potentially state altering SignedMessage application messages to a BlockEngine.

BlockEngine

Contains and manages the following sub-components:

Chainer

Receives SignedMessage application messages from Gateway instances and produces TransactionBlockEvent messages.

Gossiper

Receives TransactionBlockEvent messages and sends TransactionBlockGossipEvent messages to Voter instances.

Voter

Receives TransactionBlockGossipEvent from Gossiper instances and sends TransactionBlockVoteEvent messages to VoteTaker instances.

VoteTaker

Receives TransactionBlockVoteEvent from Voter instances and sends EndOfRoundBlockEvent messages to BlockReplayer instances.

BlockReplayer

Replays SignedMessage application messages on participating nodes, altering the perceived state of the chain to reflect the evetns agreed upon by the voting steps above.

Messages

SignedMessage application messages

For example the messages in examples/appreciation: OpeningBalance, Give, Topup.

TransactionBlockEvent

Contains one or several SignedMessage application messages proposed to be included in the next block.

TransactionBlockGossipEvent

Constitutes a new chain state and consists of one cursor for each event producing node. The cursor determines the highest numbered event from that particular node that is included in the block.

TransactionBlockVoteEvent

Consists of a block gossip event that is proposed as next block of the chain.

EndOfRoundBlockEvent

Contains the consensus of events in the block, the outcome of a voting round.

Creating a chain

Create a private/public key pair.

The KeyPair class can help.

Send a create address request

# create a new unique id/address for the chain
createAddressRequest: {
  timestampUS: 2019-02-04T14:31:56.013465,
  address: phccofmpy6ci,
  publicKey: !!binary 9M9t8hyt2kEJmL46Fs+si0VigLTMQt9OafgMm3ljIOg=
}

# create a chain for this address
createChainRequest: {
  timestampUS: 2019-02-04T14:31:56.101034,
  address: phccofmpy6ci,
  cycleOffset: -02:00,
  roundsPerDay: 1000
}

This allows you to run a private chain for yourself, however to run it on multiple node, you have to delegate to one or more IPv4:port addresses. To do this generate an IPV4:port for each of your nodes using brute force. These can be done in parallel.

# assign five delegates to run this chain.
# 165.225.124.237:25956:3b17, 101.255.243.30:17634:9989, 143.245.75.233:729:2a88, 91.102.70.210:2096:2257, 133.194.48.160:27831:945e
assignDelegatesRequest: {
  timestampUS: 2019-02-04T15:09:06.356534,
  address: phccofmpy6ci,
  delegates: [
    !!binary 9M9t8hyt2kEJmL46Fs+si0VigLTMQt9OafgMm3ljIOg=,
    !!binary Ddk/qZ8BB63XgUsBsKCOub6IWoL9+VvvK8kaea/oJfA=,
    !!binary TsXED8x8VoxtLgRu7iPaz4aAhfQUtmvee9KRyhDKk+o=,
    !!binary WClTgi5nnngj3bIkiofts5sFv8CwMPeUEL5Y5MxKwPw=,
    !!binary B/WVrcp+P2Dv7aX5tm5YXvUDk5PKuAyk6ppDoXfIiPk=
  ]
}

Finally, Start the nodes on the IPv4:port as above

chronicle-decentred's People

Contributors

dpisklov avatar jansturenielsen avatar jerryshea avatar lawesson avatar minborg avatar nickward avatar peter-lawrey avatar robaustin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chronicle-decentred's Issues

RPCServer throws exception due to thread check

java.lang.IllegalStateException: net.openhft.chronicle.decentred.remote.rpc.RPCServer component which is not thread safes used by Thread[main,5,main] and Thread[main/test-1,1,main]
	at net.openhft.chronicle.core.io.AbstractCloseable.threadSafetyCheck(AbstractCloseable.java:339)
	at net.openhft.chronicle.core.io.AbstractCloseable.throwExceptionIfClosed(AbstractCloseable.java:254)
	at net.openhft.chronicle.decentred.remote.rpc.RPCServer$XCLConnectionListener.onMessage(RPCServer.java:222)
	at net.openhft.chronicle.decentred.remote.net.VanillaTCPServerConnection.onMessage(VanillaTCPServerConnection.java:59)
	at net.openhft.chronicle.decentred.remote.net.AbstractTCPConnection.processOneMessage(AbstractTCPConnection.java:131)
	at net.openhft.chronicle.decentred.remote.net.AbstractTCPConnection.readChannel(AbstractTCPConnection.java:108)
	at net.openhft.chronicle.decentred.remote.net.VanillaTCPServerConnection.run(VanillaTCPServerConnection.java:38)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
	at net.openhft.chronicle.core.threads.CleaningThread.run(CleaningThread.java:104)

in test net.openhft.chronicle.decentred.server.DecentredClientServerTest#test

LongLongMap.java throwing Exception on @KolobokeMap annotation

Hi. Pardon me if my documenting this here is inappropriate, trying to learn low-latency BlockChain Ledger Technology on Java. Via Chronicle, of course.

Cloned this repo into IntelliJ, right-clicked 'Run all Test' on the IDE Project. Ran into this issue.

[email protected]


C:\Users\16467\IdeaProjects\Chronicle-Decentred\src\main\java\net\openhft\chronicle\decentred\util\LongLongMap.java

Error:(18, 17) java: Koloboke Compile annotation processor threw an exception while processing this type,
  please report this on https://github.com/leventov/Koloboke/issues:
  zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.problem.AbortCompilation: Pb(324) The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:159)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:226)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.problem.ProblemReporter.handle(ProblemReporter.java:2391)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.problem.ProblemReporter.isClassPathCorrect(ProblemReporter.java:4727)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:110)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:212)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.PackageBinding.getType(PackageBinding.java:155)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.Scope.findType(Scope.java:1920)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3248)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2940)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:51)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:495)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:586)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:582)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1967)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1516)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:904)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:899)
  	at zzz_koloboke_compile.shaded.org.$eclipse$.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:448)
  	at zzz_koloboke_compile.shaded.$spoon$.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:58)
  	at zzz_koloboke_compile.shaded.$spoon$.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:193)
  	at zzz_koloboke_compile.shaded.$spoon$.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:444)
  	at zzz_koloboke_compile.shaded.$spoon$.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:126)
  	at zzz_koloboke_compile.shaded.$spoon$.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:109)
  	at zzz_koloboke_compile.shaded.$spoon$.Launcher.buildModel(Launcher.java:686)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$ProcessingCxt$GenerationCxt.parallelProcess(KolobokeCollectionProcessor.kt:741)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$ProcessingCxt.parallelProcess(KolobokeCollectionProcessor.kt:358)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$process$2$$special$$inlined$map$lambda$lambda$1.invoke(KolobokeCollectionProcessor.kt:215)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$process$2$$special$$inlined$map$lambda$lambda$1.invoke(KolobokeCollectionProcessor.kt:79)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor.safeTypeProcess(KolobokeCollectionProcessor.kt:232)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor.access$safeTypeProcess(KolobokeCollectionProcessor.kt:79)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$process$2$$special$$inlined$map$lambda$1.call(KolobokeCollectionProcessor.kt:214)
  	at com.koloboke.compile.processor.KolobokeCollectionProcessor$process$2$$special$$inlined$map$lambda$1.call(KolobokeCollectionProcessor.kt:79)
  	at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1447)
  	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
  	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
  	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
  	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
  	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.