Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,11 @@ articles-papers | |
=============== | ||
|
||
Articles and Papers from Consensus Research | ||
|
||
|
||
Articles | ||
-------- | ||
|
||
|
||
Papers | ||
------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
Inside a Proof-of-Stake Cryptocurrency part 4: The Executable Forging Simulation | ||
================================================================================ | ||
|
||
Introduction | ||
------------ | ||
In first 3 parts Nxt-like 100% proof-of-stake forging algorithm was described. It would be exciting to run executable simulation of it to see | ||
network-wide consensus in action. And now [this simulation tool is published](https://github.com/ConsensusResearch/ForgingSimulation)! Please take a look to it's README for details, and this article is about some aspects of the source code unrevealed yet. | ||
|
||
Modules | ||
------- | ||
|
||
All the code is split into three modules(files): | ||
|
||
* `blockchain.hs`, module Blockchain.Structures - basic structures and functions, building bricks for the simulated cryptocurrency network & | ||
its forging algorithm | ||
|
||
* `simulation.hs`, module Blockchain.Simulation - structures & functions related to simulation | ||
|
||
* `launcher.hs`. module Main - some auxiliary functions & main function running simulation and dumping results into files | ||
|
||
Most of basic structures and functions were decscribed in first 3 parts of the series, so now we're going to take a look into simulation functions. | ||
|
||
systemTransform | ||
--------------- | ||
|
||
The most important function in simulation module is `systemTransform` taking current state of a network along with timestamp and common data for the | ||
simulation and transforming it to resulting network state by applying some partial transformers: | ||
|
||
|
||
systemTransform :: SimulationData -> Network -> Network | ||
systemTransform sd network = networkForge sd $ generateTransactions sd $ | ||
propagateLastBlock sd $ propagateTransactions sd $ downloadBlocksNetwork sd $ | ||
dropConnections sd $ generateConnections sd $ addNode sd $ addInvestorNode sd network | ||
|
||
Where | ||
|
||
* `addInvestorNode` makes some initial investor online. Network starts with just one online investor out of 20, system balance is spread uniformly in | ||
a genesis block. Max number of investors online (14,000 seconds after genesis and on) are 13, means 65% forging power being online | ||
|
||
* `addNode` adds a node to the simulated network with no blockchain & empty account. The node needs to download a blockchain from other nodes. | ||
|
||
* `generateConnections` generates a connection for a node to another node if number of outgoing connection is less than a limit given in settings | ||
file(20 by default) | ||
|
||
* `dropConnections` works once per 60 seconds, drop oldest connection for a node, if number of outgoing connections equals to the limit | ||
|
||
* `downloadBlocksNetwork` selects random neighbour for each peer and check it's cumulative difficulty, and if this metrics is better for the neighbour, | ||
the node is going to download a chunk of blockchain after common chain(14,400 blocks max) | ||
|
||
* `propagateTransactions` selects random neighbour for each peer and sends transactions from peer's unconfirmed transactions pool a naighbour doesn't have | ||
|
||
* `propagateLastBlock` selects nodes having last block generated by other node not more than 15 seconds ago and sends it out to a random neighbour | ||
|
||
* `generateTransactions` generates random transactions sending max 5% stake out(for account having more than 200 coins out of 1,000,000,000 issued) | ||
|
||
* `networkForge` asks each node whether it has a right to generate a block(by it's own opinion) and if so generates blocks for forgers found and sends them out to random neighbours | ||
|
||
|
||
|
||
|
||
Nothing-at-Stake simulation | ||
--------------------------- | ||
|
||
By mixing [multibranch forging simulation tool](https://github.com/ConsensusResearch/MultiBranch) published previously with blockchain forging simulation tool described in the article it's possible now to simulate Nothing-at-Stake attack, e.g. by mixing nodes doing blockchain forging with | ||
"attacker" doing multibranch forging. We'll publish our work on that soon. | ||
|
||
|
||
|
||
Conclusion & Further Work | ||
------------------------- | ||
Well, it's the last article in the "Inside a Proof-of-Stake Cryptocurrency" series. All of them: | ||
|
||
* [Part 1: Basic Structures](http://chepurnoy.org/blog/2014/10/inside-a-proof-of-stake-cryptocurrency-part-1/) | ||
|
||
* [Part 2: Forging Algorithm](http://chepurnoy.org/blog/2014/10/inside-a-proof-of-stake-cryptocurrency-part-2/) | ||
|
||
* [Part 3: A Local Ledger](Inside a Proof-of-Stake Cryptocurrency Part 3: A Local Ledger) | ||
|
||
* [Part 4: The Executable Forging Simulation](http://chepurnoy.org/blog/2014/12/inside-a-proof-of-stake-cryptocurrency-part-4/) | ||
|
||
And executable code corresponding is on GitHub: [https://github.com/ConsensusResearch/ForgingSimulation](https://github.com/ConsensusResearch/ForgingSimulation). Some modifications will be made, I want to replace all the constants with configurable parameters, at least. Performance optimization is also needed, for now it's performance isn't good for simplicity's sake. | ||
|
||
|
||
|
||
|
||
|