Skip to content

Commit

Permalink
7582: Back out withdrawal changes
Browse files Browse the repository at this point in the history
Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke committed Dec 12, 2024
1 parent 2fb60f8 commit 7738076
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

import java.util.Objects;
import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;
Expand All @@ -33,24 +32,13 @@ public class Withdrawal implements org.hyperledger.besu.plugin.data.Withdrawal {
private final UInt64 validatorIndex;
private final Address address;
private final GWei amount;
private final Optional<Bytes> rawRlp;

public Withdrawal(
final UInt64 index, final UInt64 validatorIndex, final Address address, final GWei amount) {
this(index, validatorIndex, address, amount, Optional.empty());
}

public Withdrawal(
final UInt64 index,
final UInt64 validatorIndex,
final Address address,
final GWei amount,
final Optional<Bytes> rawRlp) {
this.index = index;
this.validatorIndex = validatorIndex;
this.address = address;
this.amount = amount;
this.rawRlp = rawRlp;
}

public static Withdrawal readFrom(final Bytes rlpBytes) {
Expand Down Expand Up @@ -85,10 +73,6 @@ public GWei getAmount() {
return amount;
}

public Optional<Bytes> getRawRlp() {
return rawRlp;
}

@Override
public String toString() {
return "Withdrawal{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@
import org.hyperledger.besu.ethereum.rlp.RLP;
import org.hyperledger.besu.ethereum.rlp.RLPInput;

import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;

public class WithdrawalDecoder {

public static Withdrawal decode(final RLPInput rlpInput) {
final RLPInput withdrawalRlp = rlpInput.readAsRlp();
withdrawalRlp.enterList();
final UInt64 index = UInt64.valueOf(withdrawalRlp.readBigIntegerScalar());
final UInt64 validatorIndex = UInt64.valueOf(withdrawalRlp.readBigIntegerScalar());
final Address address = Address.readFrom(withdrawalRlp);
final GWei amount = GWei.of(withdrawalRlp.readUInt64Scalar());
withdrawalRlp.leaveList();
rlpInput.enterList();
final UInt64 index = UInt64.valueOf(rlpInput.readBigIntegerScalar());
final UInt64 validatorIndex = UInt64.valueOf(rlpInput.readBigIntegerScalar());
final Address address = Address.readFrom(rlpInput);
final GWei amount = GWei.of(rlpInput.readUInt64Scalar());
rlpInput.leaveList();

return new Withdrawal(index, validatorIndex, address, amount, Optional.of(withdrawalRlp.raw()));
return new Withdrawal(index, validatorIndex, address, amount);
}

public static Withdrawal decodeOpaqueBytes(final Bytes input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
public class WithdrawalEncoder {

public static void encode(final Withdrawal withdrawal, final RLPOutput rlpOutput) {
withdrawal
.getRawRlp()
.ifPresentOrElse(
rlpOutput::writeRLPBytes,
() -> {
rlpOutput.startList();
rlpOutput.writeBigIntegerScalar(withdrawal.getIndex().toBigInteger());
rlpOutput.writeBigIntegerScalar(withdrawal.getValidatorIndex().toBigInteger());
rlpOutput.writeBytes(withdrawal.getAddress());
rlpOutput.writeUInt64Scalar(withdrawal.getAmount());
rlpOutput.endList();
});
rlpOutput.startList();
rlpOutput.writeBigIntegerScalar(withdrawal.getIndex().toBigInteger());
rlpOutput.writeBigIntegerScalar(withdrawal.getValidatorIndex().toBigInteger());
rlpOutput.writeBytes(withdrawal.getAddress());
rlpOutput.writeUInt64Scalar(withdrawal.getAmount());
rlpOutput.endList();
}

public static Bytes encodeOpaqueBytes(final Withdrawal withdrawal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,5 @@ void shouldDecodeWithdrawal() {
Bytes.fromHexString("0xd803019400000000000000000000000000000000deadbeef05"));

assertThat(withdrawal).isEqualTo(expectedWithdrawal);
assertThat(withdrawal.getRawRlp().get())
.isEqualTo(Bytes.fromHexString("0xd803019400000000000000000000000000000000deadbeef05"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.hyperledger.besu.datatypes.GWei;
import org.hyperledger.besu.ethereum.core.Withdrawal;

import java.util.Optional;

import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -60,25 +58,4 @@ void shouldEncode() {
assertThat(encoded)
.isEqualTo(Bytes.fromHexString("0xd803019400000000000000000000000000000000deadbeef05"));
}

@Test
public void shouldEncodeFromRawRlp() {
final UInt64 index = UInt64.valueOf(1);
final UInt64 validatorIndex = UInt64.valueOf(2);
final Address address = Address.fromHexString("0xffffffff");
final GWei amount = GWei.of(3);
final Withdrawal withdrawal =
new Withdrawal(
index,
validatorIndex,
address,
amount,
Optional.of(
Bytes.fromHexString("0xd803019400000000000000000000000000000000deadbeef05")));

final Bytes encoded = WithdrawalEncoder.encodeOpaqueBytes(withdrawal);

assertThat(encoded)
.isEqualTo(Bytes.fromHexString("0xd803019400000000000000000000000000000000deadbeef05"));
}
}

0 comments on commit 7738076

Please sign in to comment.