Skip to content

Commit

Permalink
Add template for initializing stake and ATA accounts on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisses committed Nov 22, 2023
1 parent a964bf4 commit b1e9e64
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/nosana_node/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@
(cond
))

(defn use-set-log-level [{:nos/keys [vault] :as sys}]
(let [log-level
(nth (reverse [:trace :debug :info :warn :error
:fatal :report])
(:verbosity vault))]
(log/set-min-level! log-level)
(log/debug "Log level is " log-level))
sys)

(defn use-cli
"Parse CLI arguments using `tools.cli` and add to system map.
Expand Down Expand Up @@ -196,16 +205,7 @@

:else
(do
;; set logging level
(let [{:keys [verbosity]} options

log-level
(nth (reverse [:trace :debug :info :warn :error
:fatal :report])
verbosity)]

(log/set-min-level! log-level)
(log/debug "Log level is " log-level))

;; merge CLI over existing config
(cond->
Expand Down
17 changes: 13 additions & 4 deletions src/nosana_node/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

(ns nosana-node.main
(:require
[nosana-node.nosana :as nosana :refer [use-nosana work-loop]]
[nosana-node.nosana :as nosana :refer [use-nosana work-loop
use-create-ata-and-stake]]
[nos.core :as flow]
[clojure.core.async :refer [<!!]]
[nosana-node.system :refer [start-system use-when use-jetty] :as nos-sys]
[nosana-node.system :refer [start-system use-when use-jetty use-nrepl] :as nos-sys]
[nosana-node.pipeline :as pipeline]
[nosana-node.cli :as cli]
nosana-node.gitlab
Expand Down Expand Up @@ -50,11 +51,18 @@
:system/components [use-vault
cli/use-cli
store/use-fs-store
;; use-nrepl
;; nrepl is useful for debugging,
;; make config later
(use-when (constantly false)
use-nrepl)
(use-when :run-server?
use-jetty)
;; we change the log level after
;; jetty, as it prints a lot of INFO
cli/use-set-log-level
use-nostromo
use-nosana
use-create-ata-and-stake
nos-sys/use-wrap-ctx]
:system/profile :prod
:cli-args args
Expand All @@ -70,4 +78,5 @@
(catch Exception e
(do
(log/log :trace e)
(println (ex-message e))))))
(println (ex-message e))
(System/exit 1)))))
17 changes: 16 additions & 1 deletion src/nosana_node/nosana.clj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"0")))})

(def min-sol-balance
"Minimum Solana balance to be healthy" (sol/format-sol "10000000"))
"Minimum Solana balance to be healthy"
(sol/format-sol "10000000"))

(defn healthy
"Check if the current node is healthy."
Expand Down Expand Up @@ -740,7 +741,21 @@
(log :debug tx))))
(recur nil last-health-check true)))))))))

(defn use-create-ata-and-stake
"Component that creates the NOS ATA and stake account if they don't
exist yet."
[{:nos/keys [conf] :as sys}]
(let [ata (:nos-ata conf)
stake (get-in conf [:accounts "stake"])]
;; TODO: use `sol/get-account-data` on ata and stake. if it
;; returns `nil` the account does not exist

;; TODO: create method for opening a stake and opening an ata

sys))

(defn use-nosana
"Component that loads the Nosana config."
[{:nos/keys [store flow-chan vault] :as system}]
;; Wait a bit for podman to boot
(log :trace "Waiting 5s for podman")
Expand Down

0 comments on commit b1e9e64

Please sign in to comment.