Skip to content

Commit

Permalink
Rename targetBlobCount to targetBlobsPerBlock (#7981)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu authored Dec 4, 2024
1 parent 74929eb commit 1671306
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ public String getParentBeaconBlockRoot() {
}

/**
* Gets target blob count.
* Gets target blobs per block.
*
* @return the target blob count
* @return the target blobs per block
*/
public Optional<String> getTargetBlobCount() {
public Optional<String> getTargetBlobsPerBlock() {
// TODO SLD EIP-7742 not sure if we should use a default value here or enforce any
// "pragueAtGenesis" genesis file (used in devnets) to have this value
return JsonUtil.getValueAsString(genesisRoot, "targetblobcount");
return JsonUtil.getValueAsString(genesisRoot, "targetblobsperblock");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public enum JsonRpcResponseKey {
BASEFEE,
WITHDRAWALS_ROOT,
REQUESTS_HASH,
TARGET_BLOB_COUNT
TARGET_BLOBS_PER_BLOCK
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public JsonRpcResponse response(
values.containsKey(WITHDRAWALS_ROOT) ? hash(values.get(WITHDRAWALS_ROOT)) : null;
final Hash requestsHash =
values.containsKey(REQUESTS_HASH) ? hash(values.get(REQUESTS_HASH)) : null;
final UInt64 targetBlobCount =
values.containsKey(JsonRpcResponseKey.TARGET_BLOB_COUNT)
? UInt64.fromHexString(values.get(JsonRpcResponseKey.TARGET_BLOB_COUNT))
final UInt64 targetBlobsPerBlock =
values.containsKey(JsonRpcResponseKey.TARGET_BLOBS_PER_BLOCK)
? UInt64.fromHexString(values.get(JsonRpcResponseKey.TARGET_BLOBS_PER_BLOCK))
: null;
final List<JsonNode> ommers = new ArrayList<>();

Expand All @@ -136,7 +136,7 @@ public JsonRpcResponse response(
null, // ToDo 4844: set with the value of excess_blob_gas field
null, // TODO 4788: set with the value of the parent beacon block root field
requestsHash,
targetBlobCount,
targetBlobsPerBlock,
blockHeaderFunctions);

return new JsonRpcSuccessResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class BlockResult implements JsonRpcResult {
private final String blobGasUsed;
private final String excessBlobGas;
private final String parentBeaconBlockRoot;
private final String targetBlobCount;
private final String targetBlobsPerBlock;

public BlockResult(
final BlockHeader header,
Expand Down Expand Up @@ -139,7 +139,7 @@ public BlockResult(
this.excessBlobGas = header.getExcessBlobGas().map(Quantity::create).orElse(null);
this.parentBeaconBlockRoot =
header.getParentBeaconBlockRoot().map(Bytes32::toHexString).orElse(null);
this.targetBlobCount = header.getTargetBlobCount().map(Quantity::create).orElse(null);
this.targetBlobsPerBlock = header.getTargetBlobsPerBlock().map(Quantity::create).orElse(null);
}

@JsonGetter(value = "number")
Expand Down Expand Up @@ -278,8 +278,8 @@ public String getParentBeaconBlockRoot() {
return parentBeaconBlockRoot;
}

@JsonGetter(value = "targetBlobCount")
public String getTargetBlobCount() {
return targetBlobCount;
@JsonGetter(value = "targetBlobsPerBlock")
public String getTargetBlobsPerBlock() {
return targetBlobsPerBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ private static BlockHeader buildHeader(
.parentBeaconBlockRoot(
(isCancunAtGenesis(genesis) ? parseParentBeaconBlockRoot(genesis) : null))
.requestsHash(isPragueAtGenesis(genesis) ? Hash.EMPTY_REQUESTS_HASH : null)
.targetBlobCount(
.targetBlobsPerBlock(
isPragueAtGenesis(genesis)
// TODO SLD EIP-7742 Currently defaulting to null due to dependency on web3j
// BlockHeader in CodeDelegationTransactionAcceptanceTest
? genesis.getTargetBlobCount().map(UInt64::fromHexString).orElse(null)
? genesis.getTargetBlobsPerBlock().map(UInt64::fromHexString).orElse(null)
: null)
.buildBlockHeader();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BlockHeader(
final BlobGas excessBlobGas,
final Bytes32 parentBeaconBlockRoot,
final Hash requestsHash,
final UInt64 targetBlobCount,
final UInt64 targetBlobsPerBlock,
final BlockHeaderFunctions blockHeaderFunctions) {
super(
parentHash,
Expand All @@ -89,7 +89,7 @@ public BlockHeader(
excessBlobGas,
parentBeaconBlockRoot,
requestsHash,
targetBlobCount);
targetBlobsPerBlock);
this.nonce = nonce;
this.hash = Suppliers.memoize(() -> blockHeaderFunctions.hash(this));
this.parsedExtraData = Suppliers.memoize(() -> blockHeaderFunctions.parseExtraData(this));
Expand Down Expand Up @@ -191,8 +191,8 @@ public void writeTo(final RLPOutput out) {
if (requestsHash == null) break;
out.writeBytes(requestsHash);

if (targetBlobCount == null) break;
out.writeUInt64Scalar(targetBlobCount);
if (targetBlobsPerBlock == null) break;
out.writeUInt64Scalar(targetBlobsPerBlock);
} while (false);
out.endList();
}
Expand Down Expand Up @@ -225,7 +225,8 @@ public static BlockHeader readFrom(
!input.isEndOfCurrentList() ? BlobGas.of(input.readUInt64Scalar()) : null;
final Bytes32 parentBeaconBlockRoot = !input.isEndOfCurrentList() ? input.readBytes32() : null;
final Hash requestsHash = !input.isEndOfCurrentList() ? Hash.wrap(input.readBytes32()) : null;
final UInt64 targetBlobCount = !input.isEndOfCurrentList() ? input.readUInt64Scalar() : null;
final UInt64 targetBlobsPerBlock =
!input.isEndOfCurrentList() ? input.readUInt64Scalar() : null;
input.leaveList();
return new BlockHeader(
parentHash,
Expand All @@ -249,7 +250,7 @@ public static BlockHeader readFrom(
excessBlobGas,
parentBeaconBlockRoot,
requestsHash,
targetBlobCount,
targetBlobsPerBlock,
blockHeaderFunctions);
}

Expand Down Expand Up @@ -303,8 +304,8 @@ public String toString() {
if (requestsHash != null) {
sb.append("requestsHash=").append(requestsHash);
}
if (targetBlobCount != null) {
sb.append("targetBlobCount=").append(targetBlobCount);
if (targetBlobsPerBlock != null) {
sb.append("targetBlobsPerBlock=").append(targetBlobsPerBlock);
}
return sb.append("}").toString();
}
Expand Down Expand Up @@ -340,7 +341,7 @@ public static org.hyperledger.besu.ethereum.core.BlockHeader convertPluginBlockH
.getRequestsHash()
.map(h -> Hash.fromHexString(h.toHexString()))
.orElse(null),
pluginBlockHeader.getTargetBlobCount().orElse(null),
pluginBlockHeader.getTargetBlobsPerBlock().orElse(null),
blockHeaderFunctions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class BlockHeaderBuilder {
private Long blobGasUsed = null;
private BlobGas excessBlobGas = null;
private Bytes32 parentBeaconBlockRoot = null;
private UInt64 targetBlobCount = null;
private UInt64 targetBlobsPerBlock = null;

public static BlockHeaderBuilder create() {
return new BlockHeaderBuilder();
Expand Down Expand Up @@ -127,7 +127,7 @@ public static BlockHeaderBuilder fromHeader(final BlockHeader header) {
.excessBlobGas(header.getExcessBlobGas().orElse(null))
.parentBeaconBlockRoot(header.getParentBeaconBlockRoot().orElse(null))
.requestsHash(header.getRequestsHash().orElse(null))
.targetBlobCount(header.getTargetBlobCount().orElse(null));
.targetBlobsPerBlock(header.getTargetBlobsPerBlock().orElse(null));
}

public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilder) {
Expand All @@ -152,7 +152,7 @@ public static BlockHeaderBuilder fromBuilder(final BlockHeaderBuilder fromBuilde
.excessBlobGas(fromBuilder.excessBlobGas)
.parentBeaconBlockRoot(fromBuilder.parentBeaconBlockRoot)
.requestsHash(fromBuilder.requestsHash)
.targetBlobCount(fromBuilder.targetBlobCount)
.targetBlobsPerBlock(fromBuilder.targetBlobsPerBlock)
.blockHeaderFunctions(fromBuilder.blockHeaderFunctions);
toBuilder.nonce = fromBuilder.nonce;
return toBuilder;
Expand Down Expand Up @@ -183,7 +183,7 @@ public BlockHeader buildBlockHeader() {
excessBlobGas,
parentBeaconBlockRoot,
requestsHash,
targetBlobCount,
targetBlobsPerBlock,
blockHeaderFunctions);
}

Expand All @@ -200,7 +200,7 @@ public ProcessableBlockHeader buildProcessableBlockHeader() {
baseFee,
mixHashOrPrevRandao,
parentBeaconBlockRoot,
targetBlobCount);
targetBlobsPerBlock);
}

public SealableBlockHeader buildSealableBlockHeader() {
Expand All @@ -227,7 +227,7 @@ public SealableBlockHeader buildSealableBlockHeader() {
excessBlobGas,
parentBeaconBlockRoot,
requestsHash,
targetBlobCount);
targetBlobsPerBlock);
}

private void validateBlockHeader() {
Expand Down Expand Up @@ -267,7 +267,7 @@ public BlockHeaderBuilder populateFrom(final ProcessableBlockHeader processableB
baseFee(processableBlockHeader.getBaseFee().orElse(null));
processableBlockHeader.getPrevRandao().ifPresent(this::prevRandao);
processableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot);
processableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount);
processableBlockHeader.getTargetBlobsPerBlock().ifPresent(this::targetBlobsPerBlock);
return this;
}

Expand All @@ -293,7 +293,7 @@ public BlockHeaderBuilder populateFrom(final SealableBlockHeader sealableBlockHe
sealableBlockHeader.getExcessBlobGas().ifPresent(this::excessBlobGas);
sealableBlockHeader.getParentBeaconBlockRoot().ifPresent(this::parentBeaconBlockRoot);
requestsHash(sealableBlockHeader.getRequestsHash().orElse(null));
sealableBlockHeader.getTargetBlobCount().ifPresent(this::targetBlobCount);
sealableBlockHeader.getTargetBlobsPerBlock().ifPresent(this::targetBlobsPerBlock);
return this;
}

Expand Down Expand Up @@ -428,8 +428,8 @@ public BlockHeaderBuilder parentBeaconBlockRoot(final Bytes32 parentBeaconBlockR
return this;
}

public BlockHeaderBuilder targetBlobCount(final UInt64 targetBlobCount) {
this.targetBlobCount = targetBlobCount;
public BlockHeaderBuilder targetBlobsPerBlock(final UInt64 targetBlobsPerBlock) {
this.targetBlobsPerBlock = targetBlobsPerBlock;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ProcessableBlockHeader
// parentBeaconBlockRoot is included for Cancun
protected final Bytes32 parentBeaconBlockRoot;
// TODO SLD Quantity or UInt64Value<UInt64> instead?
protected final UInt64 targetBlobCount;
protected final UInt64 targetBlobsPerBlock;

protected ProcessableBlockHeader(
final Hash parentHash,
Expand All @@ -60,7 +60,7 @@ protected ProcessableBlockHeader(
final Wei baseFee,
final Bytes32 mixHashOrPrevRandao,
final Bytes32 parentBeaconBlockRoot,
final UInt64 targetBlobCount) {
final UInt64 targetBlobsPerBlock) {
this.parentHash = parentHash;
this.coinbase = coinbase;
this.difficulty = difficulty;
Expand All @@ -70,7 +70,7 @@ protected ProcessableBlockHeader(
this.baseFee = baseFee;
this.mixHashOrPrevRandao = mixHashOrPrevRandao;
this.parentBeaconBlockRoot = parentBeaconBlockRoot;
this.targetBlobCount = targetBlobCount;
this.targetBlobsPerBlock = targetBlobsPerBlock;
}

/**
Expand Down Expand Up @@ -184,13 +184,13 @@ public Optional<Bytes32> getParentBeaconBlockRoot() {
}

/**
* Returns the target blob count if available.
* Returns the target blobs per block if available.
*
* @return the target blob count if available.
* @return the target blobs per block if available.
*/
@Override
public Optional<UInt64> getTargetBlobCount() {
return Optional.ofNullable(targetBlobCount);
public Optional<UInt64> getTargetBlobsPerBlock() {
return Optional.ofNullable(targetBlobsPerBlock);
}

public String toLogString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected SealableBlockHeader(
final BlobGas excessBlobGas,
final Bytes32 parentBeaconBlockRoot,
final Hash requestsHash,
final UInt64 targetBlobCount) {
final UInt64 targetBlobsPerBlock) {
super(
parentHash,
coinbase,
Expand All @@ -82,7 +82,7 @@ protected SealableBlockHeader(
baseFee,
mixHashOrPrevRandao,
parentBeaconBlockRoot,
targetBlobCount);
targetBlobsPerBlock);
this.ommersHash = ommersHash;
this.stateRoot = stateRoot;
this.transactionsRoot = transactionsRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class BlockHeaderTestFixture {
private Optional<BlobGas> excessBlobGas = Optional.empty();
private Optional<Long> blobGasUsed = Optional.empty();
private Optional<Bytes32> parentBeaconBlockRoot = Optional.empty();
private Optional<UInt64> targetBlobCount = Optional.empty();
private Optional<UInt64> targetBlobsPerBlock = Optional.empty();

public BlockHeader buildHeader() {
final BlockHeaderBuilder builder = BlockHeaderBuilder.create();
Expand All @@ -82,7 +82,7 @@ public BlockHeader buildHeader() {
blobGasUsed.ifPresent(builder::blobGasUsed);
requestsHash.ifPresent(builder::requestsHash);
parentBeaconBlockRoot.ifPresent(builder::parentBeaconBlockRoot);
targetBlobCount.ifPresent(builder::targetBlobCount);
targetBlobsPerBlock.ifPresent(builder::targetBlobsPerBlock);
builder.blockHeaderFunctions(blockHeaderFunctions);

return builder.buildBlockHeader();
Expand Down Expand Up @@ -205,8 +205,8 @@ public BlockHeaderTestFixture parentBeaconBlockRoot(
return this;
}

public BlockHeaderTestFixture targetBlobCount(final UInt64 targetBlobCount) {
this.targetBlobCount = Optional.of(targetBlobCount);
public BlockHeaderTestFixture targetBlobsPerBlock(final UInt64 targetBlobsPerBlock) {
this.targetBlobsPerBlock = Optional.of(targetBlobsPerBlock);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ void genesisFromPrague(final DataStorageConfiguration dataStorageConfiguration)
.isEqualTo(
Hash.fromHexString(
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
assertThat(header.getTargetBlobCount().isPresent()).isTrue();
assertThat(header.getTargetBlobCount().get()).isEqualTo(UInt64.ONE);
assertThat(header.getTargetBlobsPerBlock().isPresent()).isTrue();
assertThat(header.getTargetBlobsPerBlock().get()).isEqualTo(UInt64.ONE);

assertThat(header.getHash())
.isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4074,5 +4074,5 @@
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x3b9aca00",
"targetBlobCount": "0x1"
"targetBlobsPerBlock": "0x1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static BlockHeader prepareWrongParentHash(final BlockHeader blockHeader)
blockHeader.getExcessBlobGas().orElse(null),
blockHeader.getParentBeaconBlockRoot().orElse(null),
blockHeader.getRequestsHash().orElse(null),
blockHeader.getTargetBlobCount().orElse(null),
blockHeader.getTargetBlobsPerBlock().orElse(null),
new MainnetBlockHeaderFunctions());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public ReferenceTestBlockHeader(
excessBlobGas != null ? BlobGas.fromHexString(excessBlobGas) : null,
parentBeaconBlockRoot != null ? Bytes32.fromHexString(parentBeaconBlockRoot) : null,
requestsHash != null ? Hash.fromHexString(requestsHash) : null,
null, // TODO SLD EIP-7742 use targetBlobCount when reference tests are updated
null, // TODO SLD EIP-7742 use targetBlobsPerBlock when reference tests are updated
new BlockHeaderFunctions() {
@Override
public Hash hash(final BlockHeader header) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public ReferenceTestEnv(
currentExcessBlobGas == null ? null : BlobGas.of(Long.decode(currentExcessBlobGas)),
beaconRoot == null ? null : Bytes32.fromHexString(beaconRoot),
null, // requestsHash
null, // TODO SLD EIP-7742 use targetBlobCount when reference tests are updated
null, // TODO SLD EIP-7742 use targetBlobsPerBlock when reference tests are updated
new MainnetBlockHeaderFunctions());
this.parentDifficulty = parentDifficulty;
this.parentBaseFee = parentBaseFee;
Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'dkhT5PziIX6nhIRA4EghMEGKkEB7NTAyqRaKDcAidKc='
knownHash = 'dsbVupAvtmZlEeEeVDtk+VrzGFvyKxHgQntaMtOq5TY='
}
check.dependsOn('checkAPIChanges')

Expand Down
Loading

0 comments on commit 1671306

Please sign in to comment.