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

Fixed eth_sendTransaction routing to the local node #351

Merged
merged 27 commits into from Sep 25, 2017

Conversation

tiabc
Copy link
Contributor

@tiabc tiabc commented Sep 20, 2017

As the result of #345 eth_sendTransaction was erroneously routed to the upstream node which is incorrect. This PR fixes it.

Todo:

  • if sendTransaction is used to call a contract function, it does not specify gasPrice. As it's a required argument, infura returns an error transaction underpriced. We need to get gasPrice if it's missing.

// as concrete types are unknown.
func setResultFromRPCResponse(result, response interface{}) (err error) {
defer func() {
if r := recover(); r != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check if it's possible to detect if the panic comes from value.Set() as we want to recover only that one.

Copy link
Contributor Author

@tiabc tiabc left a comment

Choose a reason for hiding this comment

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

LGTM except for some minor comments.

Guys, please, merge it yourself once:

  1. TestCallRPCSendTransaction passes (at least, locally).
  2. missing value for required argument 1 doesn't occur.

"params": [{
"from": "` + TestConfig.Account1.Address + `",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gasPrice": "0x9184e72a000",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the reason for setting gasPrice here, by the way?

Copy link
Contributor

Choose a reason for hiding this comment

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

The same - no idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's not needed. However, we need to add support for missing gasPrice when using the upstream. As it's described in the Todo section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's remove it unless we test gasPrice setting here.

@@ -96,7 +55,9 @@ func (ep *ExecutionPolicy) executeWithClient(client *rpc.Client, vm *vm.VM, req
if client == nil {
resp = newErrorResponse("RPC client is not available. Node is stopped?", &req.ID)
} else {
err = client.Call(&result, req.Method, req.Params...)
// TODO(adam): check if context is used
ctx := context.WithValue(context.Background(), common.MessageIDKey, messageID)
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 thought we didn't need MessageID any more?

Copy link
Contributor

Choose a reason for hiding this comment

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

Removing messageID is part of jail refactoring and is done in another branch (based on this one). https://github.com/status-im/status-go/tree/refactor/jail-%23350

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@divan an in progress PR would help.

"to", toAddr.Hex(),
"gas", gas,
"gasPrice", gasPrice,
"value", priceVal,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's rename to just value or something?


"github.com/ethereum/go-ethereum/node"
"github.com/status-im/status-go/geth/params"

gethrpc "github.com/ethereum/go-ethereum/rpc"
)

// Handler defines handler for RPC methods.
type Handler func(context.Context, ...interface{}) (interface{}, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's rename to RPCHandler or something. Handler is way too general and it's non-obvious for the reader what it's all about at all.

Copy link
Contributor

@divan divan Sep 22, 2017

Choose a reason for hiding this comment

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

Actually, typical usage of this type is rpc.Handler, and go lint suggested to rename it from RPCHandler to Handler exactly because of this :) rpc.RPCHandler is a bit clunky.

@@ -21,6 +28,9 @@ type Client struct {
upstream *gethrpc.Client

router *router

mx sync.RWMutex // mx guards handlers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

handlersMu? Sort of classic. Or handlersMx.

return err
}

// if result is nil, just ignore result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

@divan divan Sep 22, 2017

Choose a reason for hiding this comment

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

@tiabc hmm, I remember I've read in the docs that response without result is totally valid JSON-RPC, but now quick check revealed that result is required. I'll double check it, because I remember clearly reading this in some doc (hence the comment, emphasizing that it's ok).

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, it's possible to call the RPC client like client.CallContext(ctx, nil, "eth_sendRawTransaction", data), thus handling nil case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Found: I've read about it in rpc.CallContext comment:

You can also pass nil, in which case the result is ignored.

https://github.com/status-im/status-go/blob/develop/vendor/github.com/ethereum/go-ethereum/rpc/client.go#L248

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clear! Let's add a comment?

@@ -256,6 +258,54 @@ func (s *BackendTestSuite) TestCallRPC() {
}
}

func (s *BackendTestSuite) TestCallRPCSendTransaction() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can this test pass at least once?

Copy link
Contributor

Choose a reason for hiding this comment

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

No idea. Just copied this test from other place.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can get it passed in Ropsten easily but it does want to in RinkebyNetworkID :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's change it to Ropsten.

@divan divan mentioned this pull request Sep 23, 2017
12 tasks
@adambabik
Copy link
Contributor

The only test failing is

--- FAIL: TestJailWhisper (2.13s)
	backend_jail_test.go:574: test 0: ensure correct version of Whisper is used
	backend_jail_test.go:574: test 1: encrypted signed message from us (From != nil && To != nil)
        Error Trace:    backend_jail_test.go:592
	Error:      	Received unexpected error:
	            	TypeError: 'newMessageFilter' is not a function

@divan divan merged commit fc8f59e into develop Sep 25, 2017
@adambabik adambabik deleted the bugfix/eth-send-transaction-routing-#350 branch October 29, 2017 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants