Skip to content

Commit

Permalink
add db_save_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
olton committed Aug 24, 2024
1 parent 087d8e0 commit f0ee947
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/Modules/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
db_get_blocks_crt,
db_get_blocks_short,
db_get_dispute,
db_get_epoch, db_get_hard_fork_block, db_get_last_canonical_block, db_get_uptime_leader_board
db_get_epoch, db_get_hard_fork_block, db_get_last_canonical_block, db_get_uptime_leader_board, db_save_runtime
} from "./db.js";
import {parseTime} from "../Helpers/parsers.js";
import {get_price_info} from "./coingecko.js"
Expand Down Expand Up @@ -92,6 +92,7 @@ export const cache_transaction_in_pool = async () => {
export const cache_runtime = async () => {
try {
cache.runtime = await ql_get_runtime()
db_save_runtime(cache.runtime)
} finally {
setTimeout(cache_runtime, parseTime('30s'))
}
Expand Down
28 changes: 28 additions & 0 deletions server/Modules/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,3 +1313,31 @@ export const db_get_transactions_status_per_epoch = async (limit = 100) => {
`
return (await query(sql, [limit])).rows
}

export const db_save_runtime = async (conf) => {
const {version, genesisConstants, runtimeConfig, networkID} = conf
const {genesisTimestamp, coinbase = 720000000000, accountCreationFee = 1000000000} = genesisConstants
const {k, delta, slots_per_epoch, slots_per_sub_window, grace_period_slots} = runtimeConfig.genesis
const {level, sub_windows_per_window, ledger_depth, work_delay, block_window_duration_ms, supercharged_coinbase_factor, fork} = runtimeConfig.proof
const {state_hash, blockchain_length, global_slot_since_genesis} = fork
const ledger_hash = runtimeConfig.ledger.hash

const sql = `
insert into network_runtime (mina_version, genesis_timestamp, coinbase, supercharge_factor, account_creation_fee,
network_id, genesis_k, genesis_delta, genesis_slots_per_epoch, genesis_slots_per_sub_window,
genesis_grace_period_slots, fork_state_hash, fork_blockchain_length, fork_global_slot_since_genesis,
proof_level, proof_sub_windows_per_window, proof_ledger_depth, proof_work_delay,
proof_block_window_duration_ms, ledger_hash)
values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) on conflict do nothing
`

try {
return (await query(sql, [
version, genesisTimestamp, coinbase, supercharged_coinbase_factor, accountCreationFee, networkID, k, delta, slots_per_epoch, slots_per_sub_window,
grace_period_slots, state_hash, blockchain_length, global_slot_since_genesis,
level, sub_windows_per_window, ledger_depth, work_delay, block_window_duration_ms, ledger_hash
]))
} catch (e) {
return null
}
}

0 comments on commit f0ee947

Please sign in to comment.