Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable AVM inside BulkExecuter based on given config #826

Merged
merged 1 commit into from Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Expand Up @@ -220,6 +220,7 @@ protected AionBlockchainImpl(
*/
this.chainConfiguration = chainConfig;
TransactionTypeValidator.enableAvmCheck(config.isAvmEnabled());
BulkExecutor.enabledAvmCheck(config.isAvmEnabled());

this.grandParentBlockHeaderValidator =
this.chainConfiguration.createGrandParentHeaderValidator();
Expand Down
32 changes: 24 additions & 8 deletions modVM/src/org/aion/vm/BulkExecutor.java
Expand Up @@ -55,6 +55,12 @@
public class BulkExecutor {
private static final Object LOCK = new Object();

private static boolean avmEnabled = false;

public static void enabledAvmCheck(boolean isEnabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of this means of passing the value. It puts the burden of knowing how to use an internal detail on the caller, when the bulk executor can grab this answer itself internally without any assistance from the config. A detail like this will eventually leak into unit tests, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point of view, but the caller should be in charge of directing behavior here. If every class queries the config when it chooses there is more potential for errors (especially when you consider that the config is malleable and something like the GUI may choose to edit it) than if one entity directs overall behavior. The tests should be written to consider both AVM enabled and disabled.

avmEnabled = isEnabled;
}

private IRepository repository;
private IRepositoryCache<AccountState, IBlockStoreBase<?, ?>> repositoryChild;
private PostExecutionWork postExecutionWork;
Expand Down Expand Up @@ -394,11 +400,16 @@ private ExecutionBatch fetchNextBatchOfTransactionsForAionVirtualMachine(int sta
* future.
*/
private boolean transactionIsForFastVirtualMachine(AionTransaction transaction) {
if (transaction.isContractCreationTransaction()) {
return transaction.getTargetVM() != VirtualMachineSpecs.AVM_CREATE_CODE;
// first verify that the AVM is enabled
if (avmEnabled) {
if (transaction.isContractCreationTransaction()) {
return transaction.getTargetVM() != VirtualMachineSpecs.AVM_CREATE_CODE;
} else {
return transaction.getDestinationAddress().toBytes()[0]
!= NodeEnvironment.CONTRACT_PREFIX;
}
} else {
return transaction.getDestinationAddress().toBytes()[0]
!= NodeEnvironment.CONTRACT_PREFIX;
return true;
}
}

Expand All @@ -409,11 +420,16 @@ private boolean transactionIsForFastVirtualMachine(AionTransaction transaction)
* the destination is an AVM contract address
*/
private boolean transactionIsForAionVirtualMachine(AionTransaction transaction) {
if (transaction.isContractCreationTransaction()) {
return transaction.getTargetVM() == VirtualMachineSpecs.AVM_CREATE_CODE;
// first verify that the AVM is enabled
if (avmEnabled) {
if (transaction.isContractCreationTransaction()) {
return transaction.getTargetVM() == VirtualMachineSpecs.AVM_CREATE_CODE;
} else {
return transaction.getDestinationAddress().toBytes()[0]
== NodeEnvironment.CONTRACT_PREFIX;
}
} else {
return transaction.getDestinationAddress().toBytes()[0]
== NodeEnvironment.CONTRACT_PREFIX;
return false;
}
}
}