Browse Source

Pass timestamp to OnlineAccountsManager.isMemoryPoWActive() so that block timestamp can be used.

online-accounts-mempow-v2
CalDescent 2 years ago
parent
commit
a3febdf00e
  1. 17
      src/main/java/org/qortal/controller/OnlineAccountsManager.java

17
src/main/java/org/qortal/controller/OnlineAccountsManager.java

@ -302,7 +302,7 @@ public class OnlineAccountsManager {
// Validate mempow if feature trigger is active // Validate mempow if feature trigger is active
if (now >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp()) { if (now >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp()) {
if (!getInstance().verifyMemoryPoW(onlineAccountData)) { if (!getInstance().verifyMemoryPoW(onlineAccountData, now)) {
LOGGER.trace(() -> String.format("Rejecting online reward-share for account %s due to invalid PoW nonce", mintingAccount.getAddress())); LOGGER.trace(() -> String.format("Rejecting online reward-share for account %s due to invalid PoW nonce", mintingAccount.getAddress()));
return false; return false;
} }
@ -524,7 +524,7 @@ public class OnlineAccountsManager {
// Compute nonce // Compute nonce
Integer nonce; Integer nonce;
if (isMemoryPoWActive()) { if (isMemoryPoWActive(NTP.getTime())) {
try { try {
nonce = this.computeMemoryPoW(mempowBytes, publicKey, onlineAccountsTimestamp); nonce = this.computeMemoryPoW(mempowBytes, publicKey, onlineAccountsTimestamp);
if (nonce == null) { if (nonce == null) {
@ -549,7 +549,7 @@ public class OnlineAccountsManager {
OnlineAccountData ourOnlineAccountData = new OnlineAccountData(onlineAccountsTimestamp, signature, publicKey, nonce); OnlineAccountData ourOnlineAccountData = new OnlineAccountData(onlineAccountsTimestamp, signature, publicKey, nonce);
// Make sure to verify before adding // Make sure to verify before adding
if (verifyMemoryPoW(ourOnlineAccountData)) { if (verifyMemoryPoW(ourOnlineAccountData, NTP.getTime())) {
ourOnlineAccounts.add(ourOnlineAccountData); ourOnlineAccounts.add(ourOnlineAccountData);
} }
} }
@ -582,9 +582,8 @@ public class OnlineAccountsManager {
// MemoryPoW // MemoryPoW
private boolean isMemoryPoWActive() { private boolean isMemoryPoWActive(Long timestamp) {
Long now = NTP.getTime(); if (timestamp >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp() || Settings.getInstance().isOnlineAccountsMemPoWEnabled()) {
if (now >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp() || Settings.getInstance().isOnlineAccountsMemPoWEnabled()) {
return true; return true;
} }
return false; return false;
@ -600,7 +599,7 @@ public class OnlineAccountsManager {
} }
private Integer computeMemoryPoW(byte[] bytes, byte[] publicKey, long onlineAccountsTimestamp) throws TimeoutException { private Integer computeMemoryPoW(byte[] bytes, byte[] publicKey, long onlineAccountsTimestamp) throws TimeoutException {
if (!isMemoryPoWActive()) { if (!isMemoryPoWActive(NTP.getTime())) {
LOGGER.info("Mempow start timestamp not yet reached, and onlineAccountsMemPoWEnabled not enabled in settings"); LOGGER.info("Mempow start timestamp not yet reached, and onlineAccountsMemPoWEnabled not enabled in settings");
return null; return null;
} }
@ -626,8 +625,8 @@ public class OnlineAccountsManager {
return nonce; return nonce;
} }
public boolean verifyMemoryPoW(OnlineAccountData onlineAccountData) { public boolean verifyMemoryPoW(OnlineAccountData onlineAccountData, Long timestamp) {
if (!isMemoryPoWActive()) { if (!isMemoryPoWActive(timestamp)) {
// Not active yet, so treat it as valid // Not active yet, so treat it as valid
return true; return true;
} }

Loading…
Cancel
Save