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
FieldsModifier and TypeFieldDescriptionprotected final NodeCachesThe caches of the node.protected final CThe configuration of the node.protected static final Loggerprotected final SThe store of the node.protected final StoreUtilitiesAn object that provides utility methods onstore. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractLocalNode(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
Modifier and TypeMethodDescriptionfinal StorageReferencefinal StorageReferencevoidfinal StorageValuefinal TransactionReferencefinal TransactionReferencefinal StorageValueprotected booleanadmitsAfterInitialization(InitialTransactionRequest<?> request) Determines if the given initial transaction can still be run after the initialization of the node.protected final voidcheckTransaction(TransactionRequest<?> request) Checks that the given transaction request is valid.voidclose()protected final TransactionResponsedeliverTransaction(TransactionRequest<?> request) Builds a response for the given request and adds it to the store of the node.final ClassTaggetClassTag(StorageReference reference) final StorageReferencefinal Stringfinal TransactionResponsegetPolledResponse(TransactionReference reference) final TransactionRequest<?>getRequest(TransactionReference reference) protected intgetRequestStorageCost(NonInitialTransactionRequest<?> request) Yields the base cost of the given transaction.final TransactionResponsegetResponse(TransactionReference reference) getState(StorageReference reference) final TransactionReferenceprotected voidClears the caches of this node.protected voidinvalidateCachesIfNeeded(TransactionResponse response, EngineClassLoader classLoader) Invalidates the caches, if needed, after the addition of the given response into store.protected final booleanDetermines if this node has not been closed yet.protected abstract SmkStore()Factory method for creating the store of this node.protected final voidnotifyEventsOf(TransactionResponseWithEvents response) Notifies all events contained in the given response.protected final TransactionReferencepost(TransactionRequest<?> request) Posts the given request.final Node.CodeSupplier<StorageValue>final Node.JarSupplierprotected abstract voidpostRequest(TransactionRequest<?> request) Node-specific implementation to post the given request.final Node.CodeSupplier<StorageValue>protected ResponseBuilder<?,?> responseBuilderFor(TransactionReference reference, TransactionRequest<?> request) Yields the builder of a response for a request of a transaction.protected final booleanrewardValidators(String behaving, String misbehaving) Rewards the validators with the cost of the gas consumed by the transactions in the last block.final StorageValuefinal StorageValueprotected abstract voidSchedules the events in the given response for notification to all their subscribers.protected final StringYields the error message trimmed to a maximal length, to avoid overflow.Methods inherited from class io.hotmoka.nodes.AbstractNode
constructorSupplierFor, jarSupplierFor, methodSupplierFor, notifyEvent, subscribeToEvents, wrapInCaseOfExceptionFull, wrapInCaseOfExceptionMedium, wrapInCaseOfExceptionSimpleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.hotmoka.nodes.Node
getNodeInfo
-
Field Details
-
logger
-
config
The configuration of the node. -
storeUtilities
An object that provides utility methods onstore. -
caches
The caches of the node. -
store
The store of the node.
-
-
Constructor Details
-
AbstractLocalNode
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- Throws:
IOException
-
AbstractLocalNode
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- Throws:
IOException
-
AbstractLocalNode
Builds a shallow clone of the given node.- Parameters:
parent- the node to clone
-
-
Method Details
-
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
-
close
- Throws:
Exception
-
getNameOfSignatureAlgorithmForRequests
-
getTakamakaCode
- Throws:
NoSuchElementException
-
getManifest
- 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
- Throws:
NoSuchElementException
-
getState
- 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
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
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
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) throws ClassNotFoundException 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- Throws:
ClassNotFoundException- if some class cannot be found in the Takamaka code
-
getRequestStorageCost
Yields the base cost of the given transaction. Normally, this is justrequest.size(), 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
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
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
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
-