-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Research/parallel-tx/Refactor validblock (#1794)
* Refactor repeated code * Refactor repeated edges mocking * Modify test for too many edges - it was also hitting out of bounds * Refactor out of bounds validation If edges are in order, last edge decides if any was out of bounds * Rename test * Add case where first edge is zero First changed to prev = -1, then added test that failed, then set back prev = 0 * Refactor order verification * Research/refactoring code (#1817) * store and return a copy of txEdges * merged two ifs in the BlockHeaderBuilder * DummyTracker updated so it returns a copy of the maps * Unused hashmap import deleted from ProgramTraceProcessor * BlockResult returns and stores a copy of txEdges * big refactor in BlockExecutor * Refactor ParallelizeTransactionHandler * renaming Bucket to Sublist * renaming txExecutionListsEdges to txExecutionSublistEdges * simplification of Handler's code * InterruptedException solved properly in the BlockExecutor * Research/parallel-tx/optimize writes (#1811) * Avoid tracking write for add balance 0 * Avoid tracking when writing the same value * Rename assertion * Remove condition for add balance zero It is considered in "write the same value" * Revert breaks * Add test refactor back * Make remasc transaction not be in a parallelized sublist * Research/parallel-tx/Fix isRemascTransaction validation and pass correct index (#1822) * Fix isRemascTransaction validation and pass correct index * Remove -1 * Rename local data * Add tests for isRemascTransaction * Add tests for remasc transaction * Fix txindex Added test for block with rejected tx * Add missing txindex++ * Fix merge error Co-authored-by: julianlen <[email protected]>
- Loading branch information
1 parent
29b92e2
commit ecb2a65
Showing
6 changed files
with
297 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
rskj-core/src/test/java/co/rsk/core/TransactionIsRemascTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* | ||
* This file is part of RskJ | ||
* Copyright (C) 2017 RSK Labs Ltd. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package co.rsk.core; | ||
|
||
import org.bouncycastle.util.encoders.Hex; | ||
import org.ethereum.core.*; | ||
import org.ethereum.crypto.ECKey; | ||
import org.ethereum.crypto.HashUtil; | ||
import org.ethereum.util.ByteUtil; | ||
import org.ethereum.util.RLP; | ||
import org.ethereum.vm.PrecompiledContracts; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TransactionIsRemascTest { | ||
int txPosition = 6; | ||
int txsSize = 7; | ||
RskAddress destination = PrecompiledContracts.REMASC_ADDR; | ||
byte[] data = null; | ||
Coin value = Coin.ZERO; | ||
byte[] gasPrice = Hex.decode("00"); | ||
byte[] gasLimit = Hex.decode("00"); | ||
|
||
private Transaction buildTx( | ||
RskAddress destination, | ||
byte[] data, | ||
Coin value, | ||
byte[] gasPrice, | ||
byte[] gasLimit | ||
) { | ||
return Transaction.builder() | ||
.destination(destination) | ||
.data(data) | ||
.value(value) | ||
.gasPrice(gasPrice) | ||
.gasLimit(gasLimit) | ||
.build(); | ||
} | ||
|
||
private void assertIsRemascTransaction( | ||
RskAddress destination, | ||
byte[] data, | ||
Coin value, | ||
byte[] gasPrice, | ||
byte[] gasLimit, | ||
int txPosition, | ||
int txsSize | ||
) { | ||
Transaction tx = buildTx(destination, data, value, gasPrice, gasLimit); | ||
|
||
Assertions.assertTrue(tx.isRemascTransaction(txPosition, txsSize)); | ||
} | ||
|
||
private void assertIsNotRemascTransaction( | ||
Transaction tx, | ||
int txPosition, | ||
int txsSize | ||
) { | ||
Assertions.assertFalse(tx.isRemascTransaction(txPosition, txsSize)); | ||
} | ||
|
||
private void assertIsNotRemascTransaction( | ||
RskAddress destination, | ||
byte[] data, | ||
Coin value, | ||
byte[] gasPrice, | ||
byte[] gasLimit, | ||
int txPosition, | ||
int txsSize | ||
) { | ||
Transaction tx = buildTx(destination, data, value, gasPrice, gasLimit); | ||
|
||
assertIsNotRemascTransaction(tx, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void validRemascTransactionNullData() { | ||
assertIsRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void validRemascTransactionEmptyData() { | ||
byte[] data = {}; | ||
assertIsRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void notRemascTransactionNotLastTx() { | ||
int txPosition = 3; | ||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void notRemascTransactionNotEmptyData() { | ||
byte[] data = { 1, 2, 3, 4 }; | ||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void notRemascTransactionNotNullSig() { | ||
byte[] senderPrivateKey = HashUtil.keccak256("cow".getBytes()); | ||
Transaction tx = buildTx(destination, data, value, gasPrice, gasLimit); | ||
tx.sign(senderPrivateKey); | ||
|
||
assertIsNotRemascTransaction(tx, txPosition, txsSize); | ||
} | ||
|
||
@Test | ||
void notRemascTransactionReceiverIsNotRemasc() { | ||
byte[] privateKey = HashUtil.keccak256("cat".getBytes()); | ||
ECKey ecKey = ECKey.fromPrivate(privateKey); | ||
RskAddress destination = RLP.parseRskAddress(ByteUtil.cloneBytes(ecKey.getAddress())); | ||
|
||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
|
||
@Test | ||
void notRemascTransactionValueIsNotZero() { | ||
Coin value = Coin.valueOf(10); | ||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
|
||
@Test | ||
void notRemascTransactionGasPriceIsNotZero() { | ||
byte[] gasPrice = { 10 }; | ||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
|
||
|
||
@Test | ||
void notRemascTransactionGasLimitIsNotZero() { | ||
byte[] gasLimit = { 10 }; | ||
assertIsNotRemascTransaction(destination, data, value, gasPrice, gasLimit, txPosition, txsSize); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.