use of com.radixdlt.statecomputer.forks.modules.MainnetForksModule in project radixdlt by radixdlt.
the class ApiTest method setup.
@Before
public void setup() {
var injector = Guice.createInjector(MempoolConfig.asModule(mempoolMaxSize, 10), new MainnetForksModule(), new RadixEngineForksLatestOnlyModule(RERulesConfig.testingDefault().overrideFeeTable(FeeTable.create(Amount.ofSubunits(UInt256.ONE), Map.of(ValidatorRegisteredCopy.class, Amount.ofSubunits(UInt256.ONE))))), new ForksModule(), new SingleNodeAndPeersDeterministicNetworkModule(TEST_KEY, 1), new MockedGenesisModule(Set.of(TEST_KEY.getPublicKey()), totalTokenAmount, stakeAmount), new AbstractModule() {
@Override
protected void configure() {
bind(BerkeleyRecoverableProcessedTxnStore.class).in(Scopes.SINGLETON);
Multibinder.newSetBinder(binder(), BerkeleyAdditionalStore.class).addBinding().to(BerkeleyRecoverableProcessedTxnStore.class);
bindConstant().annotatedWith(DatabaseLocation.class).to(folder.getRoot().getAbsolutePath());
bindConstant().annotatedWith(NetworkId.class).to(99);
bind(P2PConfig.class).toInstance(mock(P2PConfig.class));
bind(AddressBook.class).in(Scopes.SINGLETON);
var selfUri = RadixNodeUri.fromPubKeyAndAddress(99, TEST_KEY.getPublicKey(), "localhost", 23456);
bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
var addressBookPersistence = mock(AddressBookPersistence.class);
when(addressBookPersistence.getAllEntries()).thenReturn(ImmutableList.of());
bind(AddressBookPersistence.class).toInstance(addressBookPersistence);
var runtimeProperties = mock(RuntimeProperties.class);
when(runtimeProperties.get(eq("api.transactions.enable"), anyBoolean())).thenReturn(true);
bind(RuntimeProperties.class).toInstance(runtimeProperties);
}
});
injector.injectMembers(this);
}
use of com.radixdlt.statecomputer.forks.modules.MainnetForksModule in project radixdlt by radixdlt.
the class RadixEngineStateComputerTest method getExternalModule.
private Module getExternalModule() {
return new AbstractModule() {
@Override
public void configure() {
var validatorSet = BFTValidatorSet.from(registeredNodes.stream().map(ECKeyPair::getPublicKey).map(BFTNode::create).map(n -> BFTValidator.from(n, UInt256.ONE)));
bind(ProposerElection.class).toInstance(new WeightedRotatingLeaders(validatorSet));
bind(Serialization.class).toInstance(serialization);
bind(Hasher.class).toInstance(Sha256Hasher.withDefaultSerialization());
bind(new TypeLiteral<EngineStore<LedgerAndBFTProof>>() {
}).toInstance(engineStore);
bind(PersistentVertexStore.class).toInstance(mock(PersistentVertexStore.class));
install(MempoolConfig.asModule(10, 10));
install(new MainnetForksModule());
install(new RadixEngineForksLatestOnlyModule());
install(new ForksModule());
// HACK
bind(CommittedReader.class).toInstance(new NoOpCommittedReader());
bind(ForksEpochStore.class).toInstance(new NoOpForksEpochStore());
bind(LedgerAccumulator.class).to(SimpleLedgerAccumulatorAndVerifier.class);
bind(new TypeLiteral<EventDispatcher<MempoolAddSuccess>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<InvalidProposedTxn>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<TxnsRemovedFromMempool>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<REOutput>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<MempoolRelayTrigger>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(new TypeLiteral<EventDispatcher<LedgerUpdate>>() {
}).toInstance(TypedMocks.rmock(EventDispatcher.class));
bind(SystemCounters.class).to(SystemCountersImpl.class);
}
};
}
use of com.radixdlt.statecomputer.forks.modules.MainnetForksModule in project radixdlt by radixdlt.
the class AbstractRadixEngineTest method setup.
@Before
public void setup() {
var injector = Guice.createInjector(MempoolConfig.asModule(mempoolMaxSize, 10), new MainnetForksModule(), new RadixEngineForksLatestOnlyModule(RERulesConfig.testingDefault().overrideFeeTable(FeeTable.create(Amount.ofSubunits(UInt256.ONE), Map.of(ValidatorRegisteredCopy.class, Amount.ofSubunits(UInt256.ONE)))).overrideMaxMessageLen(maxMessageLen)), new ForksModule(), new SingleNodeAndPeersDeterministicNetworkModule(TEST_KEY, 1), new MockedGenesisModule(Set.of(TEST_KEY.getPublicKey()), totalTokenAmount, stakeAmount), new AbstractModule() {
@Override
protected void configure() {
bind(BerkeleyRecoverableProcessedTxnStore.class).in(Scopes.SINGLETON);
Multibinder.newSetBinder(binder(), BerkeleyAdditionalStore.class).addBinding().to(BerkeleyRecoverableProcessedTxnStore.class);
bindConstant().annotatedWith(DatabaseLocation.class).to(folder.getRoot().getAbsolutePath());
bindConstant().annotatedWith(NetworkId.class).to(99);
bind(P2PConfig.class).toInstance(mock(P2PConfig.class));
bind(AddressBook.class).in(Scopes.SINGLETON);
var selfUri = RadixNodeUri.fromPubKeyAndAddress(99, TEST_KEY.getPublicKey(), "localhost", 23456);
bind(RadixNodeUri.class).annotatedWith(Self.class).toInstance(selfUri);
var addressBookPersistence = mock(AddressBookPersistence.class);
when(addressBookPersistence.getAllEntries()).thenReturn(ImmutableList.of());
bind(AddressBookPersistence.class).toInstance(addressBookPersistence);
var runtimeProperties = mock(RuntimeProperties.class);
when(runtimeProperties.get(eq("api.transactions.enable"), anyBoolean())).thenReturn(true);
bind(RuntimeProperties.class).toInstance(runtimeProperties);
}
});
injector.injectMembers(this);
}
use of com.radixdlt.statecomputer.forks.modules.MainnetForksModule in project radixdlt by radixdlt.
the class GenerateUniverses method main.
public static void main(String[] args) throws Exception {
Security.insertProviderAt(new BouncyCastleProvider(), 1);
Options options = new Options();
options.addOption("h", "help", false, "Show usage information (this message)");
options.addOption("p", "public-keys", true, "Specify validator keys");
options.addOption("v", "validator-count", true, "Specify number of validators to generate");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
if (!cmd.getArgList().isEmpty()) {
System.err.println("Extra arguments: " + String.join(" ", cmd.getArgList()));
usage(options);
return;
}
if (cmd.hasOption('h')) {
usage(options);
return;
}
var validatorKeys = new HashSet<ECPublicKey>();
if (cmd.getOptionValue("p") != null) {
var hexKeys = cmd.getOptionValue("p").split(",");
for (var hexKey : hexKeys) {
validatorKeys.add(ECPublicKey.fromHex(hexKey));
}
}
final int validatorsCount = cmd.getOptionValue("v") != null ? Integer.parseInt(cmd.getOptionValue("v")) : 0;
var generatedValidatorKeys = PrivateKeys.numeric(6).limit(validatorsCount).toList();
generatedValidatorKeys.stream().map(ECKeyPair::getPublicKey).forEach(validatorKeys::add);
// Issuances to mnemomic account, keys 1-5, and 1st validator
final var mnemomicKey = ECPublicKey.fromHex(mnemomicKeyHex);
final ImmutableList.Builder<TokenIssuance> tokenIssuancesBuilder = ImmutableList.builder();
tokenIssuancesBuilder.add(TokenIssuance.of(mnemomicKey, DEFAULT_ISSUANCE));
PrivateKeys.numeric(1).limit(5).map(k -> TokenIssuance.of(k.getPublicKey(), DEFAULT_ISSUANCE)).forEach(tokenIssuancesBuilder::add);
// Issue tokens to initial validators for now to support application services
validatorKeys.forEach(pk -> tokenIssuancesBuilder.add(TokenIssuance.of(pk, DEFAULT_ISSUANCE)));
// Stakes issued by mnemomic account
var stakes = validatorKeys.stream().map(pk -> new StakeTokens(REAddr.ofPubKeyAccount(mnemomicKey), pk, DEFAULT_STAKE)).collect(Collectors.toSet());
var timestamp = String.valueOf(Instant.now().getEpochSecond());
var genesisProvider = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new CryptoModule());
install(new AbstractModule() {
@Provides
@Singleton
private Forks forks(Set<ForkBuilder> forkBuilders) {
return Forks.create(forkBuilders.stream().map(ForkBuilder::build).collect(Collectors.toSet()));
}
@Provides
@Singleton
private CurrentForkView currentForkView(Forks forks) {
return new CurrentForkView(forks, forks.genesisFork());
}
@Provides
@Singleton
@NewestForkConfig
private ForkConfig newestForkConfig(Forks forks) {
return forks.newestFork();
}
});
install(new MainnetForksModule());
bind(new TypeLiteral<List<TxAction>>() {
}).annotatedWith(Genesis.class).toInstance(List.of());
bind(LedgerAccumulator.class).to(SimpleLedgerAccumulatorAndVerifier.class);
bind(SystemCounters.class).toInstance(new SystemCountersImpl());
bindConstant().annotatedWith(Genesis.class).to(timestamp);
bind(new TypeLiteral<Set<StakeTokens>>() {
}).annotatedWith(Genesis.class).toInstance(stakes);
bind(new TypeLiteral<ImmutableList<TokenIssuance>>() {
}).annotatedWith(Genesis.class).toInstance(tokenIssuancesBuilder.build());
bind(new TypeLiteral<Set<ECPublicKey>>() {
}).annotatedWith(Genesis.class).toInstance(validatorKeys);
bindConstant().annotatedWith(MaxValidators.class).to(100);
OptionalBinder.newOptionalBinder(binder(), Key.get(new TypeLiteral<List<TxAction>>() {
}, Genesis.class));
}
}).getInstance(GenesisProvider.class);
var genesis = genesisProvider.get().getTxns().get(0);
IntStream.range(0, generatedValidatorKeys.size()).forEach(i -> {
System.out.format("export RADIXDLT_VALIDATOR_%s_PRIVKEY=%s%n", i, Bytes.toBase64String(generatedValidatorKeys.get(i).getPrivateKey()));
System.out.format("export RADIXDLT_VALIDATOR_%s_PUBKEY=%s%n", i, Addressing.ofNetwork(Network.LOCALNET).forNodes().of(generatedValidatorKeys.get(i).getPublicKey()));
});
if (validatorsCount > 0) {
System.out.format("export RADIXDLT_GENESIS_TXN=%s%n", Bytes.toHexString(genesis.getPayload()));
} else {
try (var writer = new BufferedWriter(new FileWriter("genesis.json"))) {
writer.write(new JSONObject().put("genesis", Bytes.toHexString(genesis.getPayload())).toString());
}
}
}
Aggregations