Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

RevertReason changed to BytesValue #1746

Merged
merged 37 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
639b410
RevertReason changed to BytesValue
Jul 24, 2019
8bd82ae
post review
Jul 25, 2019
20f4316
Added static nodes acceptance test (#1745)
lucassaldanha Jul 24, 2019
a85980a
update vertx to 2.8.0 (#1748)
Jul 24, 2019
5b78518
Reduce number of builds retained for master (#1751)
ajsutton Jul 24, 2019
5c67f04
PIE-1792: Added chainId validation to PrivateTransactionValidator (#1…
lucassaldanha Jul 24, 2019
2f9818a
Added note about private transaction nonce (#1740)
MadelineMurray Jul 25, 2019
c3bf607
[PAN-2950] Use java.time.Clock instead of System.currentTimeMillis() …
Jul 25, 2019
09fb64c
Report node local address as the coinbase in Clique and IBFT. (#1758)
ajsutton Jul 25, 2019
fbb8736
Renamed HA section to make clearer what it is (#1750)
MadelineMurray Jul 25, 2019
e88de17
[PAN-2845] Added eea_getPrivateTransaction (#1729)
MadelineMurray Jul 25, 2019
8e6364d
Fixes PIE-1669 typo (#1763)
sgregglives Jul 25, 2019
6c07566
[PAN-2943] Renames various eea methods to priv methods, with associat…
josh-richardson Jul 25, 2019
ec7cfa0
[PAN-2727] Permissioning Acceptance Test - Verify OnChain Nodes Out o…
usmansaleem Jul 26, 2019
825242a
PAN-2723: Testing permissioning with static nodes behaviour (#1764)
lucassaldanha Jul 26, 2019
e38bec0
trying to fix stuff
Jul 26, 2019
a118716
Fixed RevertReasonAT
Jul 26, 2019
66d2b2d
Cleanup
Jul 26, 2019
d7af3d4
not sure what this one is about
Jul 26, 2019
ae80d96
repair empty revert reason
Jul 26, 2019
6bf9ff5
fixes PAN-2958 list typo (missing new line) (#1742)
NicolasMassart Jul 26, 2019
35278e7
Revert "[PAN-2950] Use java.time.Clock instead of System.currentTimeM…
Jul 26, 2019
168dcf4
[PAN-2444] Add CLI flag for setting WorldStateDownloader task cache …
Jul 26, 2019
b439d7f
Moved priv methods into priv section (#1770)
MadelineMurray Jul 27, 2019
7082eb4
[PAN-2881] [PAN-2885] Updated onchain permissioning to include accoun…
MadelineMurray Jul 27, 2019
c5f6a0a
Added privacy group methods for web3.js-eea (#1761)
MadelineMurray Jul 27, 2019
89a39a2
[PAN-2957] Add Java 11+ as a prerequisite for installing Pantheon usi…
bgravenorst Jul 27, 2019
6412d95
Updated revert reason example (#1754)
MadelineMurray Jul 27, 2019
5f4b5be
Typo doc in word "exceptoinal" (#1767)
helderjnpinto Jul 29, 2019
4c7b677
Added content on deploying for production (#1774)
MadelineMurray Jul 29, 2019
8e9bd85
Repaired empty revert reason output
Jul 29, 2019
4ed31e8
Merge remote-tracking branch 'upstream/master' into revert
Jul 29, 2019
ec7b1bf
Transaction receipt inserts 0x for empty revert reason
Jul 29, 2019
58b75cc
Merge remote-tracking branch 'upstream/master' into revert
Jul 29, 2019
e64e574
Repair failing AT
Jul 29, 2019
98fe982
Merge branch 'master' into revert
rain-on Jul 30, 2019
0ae3d4c
Merge branch 'master' into revert
rain-on Jul 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -46,7 +45,7 @@ public class TransactionReceipt {
private final LogsBloomFilter bloomFilter;
private final int status;
private final TransactionReceiptType transactionReceiptType;
private final Optional<String> revertReason;
private final Optional<BytesValue> revertReason;

/**
* Creates an instance of a state root-encoded transaction receipt.
Expand All @@ -60,7 +59,7 @@ public TransactionReceipt(
final Hash stateRoot,
final long cumulativeGasUsed,
final List<Log> logs,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this(
stateRoot,
NONEXISTENT,
Expand All @@ -75,7 +74,7 @@ private TransactionReceipt(
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this(stateRoot, NONEXISTENT, cumulativeGasUsed, logs, bloomFilter, revertReason);
}

Expand All @@ -91,7 +90,7 @@ public TransactionReceipt(
final int status,
final long cumulativeGasUsed,
final List<Log> logs,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this(null, status, cumulativeGasUsed, logs, LogsBloomFilter.compute(logs), revertReason);
}

Expand All @@ -100,7 +99,7 @@ private TransactionReceipt(
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this(null, status, cumulativeGasUsed, logs, bloomFilter, revertReason);
}

Expand All @@ -110,7 +109,7 @@ private TransactionReceipt(
final long cumulativeGasUsed,
final List<Log> logs,
final LogsBloomFilter bloomFilter,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this.stateRoot = stateRoot;
this.cumulativeGasUsed = cumulativeGasUsed;
this.status = status;
Expand Down Expand Up @@ -148,7 +147,7 @@ private void writeTo(final RLPOutput out, final boolean withRevertReason) {
out.writeBytesValue(bloomFilter.getBytes());
out.writeList(logs, Log::writeTo);
if (withRevertReason && revertReason.isPresent()) {
out.writeBytesValue(BytesValue.wrap(revertReason.get().getBytes(StandardCharsets.UTF_8)));
out.writeBytesValue(revertReason.get());
}
out.endList();
}
Expand Down Expand Up @@ -182,15 +181,14 @@ public static TransactionReceipt readFrom(
// TODO consider validating that the logs and bloom filter match.
final LogsBloomFilter bloomFilter = LogsBloomFilter.readFrom(input);
final List<Log> logs = input.readList(Log::readFrom);
final Optional<String> revertReason;
final Optional<BytesValue> revertReason;
if (input.isEndOfCurrentList()) {
revertReason = Optional.empty();
} else {
if (!revertReasonAllowed) {
throw new RLPException("Unexpected value at end of TransactionReceipt");
}
final byte[] bytes = input.readBytesValue().getArrayUnsafe();
revertReason = Optional.of(new String(bytes, StandardCharsets.UTF_8));
revertReason = Optional.of(input.readBytesValue());
}

// Status code-encoded transaction receipts have a single
Expand Down Expand Up @@ -256,7 +254,7 @@ public TransactionReceiptType getTransactionReceiptType() {
return transactionReceiptType;
}

public Optional<String> getRevertReason() {
public Optional<BytesValue> getRevertReason() {
return revertReason;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.vm.ExceptionalHaltReason;
import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

import java.util.EnumSet;
Expand All @@ -34,7 +35,7 @@ public class TraceFrame {
private final Optional<Bytes32[]> stack;
private final Optional<Bytes32[]> memory;
private final Optional<Map<UInt256, UInt256>> storage;
private final String revertReason;
private final BytesValue revertReason;

public TraceFrame(
final int pc,
Expand All @@ -46,7 +47,7 @@ public TraceFrame(
final Optional<Bytes32[]> stack,
final Optional<Bytes32[]> memory,
final Optional<Map<UInt256, UInt256>> storage,
final String revertReason) {
final BytesValue revertReason) {
this.pc = pc;
this.opcode = opcode;
this.gasRemaining = gasRemaining;
Expand Down Expand Up @@ -118,7 +119,7 @@ public Optional<Map<UInt256, UInt256>> getStorage() {
return storage;
}

public String getRevertReason() {
public BytesValue getRevertReason() {
return revertReason;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static class Result implements TransactionProcessor.Result {
private final BytesValue output;

private final ValidationResult<TransactionInvalidReason> validationResult;
private final Optional<String> revertReason;
private final Optional<BytesValue> revertReason;

public static Result invalid(
final ValidationResult<TransactionInvalidReason> validationResult) {
Expand All @@ -80,7 +80,7 @@ public static Result invalid(
public static Result failed(
final long gasRemaining,
final ValidationResult<TransactionInvalidReason> validationResult,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
return new Result(
Status.FAILED,
LogSeries.empty(),
Expand All @@ -105,7 +105,7 @@ public static Result successful(
final long gasRemaining,
final BytesValue output,
final ValidationResult<TransactionInvalidReason> validationResult,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this.status = status;
this.logs = logs;
this.gasRemaining = gasRemaining;
Expand Down Expand Up @@ -140,7 +140,7 @@ public ValidationResult<TransactionInvalidReason> getValidationResult() {
}

@Override
public Optional<String> getRevertReason() {
public Optional<BytesValue> getRevertReason() {
return revertReason;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ default boolean isSuccessful() {
*
* @return the revert reason.
*/
Optional<String> getRevertReason();
Optional<BytesValue> getRevertReason();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static class Result implements TransactionProcessor.Result {
private final BytesValue output;

private final ValidationResult<TransactionInvalidReason> validationResult;
private final Optional<String> revertReason;
private final Optional<BytesValue> revertReason;

public static Result invalid(
final ValidationResult<TransactionInvalidReason> validationResult) {
Expand All @@ -88,7 +88,7 @@ public static Result invalid(
public static Result failed(
final long gasRemaining,
final ValidationResult<TransactionInvalidReason> validationResult,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
return new Result(
Status.FAILED,
LogSeries.empty(),
Expand All @@ -113,7 +113,7 @@ public static Result successful(
final long gasRemaining,
final BytesValue output,
final ValidationResult<TransactionInvalidReason> validationResult,
final Optional<String> revertReason) {
final Optional<BytesValue> revertReason) {
this.status = status;
this.logs = logs;
this.gasRemaining = gasRemaining;
Expand Down Expand Up @@ -148,7 +148,7 @@ public ValidationResult<TransactionInvalidReason> getValidationResult() {
}

@Override
public Optional<String> getRevertReason() {
public Optional<BytesValue> getRevertReason() {
return revertReason;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public enum Type {
private final Deque<MessageFrame> messageFrameStack;
private final Address miningBeneficiary;
private final Boolean isPersistingState;
private Optional<String> revertReason;
private Optional<BytesValue> revertReason;

// Miscellaneous fields.
private final EnumSet<ExceptionalHaltReason> exceptionalHaltReasons =
Expand Down Expand Up @@ -254,7 +254,7 @@ private MessageFrame(
final Address miningBeneficiary,
final BlockHashLookup blockHashLookup,
final Boolean isPersistingState,
final Optional<String> revertReason,
final Optional<BytesValue> revertReason,
final int maxStackSize) {
this.type = type;
this.blockchain = blockchain;
Expand Down Expand Up @@ -511,11 +511,11 @@ public UInt256 memoryWordSize() {
*
* @return the revertReason string
*/
public Optional<String> getRevertReason() {
public Optional<BytesValue> getRevertReason() {
return revertReason;
}

public void setRevertReason(final String revertReason) {
public void setRevertReason(final BytesValue revertReason) {
this.revertReason = Optional.ofNullable(revertReason);
}

Expand Down Expand Up @@ -879,7 +879,7 @@ public static class Builder {
private Address miningBeneficiary;
private BlockHashLookup blockHashLookup;
private Boolean isPersistingState = false;
private Optional<String> reason = Optional.empty();
private Optional<BytesValue> reason = Optional.empty();

public Builder type(final Type type) {
this.type = type;
Expand Down Expand Up @@ -997,7 +997,7 @@ public Builder isPersistingState(final Boolean isPersistingState) {
return this;
}

public Builder reason(final String reason) {
public Builder reason(final BytesValue reason) {
this.reason = Optional.ofNullable(reason);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.uint.UInt256;

import java.nio.charset.Charset;

public class RevertOperation extends AbstractOperation {
private static final Charset CHARSET = Charset.forName("UTF-8");

public RevertOperation(final GasCalculator gasCalculator) {
super(0xFD, "REVERT", 2, 0, false, 1, gasCalculator);
Expand All @@ -42,8 +39,7 @@ public void execute(final MessageFrame frame) {
final UInt256 length = frame.popStackItem().asUInt256();
BytesValue reason = frame.readMemory(from, length);
frame.setOutputData(reason);
String reasonMessage = new String(reason.extractArray(), CHARSET);
frame.setRevertReason(reasonMessage);
frame.setRevertReason(reason);
frame.setState(MessageFrame.State.REVERT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public TransactionReceipt receipt(final long cumulativeGasUsed) {
hash(), cumulativeGasUsed, Arrays.asList(log(), log()), Optional.empty());
}

public TransactionReceipt receipt(final String revertReason) {
public TransactionReceipt receipt(final BytesValue revertReason) {
return new TransactionReceipt(
hash(), positiveLong(), Arrays.asList(log(), log()), Optional.of(revertReason));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.junit.Assert.assertEquals;

import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import org.junit.Test;

Expand All @@ -32,7 +33,7 @@ public void toFromRlp() {
@Test
public void toFromRlpWithReason() {
final BlockDataGenerator gen = new BlockDataGenerator();
final TransactionReceipt receipt = gen.receipt("RevertReason");
final TransactionReceipt receipt = gen.receipt(BytesValue.fromHexString("0x1122334455667788"));
final TransactionReceipt copy =
TransactionReceipt.readFrom(RLP.input(RLP.encode(receipt::writeToWithRevertReason)));
assertEquals(receipt, copy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
package tech.pegasys.pantheon.ethereum.vm.operations;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import tech.pegasys.pantheon.ethereum.mainnet.ConstantinopleGasCalculator;
Expand All @@ -26,47 +24,33 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(Parameterized.class)
@RunWith(MockitoJUnitRunner.class)
public class RevertOperationTest {

private final String code;

private final MessageFrame messageFrame = mock(MessageFrame.class);
@Mock private MessageFrame messageFrame;
private final RevertOperation operation = new RevertOperation(new ConstantinopleGasCalculator());

@Parameters(name = "sender: {0}, salt: {1}, code: {2}")
public static Object[][] params() {
return new Object[][] {
{
"0x6c726576657274656420646174616000557f726576657274206d657373616765000000000000000000000000000000000000600052600e6000fd",
}
};
}

public RevertOperationTest(final String code) {
this.code = code;
}
private final BytesValue revertReasonBytes =
BytesValue.fromHexString("726576657274206d657373616765");

@Before
public void setUp() {
when(messageFrame.popStackItem())
.thenReturn(Bytes32.fromHexString("0x00"))
.thenReturn(Bytes32.fromHexString("0x0e"));
when(messageFrame.readMemory(UInt256.ZERO, UInt256.of(0x0e)))
.thenReturn(BytesValue.fromHexString("726576657274206d657373616765"));
when(messageFrame.readMemory(UInt256.ZERO, UInt256.of(0x0e))).thenReturn(revertReasonBytes);
}

@Test
public void shouldReturnReason() {
assertTrue(code.contains("726576657274206d657373616765"));
ArgumentCaptor<String> arg = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<BytesValue> arg = ArgumentCaptor.forClass(BytesValue.class);
operation.execute(messageFrame);
Mockito.verify(messageFrame).setRevertReason(arg.capture());
assertEquals("revert message", arg.getValue());
assertEquals(revertReasonBytes, arg.getValue());
}
}
Loading