Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Add transaction solidifier #1805

Merged
merged 22 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
36 changes: 19 additions & 17 deletions src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.iota.iri.service.transactionpruning.DepthPruningCondition;
import com.iota.iri.service.transactionpruning.SizePruningCondition;
import com.iota.iri.service.transactionpruning.TransactionPruner;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.storage.*;
import com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider;
Expand Down Expand Up @@ -96,6 +97,8 @@ public class Iota {

public final MilestoneSolidifier milestoneSolidifier;

public final TransactionSolidifier transactionSolidifier;

public final BundleValidator bundleValidator;

public final Tangle tangle;
Expand All @@ -118,16 +121,16 @@ public class Iota {
*
*/
public Iota(IotaConfig configuration, SpentAddressesProvider spentAddressesProvider,
SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider,
SnapshotService snapshotService, LocalSnapshotManager localSnapshotManager,
MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker,
LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever,
LedgerService ledgerService, TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier,
BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator,
TransactionRequester transactionRequester, NeighborRouter neighborRouter,
TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester,
TipsViewModel tipsViewModel, TipSelector tipsSelector, LocalSnapshotsPersistenceProvider localSnapshotsDb,
CacheManager cacheManager) {
SpentAddressesService spentAddressesService, SnapshotProvider snapshotProvider,
SnapshotService snapshotService, LocalSnapshotManager localSnapshotManager,
MilestoneService milestoneService, LatestMilestoneTracker latestMilestoneTracker,
LatestSolidMilestoneTracker latestSolidMilestoneTracker, SeenMilestonesRetriever seenMilestonesRetriever,
LedgerService ledgerService, TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier,
BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator,
TransactionRequester transactionRequester, NeighborRouter neighborRouter,
TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester,
TipsViewModel tipsViewModel, TipSelector tipsSelector, LocalSnapshotsPersistenceProvider localSnapshotsDb,
CacheManager cacheManager, TransactionSolidifier transactionSolidifier) {
this.configuration = configuration;

this.ledgerService = ledgerService;
Expand All @@ -145,9 +148,9 @@ public Iota(IotaConfig configuration, SpentAddressesProvider spentAddressesProvi
this.neighborRouter = neighborRouter;
this.txPipeline = transactionProcessingPipeline;
this.tipsRequester = tipsRequester;
this.transactionSolidifier = transactionSolidifier;
this.localSnapshotsDb = localSnapshotsDb;


// legacy classes
this.bundleValidator = bundleValidator;
this.tangle = tangle;
Expand Down Expand Up @@ -200,8 +203,6 @@ public void init() throws Exception {
tangle.clearMetadata(com.iota.iri.model.persistables.Transaction.class);
}

transactionValidator.init();

txPipeline.start();
neighborRouter.start();
tipsRequester.start();
Expand All @@ -210,6 +211,7 @@ public void init() throws Exception {
latestSolidMilestoneTracker.start();
seenMilestonesRetriever.start();
milestoneSolidifier.start();
transactionSolidifier.start();

if (localSnapshotManager != null) {
localSnapshotManager.addSnapshotCondition(new SnapshotDepthCondition(configuration, snapshotProvider));
Expand Down Expand Up @@ -256,6 +258,7 @@ private void rescanDb() throws Exception {
public void shutdown() throws Exception {
// shutdown in reverse starting order (to not break any dependencies)
milestoneSolidifier.shutdown();
transactionSolidifier.shutdown();
seenMilestonesRetriever.shutdown();
latestSolidMilestoneTracker.shutdown();
latestMilestoneTracker.shutdown();
Expand All @@ -270,7 +273,6 @@ public void shutdown() throws Exception {
tipsRequester.shutdown();
txPipeline.shutdown();
neighborRouter.shutdown();
transactionValidator.shutdown();
localSnapshotsDb.shutdown();
tangle.shutdown();

Expand Down Expand Up @@ -314,10 +316,10 @@ private void initializeTangle() {
* @return A new Persistance provider
*/
private PersistenceProvider createRocksDbProvider(String path, String log, String configFile, int cacheSize,
Map<String, Class<? extends Persistable>> columnFamily,
Map.Entry<String, Class<? extends Persistable>> metadata) {
Map<String, Class<? extends Persistable>> columnFamily,
Map.Entry<String, Class<? extends Persistable>> metadata) {
return new RocksDBPersistenceProvider(
path, log, configFile, cacheSize, columnFamily, metadata);
}

}
}
54 changes: 31 additions & 23 deletions src/main/java/com/iota/iri/MainInjectionConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.iota.iri.service.tipselection.impl.*;
import com.iota.iri.service.transactionpruning.TransactionPruner;
import com.iota.iri.service.transactionpruning.async.AsyncTransactionPruner;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.service.validation.impl.TransactionSolidifierImpl;
import com.iota.iri.storage.LocalSnapshotsPersistenceProvider;
import com.iota.iri.storage.Tangle;
import com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider;
Expand Down Expand Up @@ -101,8 +103,8 @@ LatestMilestoneTracker provideLatestMilestoneTracker(Tangle tangle, SnapshotProv
@Singleton
@Provides
LatestSolidMilestoneTracker provideLatestSolidMilestoneTracker(Tangle tangle, SnapshotProvider snapshotProvider,
MilestoneService milestoneService, LedgerService ledgerService,
LatestMilestoneTracker latestMilestoneTracker, TransactionRequester transactionRequester) {
MilestoneService milestoneService, LedgerService ledgerService,
LatestMilestoneTracker latestMilestoneTracker, TransactionRequester transactionRequester) {
return new LatestSolidMilestoneTrackerImpl(tangle, snapshotProvider, milestoneService, ledgerService,
latestMilestoneTracker, transactionRequester, configuration);
}
Expand All @@ -115,8 +117,8 @@ SeenMilestonesRetriever provideSeenMilestonesRetriever(Tangle tangle, SnapshotPr

@Singleton
@Provides
MilestoneSolidifier provideMilestoneSolidifier(SnapshotProvider snapshotProvider, TransactionValidator transactionValidator) {
return new MilestoneSolidifierImpl(snapshotProvider, transactionValidator);
MilestoneSolidifier provideMilestoneSolidifier(SnapshotProvider snapshotProvider, TransactionSolidifier transactionSolidifier) {
return new MilestoneSolidifierImpl(snapshotProvider, transactionSolidifier);
}

@Singleton
Expand All @@ -137,8 +139,14 @@ LocalSnapshotManager provideLocalSnapshotManager(SnapshotProvider snapshotProvid

@Singleton
@Provides
TransactionValidator provideTransactionValidator(Tangle tangle, SnapshotProvider snapshotProvider, TipsViewModel tipsViewModel, TransactionRequester transactionRequester) {
return new TransactionValidator(tangle, snapshotProvider, tipsViewModel, transactionRequester, configuration);
TransactionValidator provideTransactionValidator(SnapshotProvider snapshotProvider, TransactionRequester transactionRequester) {
return new TransactionValidator(snapshotProvider, transactionRequester, configuration);
}

@Singleton
@Provides
TransactionSolidifier provideTransactionSolidifier(Tangle tangle, SnapshotProvider snapshotProvider, TransactionRequester transactionRequester, TipsViewModel tipsViewModel){
return new TransactionSolidifierImpl(tangle, snapshotProvider, transactionRequester, tipsViewModel);
}

@Singleton
Expand All @@ -163,21 +171,21 @@ TipSelector provideTipSelector(Tangle tangle, SnapshotProvider snapshotProvider,
@Singleton
@Provides
Iota provideIota(SpentAddressesProvider spentAddressesProvider, SpentAddressesService spentAddressesService,
SnapshotProvider snapshotProvider, SnapshotService snapshotService,
@Nullable LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService,
LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker,
SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService,
@Nullable TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier,
BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator,
TransactionRequester transactionRequester, NeighborRouter neighborRouter,
TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester,
TipsViewModel tipsViewModel, TipSelector tipsSelector, LocalSnapshotsPersistenceProvider localSnapshotsDb,
CacheManager cacheManager) {
SnapshotProvider snapshotProvider, SnapshotService snapshotService,
@Nullable LocalSnapshotManager localSnapshotManager, MilestoneService milestoneService,
LatestMilestoneTracker latestMilestoneTracker, LatestSolidMilestoneTracker latestSolidMilestoneTracker,
SeenMilestonesRetriever seenMilestonesRetriever, LedgerService ledgerService,
@Nullable TransactionPruner transactionPruner, MilestoneSolidifier milestoneSolidifier,
BundleValidator bundleValidator, Tangle tangle, TransactionValidator transactionValidator,
TransactionRequester transactionRequester, NeighborRouter neighborRouter,
TransactionProcessingPipeline transactionProcessingPipeline, TipsRequester tipsRequester,
TipsViewModel tipsViewModel, TipSelector tipsSelector, LocalSnapshotsPersistenceProvider localSnapshotsDb,
CacheManager cacheManager, TransactionSolidifier transactionSolidifier) {
return new Iota(configuration, spentAddressesProvider, spentAddressesService, snapshotProvider, snapshotService,
localSnapshotManager, milestoneService, latestMilestoneTracker, latestSolidMilestoneTracker,
seenMilestonesRetriever, ledgerService, transactionPruner, milestoneSolidifier, bundleValidator, tangle,
transactionValidator, transactionRequester, neighborRouter, transactionProcessingPipeline,
tipsRequester, tipsViewModel, tipsSelector, localSnapshotsDb, cacheManager);
tipsRequester, tipsViewModel, tipsSelector, localSnapshotsDb, cacheManager, transactionSolidifier);
}

@Singleton
Expand All @@ -189,11 +197,11 @@ IXI provideIxi(Iota iota) {
@Singleton
@Provides
API provideApi(IXI ixi, TransactionRequester transactionRequester,
SpentAddressesService spentAddressesService, Tangle tangle, BundleValidator bundleValidator,
SnapshotProvider snapshotProvider, LedgerService ledgerService, NeighborRouter neighborRouter, TipSelector tipsSelector,
TipsViewModel tipsViewModel, TransactionValidator transactionValidator,
LatestMilestoneTracker latestMilestoneTracker, TransactionProcessingPipeline txPipeline) {
return new API(configuration, ixi, transactionRequester, spentAddressesService, tangle, bundleValidator, snapshotProvider, ledgerService, neighborRouter, tipsSelector, tipsViewModel, transactionValidator, latestMilestoneTracker, txPipeline);
SpentAddressesService spentAddressesService, Tangle tangle, BundleValidator bundleValidator,
SnapshotProvider snapshotProvider, LedgerService ledgerService, NeighborRouter neighborRouter, TipSelector tipsSelector,
TipsViewModel tipsViewModel, TransactionValidator transactionValidator,
LatestMilestoneTracker latestMilestoneTracker, TransactionProcessingPipeline txPipeline, TransactionSolidifier transactionSolidifier) {
return new API(configuration, ixi, transactionRequester, spentAddressesService, tangle, bundleValidator, snapshotProvider, ledgerService, neighborRouter, tipsSelector, tipsViewModel, transactionValidator, latestMilestoneTracker, txPipeline, transactionSolidifier);
}

@Singleton
Expand All @@ -214,4 +222,4 @@ protected void configure() {
bind(BundleValidator.class).asEagerSingleton();
bind(TipsViewModel.class).asEagerSingleton();
}
}
}
22 changes: 0 additions & 22 deletions src/main/java/com/iota/iri/controllers/TransactionViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,28 +779,6 @@ public void setMetadata() {
: TransactionViewModel.FILLED_SLOT;
}

/**
* Update solid transactions
* @param tangle Tangle
* @param initialSnapshot Initial snapshot
* @param analyzedHashes analyzed hashes
* @throws Exception Exception
*/
public static void updateSolidTransactions(Tangle tangle, Snapshot initialSnapshot,
final Set<Hash> analyzedHashes) throws Exception {
Object[] hashes = analyzedHashes.toArray();
TransactionViewModel transactionViewModel;
for (int i = hashes.length - 1; i >= 0; i--) {
transactionViewModel = TransactionViewModel.fromHash(tangle, (Hash) hashes[i]);

transactionViewModel.updateHeights(tangle, initialSnapshot);

if (!transactionViewModel.isSolid()) {
transactionViewModel.updateSolid(true);
transactionViewModel.update(tangle, initialSnapshot, "solid|height");
}
}
}

/**
* Updates the {@link Transaction#solid} value of the referenced {@link Transaction} object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.conf.IotaConfig;
import com.iota.iri.controllers.TipsViewModel;
Expand Down Expand Up @@ -44,11 +45,11 @@ TipsRequester provideTipsRequester(NeighborRouter neighborRouter, Tangle tangle,
@Singleton
@Provides
TransactionProcessingPipeline provideTransactionProcessingPipeline(NeighborRouter neighborRouter,
TransactionValidator txValidator, Tangle tangle, SnapshotProvider snapshotProvider,
TipsViewModel tipsViewModel, LatestMilestoneTracker latestMilestoneTracker,
TransactionRequester transactionRequester) {
TransactionValidator txValidator, Tangle tangle, SnapshotProvider snapshotProvider,
TipsViewModel tipsViewModel, LatestMilestoneTracker latestMilestoneTracker,
TransactionRequester transactionRequester, TransactionSolidifier transactionSolidifier) {
return new TransactionProcessingPipelineImpl(neighborRouter, configuration, txValidator, tangle,
snapshotProvider, tipsViewModel, latestMilestoneTracker, transactionRequester);
snapshotProvider, tipsViewModel, latestMilestoneTracker, transactionRequester, transactionSolidifier);
}

@Singleton
Expand All @@ -57,4 +58,4 @@ NeighborRouter provideNeighborRouter(TransactionRequester transactionRequester,
return new NeighborRouterImpl(configuration, configuration, transactionRequester, transactionProcessingPipeline);
}

}
}
24 changes: 12 additions & 12 deletions src/main/java/com/iota/iri/network/pipeline/ReceivedStage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.iota.iri.network.pipeline;

import com.iota.iri.service.validation.TransactionValidator;
import com.iota.iri.service.validation.TransactionSolidifier;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.network.TransactionRequester;
import com.iota.iri.network.neighbor.Neighbor;
Expand All @@ -19,28 +19,28 @@ public class ReceivedStage implements Stage {

private Tangle tangle;
private TransactionRequester transactionRequester;
private TransactionValidator txValidator;
private TransactionSolidifier txSolidifier;
private SnapshotProvider snapshotProvider;

/**
* Creates a new {@link ReceivedStage}.
*
*
* @param tangle The {@link Tangle} database used to store/update the transaction
* @param txValidator The {@link TransactionValidator} used to store/update the transaction
* @param txSolidifier The {@link TransactionSolidifier} used to store/update the transaction
* @param snapshotProvider The {@link SnapshotProvider} used to store/update the transaction
*/
public ReceivedStage(Tangle tangle, TransactionValidator txValidator, SnapshotProvider snapshotProvider,
public ReceivedStage(Tangle tangle, TransactionSolidifier txSolidifier, SnapshotProvider snapshotProvider,
TransactionRequester transactionRequester) {
this.txValidator = txValidator;
this.txSolidifier = txSolidifier;
this.tangle = tangle;
this.snapshotProvider = snapshotProvider;
this.transactionRequester = transactionRequester;
}

/**
* Stores the given transaction in the database, updates it status
* ({@link TransactionValidator#updateStatus(TransactionViewModel)}) and updates the sender.
*
* ({@link TransactionSolidifier#updateStatus(TransactionViewModel)}) and updates the sender.
*
* @param ctx the received stage {@link ProcessingContext}
* @return a {@link ProcessingContext} which redirects to the {@link BroadcastStage}
*/
Expand All @@ -65,7 +65,7 @@ public ProcessingContext process(ProcessingContext ctx) {
if (stored) {
tvm.setArrivalTime(System.currentTimeMillis());
try {
txValidator.updateStatus(tvm);
txSolidifier.updateStatus(tvm);

// free up the recently requested transaction set
if(transactionRequester.removeRecentlyRequestedTransaction(tvm.getHash())){
Expand All @@ -91,8 +91,8 @@ public ProcessingContext process(ProcessingContext ctx) {
}

// broadcast the newly saved tx to the other neighbors
ctx.setNextStage(TransactionProcessingPipeline.Stage.BROADCAST);
ctx.setPayload(new BroadcastPayload(originNeighbor, tvm));
ctx.setNextStage(TransactionProcessingPipeline.Stage.SOLIDIFY);
ctx.setPayload(new SolidifyPayload(originNeighbor, tvm));
return ctx;
}
}
}
Loading