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

WIP Add Geth RPC to the gateway #1845

Merged
merged 77 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
7e1686d
Add new endpoint for generating messages and refactor message generation
zkokelj Mar 13, 2024
744404b
add message type in get messages
zkokelj Mar 18, 2024
6aa6cb3
fix test
zkokelj Mar 18, 2024
ab22422
lint
zkokelj Mar 18, 2024
4c15091
fix test
zkokelj Mar 18, 2024
c36ee46
- return nil instead of custom error
tudor-malene Mar 19, 2024
9284f97
Merge remote-tracking branch 'origin/main' into tudor/rpc_fixes
tudor-malene Mar 19, 2024
90b58cc
fix
tudor-malene Mar 19, 2024
bbc441d
fix
tudor-malene Mar 19, 2024
50d6d0b
lint
tudor-malene Mar 19, 2024
3fa1306
fix
tudor-malene Mar 19, 2024
324b4e0
add geth RPC
tudor-malene Mar 19, 2024
979ddc1
fix
tudor-malene Mar 19, 2024
755e159
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 20, 2024
5945629
Merge branch 'tudor/rpc_fixes' into tudor/OG_geth_RPC
tudor-malene Mar 20, 2024
c6a8a98
code review fixes
zkokelj Mar 20, 2024
65026ca
fix
tudor-malene Mar 20, 2024
e1a3077
fix
tudor-malene Mar 20, 2024
64050e8
refactor and add separate hashing functions
zkokelj Mar 20, 2024
cfda70a
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 20, 2024
871a4f0
GenerateMessage single responsibility + separate hashing
zkokelj Mar 20, 2024
6566e41
Merge branch 'main' into ziga/get_message_endpoint
zkokelj Mar 20, 2024
ab3a456
lint
zkokelj Mar 20, 2024
c9d1e6e
fix
tudor-malene Mar 20, 2024
21daaca
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 20, 2024
ba5f060
fix
tudor-malene Mar 20, 2024
d9d9e96
lint
tudor-malene Mar 20, 2024
5d5b844
lint
tudor-malene Mar 20, 2024
d838496
Merge remote-tracking branch 'origin/ziga/get_message_endpoint' into …
tudor-malene Mar 20, 2024
aa0daa7
fixes
tudor-malene Mar 20, 2024
a988875
fix
tudor-malene Mar 20, 2024
a3462e5
fix
tudor-malene Mar 20, 2024
982476b
fix
tudor-malene Mar 20, 2024
9f26b4e
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 21, 2024
77ddb5e
fix
tudor-malene Mar 21, 2024
776b06a
fix
tudor-malene Mar 21, 2024
34868cd
fix
tudor-malene Mar 21, 2024
afc5d31
fix
tudor-malene Mar 21, 2024
e2943cb
fix
tudor-malene Mar 21, 2024
889f767
fix
tudor-malene Mar 21, 2024
85b8ccb
fix
tudor-malene Mar 21, 2024
d0831bf
fix
tudor-malene Mar 21, 2024
3f92776
fix
tudor-malene Mar 22, 2024
d036a6a
fix
tudor-malene Mar 22, 2024
8862356
cleanup
tudor-malene Mar 22, 2024
4716d71
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 22, 2024
b26ab55
cleanup
tudor-malene Mar 22, 2024
63d300a
cleanup
tudor-malene Mar 22, 2024
50d6944
fix
tudor-malene Mar 22, 2024
69d1506
fix
tudor-malene Mar 22, 2024
8d9a214
fix
tudor-malene Mar 22, 2024
1cc865f
fix
tudor-malene Mar 22, 2024
3cb73ec
fix
tudor-malene Mar 22, 2024
7001ef7
fix
tudor-malene Mar 23, 2024
a5a8b81
fix
tudor-malene Mar 23, 2024
fddedeb
fix
tudor-malene Mar 24, 2024
49bcdaa
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 25, 2024
9eb55eb
merge main
tudor-malene Mar 25, 2024
7067489
fix
tudor-malene Mar 25, 2024
433d34c
Merge remote-tracking branch 'origin/main' into tudor/OG_geth_RPC
tudor-malene Mar 25, 2024
7db9f64
fix
tudor-malene Mar 25, 2024
dcb3f12
add cache for users
tudor-malene Mar 26, 2024
514f10b
add conn pool for rpc backend
tudor-malene Mar 26, 2024
0ddcdcb
disable cache
tudor-malene Mar 26, 2024
e2852c8
reenable cache
tudor-malene Mar 26, 2024
80c8f17
cleanup
tudor-malene Mar 26, 2024
5bf7c87
fix
tudor-malene Mar 26, 2024
030ed3f
fix
tudor-malene Mar 26, 2024
e4d9e2d
bump pool
tudor-malene Mar 26, 2024
3b5189e
fix
tudor-malene Mar 26, 2024
f5ee59d
fix
tudor-malene Mar 26, 2024
bf2287e
comment static
tudor-malene Mar 26, 2024
258454f
add static files
tudor-malene Mar 27, 2024
9964a61
fix
tudor-malene Mar 27, 2024
51f81b9
serve static files with /static path
zkokelj Mar 27, 2024
98dce95
Merge branch 'tudor/OG_geth_RPC' of https://github.com/ten-protocol/g…
zkokelj Mar 27, 2024
bbc9320
clean up conn pool
tudor-malene Mar 27, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package faucet

