forked from Qortal/qortal
When submitting a new transaction, treat the chain as "synced" if the latest block is less than 30 minutes old. Increased from around 7.5 minutes.
This commit is contained in:
parent
2d493a4ea2
commit
0271ef69c9
@ -638,7 +638,10 @@ public class TransactionsResource {
|
|||||||
ApiError.BLOCKCHAIN_NEEDS_SYNC, ApiError.INVALID_SIGNATURE, ApiError.INVALID_DATA, ApiError.TRANSFORMATION_ERROR, ApiError.REPOSITORY_ISSUE
|
ApiError.BLOCKCHAIN_NEEDS_SYNC, ApiError.INVALID_SIGNATURE, ApiError.INVALID_DATA, ApiError.TRANSFORMATION_ERROR, ApiError.REPOSITORY_ISSUE
|
||||||
})
|
})
|
||||||
public String processTransaction(String rawBytes58) {
|
public String processTransaction(String rawBytes58) {
|
||||||
if (!Controller.getInstance().isUpToDate())
|
// Only allow a transaction to be processed if our latest block is less than 30 minutes old
|
||||||
|
// If older than this, we should first wait until the blockchain is synced
|
||||||
|
final Long minLatestBlockTimestamp = NTP.getTime() - (30 * 60 * 1000L);
|
||||||
|
if (!Controller.getInstance().isUpToDate(minLatestBlockTimestamp))
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCKCHAIN_NEEDS_SYNC);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCKCHAIN_NEEDS_SYNC);
|
||||||
|
|
||||||
byte[] rawBytes = Base58.decode(rawBytes58);
|
byte[] rawBytes = Base58.decode(rawBytes58);
|
||||||
|
@ -2048,10 +2048,13 @@ public class Controller extends Thread {
|
|||||||
return peers;
|
return peers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns whether we think our node has up-to-date blockchain based on our info about other peers. */
|
/**
|
||||||
public boolean isUpToDate() {
|
* Returns whether we think our node has up-to-date blockchain based on our info about other peers.
|
||||||
|
* @param minLatestBlockTimestamp - the minimum block timestamp to be considered recent
|
||||||
|
* @return boolean - whether our node's blockchain is up to date or not
|
||||||
|
*/
|
||||||
|
public boolean isUpToDate(Long minLatestBlockTimestamp) {
|
||||||
// Do we even have a vaguely recent block?
|
// Do we even have a vaguely recent block?
|
||||||
final Long minLatestBlockTimestamp = getMinimumLatestBlockTimestamp();
|
|
||||||
if (minLatestBlockTimestamp == null)
|
if (minLatestBlockTimestamp == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2077,6 +2080,16 @@ public class Controller extends Thread {
|
|||||||
return !peers.isEmpty();
|
return !peers.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether we think our node has up-to-date blockchain based on our info about other peers.
|
||||||
|
* Uses the default minLatestBlockTimestamp value.
|
||||||
|
* @return boolean - whether our node's blockchain is up to date or not
|
||||||
|
*/
|
||||||
|
public boolean isUpToDate() {
|
||||||
|
final Long minLatestBlockTimestamp = getMinimumLatestBlockTimestamp();
|
||||||
|
return this.isUpToDate(minLatestBlockTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns minimum block timestamp for block to be considered 'recent', or <tt>null</tt> if NTP not synced. */
|
/** Returns minimum block timestamp for block to be considered 'recent', or <tt>null</tt> if NTP not synced. */
|
||||||
public static Long getMinimumLatestBlockTimestamp() {
|
public static Long getMinimumLatestBlockTimestamp() {
|
||||||
Long now = NTP.getTime();
|
Long now = NTP.getTime();
|
||||||
|
Loading…
Reference in New Issue
Block a user