Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<fix>(consensus,auth): fix add sealer bug when sdk connect observer to be added. #807

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading