ethereum / sharding

Sharding manager contract, and related software and tests
480 stars 105 forks source link

Add shard_chain.py and collation.py #1

Closed hwwhww closed 7 years ago

hwwhww commented 7 years ago

Description

A basic architecture of basic sharding with many TODO tags. There are two main files:

1. sharding/shard_chain.py

Installation

For more details of environment, please refer to pyethereum.

sudo apt-get install libssl-dev build-essential automake pkg-config libtool libffi-dev libgmp-dev

git clone https://github.com/ethereum/sharding/

cd sharding

pip install -r requirements.txt

To install the dependencies necessary for development (testing, ...), run:

pip install -r dev_requirements.txt

Simple Scenario Test

A simple script to describe how would the nodes use this library in sharding/tests/test_depth_one.py. In this test, there are only shard 0 and shard 1.

sharding_config['MAX_SHARD_DEPTH'] = 1
sharding_config['SHARD_CHILD_COUNT'] = 1
sharding_config['SIGNATURE_COUNT'] = 1

Four nodes:

Scenario

  1. cs_collator creates a collation of shard 1
  2. cs_signer verifies and signs the collation of shard 1 and broadcasts it
  3. ms_collator creates a collation of shard 0, includes the collation of shard 1 as one of its child
  4. ms_signer verifies and signs the collation of shard 0 and broadcast it
  5. ms_signer mines a block of top-level
  6. All of the nodes get the block and apply the collation of shard 0 or shard 1
    • The input prev_state is the state of SERENITY_FORK_BLKNUM
    • chain.shard_state may be updated
    • chain.parent_blocks would be updated
    • chain.shard_state_map would be updated
  7. cs_collator creates next collation of shard 1
    • Note that the input prev_state is the result of calling chain.get_prev_state(collation.header.parent_block_hash)
  8. cs_signer verifies and signs the new collation of shard 1
    • Note that the input prev_state is the result of calling chain.get_prev_state(collation.header.parent_block_hash)

How to run

pytest sharding/tests/test_depth_one.py -s
mhchia commented 7 years ago

Nice, pass 👍

Nichebiche commented 4 months ago

Revoke