Fix "Pausing mining" log even though node is not a validator (#1071)

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/1100/head
Karim T 4 years ago committed by GitHub
parent dab4b53601
commit c8406923dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueHelpers.java
  2. 4
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueMiningTracker.java
  3. 20
      consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMiningCoordinator.java
  4. 11
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinator.java
  5. 10
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/EthHashMiningCoordinator.java
  6. 4
      ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/MiningCoordinator.java
  7. 1
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractMiningCoordinatorTest.java

@ -36,6 +36,16 @@ public class CliqueHelpers {
return proposerSelector.selectProposerForNextBlock(parent);
}
public static boolean isSigner(
final Address candidate, final ProtocolContext protocolContext, final BlockHeader parent) {
final VoteTally validatorProvider =
protocolContext
.getConsensusState(CliqueContext.class)
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
return validatorProvider.getValidators().contains(candidate);
}
public static boolean addressIsAllowedToProduceNextBlock(
final Address candidate, final ProtocolContext protocolContext, final BlockHeader parent) {
final VoteTally validatorProvider =
@ -44,7 +54,7 @@ public class CliqueHelpers {
.getVoteTallyCache()
.getVoteTallyAfterBlock(parent);
if (!validatorProvider.getValidators().contains(candidate)) {
if (!isSigner(candidate, protocolContext, parent)) {
return false;
}

@ -35,6 +35,10 @@ public class CliqueMiningTracker {
return localAddress.equals(nextProposer);
}
public boolean isSigner(final BlockHeader header) {
return CliqueHelpers.isSigner(localAddress, protocolContext, header);
}
public boolean canMakeBlockNextRound(final BlockHeader header) {
return CliqueHelpers.addressIsAllowedToProduceNextBlock(localAddress, protocolContext, header);
}

@ -14,14 +14,20 @@
*/
package org.hyperledger.besu.consensus.clique.blockcreation;
import static org.apache.logging.log4j.LogManager.getLogger;
import org.hyperledger.besu.consensus.clique.CliqueMiningTracker;
import org.hyperledger.besu.ethereum.blockcreation.AbstractMiningCoordinator;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.apache.logging.log4j.Logger;
public class CliqueMiningCoordinator extends AbstractMiningCoordinator<CliqueBlockMiner> {
private static final Logger LOG = getLogger();
private final CliqueMiningTracker miningTracker;
public CliqueMiningCoordinator(
@ -33,6 +39,20 @@ public class CliqueMiningCoordinator extends AbstractMiningCoordinator<CliqueBlo
this.miningTracker = miningTracker;
}
@Override
public void onResumeMining() {
if (miningTracker.isSigner(blockchain.getChainHeadHeader())) {
LOG.info("Resuming block production operations");
}
}
@Override
public void onPauseMining() {
if (miningTracker.isSigner(blockchain.getChainHeadHeader())) {
LOG.info("Pausing block production while behind chain head");
}
}
@Override
protected boolean newChainHeadInvalidatesMiningOperation(final BlockHeader newChainHeadHeader) {
if (currentRunningMiner.isEmpty()) {

@ -14,8 +14,6 @@
*/
package org.hyperledger.besu.ethereum.blockcreation;
import static org.apache.logging.log4j.LogManager.getLogger;
import org.hyperledger.besu.ethereum.chain.BlockAddedEvent;
import org.hyperledger.besu.ethereum.chain.BlockAddedObserver;
import org.hyperledger.besu.ethereum.chain.Blockchain;
@ -33,7 +31,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
public abstract class AbstractMiningCoordinator<
@ -46,13 +43,11 @@ public abstract class AbstractMiningCoordinator<
STOPPED
}
private static final Logger LOG = getLogger();
private final Subscribers<MinedBlockObserver> minedBlockObservers = Subscribers.create();
private final Subscribers<EthHashObserver> ethHashObservers = Subscribers.create();
private final AbstractMinerExecutor<M> executor;
private final SyncState syncState;
private final Blockchain blockchain;
protected final Blockchain blockchain;
private State state = State.IDLE;
private boolean isEnabled = false;
@ -181,10 +176,10 @@ public abstract class AbstractMiningCoordinator<
void inSyncChanged(final boolean inSync) {
synchronized (this) {
if (inSync && startMiningIfPossible()) {
LOG.info("Resuming mining operations");
onResumeMining();
}
if (!inSync && haltCurrentMiningOperation()) {
LOG.info("Pausing mining while behind chain head");
onPauseMining();
}
}
}

@ -70,6 +70,16 @@ public class EthHashMiningCoordinator extends AbstractMiningCoordinator<EthHashB
executor.setStratumMiningEnabled(stratumMiningEnabled);
}
@Override
public void onResumeMining() {
LOG.info("Resuming mining operations");
}
@Override
public void onPauseMining() {
LOG.info("Pausing mining while behind chain head");
}
@Override
public Optional<Long> hashesPerSecond() {
if (sealerHashRate.size() <= 0) {

@ -52,6 +52,10 @@ public interface MiningCoordinator {
boolean isMining();
default void onResumeMining() {}
default void onPauseMining() {}
Wei getMinTransactionGasPrice();
void setExtraData(Bytes extraData);

@ -167,7 +167,6 @@ public class AbstractMiningCoordinatorTest {
when(syncState.isInSync()).thenReturn(true);
miningCoordinator.inSyncChanged(true);
verifyNoMoreInteractions(minerExecutor, blockMiner);
}

Loading…
Cancel
Save