diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index ff911281808..b634f01a8d5 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -64,6 +64,8 @@ import java.security.PublicKey; +import java.time.Clock; + import java.util.Arrays; import java.util.Date; import java.util.GregorianCalendar; @@ -137,6 +139,7 @@ public String getDisplayString() { private final SignedWitnessService signedWitnessService; private final ChargeBackRisk chargeBackRisk; private final AccountAgeWitnessStorageService accountAgeWitnessStorageService; + private final Clock clock; private final FilterManager filterManager; @Getter private final AccountAgeWitnessUtils accountAgeWitnessUtils; @@ -162,6 +165,7 @@ public AccountAgeWitnessService(KeyRing keyRing, ChargeBackRisk chargeBackRisk, AccountAgeWitnessStorageService accountAgeWitnessStorageService, AppendOnlyDataStoreService appendOnlyDataStoreService, + Clock clock, FilterManager filterManager) { this.keyRing = keyRing; this.p2PService = p2PService; @@ -169,6 +173,7 @@ public AccountAgeWitnessService(KeyRing keyRing, this.signedWitnessService = signedWitnessService; this.chargeBackRisk = chargeBackRisk; this.accountAgeWitnessStorageService = accountAgeWitnessStorageService; + this.clock = clock; this.filterManager = filterManager; accountAgeWitnessUtils = new AccountAgeWitnessUtils( @@ -219,13 +224,18 @@ private void onBootStrapped() { private void republishAllFiatAccounts() { if (user.getPaymentAccounts() != null) user.getPaymentAccounts().stream() - .filter(e -> !(e instanceof AssetAccount)) - .forEach(e -> { - // We delay with a random interval of 20-60 sec to ensure to be better connected and don't - // stress the P2P network with publishing all at once at startup time. - final int delayInSec = 20 + new Random().nextInt(40); - UserThread.runAfter(() -> p2PService.addPersistableNetworkPayload(getMyWitness( - e.getPaymentAccountPayload()), true), delayInSec); + .filter(account -> !(account instanceof AssetAccount)) + .forEach(account -> { + AccountAgeWitness myWitness = getMyWitness(account.getPaymentAccountPayload()); + // We only publish if the date of our witness is inside the date tolerance. + // It would be rejected otherwise from the peers. + if (myWitness.isDateInTolerance(clock)) { + // We delay with a random interval of 20-60 sec to ensure to be better connected and don't + // stress the P2P network with publishing all at once at startup time. + int delayInSec = 20 + new Random().nextInt(40); + UserThread.runAfter(() -> + p2PService.addPersistableNetworkPayload(myWitness, true), delayInSec); + } }); } diff --git a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java index 946e4db64d4..9782e37ce13 100644 --- a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java @@ -109,7 +109,7 @@ private void setupService(KeyRing keyRing) { AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class); filterManager = mock(FilterManager.class); signedWitnessService = new SignedWitnessService(keyRing, p2pService, arbitratorManager, null, appendOnlyDataStoreService, null, filterManager); - service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, dataStoreService, filterManager); + service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, dataStoreService, null, filterManager); } private File makeDir(String name) throws IOException {