Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Revert "Don't subtract fee from null sender on succesful casper vote.…
Browse files Browse the repository at this point in the history
… Instead, block should be INVALID"

This reverts commit c72cb9d.
  • Loading branch information
zilm13 committed Mar 14, 2018
1 parent 13fda70 commit 0cc765d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,33 +231,6 @@ private void finalizeCheckpoint(final Block block) {
}
}

@Override
protected boolean checkBlockSummary(BlockSummary summary, Repository track) {
boolean res = super.checkBlockSummary(summary, track);
if (!res) { // Already bad block
return res;
}

// More checks

// Check for failed casper txs
TransactionReceipt failedCasperVote = null;
for (int i = 0; i < summary.getReceipts().size(); ++i) {
TransactionReceipt receipt = summary.getReceipts().get(i);
if(!receipt.isSuccessful() && casper.isVote(receipt.getTransaction())) {
failedCasperVote = receipt;
break;
}
}
if (failedCasperVote != null) {
logger.warn("Block contains failed casper vote (receipt: {}, tx: {})",
failedCasperVote, failedCasperVote.getTransaction());
return false;
}

return true;
}

@Override
protected BlockSummary applyBlock(Repository track, Block block) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private boolean isCasperVote() {

@Override
protected void payRewards(final TransactionExecutionSummary summary) {
if (isCasperVote()) {
// Return money to sender for Casper vote
if (execError == null && isCasperVote()) {
// Return money to sender for succesful Casper vote
track.addBalance(tx.getSender(), summary.getFee());
logger.info("Refunded successful Casper Vote from [{}]", Hex.toHexString(tx.getSender()));
} else {
Expand All @@ -123,8 +123,8 @@ protected void payRewards(final TransactionExecutionSummary summary) {
@Override
public long getGasUsed() {
long gasUsed = super.getGasUsed();
// Casper vote 0 cost
if (isCasperVote()) {
// Successful Casper vote 0 cost
if (getResult() != null && execError == null && isCasperVote()) {
gasUsed = 0;
}
return gasUsed;
Expand Down
73 changes: 35 additions & 38 deletions ethereumj-core/src/main/java/org/ethereum/core/BlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,67 +592,64 @@ public synchronized BlockSummary addImpl(Repository repo, final Block block) {
}

BlockSummary summary = processBlock(repo, block);
final List<TransactionReceipt> receipts = summary.getReceipts();

// Sanity checks
if(!checkBlockSummary(summary, repo)) {
repo.rollback();
summary = null;
}

if (summary != null) {
final List<TransactionReceipt> receipts = summary.getReceipts();
repo.commit();
updateTotalDifficulty(block);
summary.setTotalDifficulty(getTotalDifficulty());

if (!byTest) {
dbFlushManager.commit(() -> {
storeBlock(block, receipts);
repository.commit();
});
} else {
storeBlock(block, receipts);
}
}

return summary;
}

/**
* Sanity checks of block import result
* @return true if block is good, otherwise false
*/
protected boolean checkBlockSummary(final BlockSummary summary, final Repository track) {
Block block = summary.getBlock();
final List<TransactionReceipt> receipts = summary.getReceipts();

if (!FastByteComparisons.equal(block.getReceiptsRoot(), calcReceiptsTrie(receipts))) {
logger.warn("Block's given Receipt Hash doesn't match: {} != {}", Hex.toHexString(block.getReceiptsRoot()), Hex.toHexString(calcReceiptsTrie(receipts)));
logger.warn("Calculated receipts: " + receipts);
return false;
repo.rollback();
summary = null;
}

if (!FastByteComparisons.equal(block.getLogBloom(), calcLogBloom(receipts))) {
logger.warn("Block's given logBloom Hash doesn't match: {} != {}", Hex.toHexString(block.getLogBloom()), Hex.toHexString(calcLogBloom(receipts)));
return false;
repo.rollback();
summary = null;
}

if (!FastByteComparisons.equal(block.getStateRoot(), track.getRoot())) {
if (!FastByteComparisons.equal(block.getStateRoot(), repo.getRoot())) {

stateLogger.warn("BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch", block.getNumber(), Hex.toHexString(track.getRoot()));
stateLogger.warn("BLOCK: State conflict or received invalid block. block: {} worldstate {} mismatch", block.getNumber(), Hex.toHexString(repo.getRoot()));
stateLogger.warn("Conflict block dump: {}", Hex.toHexString(block.getEncoded()));

// track.rollback();
// repository.rollback();
repository = repository.getSnapshotTo(origRoot);

// block is bad so 'rollback' the state root to the original state
// ((RepositoryImpl) repository).setRoot(origRoot);

// track.rollback();
// block is bad so 'rollback' the state root to the original state
// ((RepositoryImpl) repository).setRoot(origRoot);

if (config.exitOnBlockConflict()) {
track.rollback();
adminInfo.lostConsensus();
System.out.println("CONFLICT: BLOCK #" + block.getNumber() + ", dump: " + Hex.toHexString(block.getEncoded()));
System.exit(1);
} else {
return false;
summary = null;
}
}

if (summary != null) {
repo.commit();
updateTotalDifficulty(block);
summary.setTotalDifficulty(getTotalDifficulty());

if (!byTest) {
dbFlushManager.commit(() -> {
storeBlock(block, receipts);
repository.commit();
});
} else {
storeBlock(block, receipts);
}
}

return true; // Everything is good!
return summary;
}

@Override
Expand Down

0 comments on commit 0cc765d

Please sign in to comment.