update web3 transaction hash from RLP (#250)

* remove ethereum hash of web3 transaction type (always amino hash)

* Update changelog
This commit is contained in:
Austin Abell 2020-04-13 19:08:43 -04:00 committed by GitHub
parent 199484fc2e
commit 33ab63ef15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 31 deletions

View File

@ -51,7 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (keys) Marked `ExportEthKeyCommand` as **UNSAFE** * (keys) Marked `ExportEthKeyCommand` as **UNSAFE**
* (x/evm) Moved `BeginBlock` and `EndBlock` to `x/evm/abci.go` * (x/evm) Moved `BeginBlock` and `EndBlock` to `x/evm/abci.go`
## Features ### Features
* (rpc) [\#231](https://github.com/ChainSafe/ethermint/issues/231) Implement NewBlockFilter in rpc/filters.go which instantiates a polling block filter * (rpc) [\#231](https://github.com/ChainSafe/ethermint/issues/231) Implement NewBlockFilter in rpc/filters.go which instantiates a polling block filter
* Polls for new blocks via BlockNumber rpc call; if block number changes, it requests the new block via GetBlockByNumber rpc call and adds it to its internal list of blocks * Polls for new blocks via BlockNumber rpc call; if block number changes, it requests the new block via GetBlockByNumber rpc call and adds it to its internal list of blocks
@ -64,3 +64,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* for a given filter, look through each block for transactions. If there are transactions in the block, get the logs from it, and filter using the filterLogs method * for a given filter, look through each block for transactions. If there are transactions in the block, get the logs from it, and filter using the filterLogs method
* eth_getLogs and eth_getFilterChanges for log filters use the same underlying method as eth_getFilterLogs * eth_getLogs and eth_getFilterChanges for log filters use the same underlying method as eth_getFilterLogs
* update HandleMsgEthereumTx to store logs using the ethereum hash * update HandleMsgEthereumTx to store logs using the ethereum hash
### Bug Fixes
* (x/evm) [\#176](https://github.com/ChainSafe/ethermint/issues/176) Updated Web3 transaction hash from using RLP hash. Now all transaction hashes exposed are amino hashes.
* Removes `Hash()` (RLP) function from `MsgEthereumTx` to avoid confusion or misuse in future.

View File

@ -188,7 +188,7 @@ func (e *EthermintBackend) PendingTransactions() ([]*Transaction, error) {
} }
// * Should check signer and reference against accounts the node manages in future // * 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -514,7 +514,7 @@ func convertTransactionsToRPC(cliCtx context.CLIContext, txs []tmtypes.Tx, block
} }
// TODO: Remove gas usage calculation if saving gasUsed per block // TODO: Remove gas usage calculation if saving gasUsed per block
gasUsed.Add(gasUsed, ethTx.Fee()) 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 { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -558,7 +558,7 @@ func bytesToEthTx(cliCtx context.CLIContext, bz []byte) (*types.MsgEthereumTx, e
// newRPCTransaction returns a transaction that will serialize to the RPC // newRPCTransaction returns a transaction that will serialize to the RPC
// representation, with the given location metadata set (if available). // 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 // Verify signature and retrieve sender address
from, err := tx.VerifySig(tx.ChainID()) from, err := tx.VerifySig(tx.ChainID())
if err != nil { if err != nil {
@ -569,7 +569,7 @@ func newRPCTransaction(tx types.MsgEthereumTx, blockHash common.Hash, blockNumbe
From: from, From: from,
Gas: hexutil.Uint64(tx.Data.GasLimit), Gas: hexutil.Uint64(tx.Data.GasLimit),
GasPrice: (*hexutil.Big)(tx.Data.Price), GasPrice: (*hexutil.Big)(tx.Data.Price),
Hash: tx.Hash(), Hash: txHash,
Input: hexutil.Bytes(tx.Data.Payload), Input: hexutil.Bytes(tx.Data.Payload),
Nonce: hexutil.Uint64(tx.Data.AccountNonce), Nonce: hexutil.Uint64(tx.Data.AccountNonce),
To: tx.To(), To: tx.To(),
@ -609,7 +609,7 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err
} }
height := uint64(tx.Height) 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. // GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.
@ -647,7 +647,7 @@ func (e *PublicEthAPI) getTransactionByBlockNumberAndIndex(number int64, idx hex
} }
height := uint64(header.Height) 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. // GetTransactionReceipt returns the transaction receipt identified by hash.

View File

@ -43,7 +43,8 @@ func HandleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) sdk
return sdk.ResultFromError(err) return sdk.ResultFromError(err)
} }
txHash := msg.Hash() txHash := tmtypes.Tx(ctx.TxBytes()).Hash()
ethHash := common.BytesToHash(txHash)
st := types.StateTransition{ st := types.StateTransition{
Sender: sender, Sender: sender,
@ -55,12 +56,13 @@ func HandleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) sdk
Payload: msg.Data.Payload, Payload: msg.Data.Payload,
Csdb: k.CommitStateDB.WithContext(ctx), Csdb: k.CommitStateDB.WithContext(ctx),
ChainID: intChainID, ChainID: intChainID,
THash: &txHash, THash: &ethHash,
Simulate: ctx.IsCheckTx(), Simulate: ctx.IsCheckTx(),
} }
// Prepare db for logs // Prepare db for logs
// TODO: block hash // TODO: block hash
k.CommitStateDB.Prepare(txHash, txHash, k.TxCount) k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++ k.TxCount++
// TODO: move to keeper // TODO: move to keeper

View File

@ -198,18 +198,6 @@ func (msg *MsgEthereumTx) DecodeRLP(s *rlp.Stream) error {
return err 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 // Sign calculates a secp256k1 ECDSA signature and signs the transaction. It
// takes a private key and chainID to sign an Ethereum transaction according to // 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 // EIP155 standard. It mutates the transaction as it populates the V, R, S

View File

@ -89,14 +89,6 @@ func TestMsgEthereumTxRLPDecode(t *testing.T) {
require.Equal(t, expectedMsg.Data, msg.Data) 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) { func TestMsgEthereumTxSig(t *testing.T) {
chainID := big.NewInt(3) chainID := big.NewInt(3)