Skip to content

Commit

Permalink
fix blobGas serialization
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte committed Mar 1, 2024
1 parent 3b99163 commit b6689c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.hyperledger.besu.services;

import static org.assertj.core.api.Assertions.assertThat;

import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.plugin.data.BlockHeader;

import org.apache.tuweni.bytes.Bytes;
import org.junit.jupiter.api.Test;

public class RlpConverterServiceImplTest {

@Test
public void testBuildRlpFromHeader() {
// Arrange
RlpConverterServiceImpl rlpConverterServiceImpl =
new RlpConverterServiceImpl(ProtocolScheduleFixture.MAINNET);
// header with cancun fields
BlockHeader header =
new BlockHeaderTestFixture()
.timestamp(1710338135 + 1)
.baseFeePerGas(Wei.of(1000))
.depositsRoot(Hash.ZERO)
.withdrawalsRoot(Hash.ZERO)
.blobGasUsed(500L)
.excessBlobGas(BlobGas.of(500L))
.buildHeader();

Bytes rlpBytes = rlpConverterServiceImpl.buildRlpFromHeader(header);
BlockHeader deserialized = rlpConverterServiceImpl.buildHeaderFromRlp(rlpBytes);
// Assert
assertThat(header).isEqualTo(deserialized);
assertThat(header.getBlobGasUsed()).isEqualTo(deserialized.getBlobGasUsed());
assertThat(header.getExcessBlobGas()).isEqualTo(deserialized.getExcessBlobGas());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.math.BigInteger;

import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.BaseUInt64Value;
import org.apache.tuweni.units.bigints.UInt64;
Expand Down Expand Up @@ -123,6 +124,7 @@ public BigInteger getAsBigInteger() {
return toBigInteger();
}

@JsonValue
@Override
public String toHexString() {
return super.toHexString();
Expand All @@ -140,6 +142,6 @@ public String toShortHexString() {
* @return the blob gas
*/
public static BlobGas fromQuantity(final Quantity quantity) {
return BlobGas.wrap((Bytes) quantity);
return BlobGas.of(quantity.getAsBigInteger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public static org.hyperledger.besu.ethereum.core.BlockHeader convertPluginBlockH
.map(h -> Hash.fromHexString(h.toHexString()))
.orElse(null),
pluginBlockHeader.getBlobGasUsed().map(Long::longValue).orElse(null),
pluginBlockHeader.getExcessBlobGas().map(BlobGas::fromQuantity).orElse(null),
pluginBlockHeader.getExcessBlobGas().map(BlobGas.class::cast).orElse(null),
pluginBlockHeader.getParentBeaconBlockRoot().orElse(null),
pluginBlockHeader
.getDepositsRoot()
Expand Down

0 comments on commit b6689c9

Please sign in to comment.