import (
"encoding/json"
Expand Down
75 changes: 51 additions & 24 deletions integration/obscurogateway/tengateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"testing"
"time"

"github.com/ten-protocol/go-ten/tools/walletextension"

log2 "github.com/ten-protocol/go-ten/go/common/log"

"github.com/ethereum/go-ethereum"
Expand All @@ -34,8 +36,6 @@ import (
"github.com/ten-protocol/go-ten/integration/ethereummock"
"github.com/ten-protocol/go-ten/integration/simulation/network"
"github.com/ten-protocol/go-ten/integration/simulation/params"
"github.com/ten-protocol/go-ten/tools/walletextension/config"
"github.com/ten-protocol/go-ten/tools/walletextension/container"
"github.com/ten-protocol/go-ten/tools/walletextension/lib"
"github.com/valyala/fasthttp"
)
Expand All @@ -57,7 +57,7 @@ func TestTenGateway(t *testing.T) {
startPort := integration.StartPortTenGatewayUnitTest
createTenNetwork(t, startPort)

tenGatewayConf := config.Config{
tenGatewayConf := wecommon.Config{
WalletExtensionHost: "127.0.0.1",
WalletExtensionPortHTTP: startPort + integration.DefaultTenGatewayHTTPPortOffset,
WalletExtensionPortWS: startPort + integration.DefaultTenGatewayWSPortOffset,
Expand All @@ -70,7 +70,7 @@ func TestTenGateway(t *testing.T) {
StoreIncomingTxs: true,
}

tenGwContainer := container.NewWalletExtensionContainerFromConfig(tenGatewayConf, testlog.Logger())
tenGwContainer := walletextension.NewContainerFromConfig(tenGatewayConf, testlog.Logger())
go func() {
err := tenGwContainer.Start()
if err != nil {
Expand Down Expand Up @@ -120,6 +120,9 @@ func testMultipleAccountsSubscription(t *testing.T, httpURL, wsURL string, w wal
require.NoError(t, err)
testlog.Logger().Info("Created user with encryption token", "t", user0.tgClient.UserID())

_, err = user0.HTTPClient.ChainID(context.Background())
require.NoError(t, err)

user1, err := NewUser([]wallet.Wallet{datagenerator.RandomWallet(integration.TenChainID), datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL)
require.NoError(t, err)
testlog.Logger().Info("Created user with encryption token", "t", user1.tgClient.UserID())
Expand Down Expand Up @@ -204,9 +207,12 @@ func testMultipleAccountsSubscription(t *testing.T, httpURL, wsURL string, w wal
var user0logs []types.Log
var user1logs []types.Log
var user2logs []types.Log
subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user0.WSClient, &user0logs)
subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user1.WSClient, &user1logs)
subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user2.WSClient, &user2logs)
_, err = subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user0.WSClient, &user0logs)
require.NoError(t, err)
_, err = subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user1.WSClient, &user1logs)
require.NoError(t, err)
_, err = subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user2.WSClient, &user2logs)
require.NoError(t, err)

// user1 calls setMessage and setMessage2 on deployed smart contract with the account
// that was registered as the first in TG
Expand Down Expand Up @@ -313,15 +319,23 @@ func testSubscriptionTopics(t *testing.T, httpURL, wsURL string, w wallet.Wallet
contractReceipt, err := integrationCommon.AwaitReceiptEth(context.Background(), user0.HTTPClient, signedTx.Hash(), time.Minute)
require.NoError(t, err)

tx, _, err := user0.HTTPClient.TransactionByHash(context.Background(), signedTx.Hash())
if err != nil {
return
}
require.Equal(t, signedTx.Hash(), tx.Hash())

// user0 subscribes to all events from that smart contract, user1 only an event with a topic of his first account
var user0logs []types.Log
var user1logs []types.Log
var topics [][]gethcommon.Hash
t1 := gethcommon.BytesToHash(user1.Wallets[1].Address().Bytes())
topics = append(topics, nil)
topics = append(topics, []gethcommon.Hash{t1})
subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user0.WSClient, &user0logs)
subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, topics, user1.WSClient, &user1logs)
_, err = subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user0.WSClient, &user0logs)
require.NoError(t, err)
_, err = subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, topics, user1.WSClient, &user1logs)
require.NoError(t, err)

