forked from Qortal/qortal
Invalidate the cache in ArbitraryTransaction.onImportAsUnconfirmed() if we have the local data
This ensures that the local copy of a resource updates as soon as the transaction is broadcast.
This commit is contained in:
parent
a61b0685f0
commit
6d031130b9
@ -385,6 +385,24 @@ public class ArbitraryDataManager extends Thread {
|
|||||||
this.arbitraryDataCachedResources.put(resourceId, timestamp);
|
this.arbitraryDataCachedResources.put(resourceId, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void invalidateCache(ArbitraryTransactionData arbitraryTransactionData) {
|
||||||
|
if (arbitraryTransactionData.getName() != null) {
|
||||||
|
String resourceId = arbitraryTransactionData.getName().toLowerCase();
|
||||||
|
LOGGER.info("We have all data for transaction {}", Base58.encode(arbitraryTransactionData.getSignature()));
|
||||||
|
LOGGER.info("Clearing cache for name {}...", arbitraryTransactionData.getName());
|
||||||
|
|
||||||
|
if (this.arbitraryDataCachedResources.containsKey(resourceId)) {
|
||||||
|
this.arbitraryDataCachedResources.remove(resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also remove from the failed builds queue in case it previously failed due to missing chunks
|
||||||
|
ArbitraryDataBuildManager buildManager = ArbitraryDataBuildManager.getInstance();
|
||||||
|
if (buildManager.arbitraryDataFailedBuilds.containsKey(resourceId)) {
|
||||||
|
buildManager.arbitraryDataFailedBuilds.remove(resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Network handlers
|
// Network handlers
|
||||||
|
|
||||||
@ -502,21 +520,7 @@ public class ArbitraryDataManager extends Thread {
|
|||||||
|
|
||||||
// We have all the chunks for this transaction, so we should invalidate the transaction's name's
|
// We have all the chunks for this transaction, so we should invalidate the transaction's name's
|
||||||
// data cache so that it is rebuilt the next time we serve it
|
// data cache so that it is rebuilt the next time we serve it
|
||||||
if (arbitraryTransactionData.getName() != null) {
|
invalidateCache(arbitraryTransactionData);
|
||||||
String resourceId = arbitraryTransactionData.getName().toLowerCase();
|
|
||||||
LOGGER.info("We have all data for transaction {}", Base58.encode(transactionData.getSignature()));
|
|
||||||
LOGGER.info("Clearing cache for name {}...", arbitraryTransactionData.getName());
|
|
||||||
|
|
||||||
if (this.arbitraryDataCachedResources.containsKey(resourceId)) {
|
|
||||||
this.arbitraryDataCachedResources.remove(resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also remove from the failed builds queue in case it previously failed due to missing chunks
|
|
||||||
ArbitraryDataBuildManager buildManager = ArbitraryDataBuildManager.getInstance();
|
|
||||||
if (buildManager.arbitraryDataFailedBuilds.containsKey(resourceId)) {
|
|
||||||
buildManager.arbitraryDataFailedBuilds.remove(resourceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We also need to broadcast to the network that we are now hosting files for this transaction
|
// We also need to broadcast to the network that we are now hosting files for this transaction
|
||||||
// Use a null peer address to indicate our own
|
// Use a null peer address to indicate our own
|
||||||
|
@ -6,6 +6,7 @@ import java.util.Objects;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.qortal.account.Account;
|
import org.qortal.account.Account;
|
||||||
|
import org.qortal.controller.arbitrary.ArbitraryDataManager;
|
||||||
import org.qortal.crypto.Crypto;
|
import org.qortal.crypto.Crypto;
|
||||||
import org.qortal.crypto.MemoryPoW;
|
import org.qortal.crypto.MemoryPoW;
|
||||||
import org.qortal.data.PaymentData;
|
import org.qortal.data.PaymentData;
|
||||||
@ -212,6 +213,16 @@ public class ArbitraryTransaction extends Transaction {
|
|||||||
arbitraryTransactionData.getFee());
|
arbitraryTransactionData.getFee());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onImportAsUnconfirmed() throws DataException {
|
||||||
|
// Invalidate the cache for this name if we have the data already
|
||||||
|
if (arbitraryTransactionData.getName() != null) {
|
||||||
|
if (isDataLocal()) {
|
||||||
|
ArbitraryDataManager.getInstance().invalidateCache(arbitraryTransactionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preProcess() throws DataException {
|
public void preProcess() throws DataException {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
@ -252,10 +263,9 @@ public class ArbitraryTransaction extends Transaction {
|
|||||||
/** Returns arbitrary data payload, fetching from network if needed. Can block for a while! */
|
/** Returns arbitrary data payload, fetching from network if needed. Can block for a while! */
|
||||||
public byte[] fetchData() throws DataException {
|
public byte[] fetchData() throws DataException {
|
||||||
// If local, read from file
|
// If local, read from file
|
||||||
if (isDataLocal())
|
if (isDataLocal()) {
|
||||||
return this.repository.getArbitraryRepository().fetchData(this.transactionData.getSignature());
|
return this.repository.getArbitraryRepository().fetchData(this.transactionData.getSignature());
|
||||||
|
}
|
||||||
// TODO If not local, attempt to fetch via network?
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user