A basic architecture of basic sharding with many TODO tags. There are two main files:
1. sharding/shard_chain.py
The ShardChain inherits from ethereum.pow.chain.Chain, this object maintains main top-level blocks and shard chain currently, perhaps will be separated if we use networkid to connect to different shard chain.
New fields
shardId - the shard ID of the shard
parent_blocks[block_hash] - a dictionary of list which key is the hash of collation header and value is a list of block_hash. This object is used to store parent blocks of the specific collation.
shard_state_map[(shardId, block_hash)] - a dictionary which key is (shardId, block_hash) and value is the corresponding state root
shard_state - the most recent applied shard state
TODO
[ ] Store previous shard states that haven’t included in top-level block temporarily
[ ] def get_shard_head_state should find the state of Longest Shard Chain
2. sharding/collator.py
A collator may call these functions:
create_collation(chain, txqueue=None, prev_state=None, coinbase='\x35' * 20, children_header=[]) - create a new collation
verify_collation_header(chain, collation_header, prev_state=None, children_header=[], main_chain_included=False) - verify a collation header
verify_collation - verify the execution result of a collation
sign_collation_header(chain, collation_header, local_validation_code_addr) - sign a collation with local_validation_code_addr
apply_collation(chain, prev_state, collation, block_hash, children_header=[]) - apply a collation to shard chain
TODO
[ ] Call contracts to verify signatures
[ ] The algorithm to sign the collation
[ ] Apply finalization and incentives
[ ] Optimize the times of calling call_sample_function and call_validation_code_addr
Installation
For more details of environment, please refer to pyethereum.
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.
Description
A basic architecture of basic sharding with many TODO tags. There are two main files:
1.
sharding/shard_chain.py
ShardChain
inherits fromethereum.pow.chain.Chain
, this object maintains main top-level blocks and shard chain currently, perhaps will be separated if we usenetworkid
to connect to different shard chain.shardId
- the shard ID of the shardparent_blocks[block_hash]
- a dictionary of list which key is the hash of collation header and value is a list ofblock_hash
. This object is used to store parent blocks of the specific collation.shard_state_map[(shardId, block_hash)]
- a dictionary which key is(shardId, block_hash)
and value is the corresponding state rootshard_state
- the most recent applied shard statedef get_shard_head_state
should find the state of Longest Shard Chain2.
sharding/collator.py
create_collation(chain, txqueue=None, prev_state=None, coinbase='\x35' * 20, children_header=[])
- create a new collationverify_collation_header(chain, collation_header, prev_state=None, children_header=[], main_chain_included=False)
- verify a collation headerverify_collation
- verify the execution result of a collationsign_collation_header(chain, collation_header, local_validation_code_addr)
- sign a collation withlocal_validation_code_addr
apply_collation(chain, prev_state, collation, block_hash, children_header=[])
- apply a collation to shard chaincall_sample_function
andcall_validation_code_addr
Installation
To install the dependencies necessary for development (testing, ...), run:
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.Four nodes:
ms_signer
: the signer of shard 0ms_collator
: the collator of shard 0cs_signer
: the signer of shard 1cs_collator
: the collator of shard 1Scenario
cs_collator
creates a collation of shard 1cs_signer
verifies and signs the collation of shard 1 and broadcasts itms_collator
creates a collation of shard 0, includes the collation of shard 1 as one of its childms_signer
verifies and signs the collation of shard 0 and broadcast itms_signer
mines a block of top-levelprev_state
is the state ofSERENITY_FORK_BLKNUM
chain.shard_state
may be updatedchain.parent_blocks
would be updatedchain.shard_state_map
would be updatedcs_collator
creates next collation of shard 1prev_state
is the result of callingchain.get_prev_state(collation.header.parent_block_hash)
cs_signer
verifies and signs the new collation of shard 1prev_state
is the result of callingchain.get_prev_state(collation.header.parent_block_hash)
How to run