Module io.hotmoka.local
Package io.hotmoka.local
Class AbstractLocalNode<C extends Config,S extends AbstractStore<C>>
- java.lang.Object
-
- io.hotmoka.nodes.AbstractNode
-
- io.hotmoka.local.AbstractLocalNode<C,S>
-
- All Implemented Interfaces:
Node,AutoCloseable
public abstract class AbstractLocalNode<C extends Config,S extends AbstractStore<C>> extends AbstractNode
A generic implementation of a local (ie., non-remote) node. Specific implementations can subclass this and implement the abstract template methods.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.hotmoka.nodes.Node
Node.CodeSupplier<V extends StorageValue>, Node.JarSupplier, Node.Subscription
-
-
Field Summary
Fields Modifier and Type Field Description protected NodeCachescachesThe caches of the node.protected CconfigThe configuration of the node.protected static org.slf4j.Loggerloggerprotected SstoreThe store of the node.protected StoreUtilitiesstoreUtilitiesAn object that provides utility methods onstore.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLocalNode(C config)Builds a node, recycling a previous existing store.protectedAbstractLocalNode(C config, ConsensusParams consensus)Builds a node with a brand new, empty store.protectedAbstractLocalNode(AbstractLocalNode<C,S> parent)Builds a shallow clone of the given node.
-
Method Summary
-
Methods inherited from class io.hotmoka.nodes.AbstractNode
constructorSupplierFor, jarSupplierFor, methodSupplierFor, notifyEvent, subscribeToEvents, wrapInCaseOfExceptionFull, wrapInCaseOfExceptionMedium, wrapInCaseOfExceptionSimple
-
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
storeUtilities
protected final StoreUtilities storeUtilities
An object that provides utility methods onstore.
-
caches
protected final NodeCaches caches
The caches of the node.
-
store
protected final S extends AbstractStore<C> store
The store of the node.
-
-
Constructor Detail
-
AbstractLocalNode
protected AbstractLocalNode(C config, ConsensusParams consensus)
Builds a node with a brand new, empty store.- Parameters:
config- the configuration of the nodeconsensus- the consensus parameters at the beginning of the life of the node
-
AbstractLocalNode
protected AbstractLocalNode(C config)
Builds a node, recycling a previous existing store. The store must be that of an already initialized node, whose consensus parameters are recovered from its manifest.- Parameters:
config- the configuration of the node
-
AbstractLocalNode
protected AbstractLocalNode(AbstractLocalNode<C,S> parent)
Builds a shallow clone of the given node.- Parameters:
parent- the node to clone
-
-
Method Detail
-
mkStore
protected abstract S mkStore()
Factory method for creating the store of this node.- Returns:
- the store
-
isNotYetClosed
protected final boolean isNotYetClosed()
Determines if this node has not been closed yet. This thread-safe method can be called to avoid double-closing of a node.- Returns:
- true if and only if the node has not been closed yet
-
getNameOfSignatureAlgorithmForRequests
public final String getNameOfSignatureAlgorithmForRequests()
-
getTakamakaCode
public final TransactionReference getTakamakaCode() throws NoSuchElementException
- Throws:
NoSuchElementException
-
getManifest
public final StorageReference getManifest() throws NoSuchElementException
- Throws:
NoSuchElementException
-
getPolledResponse
public final TransactionResponse getPolledResponse(TransactionReference reference) throws TransactionRejectedException, TimeoutException, InterruptedException
-
getRequest
public final TransactionRequest<?> getRequest(TransactionReference reference) throws NoSuchElementException
- Throws:
NoSuchElementException
-
getResponse
public final TransactionResponse getResponse(TransactionReference reference) throws TransactionRejectedException, NoSuchElementException
-
getClassTag
public final ClassTag getClassTag(StorageReference reference) throws NoSuchElementException
- Throws:
NoSuchElementException
-
getState
public final Stream<Update> getState(StorageReference reference) throws NoSuchElementException
- Throws:
NoSuchElementException
-
addJarStoreInitialTransaction
public final TransactionReference addJarStoreInitialTransaction(JarStoreInitialTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
addInitializationTransaction
public void addInitializationTransaction(InitializationTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
addGameteCreationTransaction
public final StorageReference addGameteCreationTransaction(GameteCreationTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
addJarStoreTransaction
public final TransactionReference addJarStoreTransaction(JarStoreTransactionRequest request) throws TransactionRejectedException, TransactionException
-
addConstructorCallTransaction
public final StorageReference addConstructorCallTransaction(ConstructorCallTransactionRequest request) throws TransactionRejectedException, TransactionException, CodeExecutionException
-
addInstanceMethodCallTransaction
public final StorageValue addInstanceMethodCallTransaction(InstanceMethodCallTransactionRequest request) throws TransactionRejectedException, TransactionException, CodeExecutionException
-
addStaticMethodCallTransaction
public final StorageValue addStaticMethodCallTransaction(StaticMethodCallTransactionRequest request) throws TransactionRejectedException, TransactionException, CodeExecutionException
-
runInstanceMethodCallTransaction
public final StorageValue runInstanceMethodCallTransaction(InstanceMethodCallTransactionRequest request) throws TransactionRejectedException, TransactionException, CodeExecutionException
-
runStaticMethodCallTransaction
public final StorageValue runStaticMethodCallTransaction(StaticMethodCallTransactionRequest request) throws TransactionRejectedException, TransactionException, CodeExecutionException
-
postJarStoreTransaction
public final Node.JarSupplier postJarStoreTransaction(JarStoreTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
postConstructorCallTransaction
public final Node.CodeSupplier<StorageReference> postConstructorCallTransaction(ConstructorCallTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
postInstanceMethodCallTransaction
public final Node.CodeSupplier<StorageValue> postInstanceMethodCallTransaction(InstanceMethodCallTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
postStaticMethodCallTransaction
public final Node.CodeSupplier<StorageValue> postStaticMethodCallTransaction(StaticMethodCallTransactionRequest request) throws TransactionRejectedException
- Throws:
TransactionRejectedException
-
checkTransaction
protected final void checkTransaction(TransactionRequest<?> request) throws TransactionRejectedException
Checks that the given transaction request is valid.- Parameters:
request- the request- Throws:
TransactionRejectedException- if the request is not valid
-
deliverTransaction
protected final TransactionResponse deliverTransaction(TransactionRequest<?> request) throws TransactionRejectedException
Builds a response for the given request and adds it to the store of the node.- Parameters:
request- the request- Returns:
- the response; if this node has a notion of commit, this response is typically still uncommitted
- Throws:
TransactionRejectedException- if the response cannot be built
-
rewardValidators
protected final boolean rewardValidators(String behaving, String misbehaving)
Rewards the validators with the cost of the gas consumed by the transactions in the last block. This is meaningful only if the node has some form of commit.- Parameters:
behaving- the space-separated sequence of identifiers of the validators that behaved correctly during the creation of the last blockmisbehaving- the space-separated sequence of the identifiers that misbehaved during the creation of the last block- Returns:
- true if and only if rewarding was performed; rewarding might not be performed because the manifest is not yet installed or because the code of the validators contract failed
-
trimmedMessage
protected final String trimmedMessage(Throwable t)
Yields the error message trimmed to a maximal length, to avoid overflow.- Parameters:
t- the throwable whose error message is processed- Returns:
- the resulting message
-
notifyEventsOf
protected final void notifyEventsOf(TransactionResponseWithEvents response)
Notifies all events contained in the given response.- Parameters:
response- the response that contains the events
-
post
protected final TransactionReference post(TransactionRequest<?> request) throws TransactionRejectedException
Posts the given request. It does some preliminary preparation then callspostRequest(TransactionRequest), that will implement the node-specific logic of this post.- Parameters:
request- the request- Returns:
- the reference of the request
- Throws:
TransactionRejectedException- if the request was already present in the store
-
invalidateCaches
protected void invalidateCaches()
Clears the caches of this node.
-
invalidateCachesIfNeeded
protected void invalidateCachesIfNeeded(TransactionResponse response, EngineClassLoader classLoader)
Invalidates the caches, if needed, after the addition of the given response into store.- Parameters:
response- the storeclassLoader- the class loader of the transaction that computedresponse
-
getRequestStorageCost
protected BigInteger getRequestStorageCost(NonInitialTransactionRequest<?> request)
Yields the base cost of the given transaction. Normally, this is justrequest.size(gasCostModel), but subclasses might redefine.- Parameters:
request- the request of the transaction- Returns:
- the base cost of the transaction
-
responseBuilderFor
protected ResponseBuilder<?,?> responseBuilderFor(TransactionReference reference, TransactionRequest<?> request) throws TransactionRejectedException
Yields the builder of a response for a request of a transaction. This method can be redefined in subclasses in order to accomodate new kinds of transactions, specific to a node.- Parameters:
reference- the reference to the transaction that is building the responserequest- the request- Returns:
- the builder
- Throws:
TransactionRejectedException- if the builder cannot be created
-
admitsAfterInitialization
protected boolean admitsAfterInitialization(InitialTransactionRequest<?> request)
Determines if the given initial transaction can still be run after the initialization of the node. Normally, this is false. However, specific implementations of the node might redefine and allow it.- Parameters:
request- the request- Returns:
- true if only if the execution of
requestis allowed also after the initialization of this node
-
postRequest
protected abstract void postRequest(TransactionRequest<?> request)
Node-specific implementation to post the given request. Each node should implement this, for instance by adding the request to some mempool or queue of requests to be executed.- Parameters:
request- the request
-
scheduleForNotificationOfEvents
protected abstract void scheduleForNotificationOfEvents(TransactionResponseWithEvents response)
Schedules the events in the given response for notification to all their subscribers. This might callnotifyEventsOf(TransactionResponseWithEvents)immediately or might delay its call to the next commit, if there is a notion of commit. In this way, one can guarantee that events are notified only when they have been committed.- Parameters:
response- the response that contains events
-
-