Skip to content

Commit

Permalink
initial commit for artemis. resolves #88
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhea committed Dec 20, 2018
1 parent 1453437 commit b778931
Show file tree
Hide file tree
Showing 136 changed files with 1,629 additions and 273 deletions.
2 changes: 1 addition & 1 deletion CLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ If you have any questions, you can reach us on [Gitter].

[Gitter]: https://gitter.im/PegaSysEng/artemis
[GitHub]: https://github.com/
[the current version of the CLA]: https://gist.github.com/rojotek/978b48a5e8b68836856a8961d6887992
[the current version of the CLA]: https://gist.github.com/rojotek/978b48a5e8b68836856a8961d6887992
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
FROM openjdk:8-jdk

# copy application (with libraries inside)
ADD build/install/pantheon /opt/pantheon/
ADD integration-tests/src/test/resources/net/consensys/pantheon/tests/cluster/docker/geth/genesis.json /opt/pantheon/genesis.json
ADD build/install/artemis /opt/artemis/
ADD integration-tests/src/test/resources/net/consensys/artemis/tests/cluster/docker/geth/genesis.json /opt/artemis/genesis.json

# List Exposed Ports
EXPOSE 8084 8545 30303 30303/udp

# specify default command
ENTRYPOINT ["/opt/pantheon/bin/pantheon"]
ENTRYPOINT ["/opt/artemis/bin/artemis"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS
g

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
Expand Down
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# BeaconChain
# artemis

[![Build Status](https://jenkins.pegasys.tech/job/Artemis/job/master/badge/icon)](https://jenkins.pegasys.tech/job/Artemis/job/master/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/PegasysEng/artemis/blob/master/LICENSE)
[ ![Download](https://api.bintray.com/packages/consensys/pegasys-repo/artemis/images/download.svg) ](https://bintray.com/consensys/pegasys-repo/artemis/_latestVersion)
[![Gitter chat](https://badges.gitter.im/PegaSysEng/artemis.png)](https://gitter.im/PegaSysEng/artemis)

Implementation of the Ethereum 2.0 Beacon Chain.

Based on the (evolving) [specification](https://notes.ethereum.org/SCIg8AH5SA-O4C1G1LYZHQ?view).
Based on the (evolving) [specification](https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md).

## Build Instructions

To build, clone this repo and run with `gradle` like so:

```
git clone --recursive https://github.com/ConsenSys/BeaconChain
cd beaconchain
gradle
git clone --recursive https://github.com/PegaSysEng/artemis.git
cd artemis
./gradlew
```

After a successful build, distribution packages will be available in `build/distributions`.
Expand All @@ -26,7 +25,7 @@ After a successful build, distribution packages will be available in `build/dist
We use Google's Java coding conventions for the project. To reformat code, run:

```
gradle spotlessApply
./gradlew spotlessApply
```

Code style will be checked automatically during a build.
Expand All @@ -35,9 +34,16 @@ Code style will be checked automatically during a build.

All the unit tests are run as part of the build, but can be explicitly triggered with:
```
gradle test
./gradlew test
```
The integration tests can be triggered with:
```
gradle integrationTest
./gradlew integrationTest
```

## Run

You can run the executable from the CLI with this command:
```
./gradlew run
```
41 changes: 41 additions & 0 deletions artemis/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'java-library'

jar {
baseName 'artemis'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
}
}

dependencies {
implementation project(':crypto')
implementation project(':ethereum:core')
implementation project(':ethereum:rlp')
implementation project(':vrc:vrc')
compile ('org.web3j:core:3.5.0')

implementation 'com.google.guava:guava'
// Disable picocli while the 3.6 release with default enhancement is published.
// The jar is directly inserted until then.
// implementation 'info.picocli:picocli'
compile files('libs/picocli-3.6.0-SNAPSHOT.jar')
implementation 'net.consensys.cava:cava-toml'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'

runtime 'org.apache.logging.log4j:log4j-core'

testImplementation 'com.squareup.okhttp3:okhttp'
testImplementation 'junit:junit'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
compile 'com.google.guava:guava:27.0.1-jre'

test {
testLogging.showStandardStreams = true
}

}
27 changes: 27 additions & 0 deletions artemis/src/main/java/net/consensys/artemis/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package net.consensys.artemis;

import net.consensys.artemis.controllers.ServiceController;

public final class App {
public static void main(final String... args) {
// Process Command Line Args
// Instantiate ServiceController and start event loop
System.out.println(Constants.getConstantsAsString());
ServiceController.init();
ServiceController.start();

}
}
150 changes: 150 additions & 0 deletions artemis/src/main/java/net/consensys/artemis/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package net.consensys.artemis;

import net.consensys.artemis.util.bytes.Bytes32;

public final class Constants {

// The constants below are correct as of spec dated 2018/12/5

// Misc
public static final int SHARD_COUNT = (int) Math.pow(2, 10); // 1,024 Shards
public static final int TARGET_COMMITTEE_SIZE = (int) Math.pow(2, 8); // 256 validators
public static final int EJECTION_BALANCE = (int) Math.pow(2, 4); // 16 Eth
public static final int MAX_BALANCE_CHURN_QUOTIENT = (int) Math.pow(2, 5); // 32
public static final int GWEI_PER_ETH = (int) Math.pow(10, 9); // 1,000,000,000 Wei
public static final int BEACON_CHAIN_SHARD_NUMBER = (int) Math.pow(2, 64) - 1;
public static final String BLS_WITHDRAWAL_PREFIX_BYTE = "0x00";
public static final int MAX_CASPER_VOTES = (int) Math.pow(2, 10); // 1,024 votes

// Deposit contract
// static final Address DEPOSIT_CONTRACT_ADDRESS = Value is still TBD
public static final int DEPOSIT_CONTRACT_TREE_DEPTH = (int) Math.pow(2, 5); // 32
public static final int MIN_DEPOSIT = (int) Math.pow(2, 0); // 1 Eth
public static final int MAX_DEPOSIT = (int) Math.pow(2, 5); // 32 Eth

// Initial values
public static final int INITIAL_FORK_VERSION = 0;
public static final int INITIAL_SLOT_NUMBER = 0;
public static final Bytes32 ZERO_HASH = Bytes32.ZERO;

// Time parameters
public static final int SLOT_DURATION = 6; // 6 seconds
public static final int MIN_ATTESTATION_INCLUSION_DELAY = (int) Math.pow(2, 2); // 4 slots
public static final int EPOCH_LENGTH = (int) Math.pow(2, 6); // 64 slots
public static final int MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL = (int) Math.pow(2, 8); // 256 slots
public static final int POW_RECEIPT_ROOT_VOTING_PERIOD = (int) Math.pow(2, 10); // 1,024 slots
public static final int SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD = (int) Math.pow(2, 17); // 131,072 slots
public static final int COLLECTIVE_PENALTY_CALCULATION_PERIOD = (int) Math.pow(2, 20); // 1,048,576 slots
public static final int ZERO_BALANCE_VALIDATOR_TTL = (int) Math.pow(2, 22); // 4,194,304 slots

// Reward and penalty quotients
public static final int BASE_REWARD_QUOTIENT = (int) Math.pow(2, 11); // 2,048
public static final int WHISTLEBLOWER_REWARD_QUOTIENT = (int) Math.pow(2, 9); // 512
public static final int INCLUDER_REWARD_QUOTIENT = (int) Math.pow(2, 3); // 8
public static final int INACTIVITY_PENALTY_QUOTIENT = (int) Math.pow(2, 34); // 131,072

// Status codes
public static final int PENDING_ACTIVATION = 0;
public static final int ACTIVE = 1;
public static final int ACTIVE_PENDING_EXIT = 2;
public static final int EXITED_WITHOUT_PENALTY = 3;
public static final int EXITED_WITH_PENALTY = 4;

// Max operations per block
public static final int MAX_PROPOSER_SLASHINGS = (int) Math.pow(2, 4); // 16
public static final int MAX_CASPER_SLASHINGS = (int) Math.pow(2, 4); // 16
public static final int MAX_ATTESTATIONS = (int) Math.pow(2, 7); // 128
public static final int MAX_DEPOSITS = (int) Math.pow(2, 4); // 16
public static final int MAX_EXITS = (int) Math.pow(2, 4); // 16


// Validator registry delta flags
public static final int ACTIVATION = 0;
public static final int EXIT = 1;

// Signature domains
public static final int DOMAIN_DEPOSIT = 0;
public static final int DOMAIN_ATTESTATION = 1;
public static final int DOMAIN_PROPOSAL = 2;
public static final int DOMAIN_EXIT = 3;

public static String getConstantsAsString() {
return "--Misc--"
+ "\nSHARD_COUNT: " + SHARD_COUNT
+ "\nTARGET_COMMITTEE_SIZE: " + TARGET_COMMITTEE_SIZE
+ "\nMIN_BALANCE: " + EJECTION_BALANCE
+ "\nMAX_BALANCE_CHURN_QUOTIENT: " + MAX_BALANCE_CHURN_QUOTIENT
+ "\nGWEI_PER_ETH: " + GWEI_PER_ETH
+ "\nBEACON_CHAIN_SHARD_NUMBER: " + BEACON_CHAIN_SHARD_NUMBER
+ "\nBLS_WITHDRAWAL_CREDENTIALS: " + BLS_WITHDRAWAL_PREFIX_BYTE
+ "\nMAX_CASPER_VOTES: " + MAX_CASPER_VOTES

+ "\n\n--Deposit contract--"
// + "\nDEPOSIT_CONTRACT_ADDRESS: " + DEPOSIT_CONTRACT_ADDRESS
+ "\nDEPOSIT_CONTRACT_TREE_DEPTH: " + DEPOSIT_CONTRACT_TREE_DEPTH
+ "\nMIN_DEPOSIT: " + MIN_DEPOSIT
+ "\nMAX_DEPOSIT: " + MAX_DEPOSIT

+ "\n\n--Initial values--"
+ "\nINITIAL_FORK_VERSION: " + INITIAL_FORK_VERSION
+ "\nINITIAL_SLOT_NUMBER: " + INITIAL_SLOT_NUMBER
+ "\nZERO_HASH: " + ZERO_HASH

+ "\n\n--Time parameters--"
+ "\nSLOT_DURATION: " + SLOT_DURATION
+ "\nMIN_ATTESTATION_INCLUSION_DELAY: " + MIN_ATTESTATION_INCLUSION_DELAY
+ "\nEPOCH_LENGTH: " + EPOCH_LENGTH
+ "\nMIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL: " + MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL
+ "\nPOW_RECEIPT_ROOT_VOTING_PERIOD: " + POW_RECEIPT_ROOT_VOTING_PERIOD
+ "\nSHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD: " + SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD
+ "\nCOLLECTIVE_PENALTY_CALCULATION_PERIOD: " + COLLECTIVE_PENALTY_CALCULATION_PERIOD
+ "\nZERO_BALANCE_VALIDATOR_TTL: " + ZERO_BALANCE_VALIDATOR_TTL

+ "\n\n--Reward and penalty quotients--"
+ "\nBASE_REWARD_QUOTIENT: " + BASE_REWARD_QUOTIENT
+ "\nWHISTLEBLOWER_REWARD_QUOTIENT: " + WHISTLEBLOWER_REWARD_QUOTIENT
+ "\nINCLUDER_REWARD_QUOTIENT: " + INCLUDER_REWARD_QUOTIENT
+ "\nINACTIVITY_PENALTY_QUOTIENT: " + INACTIVITY_PENALTY_QUOTIENT

+ "\n\n--Status codes--"
+ "\nPENDING_ACTIVATION: " + PENDING_ACTIVATION
+ "\nACTIVE: " + ACTIVE
+ "\nACTIVE_PENDING_EXIT: " + ACTIVE_PENDING_EXIT
+ "\nEXITED_WITHOUT_PENALTY: " + EXITED_WITHOUT_PENALTY
+ "\nEXITED_WITH_PENALTY: " + EXITED_WITH_PENALTY


+ "\n\n--Max operations per block--"
+ "\nMAX_PROPOSER_SLASHINGS: " + MAX_PROPOSER_SLASHINGS
+ "\nMAX_CASPER_SLASHINGS: " + MAX_CASPER_SLASHINGS
+ "\nMAX_ATTESTATIONS: " + MAX_ATTESTATIONS
+ "\nMAX_DEPOSITS: " + MAX_DEPOSITS
+ "\nMAX_EXITS: " + MAX_EXITS


+ "\n\n--Validator registry delta flags--"
+ "\nACTIVATION: " + ACTIVATION
+ "\nEXIT: " + EXIT

+ "\n\n--Signature domains--"
+ "\nDOMAIN_DEPOSIT: " + DOMAIN_DEPOSIT
+ "\nDOMAIN_ATTESTATION: " + DOMAIN_ATTESTATION
+ "\nDOMAIN_PROPOSAL: " + DOMAIN_PROPOSAL
+ "\nDOMAIN_EXIT: " + DOMAIN_EXIT
+ "\n";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package net.consensys.artemis.controllers;

import net.consensys.artemis.services.BeaconChainService;
import net.consensys.artemis.services.PowchainService;
import net.consensys.artemis.services.ServiceFactory;


public class ServiceController {
private static final BeaconChainService beaconChainService = ServiceFactory.getInstance(BeaconChainService.class).getInstance();;
private static final PowchainService powchainService = ServiceFactory.getInstance(PowchainService.class).getInstance();


// initialize/register all services
public static void init(){

beaconChainService.init();
powchainService.init();

// Validator Service

// P2P Service

// RPC Service
}

public static void start(){
// start all services
beaconChainService.start();
powchainService.start();

}

public static void stop(){
// stop all services
beaconChainService.stop();
powchainService.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package net.consensys.artemis.datastructures.BeaconChainBlocks;

import net.consensys.artemis.ethereum.core.Hash;
import net.consensys.artemis.util.uint.UInt384;
import net.consensys.artemis.util.uint.UInt64;

public class BeaconBlock {

// Header
private UInt64 slot;
private Hash[] ancestor_hashes;
private Hash state_root;
private Hash randao_reveal;
private Hash candidate_pow_receipt_root;
private UInt384[] signature;

// Body
private BeaconBlockBody body;


public BeaconBlock() {

}
}
Loading

0 comments on commit b778931

Please sign in to comment.