Skip to content

Commit

Permalink
[MINOR] Rename deposit to depositRequest (hyperledger#7145)
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <[email protected]>
  • Loading branch information
Gabriel-Trintinalia authored May 29, 2024
1 parent fb25f18 commit 2df7216
Show file tree
Hide file tree
Showing 31 changed files with 237 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositRequestParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalRequestParameter;
Expand Down Expand Up @@ -161,12 +161,12 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
reqId, new JsonRpcError(INVALID_PARAMS, "Invalid withdrawals"));
}

final Optional<List<Request>> maybeDeposits =
Optional.ofNullable(blockParam.getDeposits())
.map(ds -> ds.stream().map(DepositParameter::toDeposit).collect(toList()));
final Optional<List<Request>> maybeDepositRequests =
Optional.ofNullable(blockParam.getDepositRequests())
.map(ds -> ds.stream().map(DepositRequestParameter::toDeposit).collect(toList()));
if (!getDepositRequestValidator(
protocolSchedule.get(), blockParam.getTimestamp(), blockParam.getBlockNumber())
.validateParameter(maybeDeposits)) {
.validateParameter(maybeDepositRequests)) {
return new JsonRpcErrorResponse(
reqId, new JsonRpcError(INVALID_PARAMS, "Invalid deposit request"));
}
Expand All @@ -186,7 +186,7 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
}

Optional<List<Request>> maybeRequests =
RequestUtil.combine(maybeDeposits, maybeWithdrawalRequests);
RequestUtil.combine(maybeDepositRequests, maybeWithdrawalRequests);

