-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
236 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package abci | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bnb-chain/gnfd-qa-test-monitor/utils" | ||
"github.com/tidwall/gjson" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func LastBlockHeight() (int64, error) { | ||
url := `https://gnfd-testnet-fullnode-tendermint-us.bnbchain.org/abci_info?last_block_height` | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer utils.CloseBody(resp.Body) | ||
body, err := io.ReadAll(resp.Body) | ||
result := gjson.GetBytes(body, "result.response.last_block_height") | ||
return result.Int(), nil | ||
} | ||
|
||
func BsDBInfoBlockHeight(spHost string, height int64) (string, error) { | ||
// https://gnfd-testnet-sp1.bnbchain.org/?bsdb-info&block_height=11037600 | ||
url := fmt.Sprintf("https://%v/?bsdb-info&block_height=%v", spHost, height) | ||
//fmt.Println(url) | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer utils.CloseBody(resp.Body) | ||
body, err := io.ReadAll(resp.Body) | ||
return string(body), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package checks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bnb-chain/gnfd-qa-test-monitor/abci" | ||
"github.com/bnb-chain/gnfd-qa-test-monitor/utils" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
var SelfMainNetSpHost = []string{ | ||
"greenfield-sp.bnbchain.org", | ||
"greenfield-sp.defibit.io", | ||
"greenfield-sp.ninicoin.io", | ||
"greenfield-sp.nariox.org", | ||
"greenfield-sp.lumibot.org", | ||
"greenfield-sp.voltbot.io", | ||
"greenfield-sp.nodereal.io", | ||
} | ||
|
||
var SelfTestNetSpHost = []string{ | ||
"gnfd-testnet-sp1.bnbchain.org", | ||
"gnfd-testnet-sp2.bnbchain.org", | ||
"gnfd-testnet-sp3.bnbchain.org", | ||
"gnfd-testnet-sp4.bnbchain.org", | ||
"gnfd-testnet-sp1.nodereal.io", | ||
"gnfd-testnet-sp2.nodereal.io", | ||
"gnfd-testnet-sp3.nodereal.io", | ||
} | ||
|
||
type Code float64 | ||
|
||
const ( | ||
OK Code = iota | ||
GetObjectTotalCountErr | ||
GetObjectSealCountErr | ||
CheckObjectTotalCountErr | ||
CheckObjectSealCountErr | ||
) | ||
|
||
func CheckSpDbObjectNumsPeriod(spHostArray []string) (block int64, errCode Code) { | ||
chainHeight, err := abci.LastBlockHeight() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Printf("height: %d\n", chainHeight) | ||
calcHeight := chainHeight / 3600 * 3600 | ||
fmt.Printf("calcHeight: %d\n", calcHeight) | ||
|
||
resObjectCount := make(map[string][]gjson.Result) | ||
resObjectSealCount := make(map[string][]gjson.Result) | ||
|
||
// get everyone sp object count | ||
for _, spHost := range spHostArray { | ||
xmlResult, err := abci.BsDBInfoBlockHeight(spHost, calcHeight) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
objectResString := utils.GetXmlPath(xmlResult, "GfSpGetBsDBInfoResponse/ObjectTotalCount") | ||
if objectResString == "" { | ||
fmt.Printf("sp: %v, ObjectTotalCount error\n", spHost) | ||
return calcHeight, GetObjectTotalCountErr | ||
} else { | ||
ObjectTotalCount := gjson.Parse(objectResString).Array() | ||
resObjectCount[spHost] = ObjectTotalCount | ||
} | ||
|
||
objectSealResString := utils.GetXmlPath(xmlResult, "GfSpGetBsDBInfoResponse/ObjectSealCount") | ||
if objectSealResString == "" { | ||
fmt.Printf("sp: %v, ObjectSealCount error\n", spHost) | ||
return calcHeight, GetObjectSealCountErr | ||
} else { | ||
ObjectSealCount := gjson.Parse(objectSealResString).Array() | ||
resObjectSealCount[spHost] = ObjectSealCount | ||
} | ||
} | ||
|
||
// check sp object count | ||
for i := 0; i < 64; i++ { | ||
sumObject := int64(0) | ||
sumSp1 := int64(0) | ||
for _, objectCount := range resObjectCount { | ||
sumObject = sumObject + objectCount[i].Int() | ||
sumSp1++ | ||
} | ||
sumSealedObject := int64(0) | ||
sumSp2 := int64(0) | ||
for _, sealObjectCount := range resObjectSealCount { | ||
sumSealedObject = sumSealedObject + sealObjectCount[i].Int() | ||
sumSp2++ | ||
} | ||
|
||
objectAverage := sumObject / sumSp1 | ||
sealObjectAverage := sumSealedObject / sumSp2 | ||
for _, eachValue := range resObjectCount { | ||
if objectAverage != eachValue[i].Int() { | ||
return calcHeight, CheckObjectTotalCountErr | ||
} | ||
} | ||
for _, eachValue := range resObjectSealCount { | ||
if sealObjectAverage != eachValue[i].Int() { | ||
return calcHeight, CheckObjectSealCountErr | ||
} | ||
} | ||
} | ||
|
||
return calcHeight, OK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/antchfx/xmlquery" | ||
"io" | ||
"strings" | ||
) | ||
|
||
func GetXmlPath(res, path string) string { | ||
doc, err := xmlquery.Parse(strings.NewReader(res)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
result := "" | ||
if n := doc.SelectElement(path); n != nil { | ||
result = n.InnerText() | ||
} | ||
return result | ||
} | ||
|
||
func CloseBody(Body io.ReadCloser) { | ||
err := Body.Close() | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |