Skip to content

Commit

Permalink
Clean-up of the exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed May 3, 2024
1 parent f3cf61e commit d5a36ec
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.math.BigInteger.ONE;
import static java.math.BigInteger.ZERO;

import java.io.IOException;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.LinkedList;
Expand Down Expand Up @@ -52,7 +51,6 @@
import io.hotmoka.stores.EngineClassLoader;
import io.hotmoka.stores.StoreException;
import io.hotmoka.stores.StoreTransaction;
import io.hotmoka.stores.UnsupportedVerificationVersionException;

/**
* Implementation of the creator of the response for a non-initial transaction. Non-initial transactions consume gas,
Expand Down Expand Up @@ -105,8 +103,13 @@ protected boolean transactionIsSigned() {
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
return storeTransaction.getClassLoader(request.getClasspath(), consensus);
protected EngineClassLoader mkClassLoader() throws NodeException, TransactionRejectedException {
try {
return storeTransaction.getClassLoader(request.getClasspath(), consensus);
}
catch (StoreException e) {
throw new NodeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public final void replaceReverifiedResponses() throws NoSuchElementException, Un
* @throws UnsupportedVerificationVersionException if the verification version is not available
* @throws IOException if there was an I/O error while accessing some jar
*/
protected abstract EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException ;
protected abstract EngineClassLoader mkClassLoader() throws NodeException, TransactionRejectedException;