if (mergeContext.get().isSyncing()) {
LOG.debug("We are syncing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected ValidationResult<RpcErrorType> validateParameters(
} else if (maybeBeaconBlockRootParam.isEmpty()) {
return ValidationResult.invalid(
RpcErrorType.INVALID_PARAMS, "Missing parent beacon block root field");
} else if (payloadParameter.getDeposits() == null) {
} else if (payloadParameter.getDepositRequests() == null) {
return ValidationResult.invalid(RpcErrorType.INVALID_PARAMS, "Missing deposit field");
} else {
return ValidationResult.valid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.hyperledger.besu.datatypes.BLSPublicKey;
import org.hyperledger.besu.datatypes.BLSSignature;
import org.hyperledger.besu.datatypes.GWei;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.DepositRequest;

import java.util.Objects;

Expand All @@ -28,7 +28,7 @@
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;

public class DepositParameter {
public class DepositRequestParameter {

private final String pubkey;

Expand All @@ -39,7 +39,7 @@ public class DepositParameter {
private final String index;

@JsonCreator
public DepositParameter(
public DepositRequestParameter(
@JsonProperty("pubkey") final String pubkey,
@JsonProperty("withdrawalCredentials") final String withdrawalCredentials,
@JsonProperty("amount") final String amount,
Expand All @@ -52,17 +52,17 @@ public DepositParameter(
this.index = index;
}

public static DepositParameter fromDeposit(final Deposit deposit) {
return new DepositParameter(
deposit.getPubkey().toString(),
deposit.getWithdrawalCredentials().toString(),
deposit.getAmount().toShortHexString(),
deposit.getSignature().toString(),
deposit.getIndex().toBytes().toQuantityHexString());
public static DepositRequestParameter fromDeposit(final DepositRequest depositRequest) {
return new DepositRequestParameter(
depositRequest.getPubkey().toString(),
depositRequest.getWithdrawalCredentials().toString(),
depositRequest.getAmount().toShortHexString(),
depositRequest.getSignature().toString(),
depositRequest.getIndex().toBytes().toQuantityHexString());
}

public Deposit toDeposit() {
return new Deposit(
public DepositRequest toDeposit() {
return new DepositRequest(
BLSPublicKey.fromHexString(pubkey),
Bytes32.fromHexString(withdrawalCredentials),
GWei.fromHexString(amount),
Expand Down Expand Up @@ -108,7 +108,7 @@ public String getIndex() {
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final DepositParameter that = (DepositParameter) o;
final DepositRequestParameter that = (DepositRequestParameter) o;
return Objects.equals(pubkey, that.pubkey)
&& Objects.equals(withdrawalCredentials, that.withdrawalCredentials)
&& Objects.equals(amount, that.amount)
Expand All @@ -123,7 +123,7 @@ public int hashCode() {

@Override
public String toString() {
return "DepositParameter{"
return "DepositRequestParameter{"
+ "pubKey='"
+ pubkey
+ '\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class EnginePayloadParameter {
private final List<WithdrawalParameter> withdrawals;
private final Long blobGasUsed;
private final String excessBlobGas;
private final List<DepositParameter> deposits;
private final List<DepositRequestParameter> depositRequests;
private final List<WithdrawalRequestParameter> withdrawalRequests;

/**
Expand All @@ -66,7 +66,7 @@ public class EnginePayloadParameter {
* @param withdrawals Array of Withdrawal
* @param blobGasUsed QUANTITY, 64 Bits
* @param excessBlobGas QUANTITY, 64 Bits
* @param deposits List of deposit parameters.
* @param depositRequests List of deposit parameters.
* @param withdrawalRequestParameters List of withdrawal requests parameters.
*/
@JsonCreator
Expand All @@ -88,7 +88,7 @@ public EnginePayloadParameter(
@JsonProperty("withdrawals") final List<WithdrawalParameter> withdrawals,
@JsonProperty("blobGasUsed") final UnsignedLongParameter blobGasUsed,
@JsonProperty("excessBlobGas") final String excessBlobGas,
@JsonProperty("depositRequests") final List<DepositParameter> deposits,
@JsonProperty("depositRequests") final List<DepositRequestParameter> depositRequests,
@JsonProperty("withdrawalRequests")
final List<WithdrawalRequestParameter> withdrawalRequestParameters) {
this.blockHash = blockHash;
Expand All @@ -108,7 +108,7 @@ public EnginePayloadParameter(
this.withdrawals = withdrawals;
this.blobGasUsed = blobGasUsed == null ? null : blobGasUsed.getValue();
this.excessBlobGas = excessBlobGas;
this.deposits = deposits;
this.depositRequests = depositRequests;
this.withdrawalRequests = withdrawalRequestParameters;
}

Expand Down Expand Up @@ -180,8 +180,8 @@ public String getExcessBlobGas() {
return excessBlobGas;
}

public List<DepositParameter> getDeposits() {
return deposits;
public List<DepositRequestParameter> getDepositRequests() {
return depositRequests;
}

public List<WithdrawalRequestParameter> getWithdrawalRequests() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositRequestParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalRequestParameter;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.DepositRequest;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.core.WithdrawalRequest;

Expand All @@ -42,12 +42,12 @@ public EngineGetPayloadResultV4(
final BlockHeader header,
final List<String> transactions,
final Optional<List<Withdrawal>> withdrawals,
final Optional<List<Deposit>> deposits,
final Optional<List<DepositRequest>> depositRequests,
final Optional<List<WithdrawalRequest>> withdrawalRequests,
final String blockValue,
final BlobsBundleV1 blobsBundle) {
this.executionPayload =
new PayloadResult(header, transactions, withdrawals, deposits, withdrawalRequests);
new PayloadResult(header, transactions, withdrawals, depositRequests, withdrawalRequests);
this.blockValue = blockValue;
this.blobsBundle = blobsBundle;
this.shouldOverrideBuilder = false;
Expand Down Expand Up @@ -94,14 +94,14 @@ public static class PayloadResult {

protected final List<String> transactions;
private final List<WithdrawalParameter> withdrawals;
private final List<DepositParameter> deposits;
private final List<DepositRequestParameter> depositRequests;
private final List<WithdrawalRequestParameter> withdrawalRequests;

public PayloadResult(
final BlockHeader header,
final List<String> transactions,
final Optional<List<Withdrawal>> withdrawals,
final Optional<List<Deposit>> deposits,
final Optional<List<DepositRequest>> depositRequests,
final Optional<List<WithdrawalRequest>> withdrawalRequests) {
this.blockNumber = Quantity.create(header.getNumber());
this.blockHash = header.getHash().toString();
Expand All @@ -125,10 +125,13 @@ public PayloadResult(
.map(WithdrawalParameter::fromWithdrawal)
.collect(Collectors.toList()))
.orElse(null);
this.deposits =
deposits
this.depositRequests =
depositRequests
.map(
ds -> ds.stream().map(DepositParameter::fromDeposit).collect(Collectors.toList()))
ds ->
ds.stream()
.map(DepositRequestParameter::fromDeposit)
.collect(Collectors.toList()))
.orElse(null);
this.withdrawalRequests =
withdrawalRequests
Expand Down Expand Up @@ -216,8 +219,8 @@ public List<WithdrawalParameter> getWithdrawals() {
}

@JsonGetter(value = "depositRequests")
public List<DepositParameter> getDeposits() {
return deposits;
public List<DepositRequestParameter> getDepositRequests() {
return depositRequests;
}

@JsonGetter(value = "withdrawalRequests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public AbstractEngineGetPayloadTest() {
Collections.emptyList(),
Optional.of(Collections.emptyList()),
Optional.empty()));
private static final Block mockBlockWithDeposits =
private static final Block mockBlockWithDepositRequests =
new Block(
mockHeader,
new BlockBody(
Expand All @@ -116,8 +116,8 @@ public AbstractEngineGetPayloadTest() {
protected static final BlockWithReceipts mockBlockWithReceiptsAndWithdrawals =
new BlockWithReceipts(mockBlockWithWithdrawals, Collections.emptyList());

protected static final BlockWithReceipts mockBlockWithReceiptsAndDeposits =
new BlockWithReceipts(mockBlockWithDeposits, Collections.emptyList());
protected static final BlockWithReceipts mockBlockWithReceiptsAndDepositRequests =
new BlockWithReceipts(mockBlockWithDepositRequests, Collections.emptyList());

@Mock protected ProtocolContext protocolContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositRequestParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.EnginePayloadParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
Expand All @@ -54,7 +54,7 @@
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.DepositRequest;
import org.hyperledger.besu.ethereum.core.Request;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.core.WithdrawalRequest;
Expand Down Expand Up @@ -410,7 +410,7 @@ protected EnginePayloadParameter mockEnginePayload(
final BlockHeader header,
final List<String> txs,
final List<WithdrawalParameter> withdrawals,
final List<DepositParameter> deposits,
final List<DepositRequestParameter> depositRequests,
final List<WithdrawalRequestParameter> withdrawalRequests) {
return new EnginePayloadParameter(
header.getHash(),
Expand All @@ -430,18 +430,18 @@ protected EnginePayloadParameter mockEnginePayload(
withdrawals,
header.getBlobGasUsed().map(UnsignedLongParameter::new).orElse(null),
header.getExcessBlobGas().map(BlobGas::toHexString).orElse(null),
deposits,
depositRequests,
withdrawalRequests);
}

protected BlockHeader setupValidPayload(
final BlockProcessingResult value,
final Optional<List<Withdrawal>> maybeWithdrawals,
final Optional<List<Deposit>> maybeDeposits,
final Optional<List<DepositRequest>> maybeDepositRequests,
final Optional<List<WithdrawalRequest>> maybeWithdrawalRequests) {

BlockHeader mockHeader =
createBlockHeader(maybeWithdrawals, maybeDeposits, maybeWithdrawalRequests);
createBlockHeader(maybeWithdrawals, maybeDepositRequests, maybeWithdrawalRequests);
when(blockchain.getBlockByHash(mockHeader.getHash())).thenReturn(Optional.empty());
// when(blockchain.getBlockHeader(mockHeader.getParentHash()))
// .thenReturn(Optional.of(mock(BlockHeader.class)));
Expand Down Expand Up @@ -474,21 +474,21 @@ protected JsonRpcError fromErrorResp(final JsonRpcResponse resp) {

protected BlockHeader createBlockHeader(
final Optional<List<Withdrawal>> maybeWithdrawals,
final Optional<List<Deposit>> maybeDeposits,
final Optional<List<DepositRequest>> maybeDepositRequests,
final Optional<List<WithdrawalRequest>> maybeWithdrawalRequests) {
return createBlockHeaderFixture(maybeWithdrawals, maybeDeposits, maybeWithdrawalRequests)
return createBlockHeaderFixture(maybeWithdrawals, maybeDepositRequests, maybeWithdrawalRequests)
.buildHeader();
}

protected BlockHeaderTestFixture createBlockHeaderFixture(
final Optional<List<Withdrawal>> maybeWithdrawals,
final Optional<List<Deposit>> maybeDeposits,
final Optional<List<DepositRequest>> maybeDepositRequests,
final Optional<List<WithdrawalRequest>> maybeWithdrawalRequests) {

Optional<List<Request>> maybeRequests;
if (maybeDeposits.isPresent() || maybeWithdrawalRequests.isPresent()) {
if (maybeDepositRequests.isPresent() || maybeWithdrawalRequests.isPresent()) {
List<Request> requests = new ArrayList<>();
maybeDeposits.ifPresent(requests::addAll);
maybeDepositRequests.ifPresent(requests::addAll);
maybeWithdrawalRequests.ifPresent(requests::addAll);
maybeRequests = Optional.of(requests);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void before() {
super.before();
lenient()
.when(mergeContext.retrieveBlockById(mockPid))
.thenReturn(Optional.of(mockBlockWithReceiptsAndDeposits));
.thenReturn(Optional.of(mockBlockWithReceiptsAndDepositRequests));
when(protocolContext.safeConsensusContext(Mockito.any())).thenReturn(Optional.of(mergeContext));
this.method =
new EngineGetPayloadV4(
Expand Down Expand Up @@ -146,7 +146,7 @@ public void shouldReturnBlockForKnownPayloadId() {
assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResultV4.class);
final EngineGetPayloadResultV4 res = (EngineGetPayloadResultV4) r.getResult();
assertThat(res.getExecutionPayload().getWithdrawals()).isNotNull();
assertThat(res.getExecutionPayload().getDeposits()).isNotNull();
assertThat(res.getExecutionPayload().getDepositRequests()).isNotNull();
assertThat(res.getExecutionPayload().getWithdrawalRequests()).isNotNull();
assertThat(res.getExecutionPayload().getHash())
.isEqualTo(header.getHash().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.hyperledger.besu.ethereum.core.BlobTestFixture;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.DepositRequest;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionTestFixture;
import org.hyperledger.besu.ethereum.core.Withdrawal;
Expand Down Expand Up @@ -150,7 +150,7 @@ public void shouldValidVersionedHash_whenListIsEmpty() {
@Override
protected BlockHeader createBlockHeader(
final Optional<List<Withdrawal>> maybeWithdrawals,
final Optional<List<Deposit>> maybeDeposits,
final Optional<List<DepositRequest>> maybeDepositRequests,
final Optional<List<WithdrawalRequest>> maybeWithdrawalRequests) {
BlockHeader parentBlockHeader =
new BlockHeaderTestFixture()
Expand Down
Loading

0 comments on commit 2df7216

Please sign in to comment.