From 166425bee9e943ddf8c603da7e1c7d4184481276 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Fri, 28 Oct 2022 17:20:39 +0100 Subject: [PATCH] Added feature trigger timestamp (TBC) to increase online accounts mempow difficulty (also TBC). --- src/main/java/org/qortal/block/BlockChain.java | 7 ++++++- .../controller/OnlineAccountsManager.java | 17 +++++++++++------ src/main/resources/blockchain.json | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/qortal/block/BlockChain.java b/src/main/java/org/qortal/block/BlockChain.java index 826fdd78..5e1f44f3 100644 --- a/src/main/java/org/qortal/block/BlockChain.java +++ b/src/main/java/org/qortal/block/BlockChain.java @@ -73,7 +73,8 @@ public class BlockChain { calcChainWeightTimestamp, transactionV5Timestamp, transactionV6Timestamp, - disableReferenceTimestamp; + disableReferenceTimestamp, + increaseOnlineAccountsDifficultyTimestamp; } // Custom transaction fees @@ -478,6 +479,10 @@ public class BlockChain { return this.featureTriggers.get(FeatureTrigger.disableReferenceTimestamp.name()).longValue(); } + public long getIncreaseOnlineAccountsDifficultyTimestamp() { + return this.featureTriggers.get(FeatureTrigger.increaseOnlineAccountsDifficultyTimestamp.name()).longValue(); + } + // More complex getters for aspects that change by height or timestamp diff --git a/src/main/java/org/qortal/controller/OnlineAccountsManager.java b/src/main/java/org/qortal/controller/OnlineAccountsManager.java index 1aea118b..fd2c38df 100644 --- a/src/main/java/org/qortal/controller/OnlineAccountsManager.java +++ b/src/main/java/org/qortal/controller/OnlineAccountsManager.java @@ -66,7 +66,8 @@ public class OnlineAccountsManager { // MemoryPoW - mainnet public static final int POW_BUFFER_SIZE = 1 * 1024 * 1024; // bytes - public static final int POW_DIFFICULTY = 18; // leading zero bits + public static final int POW_DIFFICULTY_V1 = 18; // leading zero bits + public static final int POW_DIFFICULTY_V2 = 19; // leading zero bits // MemoryPoW - testnet public static final int POW_BUFFER_SIZE_TESTNET = 1 * 1024 * 1024; // bytes @@ -128,11 +129,14 @@ public class OnlineAccountsManager { return POW_BUFFER_SIZE; } - private static int getPoWDifficulty() { + private static int getPoWDifficulty(long timestamp) { if (Settings.getInstance().isTestNet()) return POW_DIFFICULTY_TESTNET; - return POW_DIFFICULTY; + if (timestamp >= BlockChain.getInstance().getIncreaseOnlineAccountsDifficultyTimestamp()) + return POW_DIFFICULTY_V2; + + return POW_DIFFICULTY_V1; } private OnlineAccountsManager() { @@ -628,7 +632,8 @@ public class OnlineAccountsManager { final long nextOnlineAccountsTimestamp = toOnlineAccountTimestamp(startTime) + getOnlineTimestampModulus(); long timeUntilNextTimestamp = nextOnlineAccountsTimestamp - startTime; - Integer nonce = MemoryPoW.compute2(bytes, getPoWBufferSize(), getPoWDifficulty(), timeUntilNextTimestamp); + int difficulty = getPoWDifficulty(onlineAccountsTimestamp); + Integer nonce = MemoryPoW.compute2(bytes, getPoWBufferSize(), difficulty, timeUntilNextTimestamp); double totalSeconds = (NTP.getTime() - startTime) / 1000.0f; int minutes = (int) ((totalSeconds % 3600) / 60); @@ -637,7 +642,7 @@ public class OnlineAccountsManager { LOGGER.info(String.format("Computed nonce for timestamp %d and account %.8s: %d. Buffer size: %d. Difficulty: %d. " + "Time taken: %02d:%02d. Hashrate: %f", onlineAccountsTimestamp, Base58.encode(publicKey), - nonce, getPoWBufferSize(), getPoWDifficulty(), minutes, seconds, hashRate)); + nonce, getPoWBufferSize(), difficulty, minutes, seconds, hashRate)); return nonce; } @@ -658,7 +663,7 @@ public class OnlineAccountsManager { } // Verify the nonce - return MemoryPoW.verify2(mempowBytes, workBuffer, getPoWBufferSize(), getPoWDifficulty(), nonce); + return MemoryPoW.verify2(mempowBytes, workBuffer, getPoWBufferSize(), getPoWDifficulty(onlineAccountData.getTimestamp()), nonce); } diff --git a/src/main/resources/blockchain.json b/src/main/resources/blockchain.json index 893add5e..34671c76 100644 --- a/src/main/resources/blockchain.json +++ b/src/main/resources/blockchain.json @@ -79,7 +79,8 @@ "calcChainWeightTimestamp": 1620579600000, "transactionV5Timestamp": 1642176000000, "transactionV6Timestamp": 9999999999999, - "disableReferenceTimestamp": 1655222400000 + "disableReferenceTimestamp": 1655222400000, + "increaseOnlineAccountsDifficultyTimestamp": 9999999999999 }, "genesisInfo": { "version": 4,