// user0 calls setMessage on deployed smart contract with the account twice and expects two events
_, err = integrationCommon.InteractWithSmartContract(user0.HTTPClient, user0.Wallets[0], eventsContractABI, "setMessage", "user0Event1", contractReceipt.ContractAddress)
Expand Down Expand Up @@ -388,28 +402,32 @@ func testErrorHandling(t *testing.T, httpURL, wsURL string, w wallet.Wallet) {
// make requests to geth for comparison

for _, req := range []string{
`{"jsonrpc":"2.0","method":"eth_gasPrice","params": [],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params": ["latest", false],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_feeHistory","params":[1, "latest", [50]],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "latest"],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getBalance","params":[],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getgetget","params":["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "latest"],"id":1}`,
//`{"jsonrpc":"2.0","method":"eth_getgetget","params":["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "latest"],"id":1}`,
`{"method":"eth_getBalance","params":["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "latest"],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "latest"],"id":1,"extra":"extra_field"}`,
`{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[["0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", "0x1234"]],"id":1}`,
`{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x0000000000000000000000000000000000000000000000000000000000000000"],"id":1}`,
} {
// ensure the geth request is issued correctly (should return 200 ok with jsonRPCError)
_, response, err := httputil.PostDataJSON(ogClient.HTTP(), []byte(req))
require.NoError(t, err)

// unmarshall the response to JSONRPCMessage
jsonRPCError := wecommon.JSONRPCMessage{}
jsonRPCError := JSONRPCMessage{}
err = json.Unmarshal(response, &jsonRPCError)
require.NoError(t, err)
require.NoError(t, err, req, response)

// repeat the process for the gateway
_, response, err = httputil.PostDataJSON(fmt.Sprintf("http://localhost:%d", integration.StartPortTenGatewayUnitTest), []byte(req))
require.NoError(t, err)

// we only care about format
jsonRPCError = wecommon.JSONRPCMessage{}
jsonRPCError = JSONRPCMessage{}
err = json.Unmarshal(response, &jsonRPCError)
require.NoError(t, err)
}
Expand Down Expand Up @@ -467,7 +485,7 @@ func testErrorsRevertedArePassed(t *testing.T, httpURL, wsURL string, w wallet.W
// convert error to WE error
errBytes, err := json.Marshal(err)
require.NoError(t, err)
weError := wecommon.JSONError{}
weError := JSONError{}
err = json.Unmarshal(errBytes, &weError)
require.NoError(t, err)
require.Equal(t, "execution reverted: Forced require", weError.Message)
Expand Down Expand Up @@ -498,7 +516,10 @@ func testUnsubscribe(t *testing.T, httpURL, wsURL string, w wallet.Wallet) {
// create a user with multiple accounts
user, err := NewUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL)
require.NoError(t, err)
testlog.Logger().Info("Created user with encryption token: %s\n", user.tgClient.UserID())
testlog.Logger().Info("Created user with encryption token", "t", user.tgClient.UserID())

_, err = user.HTTPClient.ChainID(context.Background())
require.NoError(t, err)

// register all the accounts for the user
err = user.RegisterAccounts()
Expand All @@ -523,11 +544,12 @@ func testUnsubscribe(t *testing.T, httpURL, wsURL string, w wallet.Wallet) {
contractReceipt, err := integrationCommon.AwaitReceiptEth(context.Background(), user.HTTPClient, signedTx.Hash(), time.Minute)
require.NoError(t, err)

testlog.Logger().Info("Deployed contract address: ", contractReceipt.ContractAddress)
testlog.Logger().Info("Deployed contract address: ", "addr", contractReceipt.ContractAddress)

// subscribe to an event
var userLogs []types.Log
subscription := subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user.WSClient, &userLogs)
subscription, err := subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user.WSClient, &userLogs)
require.NoError(t, err)

// make an action that will trigger events
_, err = integrationCommon.InteractWithSmartContract(user.HTTPClient, user.Wallets[0], eventsContractABI, "setMessage", "foo", contractReceipt.ContractAddress)
Expand All @@ -550,7 +572,10 @@ func testClosingConnectionWhileSubscribed(t *testing.T, httpURL, wsURL string, w
// create a user with multiple accounts
user, err := NewUser([]wallet.Wallet{w, datagenerator.RandomWallet(integration.TenChainID)}, httpURL, wsURL)
require.NoError(t, err)
testlog.Logger().Info("Created user with encryption token: %s\n", user.tgClient.UserID())
testlog.Logger().Info("Created user with encryption token", "t", user.tgClient.UserID())

_, err = user.HTTPClient.ChainID(context.Background())
require.NoError(t, err)

// register all the accounts for the user
err = user.RegisterAccounts()
Expand All @@ -575,11 +600,12 @@ func testClosingConnectionWhileSubscribed(t *testing.T, httpURL, wsURL string, w
contractReceipt, err := integrationCommon.AwaitReceiptEth(context.Background(), user.HTTPClient, signedTx.Hash(), time.Minute)
require.NoError(t, err)

testlog.Logger().Info("Deployed contract address: ", contractReceipt.ContractAddress)
testlog.Logger().Info("Deployed contract address: ", "addr", contractReceipt.ContractAddress)

// subscribe to an event
var userLogs []types.Log
subscription := subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user.WSClient, &userLogs)
subscription, err := subscribeToEvents([]gethcommon.Address{contractReceipt.ContractAddress}, nil, user.WSClient, &userLogs)
require.NoError(t, err)

// Close the websocket connection and make sure nothing breaks, but user does not receive events
user.WSClient.Close()
Expand Down Expand Up @@ -742,7 +768,7 @@ func transferETHToAddress(client *ethclient.Client, wallet wallet.Wallet, toAddr
return integrationCommon.AwaitReceiptEth(context.Background(), client, signedTx.Hash(), 30*time.Second)
}

func subscribeToEvents(addresses []gethcommon.Address, topics [][]gethcommon.Hash, client *ethclient.Client, logs *[]types.Log) ethereum.Subscription {
func subscribeToEvents(addresses []gethcommon.Address, topics [][]gethcommon.Hash, client *ethclient.Client, logs *[]types.Log) (ethereum.Subscription, error) {
// Make a subscription
filterQuery := ethereum.FilterQuery{
Addresses: addresses,
Expand All @@ -754,15 +780,16 @@ func subscribeToEvents(addresses []gethcommon.Address, topics [][]gethcommon.Has

subscription, err := client.SubscribeFilterLogs(context.Background(), filterQuery, logsCh)
if err != nil {
testlog.Logger().Info("Failed to subscribe to filter logs: %v", log2.ErrKey, err)
testlog.Logger().Info("Failed to subscribe to filter logs", log2.ErrKey, err)
return nil, err
}

// Listen for logs in a goroutine
go func() {
for {
select {
case err := <-subscription.Err():
testlog.Logger().Info("Error from logs subscription: %v", log2.ErrKey, err)
testlog.Logger().Info("Error from logs subscription", log2.ErrKey, err)
return
case log := <-logsCh:
// append logs to be visible from the main thread
Expand All @@ -771,5 +798,5 @@ func subscribeToEvents(addresses []gethcommon.Address, topics [][]gethcommon.Has
}
}()

return subscription
return subscription, nil
}
2 changes: 2 additions & 0 deletions lib/gethfork/rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rpc
import (
"context"
"encoding/json"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -487,6 +488,7 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
return msg.errorResponse(&invalidRequestError{"invalid request"})

default:
fmt.Printf("Invalid request %v\n", jsonrpcMessage{})
return errorMessage(&invalidRequestError{"invalid request"})
}
}
Expand Down
1 change: 0 additions & 1 deletion tools/faucet/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
Expand Down Expand Up @@ -86,7 +85,7 @@
for now := time.Now(); time.Since(now) < _timeout; time.Sleep(time.Second) {
receipt, err := f.client.TransactionReceipt(context.Background(), tx.Hash())
// end eagerly for unexpected errors
if err != nil && !errors.Is(err, ethereum.NotFound) {

Check failure on line 88 in tools/faucet/faucet/faucet.go

View workflow job for this annotation

GitHub Actions / lint

undefined: errors) (typecheck)

Check failure on line 88 in tools/faucet/faucet/faucet.go

View workflow job for this annotation

GitHub Actions / lint

undefined: errors) (typecheck)

Check failure on line 88 in tools/faucet/faucet/faucet.go

View workflow job for this annotation

GitHub Actions / lint

undefined: errors) (typecheck)

Check failure on line 88 in tools/faucet/faucet/faucet.go

View workflow job for this annotation

GitHub Actions / lint

undefined: errors (typecheck)
return fmt.Errorf("could not retrieve transaction receipt in eth_getTransactionReceipt request. Cause: %w", err)
}

Expand Down
Loading
Loading