diff --git a/src/main/java/org/qortal/controller/OnlineAccountsManager.java b/src/main/java/org/qortal/controller/OnlineAccountsManager.java index 224228b8..25cace2f 100644 --- a/src/main/java/org/qortal/controller/OnlineAccountsManager.java +++ b/src/main/java/org/qortal/controller/OnlineAccountsManager.java @@ -414,7 +414,7 @@ public class OnlineAccountsManager { boolean isSuperiorEntry = isOnlineAccountsDataSuperior(onlineAccountData); if (isSuperiorEntry) // Remove existing inferior entry so it can be re-added below (it's likely the existing copy is missing a nonce value) - onlineAccounts.remove(onlineAccountData); + onlineAccounts.removeIf(a -> Objects.equals(a.getPublicKey(), onlineAccountData.getPublicKey())); boolean isNewEntry = onlineAccounts.add(onlineAccountData); diff --git a/src/main/java/org/qortal/data/network/OnlineAccountData.java b/src/main/java/org/qortal/data/network/OnlineAccountData.java index bd4842db..a1e1b30f 100644 --- a/src/main/java/org/qortal/data/network/OnlineAccountData.java +++ b/src/main/java/org/qortal/data/network/OnlineAccountData.java @@ -1,6 +1,7 @@ package org.qortal.data.network; import java.util.Arrays; +import java.util.Objects; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -34,10 +35,6 @@ public class OnlineAccountData { this.nonce = nonce; } - public OnlineAccountData(long timestamp, byte[] signature, byte[] publicKey) { - this(timestamp, signature, publicKey, null); - } - public long getTimestamp() { return this.timestamp; } @@ -76,6 +73,10 @@ public class OnlineAccountData { if (otherOnlineAccountData.timestamp != this.timestamp) return false; + // Almost as quick + if (!Objects.equals(otherOnlineAccountData.nonce, this.nonce)) + return false; + if (!Arrays.equals(otherOnlineAccountData.publicKey, this.publicKey)) return false; @@ -88,9 +89,10 @@ public class OnlineAccountData { public int hashCode() { int h = this.hash; if (h == 0) { - this.hash = h = Long.hashCode(this.timestamp) - ^ Arrays.hashCode(this.publicKey); + h = Objects.hash(timestamp, nonce); + h = 31 * h + Arrays.hashCode(publicKey); // We don't use signature because newer aggregate signatures use random nonces + this.hash = h; } return h; } diff --git a/src/main/java/org/qortal/network/message/OnlineAccountsV3Message.java b/src/main/java/org/qortal/network/message/OnlineAccountsV3Message.java index d554d96c..c057fbce 100644 --- a/src/main/java/org/qortal/network/message/OnlineAccountsV3Message.java +++ b/src/main/java/org/qortal/network/message/OnlineAccountsV3Message.java @@ -99,9 +99,10 @@ public class OnlineAccountsV3Message extends Message { bytes.get(publicKey); // Nonce is optional - will be -1 if missing + // ... but we should skip/ignore an online account if it has no nonce Integer nonce = bytes.getInt(); if (nonce < 0) { - nonce = null; + continue; } onlineAccounts.add(new OnlineAccountData(timestamp, signature, publicKey, nonce)); diff --git a/src/test/java/org/qortal/test/network/OnlineAccountsV3Tests.java b/src/test/java/org/qortal/test/network/OnlineAccountsV3Tests.java index cc2a54ff..2c3c01ca 100644 --- a/src/test/java/org/qortal/test/network/OnlineAccountsV3Tests.java +++ b/src/test/java/org/qortal/test/network/OnlineAccountsV3Tests.java @@ -165,7 +165,9 @@ public class OnlineAccountsV3Tests { byte[] pubkey = new byte[Transformer.PUBLIC_KEY_LENGTH]; RANDOM.nextBytes(pubkey); - onlineAccounts.add(new OnlineAccountData(timestamp, sig, pubkey)); + Integer nonce = RANDOM.nextInt(); + + onlineAccounts.add(new OnlineAccountData(timestamp, sig, pubkey, nonce)); } }