/**
* Wraps the given throwable in a {@link io.hotmoka.node.api.TransactionException}, if it not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@

package io.hotmoka.node.local.internal.transactions;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.NoSuchElementException;
import java.util.stream.Stream;

import io.hotmoka.node.TransactionResponses;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.api.requests.GameteCreationTransactionRequest;
import io.hotmoka.node.api.responses.GameteCreationTransactionResponse;
import io.hotmoka.node.api.transactions.TransactionReference;
import io.hotmoka.node.local.AbstractInitialResponseBuilder;
import io.hotmoka.node.local.internal.AbstractLocalNodeImpl;
import io.hotmoka.stores.EngineClassLoader;
import io.hotmoka.stores.StoreException;
import io.hotmoka.stores.StoreTransaction;
import io.hotmoka.stores.UnsupportedVerificationVersionException;

/**
* The creator of a response for a transaction that creates a gamete.
Expand All @@ -52,8 +49,13 @@ public GameteCreationResponseBuilder(TransactionReference reference, GameteCreat
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
return storeTransaction.getClassLoader(request.getClasspath(), consensus);
protected EngineClassLoader mkClassLoader() throws NodeException {
try {
return storeTransaction.getClassLoader(request.getClasspath(), consensus);
}
catch (StoreException e) {
throw new NodeException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@

package io.hotmoka.node.local.internal.transactions;

import java.io.IOException;
import java.util.NoSuchElementException;

import io.hotmoka.node.TransactionResponses;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.api.requests.InitializationTransactionRequest;
import io.hotmoka.node.api.responses.InitializationTransactionResponse;
import io.hotmoka.node.api.transactions.TransactionReference;
import io.hotmoka.node.local.AbstractInitialResponseBuilder;
import io.hotmoka.node.local.internal.AbstractLocalNodeImpl;
import io.hotmoka.stores.EngineClassLoader;
import io.hotmoka.stores.StoreException;
import io.hotmoka.stores.StoreTransaction;
import io.hotmoka.stores.UnsupportedVerificationVersionException;

/**
* The creator of a response for a transaction that initializes a node.
Expand Down Expand Up @@ -62,7 +58,12 @@ protected InitializationTransactionResponse body() {
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
return storeTransaction.getClassLoader(request.getClasspath(), consensus); // currently not used for this transaction
protected EngineClassLoader mkClassLoader() throws NodeException {
try {
return storeTransaction.getClassLoader(request.getClasspath(), consensus); // currently not used for this transaction
}
catch (StoreException e) {
throw new NodeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@
package io.hotmoka.node.local.internal.transactions;

import java.io.IOException;
import java.util.NoSuchElementException;

import io.hotmoka.instrumentation.InstrumentedJars;
import io.hotmoka.node.TransactionResponses;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.api.requests.JarStoreInitialTransactionRequest;
import io.hotmoka.node.api.responses.JarStoreInitialTransactionResponse;
import io.hotmoka.node.api.transactions.TransactionReference;
import io.hotmoka.node.local.AbstractInitialResponseBuilder;
import io.hotmoka.node.local.internal.AbstractLocalNodeImpl;
import io.hotmoka.stores.EngineClassLoader;
import io.hotmoka.stores.EngineClassLoaderImpl;
import io.hotmoka.stores.StoreException;
import io.hotmoka.stores.StoreTransaction;
import io.hotmoka.stores.UnsupportedVerificationVersionException;
import io.hotmoka.verification.VerificationException;
Expand All @@ -54,10 +53,19 @@ public JarStoreInitialResponseBuilder(TransactionReference reference, JarStoreIn
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
protected EngineClassLoader mkClassLoader() throws NodeException, TransactionRejectedException {
// we redefine this method, since the class loader must be able to access the
// jar that is being installed and its dependencies, in order to instrument them
return new EngineClassLoaderImpl(request.getJar(), request.getDependencies(), storeTransaction, consensus);
try {
return new EngineClassLoaderImpl(request.getJar(), request.getDependencies(), storeTransaction, consensus);
}
catch (StoreException e) {
throw new NodeException(e);
}
catch (ClassNotFoundException e) {
// the request is trying to install a jar with inconsistent dependencies
throw new TransactionRejectedException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package io.hotmoka.node.local.internal.transactions;

import java.io.IOException;
import java.math.BigInteger;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
Expand All @@ -27,16 +25,15 @@
import io.hotmoka.node.TransactionResponses;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.api.requests.JarStoreTransactionRequest;
import io.hotmoka.node.api.responses.JarStoreTransactionResponse;
import io.hotmoka.node.api.transactions.TransactionReference;
import io.hotmoka.node.local.AbstractNonInitialResponseBuilder;
import io.hotmoka.node.local.internal.AbstractLocalNodeImpl;
import io.hotmoka.stores.EngineClassLoader;
import io.hotmoka.stores.EngineClassLoaderImpl;
import io.hotmoka.stores.StoreException;
import io.hotmoka.stores.StoreTransaction;
import io.hotmoka.stores.UnsupportedVerificationVersionException;
import io.hotmoka.verification.VerifiedJars;

/**
Expand All @@ -58,10 +55,19 @@ public JarStoreResponseBuilder(TransactionReference reference, JarStoreTransacti
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
protected EngineClassLoader mkClassLoader() throws NodeException, TransactionRejectedException {
// we redefine this method, since the class loader must be able to access the
// jar that is being installed and its dependencies, in order to instrument them
return new EngineClassLoaderImpl(request.getJar(), request.getDependencies(), storeTransaction, consensus);
try {
return new EngineClassLoaderImpl(request.getJar(), request.getDependencies(), storeTransaction, consensus);
}
catch (StoreException e) {
throw new NodeException(e);
}
catch (ClassNotFoundException e) {
// the request is trying to install a jar with inconsistent dependencies
throw new TransactionRejectedException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.hotmoka.stores;

import java.io.IOException;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.PublicKey;
Expand All @@ -39,8 +38,6 @@
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.exceptions.UncheckFunction;
import io.hotmoka.node.FieldSignatures;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.api.nodes.ConsensusConfig;
import io.hotmoka.node.api.requests.InitializationTransactionRequest;
import io.hotmoka.node.api.requests.SignedTransactionRequest;
Expand Down Expand Up @@ -256,13 +253,20 @@ public final boolean signatureIsValidUncommitted(SignedTransactionRequest<?> req
}

@Override
public final EngineClassLoader getClassLoader(TransactionReference classpath, ConsensusConfig<?,?> consensus) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
var classLoader = store.classLoaders.get(classpath);
if (classLoader != null)
return classLoader;
public final EngineClassLoader getClassLoader(TransactionReference classpath, ConsensusConfig<?,?> consensus) throws StoreException {
try {
var classLoader = store.classLoaders.get(classpath);
if (classLoader != null)
return classLoader;

var classLoader2 = new EngineClassLoaderImpl(null, Stream.of(classpath), this, consensus);
return store.classLoaders.computeIfAbsent(classpath, _classpath -> classLoader2);
var classLoader2 = new EngineClassLoaderImpl(null, Stream.of(classpath), this, consensus);
return store.classLoaders.computeIfAbsent(classpath, _classpath -> classLoader2);
}
catch (ClassNotFoundException e) {
// since the class loader is created from transactions that are already in the store,
// they should be consistent and never miss a dependent class
throw new StoreException(e);
}
}

private boolean verifiesSignatureUncommitted(SignatureAlgorithm signature, SignedTransactionRequest<?> request) throws StoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,10 @@ public final class EngineClassLoaderImpl implements EngineClassLoader {
* @param dependencies the dependencies
* @param node the node for which the class loader is created
* @param consensus the consensus parameters to use for reverification
* @throws ClassNotFoundException if some class of the Takamaka runtime cannot be loaded
* @throws UnsupportedVerificationVersionException if the verification version is not available
* @throws IOException if there was an I/O error while accessing some jar
* @throws NodeException
* @throws NoSuchElementException
* @throws ClassNotFoundException if some class of the dependencies cannot be found
* @throws StoreException
*/
public EngineClassLoaderImpl(byte[] jar, Stream<TransactionReference> dependencies, StoreTransaction<?> storeTransaction, ConsensusConfig<?,?> consensus) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
public EngineClassLoaderImpl(byte[] jar, Stream<TransactionReference> dependencies, StoreTransaction<?> storeTransaction, ConsensusConfig<?,?> consensus) throws StoreException, ClassNotFoundException {
try {
var dependenciesAsList = dependencies.collect(Collectors.toList());

Expand Down Expand Up @@ -210,11 +207,8 @@ public EngineClassLoaderImpl(byte[] jar, Stream<TransactionReference> dependenci
this.balanceField = contract.getDeclaredField("balance");
this.balanceField.setAccessible(true); // it was private
}
catch (IllegalArgumentException e) {
throw e;
}
catch (NoSuchMethodException | NoSuchFieldException e) {
throw new RuntimeException("unexpected class change", e);
throw new StoreException("Unexpected class change", e);
}
}

Expand Down
Loading

0 comments on commit d5a36ec

Please sign in to comment.