ScaleChain / scalechain

A customizable blockchain for altcoins.
236 stars 64 forks source link

Get rid of PBFT #127

Closed Kangmo closed 2 years ago

Kangmo commented 7 years ago

What

PBFT is the root of evil. Get rid of it!!

Why

FIs are using PBFT, we don't make this project for FIs anymore.

How

Just get rid of PBFT, and get PoW work.

Kangmo commented 7 years ago

Update: Done upgrading Kotlin compiler to the latest one, 1.1.3.

tiero commented 7 years ago

Which POW algo? I'm interested a lot in this part

Kangmo commented 7 years ago

The first goal is to make it work with PoW used in Bitcoin.

Kangmo commented 7 years ago

Removed PBFT, now using PoW. Unit tests passed, need to run integration test.

TODO : 1) Need to implement/test initial block download 2) Need to process orphan blocks 3) Need to request parents of an orphan block to the peer who sent an orphan 4) Need to run tests with four nodes.

code commit: https://github.com/ScaleChain/scalechain/commit/b43c60d110e6be135cd591678e046683d30a79f4

Kangmo commented 7 years ago

Plan for this task

Minimize the the start-up time of a node to boost the setup time of each test case.

Write integration test cases

Write integration test cases so that we can guarantee nodes run as expected.

Make integration tests pass

Make sure all tests are passed

Launch the testnet.

Allow two configurations

  1. Run with one node.
  2. Run with four nodes.

List of test cases

Transaction processing

A transaction should

  1. be able to spend block mining reward
  2. be able to spend an output from a transaction in the same block
  3. be able to spend an output from a transaction in a parent block
  4. be rejected if an output is already spent

Basic block processing

Difficulty should

  1. be decreased by half if the actual block creation interval is doubled
  2. be doubled if the actual block creation interval is halved
  3. be adjusted for every 2016 blocks

Block reorganization

A block which has the chain-work greater than the current top block should

  1. become a new top of the blockchain
  2. remove all children block of the common parent up to the current top block.
  3. add all children block of the common parent up to the new block.

A block which has the chain-work less than or equal to the current top block should

  1. become a top of a fork(branch) without affecting any children blocks of the common parent.

A transaction in removed blocks should

  1. be moved to the transaction pool if it doesn't exist in the added block.
  2. not be moved to the transaction pool if it exists in the added block.
  3. be discarded if it depends on an output spent by a new transaction in the added block.

Orphan block processing

An orphan block should

  1. be discarded -> We will initiate IBD(Initial block download) if a node is far behind the current top block of the blockchain. Why? the orphan blocks can be used to flood the number of blocks in a blockchain resulting in a successful DoS attack.

Initial block download

A node should

  1. download blocks from scratch from other nodes upon a startup.
  2. download blocks to catch up other nodes upon a restart.

Peer Info Download

A node should

  1. download IP addresses of peers from a peer upon the setup of the connection.

Concurrency control tests

TBD

Kangmo commented 7 years ago

Status Update: Done

Dev design

Concurrency control: Create a global mutex for Tx, Block

Dev design for the concurrency control for Block message handler, Tx message handler, SubmitBlock, acceptBlock, SendRawTransaction is done.

Conclusions: (1) Need to have a global mutex so that no transaction validation is done during the block reorg or attaching the new best block. (2) Need to run transaction validations on blocks in a forked chain when the forked chain becomes the best blockchain as two chains should have different UTXO databases, but we only keep the UTXO database of the best chain only.

For the details on the dependency on modules for the concurrency control, check data/docs/design/net-layer.mdj, which is a StarUML file.

Transaction validation only for transactions in the best blockchain.

When a block is received either by the Block message or by the SubmitBlock API, we need to run validation checks on the transactions in the block to see if there is any issue in any of transactions in the block. For example, if there is any double spending transaction, we need to reject the block.

But we maintain the UTXO database of the best blockchain, so we will skip the transaction validations for transactions in a block in a forked chain. We will run validation on such a chain when the chain becomes the best blockchain.

Ignore orphan blocks, just run a single logic for initial block download

Accepting orphan blocks has two problems (1) An attacker may flood orphan blocks to fill in block chain database of peers. (2) When we receive an orphan block, we need to request parent blocks to the origin peer of the orphan block, but this makes our code quite complicated.

So, we will reject all orphan blocks(=blocks whose parents are not stored in the blockchain) but use IBD for downloading blocks from other peers if we are behind of other peers in terms of the best block height.

Create controllers for a logic instead of having code snippets in different message handlers.

Currently, we are having code snippets in each of message handlers, but it makes hard to read codes as code snippets for a logic such as initial block download is scattered in multiple message handlers.

We will create a controller interface and then create a concrete class for each logic that sends and receives messages from/to peers.

For example, 'IBD; initial block download' logic sends and receives GetBlocks, Inv, GetData, Block. And also it needs to reject Tx messages or SendRawTransaction API when the IBD is in progress.

Benefits of having such controllers are as follows. (1) We can unit test the controller as well as we have a central file for a logic which has all code snippets so that we can easily understand the code. (2) We can make the message handler code as simple as possible even though we have additional controllers dealing with different kinds of logics on the net layer.

Kangmo commented 7 years ago

In-progress

To be done

Kangmo commented 2 years ago

Closing this issue, distributing following work items into separate issues.

Punt.

136 Write Advanced Functional tests

139 Renewal of synchronization codes