Skip to content

Commit

Permalink
added readme, automatic version assignment, fixed service update time…
Browse files Browse the repository at this point in the history
…stamps
  • Loading branch information
cryi committed Feb 13, 2024
1 parent 46cdc41 commit 67f6052
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 34 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:
with:
node-version: '20.x'

- name: inject version and codename
# PEAK_VERSION = "<VERSION>"
# PEAK_CODENAME = "<CODENAME>"
env:
TEZPEAK_VERSION: ${{ github.ref_name }}
TEZPEAK_CODENAME: Vinson
run: |
# patch constants/common.go
sed -i "s/TEZPEAK_VERSION[[:space:]]*= \".*\"/TEZPEAK_VERSION = \"$TEZPEAK_VERSION\"/g" constants/common.go
sed -i "s/TEZPEAK_CODENAME[[:space:]]*= \".*\"/TEZPEAK_CODENAME = \"$TEZPEAK_CODENAME\"/g" constants/common.go
# patch web/src/common/constants.ts
sed -i "s/TEZPEAK_VERSION[[:space:]]*= \".*\"/TEZPEAK_VERSION = \"$TEZPEAK_VERSION\"/g" web/src/common/constants.ts
sed -i "s/TEZPEAK_CODENAME[[:space:]]*= \".*\"/TEZPEAK_CODENAME = \"$TEZPEAK_CODENAME\"/g" web/src/common/constants.ts
- name: Install web dependencies
working-directory: web
run: npm install
Expand Down
3 changes: 2 additions & 1 deletion constants/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package constants

