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

Remove use of AbstractRepository #1130

Merged
merged 14 commits into from
Mar 12, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,7 @@ public synchronized boolean recoverWorldState(Repository repository, Block block

// Load bestblock for executing the CLI command.
if (bestBlock == null) {
bestBlock = repo.getBlockStore().getBestBlock();
bestBlock = repo.getBestBlock();

if (bestBlock instanceof AionBlock) {
bestMiningBlock = (AionBlock) bestBlock;
Expand Down Expand Up @@ -2518,7 +2518,7 @@ public void load(AionGenesis genesis, Logger genLOG) {
}

// Note: if block DB corruption, the bestBlock may not match with the indexDB.
Block bestBlock = repository.getBlockStore().getBestBlock();
Block bestBlock = repository.getBestBlock();

boolean recovered = true;
boolean bestBlockShifted = true;
Expand Down Expand Up @@ -2574,7 +2574,7 @@ public void load(AionGenesis genesis, Logger genLOG) {
repository.getBlockStore().rollback(blockNumber);

// new best block after recovery
bestBlock = repository.getBlockStore().getBestBlock();
bestBlock = repository.getBestBlock();
if (bestBlock != null) {

bestBlock.setTotalDifficulty(getTotalDifficultyForHash(bestBlock.getHash()));
Expand Down
379 changes: 0 additions & 379 deletions modAionImpl/src/org/aion/zero/impl/db/AbstractRepository.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,6 @@ public void updateBatch(
}
}

@Override
public boolean isClosed() {
// delegate to the tracked repository
return repository.isClosed();
}

@Override
public void close() {
throw new UnsupportedOperationException(
Expand Down
283 changes: 271 additions & 12 deletions modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modAionImpl/src/org/aion/zero/impl/db/DBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public static Status queryAccount(AionAddress address) {
AionBlockchainImpl blockchain = new AionBlockchainImpl(cfg, null, false);

try {
Block bestBlock = blockchain.getRepository().getBlockStore().getBestBlock();
Block bestBlock = blockchain.getRepository().getBestBlock();

Repository<AccountState> repository =
blockchain
Expand Down
17 changes: 4 additions & 13 deletions modAionImpl/src/org/aion/zero/impl/db/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.aion.db.impl.DatabaseFactory;
import org.aion.db.impl.DatabaseFactory.Props;
import org.aion.db.impl.PersistenceMethod;
import org.aion.mcf.db.exception.InvalidFilePathException;
import org.aion.mcf.db.exception.InvalidFileTypeException;
import org.slf4j.Logger;

Expand All @@ -37,14 +36,6 @@ public static ByteArrayKeyValueDatabase connectAndOpen(Properties info, Logger L
info.getProperty(Props.DB_NAME));
}

// check persistence status
if (!db.isCreatedOnDisk() && db.getPersistenceMethod() != PersistenceMethod.DBMS) {
LOG.error(
"Database <{}> cannot be saved to disk for <{}>.",
info.getProperty(Props.DB_TYPE),
info.getProperty(Props.DB_NAME));
}

return db;
}

Expand All @@ -53,18 +44,18 @@ public static ByteArrayKeyValueDatabase connectAndOpen(Properties info, Logger L
* are missing in the path.
*
* @param dbFile the path to be verified.
* @throws InvalidFilePathException when:
* @throws IllegalArgumentException when:
* <ol>
* <li>the given path is not valid;
* <li>the directory structure cannot be created;
* <li>the path cannot be written to;
* <li>the give file is not a directory
* </ol>
*/
public static void verifyAndBuildPath(File dbFile) throws InvalidFilePathException {
public static void verifyAndBuildPath(File dbFile) {
// to throw in case of issues with the path
InvalidFilePathException exception =
new InvalidFilePathException(
IllegalArgumentException exception =
new IllegalArgumentException(
"The path «"
+ dbFile.getAbsolutePath()
+ "» is not valid as reported by the OS or a read/write permissions error occurred."
Expand Down
13 changes: 6 additions & 7 deletions modAionImpl/src/org/aion/zero/impl/db/PendingBlockStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.aion.log.AionLoggerFactory;
import org.aion.log.LogEnum;
import org.aion.mcf.blockchain.Block;
import org.aion.mcf.db.exception.InvalidFilePathException;
import org.aion.mcf.db.exception.InvalidFileTypeException;
import org.aion.rlp.RLP;
import org.aion.rlp.RLPElement;
Expand Down Expand Up @@ -92,11 +91,11 @@ public class PendingBlockStore implements Closeable {
* if persistence is requested but not achievable.
*
* @param _props properties of the databases to be used for storage
* @throws InvalidFilePathException when given a persistent database vendor for which the data
* @throws IllegalStateException when given a persistent database vendor for which the data
* store cannot be created or opened.
*/
public PendingBlockStore(final Properties _props)
throws InvalidFilePathException, IOException, InvalidFileTypeException {
throws IOException, InvalidFileTypeException {
Properties local = new Properties(_props);

// check for database persistence requirements
Expand All @@ -121,10 +120,10 @@ public PendingBlockStore(final Properties _props)
* Initializes and opens the databases where the pending blocks will be stored.
*
* @param props the database properties to be used in initializing the underlying databases
* @throws InvalidFilePathException when any of the required databases cannot be instantiated or
* @throws IllegalStateException when any of the required databases cannot be instantiated or
* opened.
*/
private void init(Properties props) throws InvalidFilePathException {
private void init(Properties props) {
// create the level source
props.setProperty(Props.DB_NAME, LEVEL_DB_NAME);
this.levelDatabase = connectAndOpen(props, LOG);
Expand All @@ -149,8 +148,8 @@ private void init(Properties props) throws InvalidFilePathException {
}
}

private InvalidFilePathException newException(String dbName, Properties props) {
return new InvalidFilePathException(
private IllegalStateException newException(String dbName, Properties props) {
return new IllegalStateException(
"The «"
+ dbName
+ "» database from the pending block store could not be initialized with the given parameters: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testTransactionTypeBeforeTheFork() {
assertThat(TransactionTypeValidator.isValid(transaction)).isTrue();

// Process the transaction.
Block parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
Block parentBlock = this.blockchain.getRepository().getBestBlock();
AionBlock block =
this.blockchain.createNewMiningBlock(
parentBlock, Collections.singletonList(transaction), true);
Expand Down Expand Up @@ -150,7 +150,7 @@ public void testTransactionTypeAfterTheFork() {
assertThat(TransactionTypeValidator.isValid(transaction)).isFalse();

// Process the transaction.
Block parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
Block parentBlock = this.blockchain.getRepository().getBestBlock();
AionBlock block =
this.blockchain.createNewMiningBlock(
parentBlock, Collections.singletonList(transaction), true);
Expand All @@ -177,7 +177,7 @@ public void testTransactionTypeAfterTheFork() {
assertThat(TransactionTypeValidator.isValid(transaction)).isFalse();

// Process the transaction.
parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
parentBlock = this.blockchain.getRepository().getBestBlock();
block =
this.blockchain.createNewMiningBlock(
parentBlock, Collections.singletonList(transaction), true);
Expand All @@ -203,7 +203,7 @@ public void testTransactionTypeAfterTheFork() {
assertThat(TransactionTypeValidator.isValid(transaction)).isTrue();

// Process the transaction.
parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
parentBlock = this.blockchain.getRepository().getBestBlock();
block =
this.blockchain.createNewMiningBlock(
parentBlock, Collections.singletonList(transaction), true);
Expand Down Expand Up @@ -339,7 +339,7 @@ private List<AionAddress> produceRecipients() {

private Pair<ImportResult, AionBlockSummary> processTransactions(
List<AionTransaction> transactions, int numNonRejectedTransactions) {
Block parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
Block parentBlock = this.blockchain.getRepository().getBestBlock();
AionBlock block = this.blockchain.createNewMiningBlock(parentBlock, transactions, false);
Pair<ImportResult, AionBlockSummary> results =
this.blockchain.tryToConnectAndFetchSummary(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void testConsensus() {
assertEquals(CONTRACT, TxUtil.calculateContractAddress(deployTransaction));

// Place the transaction in a block alone.
Block parentBlock = blockchain.getRepository().blockStore.getBestBlock();
Block parentBlock = blockchain.getRepository().getBestBlock();
List<AionTransaction> transactions = Collections.singletonList(deployTransaction);

// Run the transaction.
Expand All @@ -222,7 +222,7 @@ public void testConsensus() {
byte[] receiptPostTransactionState = receipt.getPostTxState();
byte[] receiptTrieEncoded = receipt.getReceiptTrieEncoded();

parentBlock = blockchain.getRepository().blockStore.getBestBlock();
parentBlock = blockchain.getRepository().getBestBlock();

// Place the transactions all in a block.
transactions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ private static AionTransaction makeCallPayableFunctionTx(

private Pair<ImportResult, AionBlockSummary> processTransaction(
AionTransaction transaction, int numNonRejectedTransactions) {
Block parentBlock = this.blockchain.getRepository().blockStore.getBestBlock();
Block parentBlock = this.blockchain.getRepository().getBestBlock();
List<AionTransaction> transactions = Collections.singletonList(transaction);
AionBlock block = this.blockchain.createNewMiningBlock(parentBlock, transactions, false);
Pair<ImportResult, AionBlockSummary> results =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public void testAccountStateUpdateStorageRowFlush() {
repository.flush();

/** Verify that the account has been flushed */
byte[] root = repository.getAccountState(defaultAccount).getStateRoot();
StoredContractDetails snapshot = repository.detailsDS.getSnapshot(InternalVmType.FVM, defaultAccount.toByteArray(), root);
StoredContractDetails snapshot = repository.getContractDetails(defaultAccount);

assertThat(snapshot instanceof FvmContractDetails).isTrue();

Expand Down
25 changes: 12 additions & 13 deletions modAionImpl/test/org/aion/zero/impl/db/PendingBlockStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.aion.log.LogEnum;
import org.aion.log.LogLevel;
import org.aion.mcf.blockchain.Block;
import org.aion.mcf.db.exception.InvalidFilePathException;
import org.aion.mcf.db.exception.InvalidFileTypeException;
import org.aion.util.TestResources;
import org.aion.util.types.ByteArrayWrapper;
Expand All @@ -41,7 +40,7 @@ public void testConstructor_wMockDB() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -72,7 +71,7 @@ public void testConstructor_wPersistentDB() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand All @@ -99,7 +98,7 @@ public void testConstructor_wPersistentDB() {
// check persistence of storage
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand All @@ -121,7 +120,7 @@ public void testAddBlockRange() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -195,7 +194,7 @@ public void testAddBlockRange_wException() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand All @@ -217,7 +216,7 @@ public void testLoadBlockRange() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -267,7 +266,7 @@ public void testLoadBlockRange_wException() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand All @@ -286,7 +285,7 @@ public void testDropPendingQueues() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -327,7 +326,7 @@ public void testDropPendingQueues_wException() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -366,7 +365,7 @@ public void testDropPendingQueues_wSingleQueue() {
PendingBlockStore pb = null;
try {
pb = new PendingBlockStore(props);
} catch (InvalidFilePathException | IOException | InvalidFileTypeException e) {
} catch (IOException | InvalidFileTypeException e) {
e.printStackTrace();
}
assertThat(pb.isOpen()).isTrue();
Expand Down Expand Up @@ -403,7 +402,7 @@ public void testDropPendingQueues_wSingleQueue() {

@Test(expected = InvalidFileTypeException.class)
public void testSwitchDbVendorleveldbToRocksdbException()
throws InvalidFileTypeException, IOException, InvalidFilePathException {
throws InvalidFileTypeException, IOException {

File dir = new File(System.getProperty("user.dir"), "tmp-" + System.currentTimeMillis());
Properties levelDB = new Properties();
Expand Down Expand Up @@ -441,7 +440,7 @@ public void testSwitchDbVendorleveldbToRocksdbException()

@Test(expected = InvalidFileTypeException.class)
public void testSwitchDbVendorRocksdbToLeveldbException()
throws InvalidFileTypeException, IOException, InvalidFilePathException {
throws InvalidFileTypeException, IOException {

File dir = new File(System.getProperty("user.dir"), "tmp-" + System.currentTimeMillis());
Properties rocksDB = new Properties();
Expand Down
5 changes: 2 additions & 3 deletions modDbImpl/src/org/aion/db/impl/DatabaseFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,14 @@ private static AbstractDB connectBasic(Properties info, Logger log) {

if (dbType == DBVendor.MOCKDB) {
// MockDB does not require name and path checks
log.warn("WARNING: Active vendor is set to MockDB, data will not persist!");
log.warn("WARNING: Active vendor for <{}> is set to MockDB, data will not persist!", dbName);
return new MockDB(dbName, log);
}

String dbPath = info.getProperty(Props.DB_PATH);

if (dbType == DBVendor.PERSISTENTMOCKDB) {
log.warn(
"WARNING: Active vendor is set to PersistentMockDB, data will be saved only at close!");
log.warn("WARNING: Active vendor for <{}> is set to PersistentMockDB, data will be saved only at close!", dbName);
return new PersistentMockDB(dbName, dbPath, log);
}

Expand Down
7 changes: 0 additions & 7 deletions modMcf/src/org/aion/mcf/db/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ void updateBatch(
/** Reverts all the changes performed by this repository. */
void rollback();

/**
* Checks if the current repository has an open connection to the database.
*
* @return {@code true} if the database connection is open, {@code false} otherwise
*/
boolean isClosed();

/** Closes the connection to the database. */
void close();

Expand Down
23 changes: 0 additions & 23 deletions modMcf/src/org/aion/mcf/db/exception/InvalidFilePathException.java

This file was deleted.