Skip to content

Commit 48d76f7

Browse files
change to rpchub
1 parent 2c68992 commit 48d76f7

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ To start the aggregator, the following command can be run:
2323
build/aggregator
2424
```
2525
## Configuration
26-
Default password is `blockpi`.
26+
Default password is `123456`.
2727

28-
Visit https://ag-cfg.rpchub.io/ to configure the aggregator.
28+
Visit https://ag-cfg.rpchub.io/ to configure the aggregator. See the [documents](https://docs.rpchub.io/) for more details.
2929

30-
Or get current configuration by using command, replace `<password>` to what you set or using the default password:
30+
Get current configuration by using command, replace `<password>` to what you set or using the default password:
3131
```shell
32-
curl -u blockpi:<password> 'http://localhost:8012/config'
32+
curl -u rpchub:<password> 'http://localhost:8012/config'
3333
```
3434
To update the configuration, the following command can be run:
3535
```shell
36-
curl -u blockpi:<password> -X POST 'http://localhost:8012/config' --header 'Content-Type: application/json' --data-raw '{"password":"blockpi","request_timeout":30,"max_retries":3,"nodes":{"bsc":[{"name":"blockpi-public-bsc","endpoint":"https://bsc.blockpi.network/v1/rpc/public","weight":100,"read_only":false,"disabled":false}],"ethereum":[{"name":"blockpi-public-ethereum","endpoint":"https://ethereum.blockpi.network/v1/rpc/public","weight":90,"read_only":false,"disabled":false},{"name":"ethereum-ankr","endpoint":"https://rpc.ankr.com/eth","weight":10,"read_only":false,"disabled":false}]},"phishing_db":["https://cfg.rpchub.io/agg/scam-addresses.json"],"phishing_db_update_interval":60}'
36+
curl -u rpchub:<password> -X POST 'http://localhost:8012/config' --header 'Content-Type: application/json' --data-raw '{"password":"123456","request_timeout":30,"max_retries":3,"nodes":{"bsc":[{"name":"bsc-official","endpoint":"https://bsc-dataseed.binance.org","weight":100,"read_only":false,"disabled":false}],"ethereum":[{"name":"blockpi-public-ethereum","endpoint":"https://ethereum.blockpi.network/v1/rpc/public","weight":90,"read_only":false,"disabled":false},{"name":"ethereum-ankr","endpoint":"https://rpc.ankr.com/eth","weight":10,"read_only":false,"disabled":false}]},"phishing_db":["https://cfg.rpchub.io/agg/scam-addresses.json"],"phishing_db_update_interval":3600}'
3737
```
3838

3939
## Reset configuration
4040
1. Stop the aggregator.
41-
2. Delete the configuration directory `rm -rf $HOME/.blockpi/aggregator/`.
41+
2. Delete the configuration directory `rm -rf $HOME/.rpchub/aggregator/`.
4242
3. Restart the aggregator

cmd/aggregator/commands/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func RootApp() *cli.App {
1010
runCmd := RunCommand()
1111
cmd := &cli.App{
1212
Name: "aggregator",
13-
Usage: "blockpi aggregator",
13+
Usage: "RPCHub aggregator",
1414
Flags: runCmd.Flags,
1515
EnableBashCompletion: true,
1616
BashComplete: cli.DefaultAppComplete,

cmd/aggregator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func main() {
2626
}
2727

2828
func initPath() {
29-
dir, err := gfile.Home(".blockpi/aggregator")
29+
dir, err := gfile.Home(".rpchub/aggregator")
3030
if err != nil {
3131
panic(err)
3232
}

config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/syndtr/goleveldb/leveldb"
1111
leveldbErrors "github.com/syndtr/goleveldb/leveldb/errors"
1212
"github.com/valyala/fasthttp"
13+
"sort"
1314
"sync"
1415
"time"
1516
)
@@ -21,7 +22,7 @@ var (
2122
defaultPhishingDb = "https://cfg.rpchub.io/agg/scam-addresses.json"
2223

2324
_Config = &Config{
24-
Password: "blockpi",
25+
Password: "123456",
2526
RequestTimeout: 30,
2627
MaxRetries: 3,
2728
PhishingDb: []string{defaultPhishingDb},
@@ -102,7 +103,7 @@ func LoadDefault() {
102103

103104
if retries >= 5 {
104105
notify.SendError("Load default Config failed", fmt.Sprintf("Status Code: %d\nError: %s", statusCode, errStr))
105-
logger.Warn("Load default config failed, you may manually update the config by postman or via blockpi aggregator manager [https://aggregator.blockpi.io]")
106+
logger.Warn("Load default config failed, See the documents for more details [https://docs.rpchub.io/]")
106107
return
107108
} else {
108109
time.Sleep(time.Second * 3)
@@ -172,5 +173,6 @@ func Chains() []string {
172173
for key, _ := range Default().Nodes {
173174
chains = append(chains, key)
174175
}
176+
sort.Strings(chains)
175177
return chains
176178
}

middleware/plugins/http_proxy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,20 @@ func (m *HttpProxyMiddleware) OnProcess(session *rpc.Session) error {
5959
// ctx.Response.Header.Set("X-Do-Node", session.NodeName)
6060
//}
6161

62+
shouldDisableEndpoint := false
6263
if err != nil {
6364
log.Error(err.Error(), "node", session.NodeName)
65+
shouldDisableEndpoint = true
66+
}
67+
68+
statusCode := ctx.Response.StatusCode()
69+
if statusCode/100 != 2 {
70+
log.Error("error status code", "code", statusCode, "node", session.NodeName)
71+
shouldDisableEndpoint = true
72+
}
73+
74+
if shouldDisableEndpoint {
75+
//todo disable endpoint
6476
}
6577

6678
return err

middleware/plugins/safety.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func (m *SafetyMiddleware) updatePhishingDb() {
115115

116116
var phishingAddresses []*phishingAddress
117117

118+
hasError := false
119+
118120
for _, dbUrl := range cfg.PhishingDb {
119121
logger.Info("Updating phishing db", "url", dbUrl)
120122

@@ -131,6 +133,7 @@ func (m *SafetyMiddleware) updatePhishingDb() {
131133
err := cli.Do(req, resp)
132134
if err != nil {
133135
log.Error("Phishing db update failed", "url", dbUrl, "err", err)
136+
hasError = true
134137
return
135138
}
136139
result := map[string]string{}
@@ -174,7 +177,9 @@ func (m *SafetyMiddleware) updatePhishingDb() {
174177
count := len(phishingAddressMap)
175178
logger.Info("Updated phishing db", "addresses", count)
176179

177-
lastUpdateAt = time.Now()
180+
if !hasError {
181+
lastUpdateAt = time.Now()
182+
}
178183
}
179184

180185
func (m *SafetyMiddleware) isPhishingAddress(address string) (exist bool, pha *phishingAddress) {

server/manage_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func NewManageServer() error {
9595
payload, err := base64.StdEncoding.DecodeString(string(auth[len(basicAuthPrefix):]))
9696
if err == nil {
9797
pair := bytes.SplitN(payload, []byte(":"), 2)
98-
if len(pair) == 2 && bytes.Equal(pair[0], []byte("blockpi")) && bytes.Equal(pair[1], []byte(config.Default().Password)) {
98+
if len(pair) == 2 && bytes.Equal(pair[0], []byte("rpchub")) && bytes.Equal(pair[1], []byte(config.Default().Password)) {
9999
config.Default().Mrt += 1
100100
config.Save()
101101
r.Handler(ctx)

0 commit comments

Comments
 (0)