Skip to content

Commit

Permalink
<fix>(consensus,auth): fix add sealer bug when sdk connect observer t…
Browse files Browse the repository at this point in the history
…o be added. (#807)
  • Loading branch information
kyonRay authored Jul 21, 2023
1 parent 7b291cc commit 0d2f2fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public void mockGetSyncStatusRequest(long number, String... nodeIds) {
SyncStatus syncStatus = new SyncStatus();
SyncStatus.SyncStatusInfo syncStatusInfo = new SyncStatus.SyncStatusInfo();
List<SyncStatus.PeersInfo> peersInfos = new ArrayList<>();
syncStatusInfo.setNodeId(nodeIds[0]);
syncStatusInfo.setKnownHighestNumber((int) number);
for (String nodeId : nodeIds) {
SyncStatus.PeersInfo peersInfo = new SyncStatus.PeersInfo();
peersInfo.setBlockNumber(number);
Expand Down

0 comments on commit 0d2f2fd

Please sign in to comment.