forked from Qortal/qortal
Invalidate the cache if hash validation fails, so that it can be rebuilt next time.
This commit is contained in:
parent
e1feb46de9
commit
1968496ce1
@ -9,6 +9,7 @@ import org.qortal.utils.FilesystemUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.nio.file.DirectoryNotEmptyException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -116,7 +117,7 @@ public class ArbitraryDataCombiner {
|
||||
boolean valid = digest.isHashValid(previousHash);
|
||||
if (!valid) {
|
||||
String previousHash58 = Base58.encode(previousHash);
|
||||
throw new IllegalStateException(String.format("Previous state hash mismatch. " +
|
||||
throw new InvalidObjectException(String.format("Previous state hash mismatch. " +
|
||||
"Patch prevHash: %s, actual: %s", previousHash58, digest.getHash58()));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package org.qortal.arbitrary;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.arbitrary.metadata.ArbitraryDataMetadataCache;
|
||||
|
||||
import org.qortal.crypto.AES;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData;
|
||||
import org.qortal.data.transaction.ArbitraryTransactionData.*;
|
||||
@ -24,6 +24,7 @@ import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
@ -172,17 +173,25 @@ public class ArbitraryDataReader {
|
||||
}
|
||||
|
||||
private void fetchFromName() throws IllegalStateException, IOException, DataException {
|
||||
try {
|
||||
|
||||
// Build the existing state using past transactions
|
||||
ArbitraryDataBuilder builder = new ArbitraryDataBuilder(this.resourceId, this.service);
|
||||
builder.build();
|
||||
Path builtPath = builder.getFinalPath();
|
||||
if (builtPath == null) {
|
||||
throw new IllegalStateException("Unable to build path");
|
||||
// Build the existing state using past transactions
|
||||
ArbitraryDataBuilder builder = new ArbitraryDataBuilder(this.resourceId, this.service);
|
||||
builder.build();
|
||||
Path builtPath = builder.getFinalPath();
|
||||
if (builtPath == null) {
|
||||
throw new IllegalStateException("Unable to build path");
|
||||
}
|
||||
|
||||
// Set filePath to the builtPath
|
||||
this.filePath = builtPath;
|
||||
|
||||
} catch (InvalidObjectException e) {
|
||||
// Hash validation failed. Invalidate the cache for this name, so it can be rebuilt
|
||||
LOGGER.info("Deleting {}", this.workingPath.toString());
|
||||
FilesystemUtils.safeDeleteDirectory(this.workingPath, false);
|
||||
throw(e);
|
||||
}
|
||||
|
||||
// Set filePath to the builtPath
|
||||
this.filePath = builtPath;
|
||||
}
|
||||
|
||||
private void fetchFromSignature() throws IllegalStateException, IOException, DataException {
|
||||
|
Loading…
Reference in New Issue
Block a user