Skip to content

Commit

Permalink
use beneficary of zero on epoch blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jframe committed Feb 11, 2019
1 parent cca4b15 commit f55dddb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.consensus.clique;

import tech.pegasys.pantheon.consensus.common.BlockInterface;
import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.ValidatorVote;
import tech.pegasys.pantheon.consensus.common.VoteType;
import tech.pegasys.pantheon.ethereum.core.Address;
Expand Down Expand Up @@ -58,14 +59,17 @@ public Optional<ValidatorVote> extractVoteFromHeader(final BlockHeader header) {
}

public static BlockHeaderBuilder insertVoteToHeaderBuilder(
final BlockHeaderBuilder builder, final Optional<ValidatorVote> vote) {
if (vote.isPresent()) {
final BlockHeaderBuilder builder,
final EpochManager epochManager,
Optional<ValidatorVote> vote,
final long block) {
if (epochManager.isEpochBlock(block) || !vote.isPresent()) {
builder.nonce(voteToValue.get(VoteType.DROP));
builder.coinbase(NO_VOTE_SUBJECT);
} else {
final ValidatorVote voteToCast = vote.get();
builder.nonce(voteToValue.get(voteToCast.getVotePolarity()));
builder.coinbase(voteToCast.getRecipient());
} else {
builder.nonce(voteToValue.get(VoteType.DROP));
builder.coinbase(NO_VOTE_SUBJECT);
}
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import tech.pegasys.pantheon.consensus.clique.CliqueBlockInterface;
import tech.pegasys.pantheon.consensus.clique.CliqueContext;
import tech.pegasys.pantheon.consensus.clique.CliqueExtraData;
import tech.pegasys.pantheon.consensus.common.EpochManager;
import tech.pegasys.pantheon.consensus.common.ValidatorVote;
import tech.pegasys.pantheon.consensus.common.VoteTally;
import tech.pegasys.pantheon.crypto.SECP256K1;
Expand All @@ -40,6 +41,7 @@
public class CliqueBlockCreator extends AbstractBlockCreator<CliqueContext> {

private final KeyPair nodeKeys;
private final EpochManager epochManager;

public CliqueBlockCreator(
final Address coinbase,
Expand All @@ -50,7 +52,8 @@ public CliqueBlockCreator(
final Function<Long, Long> gasLimitCalculator,
final KeyPair nodeKeys,
final Wei minTransactionGasPrice,
final BlockHeader parentHeader) {
final BlockHeader parentHeader,
final EpochManager epochManager) {
super(
coinbase,
extraDataCalculator,
Expand All @@ -62,6 +65,7 @@ public CliqueBlockCreator(
Util.publicKeyToAddress(nodeKeys.getPublicKey()),
parentHeader);
this.nodeKeys = nodeKeys;
this.epochManager = epochManager;
}

/**
Expand Down Expand Up @@ -93,7 +97,8 @@ protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableB
.getVoteProposer()
.getVote(Util.publicKeyToAddress(nodeKeys.getPublicKey()), voteTally);
final BlockHeaderBuilder builderIncludingProposedVotes =
CliqueBlockInterface.insertVoteToHeaderBuilder(builder, vote);
CliqueBlockInterface.insertVoteToHeaderBuilder(
builder, epochManager, vote, sealableBlockHeader.getNumber());

final CliqueExtraData sealedExtraData =
constructSignedExtraData(builderIncludingProposedVotes.buildBlockHeader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public CliqueBlockMiner startAsyncMining(
(gasLimit) -> gasLimit,
nodeKeys,
minTransactionGasPrice,
parentHeader);
parentHeader,
epochManager);

final CliqueBlockMiner currentRunningMiner =
new CliqueBlockMiner(
Expand Down

0 comments on commit f55dddb

Please sign in to comment.