mirror of https://github.com/hyperledger/besu
Separate round change reception from RoundChangeCertificate (#754)
IBFT2.1 requires that message content be separated, thus concepts at the message level must not leak into the business logic - eg RoundChangeCertificate should not be created by the RoundChangeManager - rather an intermediate type is to be inserted. Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
46c888c792
commit
fb019d8f18
@ -0,0 +1,62 @@ |
||||
/* |
||||
* Copyright 2019 ConsenSys AG. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
*/ |
||||
package tech.pegasys.pantheon.consensus.ibft.statemachine; |
||||
|
||||
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; |
||||
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; |
||||
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; |
||||
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; |
||||
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload; |
||||
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; |
||||
import tech.pegasys.pantheon.ethereum.core.Block; |
||||
|
||||
import java.util.Collection; |
||||
import java.util.Optional; |
||||
import java.util.stream.Collectors; |
||||
|
||||
public class RoundChangeArtefacts { |
||||
|
||||
private final Optional<Block> block; |
||||
private final Collection<SignedData<RoundChangePayload>> roundChangePayloads; |
||||
|
||||
public RoundChangeArtefacts( |
||||
final Optional<Block> block, |
||||
final Collection<SignedData<RoundChangePayload>> roundChangePayloads) { |
||||
this.block = block; |
||||
this.roundChangePayloads = roundChangePayloads; |
||||
} |
||||
|
||||
public Optional<Block> getBlock() { |
||||
return block; |
||||
} |
||||
|
||||
public RoundChangeCertificate getRoundChangeCertificate() { |
||||
return new RoundChangeCertificate(roundChangePayloads); |
||||
} |
||||
|
||||
public static RoundChangeArtefacts create(final Collection<RoundChange> roundChanges) { |
||||
|
||||
final Collection<SignedData<RoundChangePayload>> payloads = |
||||
roundChanges |
||||
.stream() |
||||
.map(roundChange -> roundChange.getSignedPayload()) |
||||
.collect(Collectors.toList()); |
||||
|
||||
final Optional<PreparedCertificate> latestPreparedCertificate = |
||||
IbftHelpers.findLatestPreparedCertificate(payloads); |
||||
|
||||
return new RoundChangeArtefacts( |
||||
latestPreparedCertificate.map(cert -> cert.getProposalPayload().getPayload().getBlock()), |
||||
payloads); |
||||
} |
||||
} |
Loading…
Reference in new issue