Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 77fbd58

Browse files
authored
Merge pull request #223 from oliverfn/dev
1.0.5-of
2 parents 62ac391 + 9cd8dc8 commit 77fbd58

14 files changed

Lines changed: 28 additions & 95 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.0.5
22
- Fixed `getBalance`: `RoundViewModel.get()` returns null on `index`=0, thus NPE was thrown when `references` were not passed and the first round hadn't been completed. In our implementation the snapshot is already constructed based on relative confirmations, thus it suffices for `getBalances` to respond with balance according to `latestSnapshot`.
3+
- Updated `previousEpochsSpentAddresses` resource files
34

45
## 1.0.4
56
- Fixed several zmq publish statements in which an incorrect format was specified.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Pendulum is a quorum based [Tangle](https://github.com/iotaledger/iri/) implementation designed towards reliable timekeeping and high-throughput messaging.
88

9-
- **Latest release:** 1.0.4 pre-release
9+
- **Latest release:** 1.0.5 pre-release
1010
- **License:** GPLv3
1111

1212
Special thanks to all of the [IOTA Contributors](https://github.com/iotaledger/iri/graphs/contributors)!

src/main/java/net/helix/pendulum/Pendulum.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,12 @@ public Pendulum(PendulumConfig configuration) throws TransactionPruningException
138138
? new LocalSnapshotManagerImpl()
139139
: null;
140140
milestoneService = new MilestoneServiceImpl();
141-
//validatorService = new ValidatorServiceImpl();
142141
validatorManagerService = new ValidatorManagerServiceImpl();
143142
latestMilestoneTracker = new MilestoneTrackerImpl();
144143
candidateTracker = new CandidateTrackerImpl();
145144
latestSolidMilestoneTracker = new LatestSolidMilestoneTrackerImpl();
146145
seenMilestonesRetriever = new SeenMilestonesRetrieverImpl();
147146
milestoneSolidifier = new MilestoneSolidifierImpl();
148-
//validatorSolidifier = new ValidatorSolidifierImpl();
149147
candidateSolidifier = new CandidateSolidifierImpl();
150148
transactionPruner = configuration.getLocalSnapshotsEnabled() && configuration.getLocalSnapshotsPruningEnabled()
151149
? new AsyncTransactionPruner()
@@ -219,7 +217,6 @@ public void init() throws Exception {
219217
}
220218
}
221219

222-
//TODO: bundleValidator should be passed to: milestoneService, spentAddressService and ledgerService.
223220
private void injectDependencies() throws SnapshotException, TransactionPruningException, SpentAddressesException {
224221
//snapshot provider must be initialized first
225222
//because we check whether spent addresses data exists
@@ -238,7 +235,6 @@ private void injectDependencies() throws SnapshotException, TransactionPruningEx
238235
latestMilestoneTracker);
239236
seenMilestonesRetriever.init(tangle, snapshotProvider, transactionRequester);
240237
milestoneSolidifier.init(snapshotProvider, transactionValidator);
241-
//validatorSolidifier.init(snapshotProvider, transactionValidator);
242238
candidateSolidifier.init(snapshotProvider, transactionValidator);
243239
ledgerService.init(tangle, snapshotProvider, snapshotService, milestoneService, configuration);
244240
if (transactionPruner != null) {

src/main/java/net/helix/pendulum/conf/BasePendulumConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ public interface Defaults {
10401040

10411041
//Snapshot
10421042
boolean LOCAL_SNAPSHOTS_ENABLED = true;
1043-
boolean LOCAL_SNAPSHOTS_PRUNING_ENABLED = true;
1043+
boolean LOCAL_SNAPSHOTS_PRUNING_ENABLED = false;
10441044
int LOCAL_SNAPSHOTS_PRUNING_DELAY = 50000;
10451045
int LOCAL_SNAPSHOTS_INTERVAL_SYNCED = 10;
10461046
int LOCAL_SNAPSHOTS_INTERVAL_UNSYNCED = 1000;

src/main/java/net/helix/pendulum/controllers/RoundViewModel.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,6 @@ public static Set<Hash> getMilestoneTrunk(Tangle tangle, TransactionViewModel tr
269269
// idx = 0 - (n-1): merkle root in branch, trunk is normal tx hash
270270
trunk.add(transaction.getTrunkTransactionHash());
271271
}
272-
if (log.isTraceEnabled()) {
273-
log.trace("trunk: {}", PendulumUtils.logHashList(trunk, 8));
274-
}
275272
return trunk;
276273
}
277274

@@ -310,9 +307,6 @@ public static Set<Hash> getMilestoneBranch(Tangle tangle, TransactionViewModel t
310307
}
311308
}
312309
}
313-
if (log.isTraceEnabled()) {
314-
log.trace("Milestone branch: {}", PendulumUtils.logHashList(branch, 8));
315-
}
316310
return branch;
317311
}
318312

src/main/java/net/helix/pendulum/service/milestone/impl/LatestSolidMilestoneTrackerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ public void trackLatestSolidMilestones() throws MilestoneException {
145145
try {
146146
int currentSolidRoundIndex = snapshotProvider.getLatestSnapshot().getIndex();
147147
RoundViewModel nextRound;
148+
if (currentSolidRoundIndex < milestoneTracker.getCurrentRoundIndex()) {
149+
log.delegate().trace("Current Solid Round = " + currentSolidRoundIndex + ", Current Round = " + milestoneTracker.getCurrentRoundIndex() + ", Still in Round = " + (currentSolidRoundIndex == milestoneTracker.getCurrentRoundIndex() - 1) + ", Round active = " + milestoneTracker.isRoundActive(RoundIndexUtil.getCurrentTime()));
150+
}
148151
while (!Thread.currentThread().isInterrupted() && (currentSolidRoundIndex < milestoneTracker.getCurrentRoundIndex())
149152
&& (currentSolidRoundIndex != milestoneTracker.getCurrentRoundIndex() - 1 || !milestoneTracker.isRoundActive(RoundIndexUtil.getCurrentTime()))) {
150153

@@ -154,6 +157,7 @@ public void trackLatestSolidMilestones() throws MilestoneException {
154157
// round has finished without milestones
155158
RoundViewModel latest = RoundViewModel.latest(tangle);
156159
if (latest != null && latest.index() > currentSolidRoundIndex + 1 && isRoundSolid(latest)) {
160+
log.delegate().trace("Round #" + (currentSolidRoundIndex + 1) + " has finished without milestones");
157161
nextRound = new RoundViewModel(currentSolidRoundIndex + 1, new HashSet<>());
158162
nextRound.store(tangle);
159163
tracer.trace("created and stored empty round: {}", nextRound.index());
@@ -164,6 +168,7 @@ public void trackLatestSolidMilestones() throws MilestoneException {
164168
break;
165169
}
166170
}
171+
log.delegate().trace("Round = " + nextRound.index() + ", solid = " + isRoundSolid(nextRound));
167172
if (isRoundSolid(nextRound)) {
168173
tracer.trace("solid round: {}", nextRound.toString());
169174
// TODO: Ask Oliver about these classes?
@@ -173,6 +178,7 @@ public void trackLatestSolidMilestones() throws MilestoneException {
173178
logChange(currentSolidRoundIndex);
174179
currentSolidRoundIndex = snapshotProvider.getLatestSnapshot().getIndex();
175180
tangle.publish("ctx %s %d", nextRound.getReferencedTransactions(tangle, nextRound.getConfirmedTips(tangle, BasePendulumConfig.Defaults.VALIDATOR_SECURITY)), nextRound.index());
181+
log.delegate().trace("ctx= " + nextRound.getReferencedTransactions(tangle, nextRound.getConfirmedTips(tangle, BasePendulumConfig.Defaults.VALIDATOR_SECURITY)) + ", round=" + nextRound.index());
176182
}
177183
}
178184
} catch (Exception e) {

src/main/java/net/helix/pendulum/service/snapshot/impl/SnapshotProviderImpl.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import net.helix.pendulum.model.Hash;
66
import net.helix.pendulum.model.HashFactory;
77
import net.helix.pendulum.service.snapshot.*;
8-
import net.helix.pendulum.service.spentaddresses.SpentAddressesException;
9-
import net.helix.pendulum.service.spentaddresses.SpentAddressesProvider;
108
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
1210

@@ -101,7 +99,7 @@ public class SnapshotProviderImpl implements SnapshotProvider {
10199
* @return the initialized instance itself to allow chaining
102100
*
103101
*/
104-
public SnapshotProviderImpl init(SnapshotConfig config) throws SnapshotException, SpentAddressesException {
102+
public SnapshotProviderImpl init(SnapshotConfig config) throws SnapshotException {
105103
this.config = config;
106104
File pathToLocalSnapshotDir = Paths.get(this.config.getLocalSnapshotsBasePath()).toFile();
107105
if (!pathToLocalSnapshotDir.exists() || !pathToLocalSnapshotDir.isDirectory()) {
@@ -201,7 +199,7 @@ public void shutdown() {
201199
*
202200
* @throws SnapshotException if anything goes wrong while loading the snapshots
203201
*/
204-
private void loadSnapshots() throws SnapshotException, SpentAddressesException {
202+
private void loadSnapshots() throws SnapshotException {
205203
initialSnapshot = loadLocalSnapshot();
206204
if (initialSnapshot == null) {
207205
initialSnapshot = loadBuiltInSnapshot();
@@ -220,7 +218,7 @@ private void loadSnapshots() throws SnapshotException, SpentAddressesException {
220218
* @return local snapshot of the node
221219
* @throws SnapshotException if local snapshot files exist but are malformed
222220
*/
223-
private Snapshot loadLocalSnapshot() throws SnapshotException, SpentAddressesException {
221+
private Snapshot loadLocalSnapshot() throws SnapshotException {
224222
if (config.getLocalSnapshotsEnabled()) {
225223
String fileSeperator = System.getProperty("file.separator");
226224
File localSnapshotFile = new File(
@@ -231,8 +229,6 @@ private Snapshot loadLocalSnapshot() throws SnapshotException, SpentAddressesExc
231229
);
232230
if (localSnapshotFile.exists() && localSnapshotFile.isFile() && localSnapshotMetaDataFile.exists() &&
233231
localSnapshotMetaDataFile.isFile()) {
234-
//TODO: enable this for mainnet-1.0. This will cause issues on a testnet where value transfers might not be guaranteed during a local snapshot und thus would always be thrown.
235-
//assertSpentAddressesDbExist();
236232
SnapshotState snapshotState = readSnapshotStatefromFile(localSnapshotFile.getAbsolutePath());
237233
if (!snapshotState.hasCorrectSupply()) {
238234
throw new SnapshotException("the snapshot state file has an invalid supply");
@@ -245,25 +241,9 @@ private Snapshot loadLocalSnapshot() throws SnapshotException, SpentAddressesExc
245241
return new SnapshotImpl(snapshotState, snapshotMetaData);
246242
}
247243
}
248-
249244
return null;
250245
}
251246

252-
private void assertSpentAddressesDbExist() throws SpentAddressesException {
253-
try {
254-
File spentAddressFolder = new File(SpentAddressesProvider.SPENT_ADDRESSES_DB);
255-
//If there is at least one file in the db the check should pass
256-
if (Files.newDirectoryStream(spentAddressFolder.toPath(), "*.sst").iterator().hasNext()) {
257-
return;
258-
}
259-
}
260-
catch (IOException e){
261-
throw new SpentAddressesException("Can't load " + SpentAddressesProvider.SPENT_ADDRESSES_DB + " folder", e);
262-
}
263-
264-
throw new SpentAddressesException(SpentAddressesProvider.SPENT_ADDRESSES_DB + " folder has no sst files");
265-
}
266-
267247
/**
268248
* Loads the builtin snapshot (last global snapshot) that is embedded in the jar (if a different path is provided it
269249
* can also load from the disk).

src/main/java/net/helix/pendulum/service/snapshot/impl/SnapshotServiceImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,6 @@ private void cleanupOldData(PendulumConfig config, TransactionPruner transaction
517517
private void persistLocalSnapshot(SnapshotProvider snapshotProvider, Snapshot newSnapshot, PendulumConfig config)
518518
throws SnapshotException {
519519

520-
try {
521-
spentAddressesService.persistSpentAddresses(snapshotProvider.getInitialSnapshot().getIndex(),
522-
newSnapshot.getIndex());
523-
524-
} catch (Exception e) {
525-
throw new SnapshotException(e);
526-
}
527-
528-
// TODO: Add timestamp and hash to this snapshot so it can be saved into hashdir/timestamp-filename
529520
snapshotProvider.writeSnapshotToDisk(newSnapshot, config.getLocalSnapshotsBasePath() );
530521

531522
snapshotProvider.getLatestSnapshot().lockWrite();

src/main/java/net/helix/pendulum/service/spentaddresses/SpentAddressesService.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ public interface SpentAddressesService {
2020
*/
2121
boolean wasAddressSpentFrom(Hash addressHash) throws SpentAddressesException;
2222

23-
/**
24-
* Calculates and persists all spent addresses in between a range that were validly signed
25-
*
26-
* @param fromMilestoneIndex the lower bound milestone index (inclusive)
27-
* @param toMilestoneIndex the upper bound milestone index (exclusive)
28-
* @throws Exception when anything went wrong whilst calculating.
29-
*/
30-
void persistSpentAddresses(int fromMilestoneIndex, int toMilestoneIndex) throws Exception;
31-
3223
/**
3324
* Persist all the verifiable spent from a given list of transactions
3425
* @param transactions transactions to obtain spends from

src/main/java/net/helix/pendulum/service/spentaddresses/impl/SpentAddressesServiceImpl.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
import net.helix.pendulum.BundleValidator;
44
import net.helix.pendulum.controllers.AddressViewModel;
5-
import net.helix.pendulum.controllers.RoundViewModel;
65
import net.helix.pendulum.controllers.TransactionViewModel;
76
import net.helix.pendulum.model.Hash;
87
import net.helix.pendulum.service.snapshot.SnapshotProvider;
9-
import net.helix.pendulum.service.snapshot.impl.SnapshotServiceImpl;
108
import net.helix.pendulum.service.spentaddresses.SpentAddressesException;
119
import net.helix.pendulum.service.spentaddresses.SpentAddressesProvider;
1210
import net.helix.pendulum.service.spentaddresses.SpentAddressesService;
1311
import net.helix.pendulum.service.tipselection.TailFinder;
1412
import net.helix.pendulum.service.tipselection.impl.TailFinderImpl;
1513
import net.helix.pendulum.storage.Tangle;
16-
import net.helix.pendulum.utils.dag.DAGHelper;
1714
import org.apache.commons.collections4.CollectionUtils;
1815
import org.slf4j.Logger;
1916
import org.slf4j.LoggerFactory;
@@ -80,42 +77,6 @@ public boolean wasAddressSpentFrom(Hash addressHash) throws SpentAddressesExcept
8077
return false;
8178
}
8279

83-
@Override
84-
public void persistSpentAddresses(int fromMilestoneIndex, int toMilestoneIndex) throws SpentAddressesException {
85-
Set<Hash> addressesToCheck = new HashSet<>();
86-
try {
87-
for (int i = fromMilestoneIndex; i < toMilestoneIndex; i++) {
88-
RoundViewModel currentMilestone = RoundViewModel.get(tangle, i);
89-
if (currentMilestone != null) {
90-
for (Hash confirmedTip : currentMilestone.getConfirmedTips(tangle, 1)) {
91-
DAGHelper.get(tangle).traverseApprovees(
92-
confirmedTip,
93-
transactionViewModel -> transactionViewModel.snapshotIndex() >= currentMilestone.index(),
94-
transactionViewModel -> addressesToCheck.add(transactionViewModel.getAddressHash())
95-
);
96-
}
97-
}
98-
}
99-
} catch (Exception e) {
100-
throw new SpentAddressesException(e);
101-
}
102-
103-
//Can only throw runtime exceptions in streams
104-
try {
105-
spentAddressesProvider.saveAddressesBatch(addressesToCheck.stream()
106-
.filter(ThrowingPredicate.unchecked(this::wasAddressSpentFrom))
107-
.collect(Collectors.toList()));
108-
log.trace("spentAddressesService.persistSpentAddresses += 1");
109-
} catch (RuntimeException e) {
110-
if (e.getCause() instanceof SpentAddressesException) {
111-
throw (SpentAddressesException) e.getCause();
112-
} else {
113-
throw e;
114-
}
115-
}
116-
117-
}
118-
11980
@Override
12081
public void persistSpentAddresses(Collection<TransactionViewModel> transactions) throws SpentAddressesException {
12182
try {

0 commit comments

Comments
 (0)