-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,178 additions
and
12 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
64 changes: 64 additions & 0 deletions
64
ethereumj-core/src/main/java/org/ethereum/sharding/ShardingEntry.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,64 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.ethereum.cli.CLIInterface; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.facade.Ethereum; | ||
import org.ethereum.facade.EthereumFactory; | ||
import org.ethereum.mine.Ethash; | ||
import org.ethereum.sharding.config.ShardingConfig; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
|
||
/** | ||
* @author Mikhail Kalinin | ||
* @since 26.07.2018 | ||
*/ | ||
public class ShardingEntry { | ||
|
||
public static void main(String args[]) throws IOException, URISyntaxException { | ||
System.setProperty("ethereumj.conf.res", "sharding.conf"); | ||
|
||
CLIInterface.call(args); | ||
|
||
final SystemProperties config = SystemProperties.getDefault(); | ||
final boolean actionBlocksLoader = !config.blocksLoader().isEmpty(); | ||
final boolean actionGenerateDag = !StringUtils.isEmpty(System.getProperty("ethash.blockNumber")); | ||
|
||
if (actionBlocksLoader || actionGenerateDag) { | ||
config.setSyncEnabled(false); | ||
config.setDiscoveryEnabled(false); | ||
} | ||
|
||
if (actionGenerateDag) { | ||
new Ethash(config, Long.parseLong(System.getProperty("ethash.blockNumber"))).getFullDataset(); | ||
// DAG file has been created, lets exit | ||
System.exit(0); | ||
} else { | ||
Ethereum ethereum = EthereumFactory.createEthereum(new Class[] { ShardingConfig.class }); | ||
|
||
if (actionBlocksLoader) { | ||
ethereum.getBlockLoader().loadBlocks(); | ||
} | ||
} | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
ethereumj-core/src/main/java/org/ethereum/sharding/config/BeaconConfig.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,111 @@ | ||
/* | ||
* 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.config; | ||
|
||
import org.ethereum.config.CommonConfig; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.datasource.BatchSourceWriter; | ||
import org.ethereum.datasource.DbSource; | ||
import org.ethereum.datasource.WriteCache; | ||
import org.ethereum.facade.Ethereum; | ||
import org.ethereum.manager.WorldManager; | ||
import org.ethereum.sharding.manager.ShardingWorldManager; | ||
import org.ethereum.sharding.service.ValidatorService; | ||
import org.ethereum.sharding.crypto.DepositAuthority; | ||
import org.ethereum.sharding.contract.DepositContract; | ||
import org.ethereum.sharding.crypto.UnsecuredDepositAuthority; | ||
import org.ethereum.sharding.util.Randao; | ||
import org.ethereum.sharding.service.ValidatorRepository; | ||
import org.ethereum.sharding.service.ValidatorServiceImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Condition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
/** | ||
* @author Mikhail Kalinin | ||
* @since 21.07.2018 | ||
*/ | ||
@Configuration | ||
@Conditional(BeaconConfig.Enabled.class) | ||
public class BeaconConfig { | ||
|
||
@Autowired | ||
CommonConfig commonConfig; | ||
|
||
@Autowired | ||
Ethereum ethereum; | ||
|
||
@Autowired | ||
WorldManager worldManager; | ||
|
||
@Autowired | ||
DepositContractConfig depositContractConfig; | ||
|
||
@Bean | ||
public ValidatorConfig validatorConfig() { | ||
return ValidatorConfig.fromFile(); | ||
} | ||
|
||
@Bean @Primary | ||
public ValidatorService validatorService() { | ||
if (validatorConfig().isEnabled()) { | ||
ValidatorService ret = new ValidatorServiceImpl(ethereum, validatorConfig(), depositContract(), | ||
depositAuthority(), randao()); | ||
((ShardingWorldManager) worldManager).setValidatorService(ret); | ||
return ret; | ||
} else { | ||
return new ValidatorService() {}; | ||
} | ||
} | ||
|
||
@Bean | ||
public ValidatorRepository validatorRepository() { | ||
return new ValidatorRepository(); | ||
} | ||
|
||
@Bean | ||
public DepositContract depositContract() { | ||
return new DepositContract(ethereum, depositContractConfig.getBin(), depositContractConfig.getAbi()); | ||
} | ||
|
||
public DepositAuthority depositAuthority() { | ||
return new UnsecuredDepositAuthority(validatorConfig()); | ||
} | ||
|
||
public Randao randao() { | ||
DbSource<byte[]> src = commonConfig.keyValueDataSource("randao"); | ||
WriteCache.BytesKey<byte[]> cache = new WriteCache.BytesKey<>( | ||
new BatchSourceWriter<>(src), WriteCache.CacheType.SIMPLE); | ||
cache.setFlushSource(true); | ||
commonConfig.dbFlushManager().addCache(cache); | ||
|
||
return new Randao(cache); | ||
} | ||
|
||
public static class Enabled implements Condition { | ||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
return SystemProperties.getDefault().processBeaconChain(); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
ethereumj-core/src/main/java/org/ethereum/sharding/config/DepositContractConfig.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,61 @@ | ||
/* | ||
* 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.config; | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import org.spongycastle.util.encoders.Hex; | ||
|
||
/** | ||
* @author Mikhail Kalinin | ||
* @since 26.07.2018 | ||
*/ | ||
public class DepositContractConfig { | ||
|
||
private String abi; | ||
private byte[] bin; | ||
private byte[] address; | ||
|
||
public DepositContractConfig(String abi, byte[] bin, byte[] address) { | ||
this.abi = abi; | ||
this.bin = bin; | ||
this.address = address; | ||
} | ||
|
||
public static DepositContractConfig fromFile() { | ||
Config config = ConfigFactory.parseResources("deposit-contract.conf"); | ||
|
||
return new DepositContractConfig( | ||
config.getString("beacon.deposit.contract.abi"), | ||
Hex.decode(config.getString("beacon.deposit.contract.bin")), | ||
Hex.decode(config.getString("beacon.deposit.contract.address")) | ||
); | ||
} | ||
|
||
public String getAbi() { | ||
return abi; | ||
} | ||
|
||
public byte[] getBin() { | ||
return bin; | ||
} | ||
|
||
public byte[] getAddress() { | ||
return address; | ||
} | ||
} |
Oops, something went wrong.