use of org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule in project aion by aionnetwork.
the class AvmVersionScheduleTest method testProhibitionWithOneToleranceUsingSingleAvmSupport.
@Test
public void testProhibitionWithOneToleranceUsingSingleAvmSupport() {
AvmVersionSchedule schedule = AvmVersionSchedule.newScheduleForOnlySingleVersionSupport(16, 1);
// Version 1 is permitted over blocks 15 onwards.
Assert.assertTrue(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_1, 0));
Assert.assertFalse(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_1, 15));
Assert.assertFalse(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_1, 16));
Assert.assertFalse(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_1, Long.MAX_VALUE));
// Ensure that version 2 is always prohibited.
Assert.assertTrue(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_2, 0));
Assert.assertTrue(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_2, 15));
Assert.assertTrue(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_2, 16));
Assert.assertTrue(schedule.isVersionProhibitedAtBlockNumber(AvmVersion.VERSION_2, Long.MAX_VALUE));
}
use of org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule in project aion by aionnetwork.
the class AvmVersionScheduleTest method testWhichVersionUnderSingleAvmSupport.
@Test
public void testWhichVersionUnderSingleAvmSupport() {
AvmVersionSchedule schedule = AvmVersionSchedule.newScheduleForOnlySingleVersionSupport(15, 7);
Assert.assertNull(schedule.whichVersionToRunWith(0));
Assert.assertNull(schedule.whichVersionToRunWith(14));
Assert.assertEquals(AvmVersion.VERSION_1, schedule.whichVersionToRunWith(15));
Assert.assertEquals(AvmVersion.VERSION_1, schedule.whichVersionToRunWith(Long.MAX_VALUE));
}
use of org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule in project aion by aionnetwork.
the class AvmVersionScheduleTest method testWhichVersionUnderNoAvmSupport.
@Test
public void testWhichVersionUnderNoAvmSupport() {
AvmVersionSchedule schedule = AvmVersionSchedule.newScheduleForNoAvmSupport();
Assert.assertNull(schedule.whichVersionToRunWith(0));
Assert.assertNull(schedule.whichVersionToRunWith(Long.MAX_VALUE));
}
use of org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule in project aion by aionnetwork.
the class AvmTransactionExecutor method updateAvmsAndGetVersionToUse.
/**
* Updates the state of the avm versions depending on the current block number.
*
* This method will ensure that any avm versions that are enabled but which are prohibited to
* be enabled at this block number will be shutdown and disabled.
*
* It will also ensure that the avm version that is considered the canonical version at this
* block number is enabled and that its avm is started.
*
* @implNote The projectRootPath is the path to the root directory of the aion project. This is
* required so that we can find the resources to load.
*
* @param projectRootPath The path of the project root directory.
* @param currentBlockNumber The current block number.
* @param enableCoinbaseAddressLocking The flag to enable the coinbase addresslock
* @return the version of the avm to use for the given block number.
*/
public static AvmVersion updateAvmsAndGetVersionToUse(String projectRootPath, long currentBlockNumber, boolean enableCoinbaseAddressLocking) throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException {
AvmVersionSchedule schedule = AvmConfigurations.getAvmVersionSchedule();
AvmVersion versionToUse = schedule.whichVersionToRunWith(currentBlockNumber);
if (versionToUse == null) {
throw new IllegalStateException("Attempted to invoke the avm at a block that has no avm support!");
}
if (versionToUse == AvmVersion.VERSION_1) {
disableVersionIfEnabledAndProhibited(schedule, AvmVersion.VERSION_2, currentBlockNumber);
ensureVersionIsEnabledAndStarted(AvmVersion.VERSION_1, projectRootPath);
} else if (versionToUse == AvmVersion.VERSION_2) {
disableVersionIfEnabledAndProhibited(schedule, AvmVersion.VERSION_1, currentBlockNumber);
if (AvmConfigurations.isCoinbaseAddressLockingEnabled() != enableCoinbaseAddressLocking || // AKI-636 workaround
currentBlockNumber == 4820587) {
if (AvmProvider.isAvmRunning(versionToUse)) {
AvmProvider.shutdownAvm(versionToUse);
}
boolean enable = (currentBlockNumber == 4820587) || enableCoinbaseAddressLocking;
AionLoggerFactory.getLogger(LogEnum.VM.toString()).info("Set the CoinbaseAddressLocking to {}, block#{}", enable, currentBlockNumber);
AvmConfigurations.setEnableCoinbaseAddressLocking(enable);
}
ensureVersionIsEnabledAndStarted(AvmVersion.VERSION_2, projectRootPath);
} else {
throw new IllegalStateException("Unknown avm version: " + versionToUse);
}
return versionToUse;
}
Aggregations