const (
TEZPEAK_VERSION = "0.0.6"
TEZPEAK_VERSION = "<VERSION>"
TEZPEAK_CODENAME = "<CODENAME>"

DEFAULT_LISTEN_ADDRESS = "localhost:8733"

Expand Down
3 changes: 2 additions & 1 deletion core/providers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package providers

import (
"context"
"fmt"
"log/slog"
"path"
"time"
Expand Down Expand Up @@ -43,7 +44,6 @@ func StartServiceStatusProvider(ctx context.Context, tezbakeHome string, statusC
signer := apps.SignerFromPath(path.Join(tezbakeHome, "signer"))

go func() {

status := ServicesStatus{
Timestamp: time.Now().Unix(),
NodeServices: map[string]base.AmiServiceInfo{},
Expand Down Expand Up @@ -91,6 +91,7 @@ func StartServiceStatusProvider(ctx context.Context, tezbakeHome string, statusC

status.SignerServices = <-signerServiceInfoChannel
status.NodeServices = <-nodeServiceInfoChannel
fmt.Println("status", time.Now().Unix())
status.Timestamp = time.Now().Unix()

statusChannel <- &ServicesStatusUpdate{
Expand Down
4 changes: 4 additions & 0 deletions core/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package core

import (
"context"
"fmt"
"log/slog"
"time"

"blockwatch.cc/tzgo/rpc"
"github.com/tez-capital/tezbake/apps/base"
Expand Down Expand Up @@ -47,6 +49,7 @@ func Run(ctx context.Context, config *configuration.Runtime) (<-chan PeakStatus,
slog.Warn("no address for node", "id", id)
continue
}

if node.IsRightsProvider {
if client, err := rpc.NewClient(node.Address, nil); err == nil {
rightProviderRpcs = append(rightProviderRpcs, client)
Expand Down Expand Up @@ -82,6 +85,7 @@ func Run(ctx context.Context, config *configuration.Runtime) (<-chan PeakStatus,
case common.ServicesStatusUpdateKind:
servicesStatus := statusUpdate.GetData().(providers.ServicesStatus)
status.Services = servicesStatus
fmt.Println("servicesStatus", time.Now().Unix())
case common.BakerStatusUpdateKind:
bakersStatus := statusUpdate.GetData().(providers.BakersStatus)
status.Bakers = bakersStatus
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
flag.Parse()

if *versionFlag {
fmt.Println(constants.TEZPEAK_VERSION)
fmt.Printf("tezpeak %s - %s \n", constants.TEZPEAK_VERSION, constants.TEZPEAK_CODENAME)
return
}

Expand Down
71 changes: 71 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## TEZPEAK

Simple monitoring interface for tezos bakers.

### Setup

Right now there are two supported ways to run tezpeak:
- as module of tezbake
- as a standalone server with ami

#### tezbake

Since tezbake 0.13.0-alpha the tezpeak is natively supported module. You can setup it in 3 simple steps:
1. `tezbake setup --peak`
2. Adjust configuration as needed
3. `tezbake start --peak`

#### standalone

TBD

### Configuration

The configuration is stored in `config.hjson` file. The default configuration is:

```yaml
{
# Id to show in the header
id: ""
# Address to listen on
listen: 127.0.0.1:8733
# List of bakers to monitor
bakers: [
]
# Baker's node to connect to
node: http://localhost:8732
# List of reference nodes to connect to
# The reference nodes are used to get the rights and blocks if the baker's node is not available
reference_nodes: {
"Tezos Foundation": {
address: https://rpc.tzbeta.net/
is_rights_provider: true
is_block_provider: false
},
"tzkt": {
address: https://rpc.tzkt.io/mainnet/
is_rights_provider: false
is_block_provider: true
}
}
# The mode tezpeak should operate in
# auto - if bound to localhost, it will operate in private mode if not, it will operate in public mode
# public - assumes public environment, only readonly operations are allowed
# private - assumes private environment, all operations are allowed
mode: auto
# The number of blocks to look for the rights
# 50 means 25 blocks in the past and 25 blocks in the future
block_window: 50
}
```

Sample minimal configuration:
```yaml
{
listen: "0.0.0.0:8733"
bakers: [
tz1P6WKJu2rcbxKiKRZHKQKmKrpC9TfW1AwM
tz1hZvgjekGo7DmQjWh7XnY5eLQD8wNYPczE
]
}
```
2 changes: 1 addition & 1 deletion web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ dist
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
vite.config.ts.timestamp-*
30 changes: 3 additions & 27 deletions web/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
import type { PeakStatus } from "./types"

export const PEAK_VERSION = "0.0.1"
export const PEAK_CODENAME = "Vinson"
export const TEZPEAK_VERSION = "<VERSION>"
export const TEZPEAK_CODENAME = "<CODENAME>"

export const DEPOSIT_LIMIT_STAKING_CAPACITY_MULTIPLIER = 10n
export const BLOCK_TIME = 15 * 1000 // 15 seconds in milliseconds

export const EMPTY_PEAK_STATUS: PeakStatus = {
// baker_node: {
// connection_status: "disconnected",
// },
baker_node: {
address: "http://localhost:8732",
connection_status: "connected",
block: {
hash: "BMW8LdcE1kGLKpNqsyqGKcsV6Beawiegp9m3HP4bLGFfCPTkRrM",
timestamp: "2024-02-12T00:40:14Z",
protocol: "ProxfordYmVfjWnRcgjWH36fW6PArwqykTFzotUxRs6gmTcZDuH",
level_info: {
level: 5084150,
level_position: 5084149,
cycle: 703,
cycle_position: 13301,
},
voting_period_info: {
position: 13301,
remaining: 68618,
voting_period: {
index: 116,
kind: "proposal",
start_position: 5070848
}
}
}
connection_status: "disconnected",
},
nodes: {

Expand Down
6 changes: 3 additions & 3 deletions web/src/routes/about/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<svelte:options immutable />

<script lang="ts">
import { PEAK_VERSION, PEAK_CODENAME } from '@src/common/constants';
import { TEZPEAK_VERSION, TEZPEAK_CODENAME } from '@src/common/constants';
import { DiscordIcon, TwitterIcon, TelegramIcon } from '@src/components/peak/icons';
</script>
Expand Down Expand Up @@ -69,8 +69,8 @@
TEZPEAK
</h2>
<h5 class="version not-selectable">
{PEAK_VERSION}
{PEAK_CODENAME}
{TEZPEAK_VERSION}
{TEZPEAK_CODENAME}
</h5>
<div class="social">
<a class="svg-icon" href="https://discord.gg/2PnCr62YgF" target="_blank" rel="noreferrer">
Expand Down
16 changes: 16 additions & 0 deletions web/src/util/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,40 @@ export function formatAddress(address: string) {
return `${address.slice(0, 10)}...${address.slice(-10)}`
}

function timestampToJSTimestamp(timestamp: number) {
if (timestamp < 10000000000) {
return timestamp * 1000
}
return timestamp
}

export function formatTimestamp(timestamp: string | number) {
if (!timestamp) {
return "N/A"
}

if (typeof timestamp === "number") timestamp = timestampToJSTimestamp(timestamp)

return new Date(timestamp).toLocaleString()
}

export function formatTimestampAgo(timestamp: string | number) {
if (!timestamp) {
return "N/A"
}

if (typeof timestamp === "number") timestamp = timestampToJSTimestamp(timestamp)

return formatDistance(new Date(timestamp), new Date())
}

export function formatTimestampAgoStrict(timestamp: string | number) {
if (!timestamp) {
return "N/A"
}

if (typeof timestamp === "number") timestamp = timestampToJSTimestamp(timestamp)

return formatDistanceStrict(new Date(timestamp), new Date(), { addSuffix: true })
}

Expand Down

0 comments on commit 67f6052

Please sign in to comment.