Skip to content

Commit

Permalink
Remove redundant methods to set the extra data
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <[email protected]>
  • Loading branch information
fab-10 committed May 8, 2024
1 parent da37511 commit 8ff0040
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void setOptionalFields(
// For simplicity only set these for PoW consensus algorithms.
// Other consensus algorithms use these fields for special purposes or ignore them.
miner.setCoinbase(blockData.getCoinbase().orElse(Address.ZERO));
miner.setExtraData(blockData.getExtraData().orElse(Bytes.EMPTY));
controller.getMiningParameters().setExtraData(blockData.getExtraData().orElse(Bytes.EMPTY));
} else if (blockData.getCoinbase().isPresent() || blockData.getExtraData().isPresent()) {
// Fail if these fields are set for non-ethash chains
final Stream.Builder<String> fields = Stream.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void shouldUseLatestVanityData() {
null,
ethScheduler);

executor.setExtraData(modifiedVanityData);
miningParameters.setExtraData(modifiedVanityData);
final Bytes extraDataBytes = executor.calculateExtraData(blockHeaderBuilder.buildHeader());

final CliqueExtraData cliqueExtraData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.CompletableFuture;

import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -108,11 +107,6 @@ public Wei getMinPriorityFeePerGas() {
return activeMiningCoordinator.getMinPriorityFeePerGas();
}

@Override
public void setExtraData(final Bytes extraData) {
activeMiningCoordinator.setExtraData(extraData);
}

@Override
public Optional<Address> getCoinbase() {
return activeMiningCoordinator.getCoinbase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ public BlockCreator create(final BlockHeader parentHeader, final int round) {
ethScheduler);
}

/**
* Sets extra data.
*
* @param extraData the extra data
*/
public void setExtraData(final Bytes extraData) {

miningParameters.setExtraData(extraData.copy());
}

/**
* Sets min transaction gas price.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -154,11 +153,6 @@ public Wei getMinPriorityFeePerGas() {
return blockCreatorFactory.getMinPriorityFeePerGas();
}

@Override
public void setExtraData(final Bytes extraData) {
blockCreatorFactory.setExtraData(extraData);
}

@Override
public Optional<Address> getCoinbase() {
return Optional.of(blockCreatorFactory.getLocalAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.List;
import java.util.function.Consumer;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -162,11 +161,6 @@ public void delegatesToActiveMiningCoordinator() {
coordinator2,
coordinator1);

verifyDelegation(
c -> c.setExtraData(Bytes.EMPTY), GENESIS_BLOCK_NUMBER, coordinator1, coordinator2);
verifyDelegation(
c -> c.setExtraData(Bytes.EMPTY), MIGRATION_BLOCK_NUMBER, coordinator2, coordinator1);

verifyDelegation(
MiningCoordinator::getCoinbase, GENESIS_BLOCK_NUMBER, coordinator1, coordinator2);
verifyDelegation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -89,13 +88,6 @@ public void getsMinTransactionGasPrice() {
assertThat(bftMiningCoordinator.getMinTransactionGasPrice()).isEqualTo(minGasPrice);
}

@Test
public void setsTheExtraData() {
final Bytes extraData = Bytes.fromHexStringLenient("0x1234");
bftMiningCoordinator.setExtraData(extraData);
verify(bftBlockCreatorFactory).setExtraData(extraData);
}

@Test
public void addsNewChainHeadEventWhenNewCanonicalHeadBlockEventReceived() throws Exception {
BlockAddedEvent headAdvancement =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import java.util.function.Supplier;

import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -225,11 +224,6 @@ public Wei getMinPriorityFeePerGas() {
return miningParameters.getMinPriorityFeePerGas();
}

@Override
public void setExtraData(final Bytes extraData) {
this.miningParameters.setExtraData(extraData);
}

@Override
public Optional<Address> getCoinbase() {
return miningParameters.getCoinbase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;

/** The Transition coordinator. */
Expand Down Expand Up @@ -107,12 +106,6 @@ public Wei getMinPriorityFeePerGas() {
return dispatchFunctionAccordingToMergeState(MiningCoordinator::getMinPriorityFeePerGas);
}

@Override
public void setExtraData(final Bytes extraData) {
miningCoordinator.setExtraData(extraData);
mergeCoordinator.setExtraData(extraData);
}

@Override
public Optional<Address> getCoinbase() {
return dispatchFunctionAccordingToMergeState(MiningCoordinator::getCoinbase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -98,10 +97,6 @@ public abstract M createMiner(
final Subscribers<PoWObserver> ethHashObservers,
final BlockHeader parentHeader);

public void setExtraData(final Bytes extraData) {
miningParameters.setExtraData(extraData.copy());
}

public void setMinTransactionGasPrice(final Wei minTransactionGasPrice) {
miningParameters.setMinTransactionGasPrice(minTransactionGasPrice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.tuweni.bytes.Bytes;

public abstract class AbstractMiningCoordinator<
M extends BlockMiner<? extends AbstractBlockCreator>>
implements BlockAddedObserver, MiningCoordinator {
Expand Down Expand Up @@ -212,11 +210,6 @@ public Wei getMinPriorityFeePerGas() {
return executor.getMinPriorityFeePerGas();
}

@Override
public void setExtraData(final Bytes extraData) {
executor.setExtraData(extraData);
}

@Override
public Optional<Address> getCoinbase() {
return executor.getCoinbase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.util.List;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;

public interface MiningCoordinator {

void start();
Expand Down Expand Up @@ -60,8 +58,6 @@ default void onPauseMining() {}

Wei getMinPriorityFeePerGas();

void setExtraData(Bytes extraData);

default void setCoinbase(final Address coinbase) {
throw new UnsupportedOperationException(
"Current consensus mechanism prevents setting coinbase.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.List;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;

public class NoopMiningCoordinator implements MiningCoordinator {

private final MiningParameters miningParameters;
Expand Down Expand Up @@ -68,9 +66,6 @@ public Wei getMinPriorityFeePerGas() {
return miningParameters.getMinPriorityFeePerGas();
}

@Override
public void setExtraData(final Bytes extraData) {}

@Override
public Optional<Address> getCoinbase() {
return miningParameters.getCoinbase();
Expand Down

0 comments on commit 8ff0040

Please sign in to comment.