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

Conversation

@noot
Copy link
Contributor

@noot noot commented Sep 17, 2020

Closes: #XXX

Description

  • update ante handler to set new accounts in the keeper if an account is not found
  • allows accounts made with personal_newAccount to send transactions
  • also update personal api logs

to test:

make install
./init.sh

start rpc server as usual

geth attach http://localhost:8545
> personal.newAccount("password")
"<new address>"
> personal.unlockAccount("<new address>", "password")
true
> eth.sendTransaction({from: <first account that has balance>, to: <new address>, value: 0x1000000000})
<tx hash>
> eth.sendTransaction({from: <new account>, to: <any other address>, value: 0x1})

can use eth.accounts[0], eth.accounts[1] etc so you don't need to copy paste addrs


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Sep 17, 2020

Codecov Report

Merging #517 into development will decrease coverage by 1.59%.
The diff coverage is 43.75%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #517      +/-   ##
===============================================
- Coverage        72.08%   70.49%   -1.60%     
===============================================
  Files               41       41              
  Lines             2723     2325     -398     
===============================================
- Hits              1963     1639     -324     
+ Misses             615      543      -72     
+ Partials           145      143       -2     
Impacted Files Coverage Δ
app/ante/eth.go 61.15% <0.00%> (-4.21%) ⬇️
app/ante/ante.go 62.31% <50.00%> (-1.02%) ⬇️
crypto/secp256k1.go 65.51% <0.00%> (-8.85%) ⬇️
x/evm/types/journal.go 80.45% <0.00%> (-5.50%) ⬇️
x/evm/types/utils.go 41.50% <0.00%> (-4.40%) ⬇️
utils/int.go 29.41% <0.00%> (-3.93%) ⬇️
x/evm/keeper/querier.go 68.50% <0.00%> (-2.72%) ⬇️
crypto/algorithm.go 78.57% <0.00%> (-2.68%) ⬇️
core/chain.go 80.95% <0.00%> (-2.39%) ⬇️
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73d6c41...884ebc7. Read the comment docs.

@noot noot marked this pull request as ready for review September 17, 2020 20:20
@noot noot requested a review from fedekunze as a code owner September 17, 2020 20:20
@noot noot self-assigned this Sep 17, 2020
@araskachoi araskachoi merged commit 517de55 into development Sep 17, 2020
@araskachoi araskachoi deleted the noot/fix-personal branch September 17, 2020 22:04
e.keybaseLock.Lock()
defer e.keybaseLock.Unlock()

if e.cliCtx.Keybase == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, this condition could be inverted for better readability

}
}

func (asd AccountSetupDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a couple of questions that I believe should be documented with comments:

  • why is this ante handler decorator only for MsgEthermint and not MsgEthereumTx too?
  • any reason why is the decorator on the second position of the chain of ante decorators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MsgEthereumTx sets up the account in the NewAccountVerificationDecorator so it didn't need to be added separately, MsgEthermint uses the auth ante handlers which can't be modified, so I added this one to set up the account before the other handlers

I put it as the second one since I figured it would be good to set up the account before the rest of the decorators run, but it could be put right before whichever one validates the account

acc := avd.ak.GetAccount(ctx, address)
if acc == nil {
return ctx, fmt.Errorf("account %s (%s) is nil", common.BytesToAddress(address.Bytes()), address)
acc = avd.ak.NewAccountWithAddress(ctx, address)
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason why the account is set to store instead of creating an error should be documented on the comments for future reference 👍

Comment on lines +380 to +382
for _, key := range e.keys {
e.logger.Debug("eth_sendTransaction", "key", fmt.Sprintf("0x%x", key.PubKey().Address().Bytes()))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was a leftover debug log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove!

Comment on lines +119 to +129
for i, key := range e.ethAPI.keys {
if !bytes.Equal(key.PubKey().Address().Bytes(), address.Bytes()) {
continue
}

tmp := make([]emintcrypto.PrivKeySecp256k1, len(e.ethAPI.keys)-1)
copy(tmp[:i], e.ethAPI.keys[:i])
copy(tmp[i:], e.ethAPI.keys[i+1:])
e.ethAPI.keys = tmp
return true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what's the context of this change in relation to the PR title

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to update the ethAPI keys to allow for it to know about the new account that we are trying to send from

I think this could be improved by having one set of keys for both APIs, I can open an issue for that

return common.Address{}, fmt.Errorf("invalid private key type: %T", privKey)
}
e.ethAPI.keys = append(e.ethAPI.keys, emintKey)
e.logger.Debug("personal_newAccount", "address", fmt.Sprintf("0x%x", emintKey.PubKey().Address().Bytes()))
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover log?


e.keys = append(e.keys, emintKey)
e.ethAPI.keys = append(e.ethAPI.keys, emintKey)
e.logger.Debug("personal_unlockAccount", "address", fmt.Sprintf("0x%x", emintKey.PubKey().Address().Bytes()))
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto?

require.NoError(t, err, string(rpcRes.Result))

require.Equal(t, "0xef7e", gas)
require.Equal(t, "0xf552", gas)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why do we have to change this all the time? shouldn't the minimum always be 21,000?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's a good question, I'm not totally sure why it changes

//
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
func (e *PersonalEthAPI) Sign(ctx context.Context, data hexutil.Bytes, addr common.Address, passwd string) (hexutil.Bytes, error) {
e.logger.Debug("personal_sign", "data", data, "address", addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these ones on purpose so it's easier to tell what RPC method is being called, is there another way to see that?

//
// https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_ecRecove
func (e *PersonalEthAPI) EcRecover(ctx context.Context, data, sig hexutil.Bytes) (common.Address, error) {
e.logger.Debug("personal_ecRecover", "data", data, "sig", sig)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants