Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gobitfly/eth2-beaconchain-explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbitfly committed Dec 6, 2022
2 parents d0a4df4 + 3c1c44a commit bd07dcc
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 143 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cmd/playground
cmd/monitor
cmd/explorer/explorer
cmd/explorer/__debug_bin
modd.conf
bin/
docker/
Expand Down
18 changes: 5 additions & 13 deletions handlers/imprint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package handlers

import (
"eth2-exporter/templates"
"eth2-exporter/utils"
"html/template"
"net/http"
"path"
)
Expand All @@ -11,26 +11,18 @@ import (
func Imprint(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")

var imprintTemplate *template.Template
var err error
var imprintTemplate = templates.GetTemplate("layout.html")

if utils.Config.Frontend.LegalDir == "" {
imprintTemplate, err = template.New("imprint").Funcs(utils.GetTemplateFuncs()).ParseFiles("templates/layout.html", utils.Config.Frontend.Imprint)
imprintTemplate = templates.AddTemplateFile(imprintTemplate, utils.Config.Frontend.Imprint)
} else {
imprintTemplate, err = template.New("imprint").Funcs(utils.GetTemplateFuncs()).ParseFiles("templates/layout.html", path.Join(utils.Config.Frontend.LegalDir, "index.html"))
}

if err != nil {
logger.Errorf("error parsing imprint page template: %v", err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
return
imprintTemplate = templates.AddTemplateFile(imprintTemplate, path.Join(utils.Config.Frontend.LegalDir, "index.html"))
}

data := InitPageData(w, r, "imprint", "/imprint", "Imprint")
data.HeaderAd = true

err = imprintTemplate.ExecuteTemplate(w, "layout", data)

err := imprintTemplate.ExecuteTemplate(w, "layout", data)
if err != nil {
logger.Errorf("error executing template for %v route: %v", r.URL.String(), err)
http.Error(w, "Internal server error", http.StatusServiceUnavailable)
Expand Down
43 changes: 25 additions & 18 deletions services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1096,27 +1096,31 @@ func getGasNowData() (*types.GasNowPageData, error) {
return nil, err
}
var raw json.RawMessage
var body rpcBlock

err = client.Call(&raw, "eth_getBlockByNumber", "pending", true)

if err != nil {
return nil, fmt.Errorf("error retrieving pending block data: %v", err)
}

var header *geth_types.Header
var body rpcBlock

err = json.Unmarshal(raw, &header)
if err != nil {
return nil, err
}
err = json.Unmarshal(raw, &body)
if err != nil {
return nil, err
}
txs := body.Transactions

logger.Infof("pending block has %v tx", len(body.Transactions))

sort.Slice(body.Transactions, func(i, j int) bool {
return body.Transactions[i].tx.GasPrice().Cmp(body.Transactions[j].tx.GasPrice()) > 0
sort.Slice(txs, func(i, j int) bool {
return txs[i].tx.GasPrice().Cmp(txs[j].tx.GasPrice()) > 0
})
if len(body.Transactions) > 1 {
medianGasPrice := body.Transactions[len(body.Transactions)/2].tx.GasPrice()
tailGasPrice := body.Transactions[len(body.Transactions)-1].tx.GasPrice()
if len(txs) > 1 {
medianGasPrice := txs[len(txs)/2].tx.GasPrice()
tailGasPrice := txs[len(txs)-1].tx.GasPrice()

gpoData.Data.Rapid = medianGasPrice
gpoData.Data.Fast = tailGasPrice
Expand Down Expand Up @@ -1151,17 +1155,20 @@ func getGasNowData() (*types.GasNowPageData, error) {
return pendingTxs[i].GasPrice().Cmp(pendingTxs[j].GasPrice()) > 0
})

standardIndex := int(math.Max(float64(2*len(body.Transactions)), 500))
slowIndex := int(math.Max(float64(5*len(body.Transactions)), 1000))
if standardIndex > len(pendingTxs)-1 {
standardIndex = len(pendingTxs) - 1
}
if slowIndex > len(pendingTxs)-1 {
slowIndex = len(pendingTxs) - 1
standardIndex := int(math.Max(float64(2*len(txs)), 500))

slowIndex := int(math.Max(float64(5*len(txs)), 1000))
if standardIndex < len(pendingTxs) {
gpoData.Data.Standard = pendingTxs[standardIndex].GasPrice()
} else {
gpoData.Data.Standard = header.BaseFee
}

gpoData.Data.Standard = pendingTxs[standardIndex].GasPrice()
gpoData.Data.Slow = pendingTxs[slowIndex].GasPrice()
if slowIndex < len(pendingTxs) {
gpoData.Data.Slow = pendingTxs[slowIndex].GasPrice()
} else {
gpoData.Data.Slow = header.BaseFee
}

err = db.BigtableClient.SaveGasNowHistory(gpoData.Data.Slow, gpoData.Data.Standard, gpoData.Data.Fast, gpoData.Data.Rapid)
if err != nil {
Expand Down
107 changes: 0 additions & 107 deletions tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -651,113 +651,6 @@ create table api_statistics
primary key (ts, apikey, call)
);

drop table if exists stats_meta_p;
CREATE TABLE stats_meta_p (
id bigserial,
version int not null default 1,
ts timestamp not null,
process character varying(20) not null,
machine character varying(50),
created_trunc timestamp not null,
exporter_version varchar(35),
day int,

user_id bigint not null,
primary key (id, day)

) PARTITION BY LIST (day);

drop table if exists stats_process;
CREATE TABLE stats_process (
id bigserial primary key,

cpu_process_seconds_total bigint not null,

memory_process_bytes bigint not null,

client_name character varying(25) not null,
client_version character varying(25) not null,
client_build int not null,

sync_eth2_fallback_configured bool not null,
sync_eth2_fallback_connected bool not null,

meta_id bigint not null,

foreign key(meta_id) references stats_meta(id)
);
create index idx_stats_process_metaid on stats_process (meta_id);

drop table if exists stats_add_beaconnode;
CREATE TABLE stats_add_beaconnode (
id bigserial primary key,

disk_beaconchain_bytes_total bigint not null,
network_libp2p_bytes_total_receive bigint not null,
network_libp2p_bytes_total_transmit bigint not null,
network_peers_connected int not null,
sync_eth1_connected bool not null,
sync_eth2_synced bool not null,
sync_beacon_head_slot bigint not null,
sync_eth1_fallback_configured bool not null,
sync_eth1_fallback_connected bool not null,

general_id bigint not null,

foreign key(general_id) references stats_process(id)
);
create index idx_stats_beaconnode_generalid on stats_add_beaconnode (general_id);

drop table if exists stats_add_validator;
CREATE TABLE stats_add_validator (
id bigserial primary key,
validator_total int not null,
validator_active int not null,

general_id bigint not null,

foreign key(general_id) references stats_process(id)
);
create index idx_stats_beaconnode_validator on stats_add_validator (general_id);

drop table if exists stats_system;
CREATE TABLE stats_system (
id bigserial primary key,

cpu_cores int not null,
cpu_threads int not null,

cpu_node_system_seconds_total bigint not null,
cpu_node_user_seconds_total bigint not null,
cpu_node_iowait_seconds_total bigint not null,
cpu_node_idle_seconds_total bigint not null,

memory_node_bytes_total bigint not null,
memory_node_bytes_free bigint not null,
memory_node_bytes_cached bigint not null,
memory_node_bytes_buffers bigint not null,

disk_node_bytes_total bigint not null,
disk_node_bytes_free bigint not null,

disk_node_io_seconds bigint not null,
disk_node_reads_total bigint not null,
disk_node_writes_total bigint not null,

network_node_bytes_total_receive bigint not null,
network_node_bytes_total_transmit bigint not null,

misc_node_boot_ts_seconds bigint not null,
misc_os character varying(6) not null,

meta_id bigint not null,


foreign key(meta_id) references stats_meta(id)
);

create index idx_stats_system_meta_id on stats_system (meta_id);

drop table if exists stake_pools_stats;
create table stake_pools_stats
(
Expand Down
29 changes: 25 additions & 4 deletions templates/block/block.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,31 @@
<script type="text/javascript" src="/js/datatable_input.js"></script>

<script>
window.onload = function () {
setupInfiniteScrollAttestations();
setupInfiniteScrollTransactions();
};
{
var attestations_tab_loaded = false
let atab = $('#attestations-tab')
if(atab.length > 0) {
atab.on('shown.bs.tab', function (event) { if(!attestations_tab_loaded) { setupInfiniteScrollAttestations(); }; attestations_tab_loaded = true; });
} else {
console.error('error getting #attestations-tab')
const att = document.getElementById('attestations');
if(att) {
att.appendChild(getInfoElementAttestations('Error loading attestations...', 'red'));
}
}

var transactions_tab_loaded = false
let ttab = $('#transactions-tab')
if(ttab.length > 0) {
ttab.on('shown.bs.tab', function (event) { if(!transactions_tab_loaded) { setupInfiniteScrollTransactions(); }; transactions_tab_loaded = true; });
} else {
console.error('error getting #transactions-tab')
const att = document.getElementById('transactions_table');
if(att) {
att.appendChild(getInfoElementTransactions('Error loading attestations...', 'red'));
}
}
}

function getInfoElementAttestations (text, color) {
const att_card = document.createElement('div'); {
Expand Down
1 change: 0 additions & 1 deletion templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,6 @@ <h5>Links</h5>
{{ end }}
<script src="/js/clipboard.min.js"></script>
{{ template "js" .Data }}
<script src="/js/instant.min.js" type="module"></script>
{{ if not .Meta.NoTrack }}
{{ if ne .Meta.GATag "" }}
<!-- Global site tag (gtag.js) - Google Analytics -->
Expand Down
21 changes: 21 additions & 0 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,24 @@ func getFileSysNames(fsys fs.FS, dirname string) ([]string, error) {

return files, nil
}

func AddTemplateFile(tmpl *template.Template, path string) *template.Template {
name := filepath.Base(path)
if utils.Config.Frontend.Debug {
return template.Must(tmpl.ParseFiles(path))
}

templateCacheMux.RLock()
if templateCache[name] != nil {
templateCacheMux.RUnlock()
return templateCache[name]
}
templateCacheMux.RUnlock()

tmpl = template.Must(tmpl.ParseFiles(path))
templateCacheMux.Lock()
templateCache[name] = tmpl
templateCacheMux.Unlock()

return templateCache[name]
}

0 comments on commit bd07dcc

Please sign in to comment.