Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Update web3 transaction hash from RLP #250

Merged
merged 2 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 rpc/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (e *EthermintBackend) PendingTransactions() ([]*Transaction, error) {
}

// * Should check signer and reference against accounts the node manages in future
rpcTx, err := newRPCTransaction(*ethTx, common.Hash{}, nil, 0)
rpcTx, err := newRPCTransaction(*ethTx, common.BytesToHash(tx.Hash()), common.Hash{}, nil, 0)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions rpc/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func convertTransactionsToRPC(cliCtx context.CLIContext, txs []tmtypes.Tx, block
}
// TODO: Remove gas usage calculation if saving gasUsed per block
gasUsed.Add(gasUsed, ethTx.Fee())
tx, err := newRPCTransaction(*ethTx, blockHash, &height, uint64(i))
tx, err := newRPCTransaction(*ethTx, common.BytesToHash(tx.Hash()), blockHash, &height, uint64(i))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -558,7 +558,7 @@ func bytesToEthTx(cliCtx context.CLIContext, bz []byte) (*types.MsgEthereumTx, e

// newRPCTransaction returns a transaction that will serialize to the RPC
// representation, with the given location metadata set (if available).
func newRPCTransaction(tx types.MsgEthereumTx, blockHash common.Hash, blockNumber *uint64, index uint64) (*Transaction, error) {
func newRPCTransaction(tx types.MsgEthereumTx, txHash, blockHash common.Hash, blockNumber *uint64, index uint64) (*Transaction, error) {
// Verify signature and retrieve sender address
from, err := tx.VerifySig(tx.ChainID())
if err != nil {
Expand All @@ -569,7 +569,7 @@ func newRPCTransaction(tx types.MsgEthereumTx, blockHash common.Hash, blockNumbe
From: from,
Gas: hexutil.Uint64(tx.Data.GasLimit),
GasPrice: (*hexutil.Big)(tx.Data.Price),
Hash: tx.Hash(),
Hash: txHash,
Input: hexutil.Bytes(tx.Data.Payload),
Nonce: hexutil.Uint64(tx.Data.AccountNonce),
To: tx.To(),
Expand Down Expand Up @@ -609,7 +609,7 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err
}

height := uint64(tx.Height)
return newRPCTransaction(*ethTx, blockHash, &height, uint64(tx.Index))
return newRPCTransaction(*ethTx, common.BytesToHash(tx.Tx.Hash()), blockHash, &height, uint64(tx.Index))
}

// GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.
Expand Down Expand Up @@ -647,7 +647,7 @@ func (e *PublicEthAPI) getTransactionByBlockNumberAndIndex(number int64, idx hex
}

height := uint64(header.Height)
return newRPCTransaction(*ethTx, common.BytesToHash(header.Hash()), &height, uint64(idx))
return newRPCTransaction(*ethTx, common.BytesToHash(txs[idx].Hash()), common.BytesToHash(header.Hash()), &height, uint64(idx))
}

// GetTransactionReceipt returns the transaction receipt identified by hash.
Expand Down
8 changes: 5 additions & 3 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func HandleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) sdk
return sdk.ResultFromError(err)
}

txHash := msg.Hash()
txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
ethHash := common.BytesToHash(txHash)

st := types.StateTransition{
Sender: sender,
Expand All @@ -55,12 +56,13 @@ func HandleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) sdk
Payload: msg.Data.Payload,
Csdb: k.CommitStateDB.WithContext(ctx),
ChainID: intChainID,
THash: &txHash,
THash: &ethHash,
Simulate: ctx.IsCheckTx(),
}

// Prepare db for logs
// TODO: block hash
k.CommitStateDB.Prepare(txHash, txHash, k.TxCount)
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove the second field from the Prepare function signature if it's not going to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's matching the Geth interface, and will be used in the future (for adding block hash for the transactions logs)

k.TxCount++

// TODO: move to keeper
Expand Down
12 changes: 0 additions & 12 deletions x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,6 @@ func (msg *MsgEthereumTx) DecodeRLP(s *rlp.Stream) error {
return err
}

// Hash hashes the RLP encoding of a transaction.
func (msg *MsgEthereumTx) Hash() ethcmn.Hash {
if hash := msg.hash.Load(); hash != nil {
return hash.(ethcmn.Hash)
}

v := rlpHash(msg)
msg.hash.Store(v)

return v
}

// Sign calculates a secp256k1 ECDSA signature and signs the transaction. It
// takes a private key and chainID to sign an Ethereum transaction according to
// EIP155 standard. It mutates the transaction as it populates the V, R, S
Expand Down
8 changes: 0 additions & 8 deletions x/evm/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ func TestMsgEthereumTxRLPDecode(t *testing.T) {
require.Equal(t, expectedMsg.Data, msg.Data)
}

func TestMsgEthereumTxHash(t *testing.T) {
addr := ethcmn.BytesToAddress([]byte("test_address"))
msg := NewMsgEthereumTx(0, &addr, nil, 100000, nil, []byte("test"))

hash := msg.Hash()
require.Equal(t, "E2AA2E68E7586AE9700F1D3D643330866B6AC2B6CA4C804F7C85ECB11D0B0B29", fmt.Sprintf("%X", hash))
}

func TestMsgEthereumTxSig(t *testing.T) {
chainID := big.NewInt(3)

Expand Down