Skip to content

Commit

Permalink
enhancement: refactored the VM specs and introduced default transacti…
Browse files Browse the repository at this point in the history
…on type

 - using the local version of the vm_api since more changes are expected
  • Loading branch information
AlexandraRoatis committed Mar 19, 2019
1 parent 97253c2 commit 7c4d198
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 82 deletions.
2 changes: 1 addition & 1 deletion aion_fastvm
2 changes: 1 addition & 1 deletion aion_vm_api
10 changes: 5 additions & 5 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.aion.evtmgr.impl.evt.EventBlock;
import org.aion.interfaces.db.Repository;
import org.aion.interfaces.db.RepositoryCache;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.log.AionLoggerFactory;
import org.aion.log.LogEnum;
import org.aion.mcf.core.ImportResult;
Expand All @@ -47,7 +46,6 @@
import org.aion.mcf.valid.BlockHeaderValidator;
import org.aion.mcf.valid.GrandParentBlockHeaderValidator;
import org.aion.mcf.valid.ParentBlockHeaderValidator;
import org.aion.mcf.valid.TransactionTypeRule;
import org.aion.mcf.vm.types.Bloom;
import org.aion.rlp.RLP;
import org.aion.types.Address;
Expand Down Expand Up @@ -75,7 +73,9 @@
import org.aion.zero.impl.types.AionTxInfo;
import org.aion.zero.impl.types.RetValidPreBlock;
import org.aion.zero.impl.valid.TXValidator;
import org.aion.mcf.valid.TransactionTypeRule;
import org.aion.zero.impl.valid.TransactionTypeValidator;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.types.A0BlockHeader;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxExecSummary;
Expand Down Expand Up @@ -919,9 +919,9 @@ public AionBlockSummary add(AionBlock block, boolean rebuild) {
repository.saveIndexedContractInformation(
tx.getContractAddress(),
block.getNumber(),
TransactionTypeRule.isValidAVMTransactionType(tx.getTargetVM())
? VirtualMachineSpecs.AVM_CREATE_CODE
: VirtualMachineSpecs.FVM_CREATE_CODE,
TransactionTypeRule.isValidAVMContractDeployment(tx.getTargetVM())
? TransactionTypes.AVM_CREATE_CODE
: TransactionTypes.FVM_CREATE_CODE,
true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.aion.interfaces.db.Repository;
import org.aion.interfaces.db.RepositoryCache;
import org.aion.interfaces.db.RepositoryConfig;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.mcf.core.AccountState;
import org.aion.mcf.db.AbstractRepository;
import org.aion.mcf.db.ContractDetailsCacheImpl;
Expand All @@ -38,6 +37,7 @@
import org.aion.zero.impl.sync.DatabaseType;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionTxInfo;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.types.A0BlockHeader;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxReceipt;
Expand Down Expand Up @@ -930,7 +930,7 @@ public byte getVMUsed(Address contract) {
ContractInformation ci = getIndexedContractInformation(contract);
if (ci == null) {
// defaults to FastVM for backwards compatibility
return VirtualMachineSpecs.FVM_CREATE_CODE;
return TransactionTypes.FVM_CREATE_CODE;
} else {
return ci.getVmUsed();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.aion.zero.impl.valid;

// import static org.aion.mcf.valid.TransactionTypeRule.isValidAVMTransactionType;
// import static org.aion.mcf.valid.TransactionTypeRule.isValidFVMTransactionType;
import static org.aion.mcf.valid.TransactionTypeRule.isValidTransactionType;

/**
* Validator for the type field of transactions allowed by the network. The transaction types
Expand All @@ -21,11 +20,10 @@ public static void enableAvmCheck(boolean enableAVM) {
}

public static boolean isValid(byte type) {
/* TODO: re-enable when the fork point is established
// the type must be either valid for the FVM
// or for the AVM when the AVM is enabled
return isValidFVMTransactionType(type) || (avmEnabled && isValidAVMTransactionType(type));
*/
return true;
}

public static boolean isValidAfterFork(byte type) {
return isValidTransactionType(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import org.aion.crypto.ECKey;
import org.aion.crypto.HashUtil;
import org.aion.interfaces.db.Repository;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.mcf.core.ImportResult;
import org.aion.types.Address;
import org.aion.util.bytes.ByteUtil;
import org.aion.zero.impl.blockchain.ChainConfiguration;
import org.aion.zero.impl.db.ContractInformation;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxReceipt;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -260,7 +260,7 @@ public void testDeployCryptoKitties() {
.getIndexedContractInformation(contractDeploymentTx.getContractAddress());
assertThat(ci).isNotNull();
assertThat(ci.getInceptionBlock()).isEqualTo(block.getNumber());
assertThat(ci.getVmUsed()).isEqualTo(VirtualMachineSpecs.FVM_CREATE_CODE);
assertThat(ci.getVmUsed()).isEqualTo(TransactionTypes.FVM_CREATE_CODE);
assertThat(ci.isComplete()).isEqualTo(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
import org.aion.avm.api.ABIEncoder;
import org.aion.avm.core.dappreading.JarBuilder;
import org.aion.avm.core.util.CodeAndArguments;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.types.Address;
import org.aion.crypto.ECKey;
import org.aion.crypto.ECKeyFac;
import org.aion.mcf.core.ImportResult;
import org.aion.types.Address;
import org.aion.vm.VirtualMachineProvider;

import org.aion.zero.impl.StandaloneBlockchain;
import org.aion.zero.impl.vm.contracts.Statefulness;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.impl.vm.contracts.Statefulness;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxExecSummary;
import org.apache.commons.lang3.RandomUtils;
Expand Down Expand Up @@ -216,7 +215,7 @@ private AionTransaction makeAvmContractCreateTransaction(ECKey sender, BigIntege
jar,
5_000_000,
this.energyPrice,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
transaction.sign(this.deployerKey);
return transaction;
}
Expand All @@ -232,7 +231,7 @@ private AionTransaction makeAvmContractCallTransaction(
abiEncodeMethodCall("incrementCounter"),
2_000_000,
this.energyPrice,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
transaction.sign(this.deployerKey);
return transaction;
}
Expand Down Expand Up @@ -268,7 +267,7 @@ private int getDeployedStatefulnessCountValue(
abiEncodeMethodCall("getCount"),
2_000_000,
this.energyPrice,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
transaction.sign(sender);

AionBlockSummary summary =
Expand Down
4 changes: 2 additions & 2 deletions modAionImpl/test/org/aion/zero/impl/vm/AvmHelloWorldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.aion.avm.core.util.CodeAndArguments;
import org.aion.crypto.AddressSpecs;
import org.aion.crypto.ECKey;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.mcf.core.ImportResult;
import org.aion.types.Address;
import org.aion.vm.VirtualMachineProvider;
import org.aion.zero.impl.StandaloneBlockchain;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.impl.vm.contracts.AvmHelloWorld;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxReceipt;
Expand Down Expand Up @@ -162,6 +162,6 @@ private AionTransaction newTransaction(
data,
energyLimit,
1,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
}
}
6 changes: 3 additions & 3 deletions modAionImpl/test/org/aion/zero/impl/vm/StatefulnessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import org.aion.avm.core.util.CodeAndArguments;
import org.aion.crypto.AddressSpecs;
import org.aion.crypto.ECKey;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.mcf.core.ImportResult;
import org.aion.types.Address;
import org.aion.vm.VirtualMachineProvider;
import org.aion.zero.impl.StandaloneBlockchain;
import org.aion.zero.impl.types.AionBlock;
import org.aion.zero.impl.types.AionBlockSummary;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.zero.impl.vm.contracts.Statefulness;
import org.aion.zero.types.AionTransaction;
import org.aion.zero.types.AionTxReceipt;
Expand Down Expand Up @@ -180,7 +180,7 @@ private AionTxReceipt deployContract() {
jar,
5_000_000,
this.energyPrice,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
transaction.sign(this.deployerKey);

return sendTransactions(transaction);
Expand All @@ -196,7 +196,7 @@ private AionTxReceipt callContract(Address contract, String method, Object... ar
abiEncodeMethodCall(method, arguments),
2_000_000,
this.energyPrice,
VirtualMachineSpecs.AVM_CREATE_CODE);
TransactionTypes.AVM_CREATE_CODE);
transaction.sign(this.deployerKey);

return sendTransactions(transaction);
Expand Down
2 changes: 1 addition & 1 deletion modApiServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceSets {
}

dependencies {
compile 'network.aion:vm-api4j:0.4.0'
compile project(':aion_vm_api')
compile 'network.aion:util4j:0.4.0'
compile 'network.aion:log4j:0.4.0'
compile 'network.aion:crypto4j:0.4.0'
Expand Down
12 changes: 2 additions & 10 deletions modApiServer/src/org/aion/api/server/types/ArgTxCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import java.math.BigInteger;

import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.types.Address;
import org.aion.log.AionLoggerFactory;
import org.aion.log.LogEnum;
import org.aion.util.bytes.ByteUtil;
import org.aion.util.string.StringUtils;
import org.aion.mcf.tx.TransactionTypes;
import org.json.JSONObject;
import org.slf4j.Logger;

Expand Down Expand Up @@ -39,15 +39,7 @@ public ArgTxCall(
final BigInteger _value,
final long _nrg,
final long _nrgPrice) {
this(
_from,
_to,
_data,
_nonce,
_value,
_nrg,
_nrgPrice,
VirtualMachineSpecs.FVM_DEFAULT_TX_TYPE);
this(_from, _to, _data, _nonce, _value, _nrg, _nrgPrice, TransactionTypes.DEFAULT);
}

public ArgTxCall(
Expand Down
8 changes: 5 additions & 3 deletions modApiServer/test/org/aion/api/server/TxRecptLgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import org.aion.crypto.ECKey;
import org.aion.crypto.HashUtil;
import org.aion.mcf.core.ImportResult;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.solidity.CompilationResult;
import org.aion.solidity.Compiler;

import org.aion.types.Address;
import org.aion.util.bytes.ByteUtil;
import org.aion.vm.api.interfaces.IExecutionLog;
Expand Down Expand Up @@ -70,7 +70,8 @@ public void TestTxRecptLg() throws InterruptedException, IOException {
new byte[0],
ByteUtil.hexStringToBytes(contractA),
1_000_000L,
1L);
1L,
TransactionTypes.FVM_CREATE_CODE);
tx1.sign(deployerAccount);

nonce = nonce.add(BigInteger.ONE);
Expand All @@ -81,7 +82,8 @@ public void TestTxRecptLg() throws InterruptedException, IOException {
new byte[0],
ByteUtil.hexStringToBytes(contractB),
1_000_000L,
1L);
1L,
TransactionTypes.FVM_CREATE_CODE);
tx2.sign(deployerAccount);

BlockContext context =
Expand Down
2 changes: 1 addition & 1 deletion modBoot/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext.moduleName = 'aion.boot'

dependencies {
compile 'network.aion:vm-api4j:0.4.0'
compile project(':aion_vm_api')
compile 'network.aion:util4j:0.4.0'
compile 'network.aion:log4j:0.4.0'
compile 'network.aion:crypto4j:0.4.0'
Expand Down
2 changes: 1 addition & 1 deletion modDbImpl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceSets {
}

dependencies {
compile 'network.aion:vm-api4j:0.4.0'
compile project(':aion_vm_api')
compile 'network.aion:util4j:0.4.0'
compile 'network.aion:log4j:0.4.0'

Expand Down
19 changes: 19 additions & 0 deletions modMcf/src/org/aion/mcf/tx/TransactionTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.aion.mcf.tx;

import java.util.Set;

/** Transaction type values supported by the kernel implementation. */
public class TransactionTypes {
public static final byte DEFAULT = 0x00;
public static final byte FVM_CREATE_CODE = 0x01;
public static final byte AVM_CREATE_CODE = 0x0f;

/** Set of transaction types allowed by any of the Virtual Machine implementations. */
public static final Set<Byte> ALL = Set.of(DEFAULT, FVM_CREATE_CODE, AVM_CREATE_CODE);

/** Set of transaction types allowed by the Fast Virtual Machine implementation. */
public static final Set<Byte> FVM = Set.of(DEFAULT, FVM_CREATE_CODE);

/** Set of transaction types allowed by the Aion Virtual Machine implementation. */
public static final Set<Byte> AVM = Set.of(DEFAULT, AVM_CREATE_CODE);
}
4 changes: 2 additions & 2 deletions modMcf/src/org/aion/mcf/types/AbstractTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.math.BigInteger;
import org.aion.crypto.ISignature;
import org.aion.interfaces.tx.Transaction;
import org.aion.interfaces.vm.VirtualMachineSpecs;
import org.aion.log.AionLoggerFactory;
import org.aion.log.LogEnum;
import org.aion.mcf.tx.TransactionTypes;
import org.aion.types.Address;
import org.slf4j.Logger;

Expand Down Expand Up @@ -55,7 +55,7 @@ public AbstractTransaction(byte[] nonce, Address receiveAddress, byte[] value, b
this.value = value;
this.data = data;
// default type 0x01; reserve date for multi-type transaction
this.type = VirtualMachineSpecs.FVM_CREATE_CODE;
this.type = TransactionTypes.DEFAULT;
}

public AbstractTransaction(
Expand Down
Loading

0 comments on commit 7c4d198

Please sign in to comment.