diff --git a/build.gradle b/build.gradle index 32f8116a4..c8bf7f41a 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ ext { // integrationTest.mustRunAfter test allprojects { group = 'org.fisco-bcos.java-sdk' - version = '3.2.2' + version = '3.2.3-SNAPSHOT' apply plugin: 'maven-publish' apply plugin: 'idea' diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java index 72eff7f7c..b94e0316c 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java @@ -261,15 +261,25 @@ private void checkSetConsensusWeightParams(String node, BigInteger weight, boole PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getCode()); } SyncStatus syncStatus = client.getSyncStatus(); - BigInteger blockNumber = client.getBlockNumber().getBlockNumber(); - boolean anyMatch = - syncStatus.getSyncStatus().getPeers().stream() - .anyMatch( - peersInfo -> - peersInfo.getNodeId().equals(node) - && peersInfo.getBlockNumber() - >= (blockNumber.longValue() - - SYNC_KEEP_UP_THRESHOLD)); + // sdk block number + BigInteger highestNumber = + BigInteger.valueOf(syncStatus.getSyncStatus().getKnownHighestNumber()); + boolean anyMatch; + if (syncStatus.getSyncStatus().getNodeId().equals(node)) { + // sdk connect observer to be added to sealerList + anyMatch = + syncStatus.getSyncStatus().getBlockNumber() + >= highestNumber.longValue() - SYNC_KEEP_UP_THRESHOLD; + } else { + anyMatch = + syncStatus.getSyncStatus().getPeers().stream() + .anyMatch( + peersInfo -> + peersInfo.getNodeId().equals(node) + && peersInfo.getBlockNumber() + >= (highestNumber.longValue() + - SYNC_KEEP_UP_THRESHOLD)); + } if (!anyMatch) { throw new ContractException( "Observer should keep up the block number sync threshold: " diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/consensus/ConsensusService.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/consensus/ConsensusService.java index 3668596f5..e952bf840 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/consensus/ConsensusService.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/consensus/ConsensusService.java @@ -75,15 +75,25 @@ public RetCode addSealer(String nodeId, BigInteger weight) throws ContractExcept PrecompiledRetCode.CODE_ADD_SEALER_SHOULD_IN_OBSERVER.getCode()); } SyncStatus syncStatus = client.getSyncStatus(); - BigInteger blockNumber = client.getBlockNumber().getBlockNumber(); - boolean anyMatch = - syncStatus.getSyncStatus().getPeers().stream() - .anyMatch( - peersInfo -> - peersInfo.getNodeId().equals(nodeId) - && peersInfo.getBlockNumber() - >= (blockNumber.longValue() - - SYNC_KEEP_UP_THRESHOLD)); + // sdk block number + BigInteger highestNumber = + BigInteger.valueOf(syncStatus.getSyncStatus().getKnownHighestNumber()); + boolean anyMatch; + if (syncStatus.getSyncStatus().getNodeId().equals(nodeId)) { + // sdk connect observer to be added to sealerList + anyMatch = + syncStatus.getSyncStatus().getBlockNumber() + >= highestNumber.longValue() - SYNC_KEEP_UP_THRESHOLD; + } else { + anyMatch = + syncStatus.getSyncStatus().getPeers().stream() + .anyMatch( + peersInfo -> + peersInfo.getNodeId().equals(nodeId) + && peersInfo.getBlockNumber() + >= (highestNumber.longValue() + - SYNC_KEEP_UP_THRESHOLD)); + } if (!anyMatch) { throw new ContractException( "Observer should keep up the block number sync threshold: " diff --git a/src/test/java/org/fisco/bcos/sdk/v3/test/transaction/contract/PrecompiledTest.java b/src/test/java/org/fisco/bcos/sdk/v3/test/transaction/contract/PrecompiledTest.java index 01bad6053..431d9e498 100644 --- a/src/test/java/org/fisco/bcos/sdk/v3/test/transaction/contract/PrecompiledTest.java +++ b/src/test/java/org/fisco/bcos/sdk/v3/test/transaction/contract/PrecompiledTest.java @@ -150,6 +150,8 @@ public void mockGetSyncStatusRequest(long number, String... nodeIds) { SyncStatus syncStatus = new SyncStatus(); SyncStatus.SyncStatusInfo syncStatusInfo = new SyncStatus.SyncStatusInfo(); List peersInfos = new ArrayList<>(); + syncStatusInfo.setNodeId(nodeIds[0]); + syncStatusInfo.setKnownHighestNumber((int) number); for (String nodeId : nodeIds) { SyncStatus.PeersInfo peersInfo = new SyncStatus.PeersInfo(); peersInfo.setBlockNumber(number);