Skip to content

Commit ce640ae

Browse files
Merge branch 'master' into release_v2.13.0
2 parents 8bfedc4 + 0fa4329 commit ce640ae

13 files changed

Lines changed: 76 additions & 13 deletions

File tree

.github/workflows/release-build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ jobs:
5353
with:
5454
username: ${{ secrets.DOCKER_USERNAME }}
5555
password: ${{ secrets.DOCKER_PASSWORD }}
56+
- name: Set up Docker QEMU
57+
uses: docker/setup-qemu-action@v2
58+
- name: Set up Docker Buildx
59+
id: buildx
60+
uses: docker/setup-buildx-action@v2
61+
- name: Available Docker platforms
62+
run: echo ${{ steps.buildx.outputs.platforms }}
5663
- name: Push to Docker Hub
5764
uses: docker/build-push-action@v2
5865
with:
5966
push: true
6067
context: .
6168
file: docker/Dockerfile
69+
platforms: linux/amd64, linux/arm64
6270
tags: vitelabs/gvite:${{ github.event.inputs.tag }},vitelabs/gvite:latest

node/config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7+
"github.com/vitelabs/go-vite/v2/common"
78
"io/ioutil"
89
"os"
910
"path/filepath"
@@ -76,6 +77,7 @@ type Config struct {
7677
HttpVirtualHosts []string `json:"HttpVirtualHosts"`
7778
WSHost string `json:"WSHost"`
7879
WSPort int `json:"WSPort"`
80+
PrivateHttpPort int `json:"PrivateHttpPort"`
7981

8082
HTTPCors []string `json:"HTTPCors"`
8183
WSOrigins []string `json:"WSOrigins"`
@@ -242,6 +244,13 @@ func (c *Config) WSEndpoint() string {
242244
return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
243245
}
244246

247+
func (c *Config) PrivateHTTPEndpoint() string {
248+
if c.PrivateHttpPort == 0 {
249+
return ""
250+
}
251+
return fmt.Sprintf("%s:%d", common.DefaultHTTPHost, c.PrivateHttpPort)
252+
}
253+
245254
func (c *Config) SetPrivateKey(privateKey string) {
246255
c.PeerKey = privateKey
247256
}

node/config/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var DefaultNodeConfig = Config{
2020
LogLevel: "info",
2121
HTTPCors: []string{"*"},
2222
WSOrigins: []string{"*"},
23-
WSExposeAll: true,
24-
HttpExposeAll: true,
23+
WSExposeAll: false,
24+
HttpExposeAll: false,
2525

2626
Single: config.DefaultSingle,
2727
Identity: config.DefaultNodeName,

node/node.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type Node struct {
5454
httpWhitelist []string
5555
httpListener net.Listener
5656
httpHandler *rpc.Server
57+
privateHttpEndpoint string
58+
privateHttpListener net.Listener
59+
privateHttpHandler *rpc.Server
5760

5861
wsEndpoint string
5962
wsListener net.Listener
@@ -75,6 +78,7 @@ func New(conf *nodeconfig.Config) (*Node, error) {
7578
ipcEndpoint: conf.IPCEndpoint(),
7679
httpEndpoint: conf.HTTPEndpoint(),
7780
wsEndpoint: conf.WSEndpoint(),
81+
privateHttpEndpoint: conf.PrivateHTTPEndpoint(),
7882
stop: make(chan struct{}),
7983
}, nil
8084
}
@@ -312,7 +316,7 @@ func (node *Node) startRPC() (e error) {
312316
}
313317

314318
if node.config.RPCEnabled {
315-
if err := node.startHTTP(node.httpEndpoint, apis, nil, node.config.HTTPCors, node.config.HttpVirtualHosts, rpc.HTTPTimeouts{}, node.config.HttpExposeAll); err != nil {
319+
if err := node.startHTTP(node.httpEndpoint, node.privateHttpEndpoint, apis, nil, node.config.HTTPCors, node.config.HttpVirtualHosts, rpc.HTTPTimeouts{}, node.config.HttpExposeAll); err != nil {
316320
return err
317321
}
318322
defer func() {

node/rpc.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func (node *Node) stopIPC() {
3737
}
3838

3939
// startHTTP initializes and starts the HTTP RPC endpoint.
40-
func (node *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string, timeouts rpc.HTTPTimeouts, exposeAll bool) error {
40+
func (node *Node) startHTTP(endpoint string, privateEndpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string, timeouts rpc.HTTPTimeouts, exposeAll bool) error {
4141
// Short circuit if the HTTP endpoint isn't being exposed
4242
if endpoint == "" {
4343
return nil
4444
}
45-
listener, handler, err := rpc.StartHTTPEndpoint(endpoint, apis, modules, cors, vhosts, timeouts, exposeAll)
45+
listener, handler, privateListener, privateHandler, err := rpc.StartHTTPEndpoint(endpoint, privateEndpoint, apis, modules, cors, vhosts, timeouts, exposeAll)
4646
if err != nil {
4747
return err
4848
}
@@ -51,6 +51,8 @@ func (node *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, c
5151
node.httpEndpoint = endpoint
5252
node.httpListener = listener
5353
node.httpHandler = handler
54+
node.privateHttpListener = privateListener
55+
node.privateHttpHandler = privateHandler
5456

5557
return nil
5658
}
@@ -67,6 +69,15 @@ func (node *Node) stopHTTP() {
6769
node.httpHandler.Stop()
6870
node.httpHandler = nil
6971
}
72+
73+
if node.privateHttpListener != nil {
74+
node.privateHttpListener.Close()
75+
node.privateHttpListener = nil
76+
}
77+
if node.privateHttpHandler != nil {
78+
node.privateHttpHandler.Stop()
79+
node.privateHttpHandler = nil
80+
}
7081
}
7182

7283
// startWS initializes and starts the websocket RPC endpoint.

rpc/endpoints.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,50 @@ import (
2727
)
2828

2929
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules
30-
func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []string, vhosts []string, timeouts HTTPTimeouts, exposeAll bool) (net.Listener, *Server, error) {
30+
func StartHTTPEndpoint(endpoint string, privateEndpoint string, apis []API, modules []string, cors []string, vhosts []string, timeouts HTTPTimeouts, exposeAll bool) (net.Listener, *Server, net.Listener, *Server, error) {
3131
// Generate the whitelist based on the allowed modules
3232
whitelist := make(map[string]bool)
3333
for _, module := range modules {
3434
whitelist[module] = true
3535
}
3636
// Register all the APIs exposed by the services
3737
handler := NewServer()
38+
privateHandler := NewServer()
39+
privateBind := false
3840
for _, api := range apis {
3941
if exposeAll || whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
4042
if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
41-
return nil, nil, err
43+
return nil, nil, nil, nil, err
4244
}
4345
log.Debug("HTTP registered", "namespace", api.Namespace)
46+
} else if !api.Public {
47+
if err := privateHandler.RegisterName(api.Namespace, api.Service); err != nil {
48+
return nil, nil, nil, nil, err
49+
}
50+
privateBind = true
51+
log.Debug("Private HTTP API registered", "namespace", api.Namespace)
4452
}
4553
}
4654
// All APIs registered, start the HTTP listener
4755
var (
4856
listener net.Listener
57+
privateListener net.Listener
4958
err error
5059
)
5160
if listener, err = net.Listen("tcp", endpoint); err != nil {
52-
return nil, nil, err
61+
return nil, nil, nil, nil, err
5362
}
5463

5564
go NewHTTPServer(cors, vhosts, timeouts, handler).Serve(listener)
5665

57-
return listener, handler, err
66+
if privateBind && len(privateEndpoint) > 0 {
67+
if privateListener, err = net.Listen("tcp", privateEndpoint); err != nil {
68+
return nil, nil, nil, nil, err
69+
}
70+
go NewHTTPServer(cors, vhosts, timeouts, privateHandler).Serve(privateListener)
71+
}
72+
73+
return listener, handler, privateListener, privateHandler, err
5874
}
5975

6076
// StartWSEndpoint starts chain websocket endpoint

rpcapi/api/common_error.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import "errors"
55
var (
66
ErrStrToBigInt = errors.New("convert to big.Int failed")
77
ErrPoWNotSupportedUnderCongestion = errors.New("PoW service not supported")
8+
ErrDifficultyTooLarge = errors.New("difficulty is too large")
89
)

rpcapi/api/contract_v2.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func (r *ContractApi) GetSBPRewardPendingWithdrawal(name string) (*SBPReward, er
438438
return nil, err
439439
}
440440
if info == nil {
441-
return nil, nil
441+
return nil, util.ErrSBPNotExists
442442
}
443443
sb, err := db.LatestSnapshotBlock()
444444
if err != nil {
@@ -507,6 +507,9 @@ func (r *ContractApi) GetSBP(name string) (*SBPInfo, error) {
507507
if err != nil {
508508
return nil, err
509509
}
510+
if info == nil {
511+
return nil, util.ErrSBPNotExists
512+
}
510513
sb, err := db.LatestSnapshotBlock()
511514
if err != nil {
512515
return nil, err

rpcapi/api/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func (p UtilApi) GetPoWNonce(difficulty string, data types.Hash) ([]byte, error)
3939
return nil, ErrStrToBigInt
4040
}
4141

42+
difficultyCap := big.NewInt(8034995932)
43+
difficultyCap.Mul(difficultyCap, big.NewInt(50))
44+
if realDifficulty.Cmp(difficultyCap) > 0 {
45+
return nil, ErrDifficultyTooLarge
46+
}
47+
4248
if _, _, isCongestion := quota.CalcQc(p.vite.Chain(), p.vite.Chain().GetLatestSnapshotBlock().Height); isCongestion {
4349
return nil, ErrPoWNotSupportedUnderCongestion
4450
}

version/buildversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.12.0
1+
v2.12.1

0 commit comments

Comments
 (0)