From 1a79fb6987feae8a601001376b879a21585e7273 Mon Sep 17 00:00:00 2001 From: Alexandra Roatis Date: Tue, 9 Apr 2019 11:22:13 -0400 Subject: [PATCH] bug fix: removing the dirty setting cause a break in consensus for contracts deployed without code or storage --- .../src/org/aion/zero/impl/db/AionRepositoryCache.java | 6 +++++- .../src/org/aion/zero/impl/db/AionRepositoryImpl.java | 5 ++++- .../src/org/aion/zero/impl/db/ContractDetailsCacheImpl.java | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryCache.java b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryCache.java index 5a17ef1d27..110aa2c49c 100644 --- a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryCache.java +++ b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryCache.java @@ -20,6 +20,7 @@ import org.aion.log.LogEnum; import org.aion.mcf.core.AccountState; import org.aion.mcf.db.IBlockStoreBase; +import org.aion.mcf.tx.TransactionTypes; import org.aion.types.Address; import org.aion.types.ByteArrayWrapper; import org.slf4j.Logger; @@ -61,6 +62,7 @@ public AccountState createAccount(Address address) { // TODO: unify contract details initialization from Impl and Track ContractDetails contractDetails = new ContractDetailsCacheImpl(null); + contractDetails.setDirty(true); cachedDetails.put(address, contractDetails); return accountState; @@ -482,7 +484,9 @@ public void flushCopiesTo(Repository other, boolean clearStateAfterFlush) { ContractDetails ctd = entry.getValue().copy(); // TODO: this functionality will be improved with the switch to a // different ContractDetails implementation - if (ctd != null && ctd instanceof ContractDetailsCacheImpl) { + if (ctd != null + && ctd instanceof ContractDetailsCacheImpl + && ctd.getVmType() != TransactionTypes.DEFAULT) { ContractDetailsCacheImpl contractDetailsCache = (ContractDetailsCacheImpl) ctd; contractDetailsCache.commit(); diff --git a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java index 0d801e122e..93b2517ef6 100644 --- a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java @@ -29,6 +29,7 @@ import org.aion.mcf.trie.TrieNodeResult; import org.aion.mcf.tx.TransactionTypes; import org.aion.p2p.V1Constants; +import org.aion.precompiled.ContractFactory; import org.aion.types.Address; import org.aion.types.ByteArrayWrapper; import org.aion.util.conversions.Hex; @@ -136,7 +137,9 @@ public void updateBatch( } } else { - if (!contractDetails.isDirty()) { + if (!contractDetails.isDirty() + || (contractDetails.getVmType() == TransactionTypes.DEFAULT + && !ContractFactory.isPrecompiledContract(address))) { // code added because contract details are not reliably // marked as dirty at present // TODO: issue above will be solved with the conversion to a diff --git a/modAionImpl/src/org/aion/zero/impl/db/ContractDetailsCacheImpl.java b/modAionImpl/src/org/aion/zero/impl/db/ContractDetailsCacheImpl.java index 61e49a1654..6822692824 100644 --- a/modAionImpl/src/org/aion/zero/impl/db/ContractDetailsCacheImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/db/ContractDetailsCacheImpl.java @@ -102,9 +102,11 @@ public ByteArrayWrapper get(ByteArrayWrapper key) { } public void setVmType(byte vmType) { - this.vmType = vmType; + if (this.vmType != vmType) { + this.vmType = vmType; - setDirty(true); + setDirty(true); + } } public byte getVmType() {