mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
* Added checks to RPC requests and introduced new flags to customise the parameters (#657) * added a check to reject rpc requests with batch size > the one set using a newly added flag (rpcbatchlimit) * added a check to reject rpc requests whose result size > the one set using a newly added flag (rpcreturndatalimit) * updated the config files and docs * chg : trieTimeout from 60 to 10 mins (#692) * chg : trieTimeout from 60 to 10 mins * chg : cache.timout to 10m from 1h in configs * internal/cli/server : fix : added triesInMemory in config (#691) * changed version from 0.3.0 to 0.3.4-beta (#693) * fix nil state-sync issue, increase grpc limit (#695) * Increase grpc message size limit in pprof * consensus/bor/bor.go : stateSyncs init fixed [Fix #686] * eth/filters: handle nil state-sync before notify * eth/filters: update check Co-authored-by: Jerry <jerrycgh@gmail.com> Co-authored-by: Daniil <daniil.melnik@chainstack.com> * core, tests/bor: add more tests for state-sync validation (#710) * core: add get state sync function for tests * tests/bor: add validation for state sync events post consensus * Arpit/temp bor sync (#701) * Increase grpc message size limit in pprof * ReadBorReceipts improvements * use internal function * fix tests * fetch geth upstread for ReadBorReceiptRLP * Only query bor receipt when the query index is equal to # tx in block body This change reduces the frequency of calling ReadBorReceipt and ReadBorTransaction, which are CPU and db intensive. * Revert "fetch geth upstread for ReadBorReceiptRLP" This reverts commit 2e838a6b1313d26674f3a8df4b044e35dcbf35a0. * Restore ReadBorReceiptRLP * fix bor receipts * remove unused * fix lints --------- Co-authored-by: Jerry <jerrycgh@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Evgeny Danienko <6655321@bk.ru> * Revert "chg : trieTimeout from 60 to 10 mins (#692)" (#720) This reverts commit241843c7e7. * Arpit/add execution pool 2 (#719) * initial * linters * linters * remove timeout * update pool * change pool size function * check nil * check nil * fix tests * Use execution pool from server in all handlers * simplify things * test fix * add support for cli, config * add to cli and config * merge base branch * debug statements * fix bug * atomic pointer timeout * add apis * update workerpool * fix issues * change params * fix issues * fix ipc issue * remove execution pool from IPC * revert * fix tests * mutex * refactor flag and value names * ordering fix * refactor flag and value names * update default ep size to 40 * fix bor start issues * revert file changes * debug statements * fix bug * update workerpool * atomic pointer timeout * add apis * Merge branch 'add-execution-pool' of github.com:maticnetwork/bor into arpit/add-execution-pool * fix issues * change params * fix issues * fix ipc issue * remove execution pool from IPC * revert * merge base branch * Merge branch 'add-execution-pool' of github.com:maticnetwork/bor into arpit/add-execution-pool * mutex * fix tests * Merge branch 'arpit/add-execution-pool' of github.com:maticnetwork/bor into arpit/add-execution-pool * Change default size of execution pool to 40 * refactor flag and value names * fix merge conflicts * ordering fix * refactor flag and value names * update default ep size to 40 * fix bor start issues * revert file changes * fix linters * fix go.mod * change sec to ms * change default value for ep timeout * fix node api calls * comment setter for ep timeout --------- Co-authored-by: Evgeny Danienko <6655321@bk.ru> Co-authored-by: Jerry <jerrycgh@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> * version change (#721) * Event based pprof (#732) * feature * Save pprof to /tmp --------- Co-authored-by: Jerry <jerrycgh@gmail.com> * Cherry-pick changes from develop (#738) * Check if block is nil to prevent panic (#736) * miner: use env for tracing instead of block object (#728) --------- Co-authored-by: Dmitry <46797839+dkeysil@users.noreply.github.com> * add max code init size check in txpool (#739) * Revert "Event based pprof" and update version (#742) * Revert "Event based pprof (#732)" This reverts commit22fa4033e8. * params: update version to 0.3.4-beta3 * packaging/templates: update bor version * params, packaging/templates: update bor version --------- Co-authored-by: SHIVAM SHARMA <shivam691999@gmail.com> Co-authored-by: Pratik Patil <pratikspatil024@gmail.com> Co-authored-by: Jerry <jerrycgh@gmail.com> Co-authored-by: Daniil <daniil.melnik@chainstack.com> Co-authored-by: Arpit Temani <temaniarpit27@gmail.com> Co-authored-by: Evgeny Danienko <6655321@bk.ru> Co-authored-by: Dmitry <46797839+dkeysil@users.noreply.github.com>
220 lines
6.3 KiB
Go
220 lines
6.3 KiB
Go
// Copyright 2016 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package rpc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNewID(t *testing.T) {
|
|
hexchars := "0123456789ABCDEFabcdef"
|
|
for i := 0; i < 100; i++ {
|
|
id := string(NewID())
|
|
if !strings.HasPrefix(id, "0x") {
|
|
t.Fatalf("invalid ID prefix, want '0x...', got %s", id)
|
|
}
|
|
|
|
id = id[2:]
|
|
if len(id) == 0 || len(id) > 32 {
|
|
t.Fatalf("invalid ID length, want len(id) > 0 && len(id) <= 32), got %d", len(id))
|
|
}
|
|
|
|
for i := 0; i < len(id); i++ {
|
|
if strings.IndexByte(hexchars, id[i]) == -1 {
|
|
t.Fatalf("unexpected byte, want any valid hex char, got %c", id[i])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSubscriptions(t *testing.T) {
|
|
var (
|
|
namespaces = []string{"eth", "shh", "bzz"}
|
|
service = ¬ificationTestService{}
|
|
subCount = len(namespaces)
|
|
notificationCount = 3
|
|
|
|
server = NewServer(0, 0)
|
|
clientConn, serverConn = net.Pipe()
|
|
out = json.NewEncoder(clientConn)
|
|
in = json.NewDecoder(clientConn)
|
|
successes = make(chan subConfirmation)
|
|
notifications = make(chan subscriptionResult)
|
|
errors = make(chan error, subCount*notificationCount+1)
|
|
)
|
|
|
|
// setup and start server
|
|
for _, namespace := range namespaces {
|
|
if err := server.RegisterName(namespace, service); err != nil {
|
|
t.Fatalf("unable to register test service %v", err)
|
|
}
|
|
}
|
|
go server.ServeCodec(NewCodec(serverConn), 0)
|
|
defer server.Stop()
|
|
|
|
// wait for message and write them to the given channels
|
|
go waitForMessages(in, successes, notifications, errors)
|
|
|
|
// create subscriptions one by one
|
|
for i, namespace := range namespaces {
|
|
request := map[string]interface{}{
|
|
"id": i,
|
|
"method": fmt.Sprintf("%s_subscribe", namespace),
|
|
"version": "2.0",
|
|
"params": []interface{}{"someSubscription", notificationCount, i},
|
|
}
|
|
if err := out.Encode(&request); err != nil {
|
|
t.Fatalf("Could not create subscription: %v", err)
|
|
}
|
|
}
|
|
|
|
timeout := time.After(30 * time.Second)
|
|
subids := make(map[string]string, subCount)
|
|
count := make(map[string]int, subCount)
|
|
allReceived := func() bool {
|
|
done := len(count) == subCount
|
|
for _, c := range count {
|
|
if c < notificationCount {
|
|
done = false
|
|
}
|
|
}
|
|
return done
|
|
}
|
|
for !allReceived() {
|
|
select {
|
|
case confirmation := <-successes: // subscription created
|
|
subids[namespaces[confirmation.reqid]] = string(confirmation.subid)
|
|
case notification := <-notifications:
|
|
count[notification.ID]++
|
|
case err := <-errors:
|
|
t.Fatal(err)
|
|
case <-timeout:
|
|
for _, namespace := range namespaces {
|
|
subid, found := subids[namespace]
|
|
if !found {
|
|
t.Errorf("subscription for %q not created", namespace)
|
|
continue
|
|
}
|
|
if count, found := count[subid]; !found || count < notificationCount {
|
|
t.Errorf("didn't receive all notifications (%d<%d) in time for namespace %q", count, notificationCount, namespace)
|
|
}
|
|
}
|
|
t.Fatal("timed out")
|
|
}
|
|
}
|
|
}
|
|
|
|
// This test checks that unsubscribing works.
|
|
func TestServerUnsubscribe(t *testing.T) {
|
|
p1, p2 := net.Pipe()
|
|
defer p2.Close()
|
|
|
|
// Start the server.
|
|
server := newTestServer()
|
|
service := ¬ificationTestService{unsubscribed: make(chan string, 1)}
|
|
server.RegisterName("nftest2", service)
|
|
go server.ServeCodec(NewCodec(p1), 0)
|
|
|
|
// Subscribe.
|
|
p2.SetDeadline(time.Now().Add(10 * time.Second))
|
|
p2.Write([]byte(`{"jsonrpc":"2.0","id":1,"method":"nftest2_subscribe","params":["someSubscription",0,10]}`))
|
|
|
|
// Handle received messages.
|
|
var (
|
|
resps = make(chan subConfirmation)
|
|
notifications = make(chan subscriptionResult)
|
|
errors = make(chan error, 1)
|
|
)
|
|
go waitForMessages(json.NewDecoder(p2), resps, notifications, errors)
|
|
|
|
// Receive the subscription ID.
|
|
var sub subConfirmation
|
|
select {
|
|
case sub = <-resps:
|
|
case err := <-errors:
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Unsubscribe and check that it is handled on the server side.
|
|
p2.Write([]byte(`{"jsonrpc":"2.0","method":"nftest2_unsubscribe","params":["` + sub.subid + `"]}`))
|
|
for {
|
|
select {
|
|
case id := <-service.unsubscribed:
|
|
if id != string(sub.subid) {
|
|
t.Errorf("wrong subscription ID unsubscribed")
|
|
}
|
|
return
|
|
case err := <-errors:
|
|
t.Fatal(err)
|
|
case <-notifications:
|
|
// drop notifications
|
|
}
|
|
}
|
|
}
|
|
|
|
type subConfirmation struct {
|
|
reqid int
|
|
subid ID
|
|
}
|
|
|
|
// waitForMessages reads RPC messages from 'in' and dispatches them into the given channels.
|
|
// It stops if there is an error.
|
|
func waitForMessages(in *json.Decoder, successes chan subConfirmation, notifications chan subscriptionResult, errors chan error) {
|
|
for {
|
|
resp, notification, err := readAndValidateMessage(in)
|
|
if err != nil {
|
|
errors <- err
|
|
return
|
|
} else if resp != nil {
|
|
successes <- *resp
|
|
} else {
|
|
notifications <- *notification
|
|
}
|
|
}
|
|
}
|
|
|
|
func readAndValidateMessage(in *json.Decoder) (*subConfirmation, *subscriptionResult, error) {
|
|
var msg jsonrpcMessage
|
|
if err := in.Decode(&msg); err != nil {
|
|
return nil, nil, fmt.Errorf("decode error: %v", err)
|
|
}
|
|
switch {
|
|
case msg.isNotification():
|
|
var res subscriptionResult
|
|
if err := json.Unmarshal(msg.Params, &res); err != nil {
|
|
return nil, nil, fmt.Errorf("invalid subscription result: %v", err)
|
|
}
|
|
return nil, &res, nil
|
|
case msg.isResponse():
|
|
var c subConfirmation
|
|
if msg.Error != nil {
|
|
return nil, nil, msg.Error
|
|
} else if err := json.Unmarshal(msg.Result, &c.subid); err != nil {
|
|
return nil, nil, fmt.Errorf("invalid response: %v", err)
|
|
} else {
|
|
json.Unmarshal(msg.ID, &c.reqid)
|
|
return &c, nil, nil
|
|
}
|
|
default:
|
|
return nil, nil, fmt.Errorf("unrecognized message: %v", msg)
|
|
}
|
|
}
|