Skip to content

Commit

Permalink
Clean-up of the API of Node.getRequest()
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Apr 17, 2024
1 parent 334e665 commit f81fa3e
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.verification.api.TakamakaClassLoader;

/**
Expand All @@ -48,5 +49,5 @@ public interface ClassLoaderHelper {
* @throws TimeoutException if no answer arrives before a time window
* @throws InterruptedException if the current thread is interrupted while waiting for an answer to arrive
*/
TakamakaClassLoader classloaderFor(TransactionReference jar) throws TransactionRejectedException, TransactionException, CodeExecutionException, ClassNotFoundException, NodeException, TimeoutException, InterruptedException, NoSuchElementException;
TakamakaClassLoader classloaderFor(TransactionReference jar) throws TransactionRejectedException, TransactionException, CodeExecutionException, ClassNotFoundException, NodeException, TimeoutException, InterruptedException, NoSuchElementException, UnknownReferenceException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public String getConsensusConfig() throws NodeException, TimeoutException, Inter
}

@Override
public TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException, TimeoutException, InterruptedException {
public TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException, TimeoutException, InterruptedException {
return parent.getRequest(reference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeoutException;

import io.hotmoka.beans.MethodSignatures;
Expand All @@ -34,6 +33,7 @@
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.verification.TakamakaClassLoaders;
import io.hotmoka.verification.api.TakamakaClassLoader;

Expand Down Expand Up @@ -68,7 +68,7 @@ public ClassLoaderHelperImpl(Node node) throws TransactionRejectedException, Tra
}

@Override
public TakamakaClassLoader classloaderFor(TransactionReference jar) throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, NoSuchElementException, NodeException, TimeoutException, InterruptedException {
public TakamakaClassLoader classloaderFor(TransactionReference jar) throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, NodeException, TimeoutException, InterruptedException, UnknownReferenceException {
var ws = new ArrayList<TransactionReference>();
var seen = new HashSet<TransactionReference>();
var jars = new ArrayList<byte[]>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public String getConsensusConfig() throws NodeException, TimeoutException, Inter
}

@Override
public TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException, TimeoutException, InterruptedException {
public TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException, TimeoutException, InterruptedException {
return parent.getRequest(reference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public String getConsensusConfig() throws NodeException, TimeoutException, Inter
}

@Override
public TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException, TimeoutException, InterruptedException {
public TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException, TimeoutException, InterruptedException {
return parent.getRequest(reference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -34,6 +33,7 @@
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.verification.api.TakamakaClassLoader;
import io.hotmoka.whitelisting.api.WhiteListingWizard;
import io.takamaka.code.constants.Constants;
Expand All @@ -42,7 +42,7 @@ class PrintAPI {
private final Class<?> clazz;
private final WhiteListingWizard whiteListingWizard;

PrintAPI(Node node, ClassTag tag) throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, NoSuchElementException, NodeException, TimeoutException, InterruptedException {
PrintAPI(Node node, ClassTag tag) throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, NodeException, TimeoutException, InterruptedException, UnknownReferenceException {
TakamakaClassLoader classloader = ClassLoaderHelpers.of(node).classloaderFor(tag.getJar());
this.clazz = classloader.loadClass(tag.getClazz().getName());
this.whiteListingWizard = classloader.getWhiteListingWizard();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.hotmoka.moka.internal;

import java.net.URI;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

Expand All @@ -33,6 +32,7 @@
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.remote.RemoteNodes;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
Expand Down Expand Up @@ -77,7 +77,7 @@ private Run() throws Exception {
}
}

private void printAPI() throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, NoSuchElementException, NodeException, TimeoutException, InterruptedException {
private void printAPI() throws ClassNotFoundException, TransactionRejectedException, TransactionException, CodeExecutionException, UnknownReferenceException, NodeException, TimeoutException, InterruptedException {
System.out.println();
if (api)
new PrintAPI(node, tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ public interface Node extends AutoCloseable, OnCloseHandlersContainer {
*
* @param reference the reference of the transaction
* @return the request
* @throws NoSuchElementException if there is no request with that reference
* @throws UnknownReferenceException if {@code reference} cannot be found in this node
* @throws NodeException if the node is not able to perform the operation
* @throws TimeoutException if no answer arrives before a time window
* @throws InterruptedException if the current thread is interrupted while waiting for an answer to arrive
*/
TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException, TimeoutException, InterruptedException; // throw UnknownReferenceException
TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException, TimeoutException, InterruptedException;

/**
* Yields the response generated for the request for the given transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Objects;

import io.hotmoka.beans.api.transactions.TransactionReference;
import io.hotmoka.beans.api.values.StorageReference;

/**
Expand All @@ -42,6 +43,15 @@ public UnknownReferenceException(StorageReference reference) {
super("Unknown reference " + reference);
}

/**
* Creates a new exception.
*
* @param reference the reference that cannot be found
*/
public UnknownReferenceException(TransactionReference reference) {
super("Unknown reference " + reference);
}

/**
* Creates a new exception with the given message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.hotmoka.crypto.api.SignatureAlgorithm;
import io.hotmoka.node.api.ConsensusConfig;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.UnknownReferenceException;

/**
* The cache of a local node.
Expand Down Expand Up @@ -95,7 +96,7 @@ public interface NodeCache {
* @throws UnsupportedVerificationVersionException if the verification version is not supported
* @throws IOException if there was an I/O error while accessing some jar
*/
EngineClassLoader getClassLoader(TransactionReference classpath) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, NodeException;
EngineClassLoader getClassLoader(TransactionReference classpath) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException;

/**
* Checks that the given request is signed with the private key of its caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.hotmoka.beans.api.responses.TransactionResponse;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;

/**
* The creator of a response from a request. It executes a transaction from the request and builds the corresponding response.
Expand Down Expand Up @@ -50,7 +51,7 @@ public interface ResponseBuilder<Request extends TransactionRequest<Response>, R
/**
* Replaces all reverified responses into the store of the node for which the response is built.
*/
void replaceReverifiedResponses() throws NoSuchElementException, NodeException;
void replaceReverifiedResponses() throws NoSuchElementException, UnknownReferenceException, NodeException;

/**
* Yields the class loader used to build the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public final TransactionResponse getPolledResponse(TransactionReference referenc
getRequest(reference);
return response;
}
catch (NoSuchElementException e) {
catch (NoSuchElementException | UnknownReferenceException e) {
Thread.sleep(delay);
}

Expand All @@ -430,20 +430,17 @@ public final TransactionResponse getPolledResponse(TransactionReference referenc
}

@Override
public final TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException {
public final TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException {
try (var scope = mkScope()) {
Objects.requireNonNull(reference);
Optional<TransactionRequest<?>> request;

try {
request = caches.getRequest(reference);
return caches.getRequest(reference).orElseThrow(() -> new UnknownReferenceException(reference));
}
catch (RuntimeException e) {
LOGGER.log(Level.WARNING, "unexpected exception", e);
throw e;
}

return request.orElseThrow(() -> new NoSuchElementException("unknown transaction reference " + reference));
}
}

Expand Down Expand Up @@ -687,7 +684,7 @@ protected final TransactionResponse deliverTransaction(TransactionRequest<?> req
LOGGER.log(Level.INFO, "transaction rejected", e);
throw e;
}
catch (IOException | ClassNotFoundException | NodeException e) {
catch (IOException | ClassNotFoundException | NodeException | UnknownReferenceException e) {
store.push(reference, request, trimmedMessage(e));
LOGGER.log(Level.SEVERE, reference + ": delivering failed with unexpected exception", e);
throw new RuntimeException(e);
Expand Down Expand Up @@ -1137,7 +1134,7 @@ public StoreUtility getStoreUtilities() {
}

@Override
public TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException {
public TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException {
return AbstractLocalNodeImpl.this.getRequest(reference);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import io.hotmoka.instrumentation.InstrumentationFields;
import io.hotmoka.node.api.ConsensusConfig;
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.local.api.EngineClassLoader;
import io.hotmoka.node.local.api.UnsupportedVerificationVersionException;
import io.hotmoka.verification.TakamakaClassLoaders;
Expand Down Expand Up @@ -167,7 +168,7 @@ public final class EngineClassLoaderImpl implements EngineClassLoader {
* @throws NodeException
* @throws NoSuchElementException
*/
public EngineClassLoaderImpl(byte[] jar, Stream<TransactionReference> dependencies, NodeInternal node, boolean reverify, ConsensusConfig<?,?> consensus) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, NodeException {
public EngineClassLoaderImpl(byte[] jar, Stream<TransactionReference> dependencies, NodeInternal node, boolean reverify, ConsensusConfig<?,?> consensus) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
try {
List<TransactionReference> dependenciesAsList = dependencies.collect(Collectors.toList());

Expand Down Expand Up @@ -662,7 +663,7 @@ public final void redPayableFromContract(Object callee, Object caller, long amou
* @throws NodeException
* @throws NoSuchElementException
*/
public void replaceReverifiedResponses() throws NoSuchElementException, NodeException {
public void replaceReverifiedResponses() throws NoSuchElementException, UnknownReferenceException, NodeException {
reverification.replace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.hotmoka.node.api.NodeException;
import io.hotmoka.node.api.TransactionException;
import io.hotmoka.node.api.TransactionRejectedException;
import io.hotmoka.node.api.UnknownReferenceException;
import io.hotmoka.node.local.AbstractLocalNode;
import io.hotmoka.node.local.api.EngineClassLoader;
import io.hotmoka.node.local.api.NodeCache;
Expand Down Expand Up @@ -320,7 +321,7 @@ public final Optional<TransactionResponse> getResponseUncommitted(TransactionRef
}

@Override
public final EngineClassLoader getClassLoader(TransactionReference classpath) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, NodeException {
public final EngineClassLoader getClassLoader(TransactionReference classpath) throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
var classLoader = classLoaders.get(classpath);
if (classLoader != null)
return classLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public interface NodeInternal {
*
* @param reference the reference of the transaction
* @return the request
* @throws NoSuchElementException if there is no request with that reference
* @throws UnknownReferenceException if {@code reference} cannot be found in the node
*/
TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException, NodeException;
TransactionRequest<?> getRequest(TransactionReference reference) throws UnknownReferenceException, NodeException;

/**
* Yields the response generated for the request for the given transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected boolean transactionIsSigned() {
}

@Override
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, NodeException {
protected EngineClassLoader mkClassLoader() throws ClassNotFoundException, UnsupportedVerificationVersionException, IOException, NoSuchElementException, UnknownReferenceException, NodeException {
return node.getCaches().getClassLoader(request.getClasspath());
}

Expand Down
Loading

0 comments on commit f81fa3e

Please sign in to comment.