-
Notifications
You must be signed in to change notification settings - Fork 249
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
Conversation
…:status-im/status-go into bugfix/eth-send-transaction-routing-#350
// as concrete types are unknown. | ||
func setResultFromRPCResponse(result, response interface{}) (err error) { | ||
defer func() { | ||
if r := recover(); r != nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
TestCallRPCSendTransaction
passes (at least, locally).missing value for required argument 1
doesn't occur.
geth/api/backend_test.go
Outdated
"params": [{ | ||
"from": "` + TestConfig.Account1.Address + `", | ||
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567", | ||
"gasPrice": "0x9184e72a000", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same - no idea.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
geth/node/txqueue_manager.go
Outdated
"to", toAddr.Hex(), | ||
"gas", gas, | ||
"gasPrice", gasPrice, | ||
"value", priceVal, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
geth/rpc/client.go
Outdated
@@ -21,6 +28,9 @@ type Client struct { | |||
upstream *gethrpc.Client | |||
|
|||
router *router | |||
|
|||
mx sync.RWMutex // mx guards handlers |
There was a problem hiding this comment.
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
.
geth/rpc/client.go
Outdated
return err | ||
} | ||
|
||
// if result is nil, just ignore result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :/
There was a problem hiding this comment.
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.
…endTransactionRPCHandler
The only test failing is
|
This reverts commit f9066f9.
As the result of #345
eth_sendTransaction
was erroneously routed to the upstream node which is incorrect. This PR fixes it.Todo:
sendTransaction
is used to call a contract function, it does not specifygasPrice
. As it's a required argument, infura returns an errortransaction underpriced
. We need to getgasPrice
if it's missing.