kopia lustrzana https://github.com/bugout-dev/moonstream
Merge pull request #941 from moonstream-to/nb-starknet-support
Nodebalancer starknet blockchain supportpull/945/head
commit
1bb132d63c
|
@ -15,6 +15,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Main variable of pool of blockchains which contains pool of nodes
|
||||
|
@ -50,7 +51,8 @@ type BlockchainPool struct {
|
|||
|
||||
// Node status response struct for HealthCheck
|
||||
type NodeStatusResultResponse struct {
|
||||
Number string `json:"number"`
|
||||
BlockNumber uint64 `json:"block_number"`
|
||||
Number string `json:"number"`
|
||||
}
|
||||
|
||||
type NodeStatusResponse struct {
|
||||
|
@ -194,14 +196,21 @@ func (bpool *BlockchainPool) StatusLog() {
|
|||
// HealthCheck fetch the node latest block
|
||||
func (bpool *BlockchainPool) HealthCheck() {
|
||||
for _, b := range bpool.Blockchains {
|
||||
var timeout time.Duration
|
||||
getLatestBlockReq := `{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}`
|
||||
if b.Blockchain == "starknet" {
|
||||
getLatestBlockReq = `{"jsonrpc":"2.0","method":"starknet_getBlockWithTxHashes","params":["latest"],"id":"0"}`
|
||||
timeout = NB_HEALTH_CHECK_CALL_TIMEOUT * 2
|
||||
}
|
||||
|
||||
for _, n := range b.Nodes {
|
||||
alive := false
|
||||
|
||||
httpClient := http.Client{Timeout: NB_HEALTH_CHECK_CALL_TIMEOUT}
|
||||
httpClient := http.Client{Timeout: timeout}
|
||||
resp, err := httpClient.Post(
|
||||
n.Endpoint.String(),
|
||||
"application/json",
|
||||
bytes.NewBuffer([]byte(`{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}`)),
|
||||
bytes.NewBuffer([]byte(getLatestBlockReq)),
|
||||
)
|
||||
if err != nil {
|
||||
n.UpdateNodeState(0, alive)
|
||||
|
@ -231,12 +240,17 @@ func (bpool *BlockchainPool) HealthCheck() {
|
|||
continue
|
||||
}
|
||||
|
||||
blockNumberHex := strings.Replace(statusResponse.Result.Number, "0x", "", -1)
|
||||
blockNumber, err := strconv.ParseUint(blockNumberHex, 16, 64)
|
||||
if err != nil {
|
||||
n.UpdateNodeState(0, alive)
|
||||
log.Printf("Unable to parse block number from hex to string, err: %v", err)
|
||||
continue
|
||||
var blockNumber uint64
|
||||
if b.Blockchain == "starknet" {
|
||||
blockNumber = statusResponse.Result.BlockNumber
|
||||
} else {
|
||||
blockNumberHex := strings.Replace(statusResponse.Result.Number, "0x", "", -1)
|
||||
blockNumber, err = strconv.ParseUint(blockNumberHex, 16, 64)
|
||||
if err != nil {
|
||||
n.UpdateNodeState(0, alive)
|
||||
log.Printf("Unable to parse block number from hex to string, err: %v", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Mark node in list of pool as alive and update current block
|
||||
|
|
|
@ -27,9 +27,9 @@ var (
|
|||
"eth_getUncleCountByBlockNumber": true,
|
||||
"eth_getWork": true,
|
||||
"eth_mining": true,
|
||||
// "eth_sendRawTransaction": true,
|
||||
"eth_protocolVersion": true,
|
||||
"eth_syncing": true,
|
||||
"eth_sendRawTransaction": true,
|
||||
"eth_protocolVersion": true,
|
||||
"eth_syncing": true,
|
||||
|
||||
"net_listening": true,
|
||||
"net_peerCount": true,
|
||||
|
@ -56,14 +56,46 @@ var (
|
|||
"zks_getTransactionDetails": true,
|
||||
"zks_L1BatchNumber": true,
|
||||
"zks_L1ChainId": true,
|
||||
|
||||
// starknet methods
|
||||
"starknet_specVersion": true,
|
||||
"starknet_getBlockWithTxHashes": true,
|
||||
"starknet_getBlockWithTxs": true,
|
||||
"starknet_getStateUpdate": true,
|
||||
"starknet_getStorageAt": true,
|
||||
"starknet_getTransactionStatus": true,
|
||||
"starknet_getTransactionByHash": true,
|
||||
"starknet_getTransactionByBlockIdAndIndex": true,
|
||||
"starknet_getTransactionReceipt": true,
|
||||
"starknet_getClass": true,
|
||||
"starknet_getClassHashAt": true,
|
||||
"starknet_getClassAt": true,
|
||||
"starknet_getBlockTransactionCount": true,
|
||||
"starknet_call": true,
|
||||
"starknet_estimateFee": true,
|
||||
"starknet_estimateMessageFee": true,
|
||||
"starknet_blockNumber": true,
|
||||
"starknet_blockHashAndNumber": true,
|
||||
"starknet_chainId": true,
|
||||
"starknet_syncing": true,
|
||||
"starknet_getEvents": true,
|
||||
"starknet_getNonce": true,
|
||||
|
||||
"starknet_traceTransaction": true,
|
||||
"starknet_simulateTransactions": true,
|
||||
"starknet_traceBlockTransactions": true,
|
||||
|
||||
"starknet_addInvokeTransaction": true,
|
||||
"starknet_addDeclareTransaction": true,
|
||||
"starknet_addDeployAccountTransaction": true,
|
||||
}
|
||||
)
|
||||
|
||||
type JSONRPCRequest struct {
|
||||
Jsonrpc string `json:"jsonrpc"`
|
||||
Method string `json:"method"`
|
||||
Params []interface{} `json:"params"`
|
||||
ID interface{} `json:"id"` // According to the JSON-RPC specification, the id can be a string, number, or null
|
||||
Jsonrpc string `json:"jsonrpc"`
|
||||
Method string `json:"method"`
|
||||
Params interface{} `json:"params"`
|
||||
ID interface{} `json:"id"` // According to the JSON-RPC specification, the id can be a string, number, or null
|
||||
}
|
||||
|
||||
type BlockchainConfig struct {
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package main
|
||||
|
||||
var NB_VERSION = "0.2.4"
|
||||
var NB_VERSION = "0.2.5"
|
||||
|
|
Ładowanie…
Reference in New Issue