Add network parameter to getInfo ws request

This commit is contained in:
Martin Boehm 2024-08-06 10:50:01 +02:00
parent c1f2e62c45
commit a0960c8e17
17 changed files with 165 additions and 135 deletions

View File

@ -503,6 +503,7 @@ type BlockRaw struct {
// BlockbookInfo contains information about the running blockbook instance
type BlockbookInfo struct {
Coin string `json:"coin"`
Network string `json:"network"`
Host string `json:"host"`
Version string `json:"version"`
GitCommit string `json:"gitCommit"`

View File

@ -2413,6 +2413,7 @@ func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) {
}
blockbookInfo := &BlockbookInfo{
Coin: w.is.Coin,
Network: w.is.GetNetwork(),
Host: w.is.Host,
Version: vi.Version,
GitCommit: vi.GitCommit,

View File

@ -33,6 +33,10 @@ export interface EthereumSpecific {
gasLimit: number;
gasUsed?: number;
gasPrice?: string;
l1Fee?: number;
l1FeeScalar?: string;
l1GasPrice?: string;
l1GasUsed?: number;
data?: string;
parsedData?: EthereumParsedInputData;
internalTransfers?: EthereumInternalTransfer[];
@ -351,6 +355,7 @@ export interface WsBackendInfo {
export interface WsInfoRes {
name: string;
shortcut: string;
network: string;
decimals: number;
version: string;
bestHeight: number;

View File

@ -7,6 +7,8 @@
{{end}}
"coin_name": "{{.Coin.Name}}",
"coin_shortcut": "{{.Coin.Shortcut}}",
{{- if .Coin.Network}}
"network": "{{.Coin.Network}}",{{end}}
"coin_label": "{{.Coin.Label}}",
"rpc_url": "{{template "IPC.RPCURLTemplate" .}}",
"rpc_user": "{{.IPC.RPCUser}}",

View File

@ -44,6 +44,7 @@ type Config struct {
Coin struct {
Name string `json:"name"`
Shortcut string `json:"shortcut"`
Network string `json:"network,omitempty"`
Label string `json:"label"`
Alias string `json:"alias"`
} `json:"coin"`

View File

@ -12,6 +12,7 @@ type Config struct {
CoinName string `json:"coin_name"`
CoinShortcut string `json:"coin_shortcut"`
CoinLabel string `json:"coin_label"`
Network string `json:"network"`
FourByteSignatures string `json:"fourByteSignatures"`
FiatRates string `json:"fiat_rates"`
FiatRatesParams string `json:"fiat_rates_params"`

View File

@ -57,6 +57,7 @@ type InternalState struct {
CoinShortcut string `json:"coinShortcut"`
CoinLabel string `json:"coinLabel"`
Host string `json:"host"`
Network string `json:"network,omitempty"`
DbState uint32 `json:"dbState"`
ExtendedIndex bool `json:"extendedIndex"`
@ -305,6 +306,15 @@ func (is *InternalState) computeAvgBlockPeriod() {
is.AvgBlockPeriod = (is.BlockTimes[last] - is.BlockTimes[first]) / avgBlockPeriodSample
}
// GetNetwork returns network. If not set returns the same value as CoinShortcut
func (is *InternalState) GetNetwork() string {
network := is.Network
if network == "" {
return is.CoinShortcut
}
return network
}
// SetBackendInfo sets new BackendInfo
func (is *InternalState) SetBackendInfo(bi *BackendInfo) {
is.mux.Lock()

View File

@ -2,6 +2,7 @@
"coin": {
"name": "BNB Smart Chain",
"shortcut": "BNB",
"network": "BNB",
"label": "BNB Smart Chain",
"alias": "bsc"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "BNB Smart Chain Archive",
"shortcut": "BNB",
"network": "BNB",
"label": "BNB Smart Chain",
"alias": "bsc_archive"
},

View File

@ -1,66 +1,67 @@
{
"coin": {
"name": "Optimism",
"shortcut": "ETH",
"label": "Optimism",
"alias": "optimism"
},
"ports": {
"backend_rpc": 8200,
"backend_p2p": 38400,
"backend_http": 8300,
"backend_authrpc": 8400,
"blockbook_internal": 9200,
"blockbook_public": 9300
},
"ipc": {
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_timeout": 25
},
"backend": {
"package_name": "backend-optimism",
"package_revision": "satoshilabs-1",
"system_user": "optimism",
"version": "1.101315.1",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_type": "sha256",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"exec_script": "optimism.sh",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_type": "simple",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "",
"client_config_file": ""
},
"blockbook": {
"package_name": "blockbook-optimism",
"system_user": "blockbook-optimism",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 300,
"additional_params": {
"mempoolTxTimeoutHours": 48,
"queryBackendOnMempoolResync": false,
"fiat_rates": "coingecko",
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}"
}
"coin": {
"name": "Optimism",
"shortcut": "ETH",
"network": "OP",
"label": "Optimism",
"alias": "optimism"
},
"ports": {
"backend_rpc": 8200,
"backend_p2p": 38400,
"backend_http": 8300,
"backend_authrpc": 8400,
"blockbook_internal": 9200,
"blockbook_public": 9300
},
"ipc": {
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_timeout": 25
},
"backend": {
"package_name": "backend-optimism",
"package_revision": "satoshilabs-1",
"system_user": "optimism",
"version": "1.101315.1",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_type": "sha256",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"exec_script": "optimism.sh",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_type": "simple",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "",
"client_config_file": ""
},
"blockbook": {
"package_name": "blockbook-optimism",
"system_user": "blockbook-optimism",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 300,
"additional_params": {
"mempoolTxTimeoutHours": 48,
"queryBackendOnMempoolResync": false,
"fiat_rates": "coingecko",
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
}
}

View File

@ -1,69 +1,70 @@
{
"coin": {
"name": "Optimism Archive",
"shortcut": "ETH",
"label": "Optimism",
"alias": "optimism_archive"
},
"ports": {
"backend_rpc": 8202,
"backend_p2p": 38402,
"backend_http": 8302,
"backend_authrpc": 8402,
"blockbook_internal": 9202,
"blockbook_public": 9302
},
"ipc": {
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_timeout": 25
},
"backend": {
"package_name": "backend-optimism-archive",
"package_revision": "satoshilabs-1",
"system_user": "optimism",
"version": "1.101315.1",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_type": "sha256",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_archive_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"exec_script": "optimism_archive.sh",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_type": "simple",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "",
"client_config_file": ""
},
"blockbook": {
"package_name": "blockbook-optimism-archive",
"system_user": "blockbook-optimism",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "-workers=16",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 600,
"additional_params": {
"address_aliases": true,
"mempoolTxTimeoutHours": 48,
"processInternalTransactions": true,
"queryBackendOnMempoolResync": false,
"fiat_rates": "coingecko",
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}",
"fourByteSignatures": "https://www.4byte.directory/api/v1/signatures/"
}
"coin": {
"name": "Optimism Archive",
"shortcut": "ETH",
"network": "OP",
"label": "Optimism",
"alias": "optimism_archive"
},
"ports": {
"backend_rpc": 8202,
"backend_p2p": 38402,
"backend_http": 8302,
"backend_authrpc": 8402,
"blockbook_internal": 9202,
"blockbook_public": 9302
},
"ipc": {
"rpc_url_template": "ws://127.0.0.1:{{.Ports.BackendRPC}}",
"rpc_timeout": 25
},
"backend": {
"package_name": "backend-optimism-archive",
"package_revision": "satoshilabs-1",
"system_user": "optimism",
"version": "1.101315.1",
"binary_url": "https://github.com/ethereum-optimism/op-geth/archive/refs/tags/v1.101315.1.tar.gz",
"verification_type": "sha256",
"verification_source": "f0f31ef2982f87f9e3eb90f2b603f5fcd9d680e487d35f5bdcf5aeba290b153f",
"extract_command": "mkdir backend/source && tar -C backend/source --strip 1 -xf v1.101315.1.tar.gz && cd backend/source && make geth && mv build/bin/geth ../ && rm -rf ../source && echo",
"exclude_files": [],
"exec_command_template": "/bin/sh -c '{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/optimism_archive_exec.sh 2>> {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log'",
"exec_script": "optimism_archive.sh",
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/{{.Coin.Alias}}.log",
"postinst_script_template": "openssl rand -hex 32 > {{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/jwtsecret",
"service_type": "simple",
"service_additional_params_template": "",
"protect_memory": true,
"mainnet": true,
"server_config_file": "",
"client_config_file": ""
},
"blockbook": {
"package_name": "blockbook-optimism-archive",
"system_user": "blockbook-optimism",
"internal_binding_template": ":{{.Ports.BlockbookInternal}}",
"public_binding_template": ":{{.Ports.BlockbookPublic}}",
"explorer_url": "",
"additional_params": "-workers=16",
"block_chain": {
"parse": true,
"mempool_workers": 8,
"mempool_sub_workers": 2,
"block_addresses_to_keep": 600,
"additional_params": {
"address_aliases": true,
"mempoolTxTimeoutHours": 48,
"processInternalTransactions": true,
"queryBackendOnMempoolResync": false,
"fiat_rates": "coingecko",
"fiat_rates_vs_currencies": "AED,ARS,AUD,BDT,BHD,BMD,BRL,CAD,CHF,CLP,CNY,CZK,DKK,EUR,GBP,HKD,HUF,IDR,ILS,INR,JPY,KRW,KWD,LKR,MMK,MXN,MYR,NGN,NOK,NZD,PHP,PKR,PLN,RUB,SAR,SEK,SGD,THB,TRY,TWD,UAH,USD,VEF,VND,ZAR,BTC,ETH",
"fiat_rates_params": "{\"url\": \"https://api.coingecko.com/api/v3\", \"coin\": \"ethereum\",\"platformIdentifier\": \"ethereum\",\"platformVsCurrency\": \"eth\",\"periodSeconds\": 900}",
"fourByteSignatures": "https://www.4byte.directory/api/v1/signatures/"
}
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
},
"meta": {
"package_maintainer": "IT",
"package_maintainer_email": "it@satoshilabs.com"
}
}
}

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Polygon",
"shortcut": "MATIC",
"network": "MATIC",
"label": "Polygon",
"alias": "polygon_bor"
},

View File

@ -2,6 +2,7 @@
"coin": {
"name": "Polygon Archive",
"shortcut": "MATIC",
"network": "MATIC",
"label": "Polygon",
"alias": "polygon_archive_bor"
},

View File

@ -1962,6 +1962,7 @@ func (d *RocksDB) LoadInternalState(config *common.Config) (*common.InternalStat
} else {
is.CoinLabel = config.CoinLabel
}
is.Network = config.Network
return is, nil
}

View File

@ -1039,7 +1039,7 @@ var websocketTestsBitcoinType = []websocketTest{
req: websocketReq{
Method: "getInfo",
},
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","network":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
},
{
name: "websocket getBlockHash",
@ -1681,7 +1681,7 @@ var websocketTestsBitcoinTypeExtendedIndex = []websocketTest{
req: websocketReq{
Method: "getInfo",
},
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
want: `{"id":"0","data":{"name":"Fakecoin","shortcut":"FAKE","network":"FAKE","decimals":8,"version":"unknown","bestHeight":225494,"bestHash":"00000000eb0443fd7dc4a1ed5c686a8e995057805f9a161d9a5a77a95e72b7b6","block0Hash":"","testnet":true,"backend":{"version":"001001","subversion":"/Fakecoin:0.0.1/"}}}`,
},
{
name: "websocket getBlockHash",

View File

@ -277,8 +277,8 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *WsRe
c.getAddressInfoDescriptorsMux.Unlock()
if l > s.is.WsGetAccountInfoLimit {
if s.closeChannel(c) {
glog.Info("Client ", c.id, " exceeded getAddressInfo limit, ", c.ip)
s.is.AddWsLimitExceedingIP(c.ip)
glog.Info("Client ", c.id, " exceeded getAddressInfo limit, ", c.ip)
s.is.AddWsLimitExceedingIP(c.ip)
}
return
}
@ -580,6 +580,7 @@ func (s *WebsocketServer) getInfo() (*WsInfoRes, error) {
return &WsInfoRes{
Name: s.is.Coin,
Shortcut: s.is.CoinShortcut,
Network: s.is.GetNetwork(),
Decimals: s.chainParser.AmountDecimals(),
BestHeight: int(height),
BestHash: hash,

View File

@ -36,6 +36,7 @@ type WsBackendInfo struct {
type WsInfoRes struct {
Name string `json:"name"`
Shortcut string `json:"shortcut"`
Network string `json:"network"`
Decimals int `json:"decimals"`
Version string `json:"version"`
BestHeight int `json:"bestHeight"`