Search in sources :

Example 16 with AvmVersionSchedule

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));
}
Also used : AvmVersionSchedule(org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule) Test(org.junit.Test)

Example 17 with AvmVersionSchedule

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));
}
Also used : AvmVersionSchedule(org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule) Test(org.junit.Test)

Example 18 with AvmVersionSchedule

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));
}
Also used : AvmVersionSchedule(org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule) Test(org.junit.Test)

Example 19 with AvmVersionSchedule

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;
}
Also used : AvmVersionSchedule(org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule) AvmVersion(org.aion.avm.stub.AvmVersion)

Aggregations

AvmVersionSchedule (org.aion.zero.impl.vm.avm.schedule.AvmVersionSchedule)19 Test (org.junit.Test)13 Console (java.io.Console)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 AvmVersion (org.aion.avm.stub.AvmVersion)1 LogEnum (org.aion.log.LogEnum)1 LogLevel (org.aion.log.LogLevel)1 AionBlockchainImpl (org.aion.zero.impl.blockchain.AionBlockchainImpl)1 CfgAion (org.aion.zero.impl.config.CfgAion)1 CfgDb (org.aion.zero.impl.config.CfgDb)1 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)1 BeforeClass (org.junit.BeforeClass)1 Logger (org.slf4j.Logger)1 CommandLine (picocli.CommandLine)1 CommandSpec (picocli.CommandLine.Model.CommandSpec)1