Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1185 from ethereum/sharding/committees
[WIP] Attestation committees
- Loading branch information
Showing
36 changed files
with
1,326 additions
and
214 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
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
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
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
52 changes: 52 additions & 0 deletions
52
...reumj-core/src/main/java/org/ethereum/sharding/processing/consensus/CommitteeFactory.java
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,52 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.sharding.processing.consensus; | ||
|
||
import org.ethereum.sharding.processing.state.Committee; | ||
|
||
/** | ||
* An interface of committee factory. | ||
* | ||
* <p> | ||
* Used to produce new shards and committees array. | ||
* | ||
* <p> | ||
* in: {@code [validators]} <br/> | ||
* out: {@code [slot: [shardId, [validators]]]} | ||
* | ||
* | ||
* @see Committee | ||
* | ||
* @author Mikhail Kalinin | ||
* @since 14.09.2018 | ||
*/ | ||
public interface CommitteeFactory { | ||
|
||
/** | ||
* Creates new committees set. | ||
* | ||
* @param seed seed for random shuffling | ||
* @param validators array of active validator numbers | ||
* @param startShard shard id that first committee in resulting array will be assigned to | ||
* | ||
* @return shards and committee array for each slot of cycle | ||
* | ||
* @see BeaconConstants#CYCLE_LENGTH | ||
*/ | ||
Committee[][] create(byte[] seed, int[] validators, int startShard); | ||
} |
50 changes: 48 additions & 2 deletions
50
...eumj-core/src/main/java/org/ethereum/sharding/processing/consensus/DynastyTransition.java
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 |
---|---|---|
@@ -1,20 +1,66 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.sharding.processing.consensus; | ||
|
||
import org.ethereum.sharding.domain.Beacon; | ||
import org.ethereum.sharding.processing.db.ValidatorSet; | ||
import org.ethereum.sharding.processing.state.Committee; | ||
import org.ethereum.sharding.processing.state.Dynasty; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.ethereum.sharding.processing.consensus.BeaconConstants.CYCLE_LENGTH; | ||
import static org.ethereum.sharding.processing.consensus.BeaconConstants.MIN_DYNASTY_LENGTH; | ||
import static org.ethereum.sharding.util.BeaconUtils.cycleStartSlot; | ||
|
||
/** | ||
* @author Mikhail Kalinin | ||
* @since 12.09.2018 | ||
*/ | ||
public class DynastyTransition implements StateTransition<Dynasty> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("beacon"); | ||
|
||
StateTransition<ValidatorSet> validatorSetTransition; | ||
CommitteeFactory committeeFactory = new ShufflingCommitteeFactory(); | ||
|
||
public DynastyTransition(StateTransition<ValidatorSet> validatorSetTransition) { | ||
this.validatorSetTransition = validatorSetTransition; | ||
} | ||
|
||
@Override | ||
public Dynasty applyBlock(Beacon block, Dynasty to) { | ||
if (block.getSlotNumber() - to.getStartSlot() < BeaconConstants.MIN_DYNASTY_LENGTH) | ||
if (block.getSlotNumber() - to.getStartSlot() < MIN_DYNASTY_LENGTH) | ||
return to; | ||
|
||
logger.info("Calculate new dynasty, slot: {}, prev slot: {}", block.getSlotNumber(), to.getStartSlot()); | ||
|
||
// validator set transition | ||
ValidatorSet validatorSet = validatorSetTransition.applyBlock(block, to.getValidatorSet()); | ||
|
||
// committee transition | ||
int startShard = to.getCommitteesEndShard() + 1; | ||
int[] validators = validatorSet.getActiveIndices(); | ||
Committee[][] committees = committeeFactory.create(block.getHash(), validators, startShard); | ||
|
||
return to.withNumberIncrement(1L) | ||
.withCrosslinkingStartShardIncrement(1L); | ||
.withStartSlot(cycleStartSlot(block)) | ||
.withValidatorSet(validatorSet) | ||
.withCommittees(committees); | ||
} | ||
} |
Oops, something went wrong.