Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect reported txid in txpool rpc #674

Merged
merged 4 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/rpc/txpool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ license = 'GPL-3.0-only'
repository = 'https://github.com/PureStake/moonbeam/'

[dependencies]
rlp = "0.5"
sha3 = "0.8"
jsonrpc-core = "15.0.0"
ethereum-types = "0.11.0"
ethereum = { version = "0.7.1", default-features = false, features = ["with-codec"] }
moonbeam-rpc-core-txpool = { path = "../../rpc-core/txpool" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
Expand Down
7 changes: 2 additions & 5 deletions client/rpc/txpool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

use ethereum::TransactionMessage;
use ethereum_types::{H160, H256, U256};
use fc_rpc::{internal_err, public_key};
use jsonrpc_core::Result as RpcResult;
Expand Down Expand Up @@ -83,8 +82,7 @@ where
// Build the T response.
let mut pending = TransactionMap::<T>::new();
for txn in ethereum_txns.ready.iter() {
let transaction_message = TransactionMessage::from(txn.clone());
let hash = transaction_message.hash();
let hash = H256::from_slice(Keccak256::digest(&rlp::encode(txn)).as_slice());
let from_address = match public_key(txn) {
Ok(pk) => H160::from(H256::from_slice(Keccak256::digest(&pk).as_slice())),
Err(_e) => H160::default(),
Expand All @@ -96,8 +94,7 @@ where
}
let mut queued = TransactionMap::<T>::new();
for txn in ethereum_txns.future.iter() {
let transaction_message = TransactionMessage::from(txn.clone());
let hash = transaction_message.hash();
let hash = H256::from_slice(Keccak256::digest(&rlp::encode(txn)).as_slice());
let from_address = match public_key(txn) {
Ok(pk) => H160::from(H256::from_slice(Keccak256::digest(&pk).as_slice())),
Err(_e) => H160::default(),
Expand Down
1 change: 1 addition & 0 deletions tests/tests/test-txpool-future.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describeDevMoonbeam("TxPool - Future Ethereum transaction", (context) => {
from: GENESIS_ACCOUNT.toLowerCase(),
gas: "0x100000",
gasPrice: "0x3b9aca00",
hash: txHash,
nonce: context.web3.utils.toHex(1),
to: "0x0000000000000000000000000000000000000000",
value: "0x0",
Expand Down
18 changes: 11 additions & 7 deletions tests/tests/test-txpool-pending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describeDevMoonbeam("TxPool - Pending Ethereum transaction", (context) => {
from: GENESIS_ACCOUNT.toLowerCase(),
gas: "0x100000",
gasPrice: "0x3b9aca00",
hash: txHash,
nonce: context.web3.utils.toHex(0),
to: "0x0000000000000000000000000000000000000000",
value: "0x0",
Expand All @@ -53,7 +54,7 @@ describeDevMoonbeam("TxPool - Pending Ethereum transaction", (context) => {
});

describeDevMoonbeam("TxPool - Ethereum Contract Call", (context) => {
let testContract: Contract;
let testContract: Contract, txHash;

before("Setup: Create contract block and add call transaction", async () => {
const { contract, rawTx } = await createContract(context.web3, "TestContract", {
Expand All @@ -62,12 +63,14 @@ describeDevMoonbeam("TxPool - Ethereum Contract Call", (context) => {
testContract = contract;
await context.createBlock({ transactions: [rawTx] });

await customWeb3Request(context.web3, "eth_sendRawTransaction", [
await createContractExecution(context.web3, {
contract,
contractCall: contract.methods.multiply(5),
}),
]);
txHash = (
await customWeb3Request(context.web3, "eth_sendRawTransaction", [
await createContractExecution(context.web3, {
contract,
contractCall: contract.methods.multiply(5),
}),
])
).result;
});

it("should appear in the txpool inspection", async function () {
Expand All @@ -90,6 +93,7 @@ describeDevMoonbeam("TxPool - Ethereum Contract Call", (context) => {
from: GENESIS_ACCOUNT.toLowerCase(),
gas: "0xb71b00",
gasPrice: "0x3b9aca00",
hash: txHash,
nonce: context.web3.utils.toHex(1),
to: testContract.options.address.toString().toLowerCase(),
value: "0x0",
Expand Down