Fix COINBASE operation to return mining beneficiary (which may not match coinbase header in Clique) (#33)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by Adrian Sutton
parent 43e471b33d
commit 3d9ed51d9d
  1. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/mainnet/MainnetTransactionProcessor.java
  2. 1
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/vm/AbstractCallOperation.java
  3. 24
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/vm/MessageFrame.java
  4. 1
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/vm/operations/AbstractCreateOperation.java
  5. 2
      ethereum/core/src/main/java/net/consensys/pantheon/ethereum/vm/operations/CoinbaseOperation.java
  6. 1
      ethereum/core/src/test-support/java/net/consensys/pantheon/ethereum/core/TestCodeExecutor.java
  7. 4
      ethereum/core/src/test/java/net/consensys/pantheon/ethereum/vm/DebugOperationTracerTest.java
  8. 1
      ethereum/core/src/test/java/net/consensys/pantheon/ethereum/vm/VMReferenceTest.java
  9. 1
      ethereum/core/src/test/java/net/consensys/pantheon/ethereum/vm/operations/ExtCodeHashOperationTest.java

@ -198,6 +198,7 @@ public class MainnetTransactionProcessor implements TransactionProcessor {
.blockHeader(blockHeader) .blockHeader(blockHeader)
.depth(0) .depth(0)
.completer(c -> {}) .completer(c -> {})
.miningBeneficiary(miningBenficiary)
.build(); .build();
} else { } else {
@ -223,6 +224,7 @@ public class MainnetTransactionProcessor implements TransactionProcessor {
.blockHeader(blockHeader) .blockHeader(blockHeader)
.depth(0) .depth(0)
.completer(c -> {}) .completer(c -> {})
.miningBeneficiary(miningBenficiary)
.build(); .build();
} }

@ -170,6 +170,7 @@ public abstract class AbstractCallOperation extends AbstractOperation {
.depth(frame.getMessageStackDepth() + 1) .depth(frame.getMessageStackDepth() + 1)
.isStatic(isStatic(frame)) .isStatic(isStatic(frame))
.completer(child -> complete(frame, child)) .completer(child -> complete(frame, child))
.miningBeneficiary(frame.getMiningBeneficiary())
.build(); .build();
frame.getMessageFrameStack().addFirst(childFrame); frame.getMessageFrameStack().addFirst(childFrame);

@ -200,6 +200,7 @@ public class MessageFrame {
private final ProcessableBlockHeader blockHeader; private final ProcessableBlockHeader blockHeader;
private final int depth; private final int depth;
private final Deque<MessageFrame> messageFrameStack; private final Deque<MessageFrame> messageFrameStack;
private final Address miningBeneficiary;
// Miscellaneous fields. // Miscellaneous fields.
private final EnumSet<ExceptionalHaltReason> exceptionalHaltReasons = private final EnumSet<ExceptionalHaltReason> exceptionalHaltReasons =
@ -229,7 +230,8 @@ public class MessageFrame {
final ProcessableBlockHeader blockHeader, final ProcessableBlockHeader blockHeader,
final int depth, final int depth,
final boolean isStatic, final boolean isStatic,
final Consumer<MessageFrame> completer) { final Consumer<MessageFrame> completer,
final Address miningBeneficiary) {
this.type = type; this.type = type;
this.blockchain = blockchain; this.blockchain = blockchain;
this.messageFrameStack = messageFrameStack; this.messageFrameStack = messageFrameStack;
@ -257,6 +259,7 @@ public class MessageFrame {
this.state = State.NOT_STARTED; this.state = State.NOT_STARTED;
this.isStatic = isStatic; this.isStatic = isStatic;
this.completer = completer; this.completer = completer;
this.miningBeneficiary = miningBeneficiary;
} }
/** /**
@ -771,6 +774,15 @@ public class MessageFrame {
return exceptionalHaltReasons; return exceptionalHaltReasons;
} }
/**
* Returns the current miningBeneficiary (aka coinbase)
*
* @return the current mining beneficiary
*/
public Address getMiningBeneficiary() {
return miningBeneficiary;
}
public Operation getCurrentOperation() { public Operation getCurrentOperation() {
return currentOperation; return currentOperation;
} }
@ -799,6 +811,7 @@ public class MessageFrame {
private int depth = -1; private int depth = -1;
private boolean isStatic = false; private boolean isStatic = false;
private Consumer<MessageFrame> completer; private Consumer<MessageFrame> completer;
private Address miningBeneficiary;
public Builder type(final Type type) { public Builder type(final Type type) {
this.type = type; this.type = type;
@ -890,6 +903,11 @@ public class MessageFrame {
return this; return this;
} }
public Builder miningBeneficiary(final Address miningBeneficiary) {
this.miningBeneficiary = miningBeneficiary;
return this;
}
private void validate() { private void validate() {
checkState(type != null, "Missing message frame type"); checkState(type != null, "Missing message frame type");
checkState(blockchain != null, "Missing message frame blockchain"); checkState(blockchain != null, "Missing message frame blockchain");
@ -908,6 +926,7 @@ public class MessageFrame {
checkState(blockHeader != null, "Missing message frame block header"); checkState(blockHeader != null, "Missing message frame block header");
checkState(depth > -1, "Missing message frame depth"); checkState(depth > -1, "Missing message frame depth");
checkState(completer != null, "Missing message frame completer"); checkState(completer != null, "Missing message frame completer");
checkState(miningBeneficiary != null, "Missing mining beneficiary");
} }
public MessageFrame build() { public MessageFrame build() {
@ -931,7 +950,8 @@ public class MessageFrame {
blockHeader, blockHeader,
depth, depth,
isStatic, isStatic,
completer); completer,
miningBeneficiary);
} }
} }
} }

@ -108,6 +108,7 @@ public abstract class AbstractCreateOperation extends AbstractOperation {
.blockHeader(frame.getBlockHeader()) .blockHeader(frame.getBlockHeader())
.depth(frame.getMessageStackDepth() + 1) .depth(frame.getMessageStackDepth() + 1)
.completer(child -> complete(frame, child)) .completer(child -> complete(frame, child))
.miningBeneficiary(frame.getMiningBeneficiary())
.build(); .build();
frame.getMessageFrameStack().addFirst(childFrame); frame.getMessageFrameStack().addFirst(childFrame);

@ -20,7 +20,7 @@ public class CoinbaseOperation extends AbstractOperation {
@Override @Override
public void execute(final MessageFrame frame) { public void execute(final MessageFrame frame) {
final Address coinbase = frame.getBlockHeader().getCoinbase(); final Address coinbase = frame.getMiningBeneficiary();
frame.pushStackItem(Words.fromAddress(coinbase)); frame.pushStackItem(Words.fromAddress(coinbase));
} }
} }

@ -67,6 +67,7 @@ public class TestCodeExecutor {
.blockHeader(blockHeader) .blockHeader(blockHeader)
.depth(0) .depth(0)
.completer(c -> {}) .completer(c -> {})
.miningBeneficiary(blockHeader.coinbase)
.build(); .build();
messageFrameStack.addFirst(initialFrame); messageFrameStack.addFirst(initialFrame);

@ -9,6 +9,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import net.consensys.pantheon.ethereum.core.Address; import net.consensys.pantheon.ethereum.core.Address;
import net.consensys.pantheon.ethereum.core.AddressHelpers;
import net.consensys.pantheon.ethereum.core.BlockHeaderTestFixture; import net.consensys.pantheon.ethereum.core.BlockHeaderTestFixture;
import net.consensys.pantheon.ethereum.core.Gas; import net.consensys.pantheon.ethereum.core.Gas;
import net.consensys.pantheon.ethereum.core.MutableAccount; import net.consensys.pantheon.ethereum.core.MutableAccount;
@ -205,7 +206,8 @@ public class DebugOperationTracerTest {
.code(new Code()) .code(new Code())
.blockHeader(new BlockHeaderTestFixture().buildHeader()) .blockHeader(new BlockHeaderTestFixture().buildHeader())
.depth(DEPTH) .depth(DEPTH)
.completer(c -> {}); .completer(c -> {})
.miningBeneficiary(AddressHelpers.ofValue(0));
} }
private Map<UInt256, UInt256> setupStorageForCapture(final MessageFrame frame) { private Map<UInt256, UInt256> setupStorageForCapture(final MessageFrame frame) {

@ -120,6 +120,7 @@ public class VMReferenceTest extends AbstractRetryingTest {
.blockHeader(execEnv.getBlockHeader()) .blockHeader(execEnv.getBlockHeader())
.depth(execEnv.getDepth()) .depth(execEnv.getDepth())
.completer(c -> {}) .completer(c -> {})
.miningBeneficiary(execEnv.getBlockHeader().getCoinbase())
.build(); .build();
// This is normally set inside the containing message executing the code. // This is normally set inside the containing message executing the code.

@ -123,6 +123,7 @@ public class ExtCodeHashOperationTest {
.code(new Code(BytesValue.EMPTY)) .code(new Code(BytesValue.EMPTY))
.blockchain(blockchain) .blockchain(blockchain)
.completer(messageFrame -> {}) .completer(messageFrame -> {})
.miningBeneficiary(AddressHelpers.ofValue(0))
.build(); .build();
frame.pushStackItem(stackItem); frame.pushStackItem(stackItem);

Loading…
Cancel
Save