ceremonyclient/node/app/db_console.go
Cassandra Heart 9e1d07d1a0
Squashed commit of the following:
commit d05a4d5f688dbd09900ceccdcc5f8109dd0671c2
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Wed Jun 12 00:50:16 2024 -0500

    merge

commit db57ff1f191f9dedc87ca77da1c71244dd2325bd
Merge: 7b43494 2e3279a
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Wed Jun 12 00:49:32 2024 -0500

    Merge branch 'v1.4.19' into not-release

commit 7b43494246e28152b46710c8c9821429d4231f7e
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Wed Jun 12 00:49:13 2024 -0500

    pull from release site

commit 2e3279ac930ac630d9ca2b26cf4f3232abe79823
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 06:31:02 2024 -0500

    remove binaries

commit 2768a8778b3860c5736352c8aa950e3496a46e56
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 06:24:44 2024 -0500

    signatory #8 added

commit 6a944628575ccadd17c9f9f4a11a49c032fa0c1d
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 06:08:26 2024 -0500

    signatory #6 added

commit b401fb65e5ddbe0340fe85aab1182d6120a4e161
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 05:39:03 2024 -0500

    signatory #3 added

commit e5700913c0f6246fb607bcd3e219c257cb4a80e9
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 05:31:24 2024 -0500

    signatory #15 added

commit 9b1da6c03e517135bfcd59226f900adab42f3687
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 05:23:02 2024 -0500

    signatories #4 and #16 added

commit 9c97d1bbc399a070ac21b35ed9b1af127fa4c7ea
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 04:59:27 2024 -0500

    signatories #1 and #2 added

commit 905e3f78a8121eade1c331ae910ed25dd534f27a
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 04:40:32 2024 -0500

    build, binaries, signatory #13

commit ebfb57bc29d9ed1fb25d0dd100e38709354b3d84
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Sat Jun 8 03:38:53 2024 -0500

    tests pass, let's go

commit 5d4612c6c624c3dc18f9a5657936034ac9d9d8dd
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 03:53:15 2024 -0500

    update version info + readme

commit 6b0dd69e930d01b98acb8d7b56bb5d572e1a4324
Merge: 090d630 859221b
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 08:25:16 2024 +0000

    Merge branch 'feat-data-worker-direct-config' into 'v1.4.19'

    feat: support detached configuration mode for data workers

    See merge request quilibrium/ceremonyclient!7

commit 859221b179ab2631fa474be2494259afaaa6bd51
Author: Cassandra Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 03:24:22 2024 -0500

    feat: support detached configuration mode for data workers

commit 090d6301d44a2aa88886120783cd5a6e537aa6d1
Merge: 62db30c d1cae94
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 06:25:43 2024 +0000

    Merge branch 'feat-go-1-22' into 'v1.4.19'

    feat: go 1.22 support

    See merge request quilibrium/ceremonyclient!6

commit d1cae942165f4871f8051e266722c0ca717780cb
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 06:25:43 2024 +0000

    feat: go 1.22 support

commit 62db30c54f9258c92113c6664ce817670a339083
Merge: 0cbc0d0 f36cea3
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 03:52:17 2024 +0000

    Merge branch 'rust-vdf' into 'v1.4.19'

    Switch to Rust VDF

    See merge request quilibrium/ceremonyclient!2

commit f36cea323bfe5e56f519f59f9a0cce35f0f8b6ab
Author: Agost Biro <agostbiro@gmail.com>
Date:   Fri Jun 7 03:52:16 2024 +0000

    Switch to Rust VDF

commit 0cbc0d0d319713e20ca7f48588c4153833e58429
Merge: 986e12c 0c48a83
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Fri Jun 7 00:50:15 2024 +0000

    Merge branch 'release_image' into 'v1.4.19'

    create docker image based on release binaries

    See merge request quilibrium/ceremonyclient!4

commit 0c48a83bb5751abf7c8c0ff188bfdc2130631e78
Author: Marius Scurtescu <marius.scurtescu@gmail.com>
Date:   Fri Jun 7 00:50:15 2024 +0000

    create docker image based on release binaries

commit 986e12c88bb2d2b412b59f7db1ae39f828304dbe
Merge: 58456c1 a3ef5c6
Author: Cassie Heart <cassandra@quilibrium.com>
Date:   Wed Jun 5 22:01:37 2024 +0000

    Merge branch 'signature_check' into 'v1.4.19'

    add default of signature check from QUILIBRIUM_SIGNATURE_CHECK env var

    See merge request quilibrium/ceremonyclient!1

commit a3ef5c6af2d5de107d01c45a62d7324165e2551b
Author: Marius Scurtescu <marius.scurtescu@gmail.com>
Date:   Wed Jun 5 14:37:50 2024 -0700

    add default of signature check from QUILIBRIUM_SIGNATURE_CHECK env var
2024-06-12 00:51:16 -05:00

905 lines
26 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
"bytes"
"context"
"encoding/base64"
"encoding/hex"
"fmt"
"math/big"
"os"
"strings"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
mn "github.com/multiformats/go-multiaddr/net"
"github.com/pkg/errors"
"golang.org/x/term"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
"source.quilibrium.com/quilibrium/monorepo/node/config"
"source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/ceremony/application"
"source.quilibrium.com/quilibrium/monorepo/node/p2p"
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
"source.quilibrium.com/quilibrium/monorepo/node/tries"
)
var (
textColor = lipgloss.Color("#fff")
primaryColor = lipgloss.Color("#ff0070")
secondaryColor = lipgloss.Color("#ff5c00")
windowHeader = lipgloss.NewStyle().
Foreground(textColor).
Padding(0, 1)
unselectedListStyle = lipgloss.NewStyle().
Foreground(textColor).
Width(28).
Padding(0, 1)
navigatedListStyle = lipgloss.NewStyle().
Foreground(textColor).
Width(28).
Bold(true).
Padding(0, 1)
selectedListStyle = lipgloss.NewStyle().
Foreground(textColor).
Background(primaryColor).
Width(28).
Padding(0, 1)
statusBarStyle = lipgloss.NewStyle().
Foreground(textColor).
Background(primaryColor)
statusStyle = lipgloss.NewStyle().
Foreground(textColor).
Background(primaryColor).
Padding(0, 1)
statusItemStyle = lipgloss.NewStyle().
Foreground(textColor).
Background(secondaryColor).
Padding(0, 1)
docStyle = lipgloss.NewStyle().Padding(0)
border = lipgloss.Border{
Top: "─",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "└",
BottomRight: "┘",
}
)
type DBConsole struct {
nodeConfig *config.Config
}
func newDBConsole(nodeConfig *config.Config) (*DBConsole, error) {
return &DBConsole{
nodeConfig,
}, nil
}
type model struct {
filters []string
cursor int
selectedFilter string
conn *grpc.ClientConn
client protobufs.NodeServiceClient
peerId string
errorMsg string
frame *protobufs.ClockFrame
frames []*protobufs.ClockFrame
frameIndex int
grpcWarn bool
committed bool
lastChecked int64
owned *big.Int
unconfirmedOwned *big.Int
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.conn.GetState() == connectivity.Ready {
if m.lastChecked < (time.Now().UnixMilli() - 10_000) {
m.lastChecked = time.Now().UnixMilli()
tokenBalance, err := FetchTokenBalance(m.client)
if err == nil {
m.owned = tokenBalance.Owned
m.unconfirmedOwned = tokenBalance.UnconfirmedOwned
}
}
}
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
case "up", "w":
if m.cursor > 0 {
m.cursor--
}
case "down", "s":
if m.cursor < len(m.filters)-1 {
m.cursor++
}
case "left", "a":
m.committed = false
m.errorMsg = ""
if m.frameIndex > 0 {
m.frameIndex--
if len(m.frames) != 0 && m.conn.GetState() == connectivity.Ready {
filter, _ := hex.DecodeString(m.selectedFilter)
selector, err := m.frames[m.frameIndex].GetSelector()
if err != nil {
m.errorMsg = err.Error()
break
}
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
},
)
if err == nil && bytes.Equal(
frameInfo.ClockFrame.Output,
m.frames[m.frameIndex].Output,
) {
m.committed = true
m.frame = frameInfo.ClockFrame
} else {
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
Selector: selector.FillBytes(make([]byte, 32)),
},
)
if err != nil {
m.errorMsg = hex.EncodeToString(
selector.FillBytes(make([]byte, 32)),
) + ":" + err.Error()
break
}
m.frame = frameInfo.ClockFrame
}
} else {
m.errorMsg = "Not currently connected to node, cannot query."
}
} else {
first := uint64(0)
if len(m.frames) != 0 {
first = m.frames[0].FrameNumber - 1
}
if first == 0 {
break
}
max := uint64(17)
if len(m.frames) != 0 {
max = first
}
min := max - 16
filter, _ := hex.DecodeString(m.selectedFilter)
frames, err := m.client.GetFrames(
context.Background(),
&protobufs.GetFramesRequest{
Filter: filter,
FromFrameNumber: min,
ToFrameNumber: max + 1,
IncludeCandidates: true,
},
)
if err != nil {
m.selectedFilter = ""
m.errorMsg = err.Error()
break
}
if frames.TruncatedClockFrames != nil {
m.frames = frames.TruncatedClockFrames
m.frameIndex = len(m.frames) - 1
selector, err := m.frames[m.frameIndex].GetSelector()
if err != nil {
m.errorMsg = err.Error()
break
}
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
},
)
if err == nil && bytes.Equal(
frameInfo.ClockFrame.Output,
m.frames[m.frameIndex].Output,
) {
m.committed = true
m.frame = frameInfo.ClockFrame
} else {
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
Selector: selector.FillBytes(make([]byte, 32)),
},
)
if err != nil {
m.errorMsg = err.Error()
break
}
m.frame = frameInfo.ClockFrame
}
}
}
case "right", "d":
m.committed = false
m.errorMsg = ""
if m.frameIndex < len(m.frames)-1 {
m.frameIndex++
if len(m.frames) != 0 && m.conn.GetState() == connectivity.Ready {
filter, _ := hex.DecodeString(m.selectedFilter)
selector, err := m.frames[m.frameIndex].GetSelector()
if err != nil {
m.errorMsg = err.Error()
break
}
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
},
)
if err == nil && bytes.Equal(
frameInfo.ClockFrame.Output,
m.frames[m.frameIndex].Output,
) {
m.committed = true
m.frame = frameInfo.ClockFrame
} else {
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
Selector: selector.FillBytes(make([]byte, 32)),
},
)
if err != nil {
m.errorMsg = hex.EncodeToString(
selector.FillBytes(make([]byte, 32)),
) + ":" + err.Error()
break
}
m.frame = frameInfo.ClockFrame
}
} else {
m.errorMsg = "Not currently connected to node, cannot query."
}
} else {
min := uint64(1)
if len(m.frames) != 0 {
min = m.frames[len(m.frames)-1].FrameNumber + 1
}
max := min + 16
filter, _ := hex.DecodeString(m.selectedFilter)
frames, err := m.client.GetFrames(
context.Background(),
&protobufs.GetFramesRequest{
Filter: filter,
FromFrameNumber: min,
ToFrameNumber: max,
IncludeCandidates: true,
},
)
if err != nil {
m.selectedFilter = ""
m.errorMsg = err.Error()
break
}
if frames.TruncatedClockFrames != nil {
m.frames = frames.TruncatedClockFrames
m.frameIndex = 0
selector, err := m.frames[m.frameIndex].GetSelector()
if err != nil {
m.errorMsg = err.Error()
break
}
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
},
)
if err == nil && bytes.Equal(
frameInfo.ClockFrame.Output,
m.frames[m.frameIndex].Output,
) {
m.committed = true
m.frame = frameInfo.ClockFrame
} else {
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
Selector: selector.FillBytes(make([]byte, 32)),
},
)
if err != nil {
m.errorMsg = err.Error()
break
}
m.frame = frameInfo.ClockFrame
}
}
}
case "enter", " ":
m.errorMsg = ""
m.frame = nil
m.committed = false
if m.conn.GetState() == connectivity.Ready {
if m.selectedFilter != m.filters[m.cursor] {
m.selectedFilter = m.filters[m.cursor]
m.frames = []*protobufs.ClockFrame{}
}
min := uint64(1)
if len(m.frames) != 0 {
min = m.frames[len(m.frames)-1].FrameNumber + 1
}
max := min + 16
filter, _ := hex.DecodeString(m.selectedFilter)
frames, err := m.client.GetFrames(
context.Background(),
&protobufs.GetFramesRequest{
Filter: filter,
FromFrameNumber: min,
ToFrameNumber: max,
IncludeCandidates: true,
},
)
if err != nil {
m.selectedFilter = ""
m.errorMsg = err.Error()
break
}
if frames.TruncatedClockFrames != nil {
m.frames = frames.TruncatedClockFrames
m.frameIndex = 0
selector, err := m.frames[m.frameIndex].GetSelector()
if err != nil {
m.errorMsg = err.Error()
break
}
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
},
)
if err == nil && bytes.Equal(
frameInfo.ClockFrame.Output,
m.frames[m.frameIndex].Output,
) {
m.committed = true
m.frame = frameInfo.ClockFrame
} else {
frameInfo, err := m.client.GetFrameInfo(
context.Background(),
&protobufs.GetFrameInfoRequest{
Filter: filter,
FrameNumber: m.frames[m.frameIndex].FrameNumber,
Selector: selector.FillBytes(make([]byte, 32)),
},
)
if err != nil {
m.errorMsg = err.Error()
break
}
m.frame = frameInfo.ClockFrame
}
}
} else {
m.errorMsg = "Not currently connected to node, cannot query."
}
}
}
return m, nil
}
func (m model) View() string {
physicalWidth, physicalHeight, _ := term.GetSize(int(os.Stdout.Fd()))
doc := strings.Builder{}
window := lipgloss.NewStyle().
Border(border, true).
BorderForeground(primaryColor).
Padding(0, 1)
list := []string{}
for i, item := range m.filters {
str := item[0:12] + ".." + item[len(item)-12:]
if m.selectedFilter == item {
list = append(list, selectedListStyle.Render(str))
} else if i == m.cursor {
list = append(list, navigatedListStyle.Render(str))
} else {
list = append(list, unselectedListStyle.Render(str))
}
}
w := lipgloss.Width
statusKey := statusItemStyle.Render("STATUS")
info := statusStyle.Render("(Press Ctrl-C or Q to quit)")
onlineStatus := "gRPC Not Enabled, Please Configure"
if !m.grpcWarn {
switch m.conn.GetState() {
case connectivity.Connecting:
onlineStatus = "CONNECTING"
case connectivity.Idle:
onlineStatus = "IDLE"
case connectivity.Shutdown:
onlineStatus = "SHUTDOWN"
case connectivity.TransientFailure:
onlineStatus = "DISCONNECTED"
default:
onlineStatus = "CONNECTED"
}
}
ownedVal := statusItemStyle.Copy().
Render("Owned: " + m.owned.String())
if m.owned.Cmp(big.NewInt(-1)) == 0 {
ownedVal = statusItemStyle.Copy().
Render("")
}
unconfirmedOwnedVal := statusItemStyle.Copy().
Render("Unconfirmed: " + m.unconfirmedOwned.String())
if m.unconfirmedOwned.Cmp(big.NewInt(-1)) == 0 {
unconfirmedOwnedVal = statusItemStyle.Copy().
Render("")
}
peerIdVal := statusItemStyle.Render(m.peerId)
statusVal := statusBarStyle.Copy().
Width(physicalWidth-w(statusKey)-w(info)-w(peerIdVal)-w(ownedVal)-
w(unconfirmedOwnedVal)).
Padding(0, 1).
Render(onlineStatus)
bar := lipgloss.JoinHorizontal(lipgloss.Top,
statusKey,
statusVal,
info,
peerIdVal,
ownedVal,
unconfirmedOwnedVal,
)
explorerContent := ""
if m.errorMsg != "" {
explorerContent = m.errorMsg
} else if m.frame != nil {
selector, err := m.frame.GetSelector()
if err != nil {
panic(err)
}
committed := "Unconfirmed"
if m.committed {
committed = "Confirmed"
}
explorerContent = fmt.Sprintf(
"Frame %d (Selector: %x, %s):\n\tParent: %x\n\tVDF Proof: %x\n",
m.frame.FrameNumber,
selector.FillBytes(make([]byte, 32)),
committed,
m.frame.ParentSelector,
m.frame.Input[:516],
)
for i := 0; i < len(m.frame.Input[516:])/74; i++ {
commit := m.frame.Input[516+(i*74) : 516+((i+1)*74)]
explorerContent += fmt.Sprintf(
"\tCommitment %+x\n",
commit,
)
explorerContent += fmt.Sprintf(
"\t\tType: %s\n",
m.frame.AggregateProofs[i].InclusionCommitments[0].TypeUrl,
)
switch m.frame.AggregateProofs[i].InclusionCommitments[0].TypeUrl {
case protobufs.IntrinsicExecutionOutputType:
explorerContent += "Application: Ceremony\n"
app, err := application.MaterializeApplicationFromFrame(m.frame)
if err != nil {
explorerContent += "Error: " + err.Error() + "\n"
continue
}
total := new(big.Int)
if app.RewardTrie.Root == nil ||
(app.RewardTrie.Root.External == nil &&
app.RewardTrie.Root.Internal == nil) {
explorerContent += "Total Rewards: 0 QUIL\n"
continue
}
limbs := []*tries.RewardInternalNode{}
if app.RewardTrie.Root.Internal != nil {
limbs = append(limbs, app.RewardTrie.Root.Internal)
} else {
total = total.Add(
total,
new(big.Int).SetUint64(app.RewardTrie.Root.External.Total),
)
}
for len(limbs) != 0 {
nextLimbs := []*tries.RewardInternalNode{}
for _, limb := range limbs {
for _, child := range limb.Child {
child := child
if child.Internal != nil {
nextLimbs = append(nextLimbs, child.Internal)
} else {
total = total.Add(
total,
new(big.Int).SetUint64(child.External.Total),
)
}
}
}
limbs = nextLimbs
}
explorerContent += "Total Rewards: " + total.String() + " QUIL\n"
state := app.LobbyState.String()
explorerContent += "Round State: " + state + "\n"
switch app.LobbyState {
case application.CEREMONY_APPLICATION_STATE_OPEN:
explorerContent += "Joins: \n"
for _, join := range app.LobbyJoins {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
join.PublicKeySignatureEd448.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Preferred Next Round Participants: \n"
for _, next := range app.NextRoundPreferredParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
next.KeyValue,
) + "\n"
}
explorerContent += fmt.Sprintf(
"State Transition Counter: %d\n",
app.StateCount,
)
case application.CEREMONY_APPLICATION_STATE_IN_PROGRESS:
explorerContent += fmt.Sprintf("Sub-Round: %d\n", app.RoundCount)
explorerContent += "Participants: \n"
for _, active := range app.ActiveParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
active.PublicKeySignatureEd448.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Latest Seen: \n"
for _, latest := range app.LatestSeenProverAttestations {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
latest.SeenProverKey.KeyValue,
) + " seen by " + base64.StdEncoding.EncodeToString(
latest.ProverSignature.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Dropped: \n"
for _, dropped := range app.DroppedParticipantAttestations {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
dropped.DroppedProverKey.KeyValue,
) + " confirmed by " + base64.StdEncoding.EncodeToString(
dropped.ProverSignature.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Preferred Next Round Participants: \n"
for _, next := range app.NextRoundPreferredParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
next.KeyValue,
) + "\n"
}
case application.CEREMONY_APPLICATION_STATE_FINALIZING:
explorerContent += fmt.Sprintf(
"Confirmed Shares: %d\n",
len(app.TranscriptShares),
)
explorerContent += "Participants: \n"
for _, active := range app.ActiveParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
active.PublicKeySignatureEd448.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Latest Seen: \n"
for _, latest := range app.LatestSeenProverAttestations {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
latest.SeenProverKey.KeyValue,
) + " seen by " + base64.StdEncoding.EncodeToString(
latest.ProverSignature.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Dropped: \n"
for _, dropped := range app.DroppedParticipantAttestations {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
dropped.DroppedProverKey.KeyValue,
) + " confirmed by " + base64.StdEncoding.EncodeToString(
dropped.ProverSignature.PublicKey.KeyValue,
) + "\n"
}
explorerContent += "Preferred Next Round Participants: \n"
for _, next := range app.NextRoundPreferredParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
next.KeyValue,
) + "\n"
}
case application.CEREMONY_APPLICATION_STATE_VALIDATING:
explorerContent += fmt.Sprintf(
"G1 Powers: %d\n", len(app.UpdatedTranscript.G1Powers),
)
explorerContent += "Preferred Next Round Participants: \n"
for _, next := range app.NextRoundPreferredParticipants {
explorerContent += "\t" + base64.StdEncoding.EncodeToString(
next.KeyValue,
) + "\n"
}
}
}
}
} else {
explorerContent = logoVersion(physicalWidth - 34)
}
doc.WriteString(
lipgloss.JoinVertical(
lipgloss.Left,
lipgloss.JoinHorizontal(
lipgloss.Top,
lipgloss.JoinVertical(
lipgloss.Left,
windowHeader.Render("Filters (Up/Down, Enter)"),
window.Width(30).Height(physicalHeight-4).Render(lipgloss.JoinVertical(lipgloss.Left, list...)),
),
lipgloss.JoinVertical(
lipgloss.Left,
windowHeader.Render("Explorer (Left/Right)"),
window.Width(physicalWidth-34).Height(physicalHeight-4).Render(explorerContent),
),
),
statusBarStyle.Width(physicalWidth).Render(bar),
),
)
if physicalWidth > 0 {
docStyle = docStyle.MaxWidth(physicalWidth)
docStyle = docStyle.MaxHeight(physicalHeight)
}
return docStyle.Render(doc.String())
}
func consoleModel(
conn *grpc.ClientConn,
nodeConfig *config.Config,
grpcWarn bool,
) model {
peerPrivKey, err := hex.DecodeString(nodeConfig.P2P.PeerPrivKey)
if err != nil {
panic(errors.Wrap(err, "error unmarshaling peerkey"))
}
privKey, err := crypto.UnmarshalEd448PrivateKey(peerPrivKey)
if err != nil {
panic(errors.Wrap(err, "error unmarshaling peerkey"))
}
pub := privKey.GetPublic()
id, err := peer.IDFromPublicKey(pub)
if err != nil {
panic(errors.Wrap(err, "error getting peer id"))
}
return model{
filters: []string{
hex.EncodeToString([]byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}),
hex.EncodeToString(append(
p2p.GetBloomFilter(application.CEREMONY_ADDRESS, 256, 3),
p2p.GetBloomFilterIndices(application.CEREMONY_ADDRESS, 65536, 24)...,
)),
},
cursor: 0,
conn: conn,
client: protobufs.NewNodeServiceClient(conn),
owned: big.NewInt(-1),
unconfirmedOwned: big.NewInt(-1),
peerId: id.String(),
grpcWarn: grpcWarn,
}
}
var defaultGrpcAddress = "localhost:8337"
// Connect to the node via GRPC
func ConnectToNode(nodeConfig *config.Config) (*grpc.ClientConn, error) {
addr := defaultGrpcAddress
if nodeConfig.ListenGRPCMultiaddr != "" {
ma, err := multiaddr.NewMultiaddr(nodeConfig.ListenGRPCMultiaddr)
if err != nil {
panic(err)
}
_, addr, err = mn.DialArgs(ma)
if err != nil {
panic(err)
}
}
return grpc.Dial(
addr,
grpc.WithTransportCredentials(
insecure.NewCredentials(),
),
grpc.WithDefaultCallOptions(
grpc.MaxCallSendMsgSize(600*1024*1024),
grpc.MaxCallRecvMsgSize(600*1024*1024),
),
)
}
type TokenBalance struct {
Owned *big.Int
UnconfirmedOwned *big.Int
}
func FetchTokenBalance(client protobufs.NodeServiceClient) (TokenBalance, error) {
info, err := client.GetTokenInfo(
context.Background(),
&protobufs.GetTokenInfoRequest{},
)
if err != nil {
return TokenBalance{}, errors.Wrap(err, "error getting token info")
}
// owned := new(big.Int).SetBytes(info.OwnedTokens)
unconfirmedOwned := new(big.Int).SetBytes(info.UnconfirmedOwnedTokens)
return TokenBalance{
// Owned: owned,
UnconfirmedOwned: unconfirmedOwned,
}, nil
}
func FetchNodeInfo(client protobufs.NodeServiceClient) (*protobufs.NodeInfoResponse, error) {
info, err := client.GetNodeInfo(
context.Background(),
&protobufs.GetNodeInfoRequest{},
)
if err != nil {
return nil, errors.Wrap(err, "error getting node info")
}
return info, nil
}
// Runs the DB console
func (c *DBConsole) Run() {
conn, err := ConnectToNode(c.nodeConfig)
if err != nil {
panic(err)
}
defer conn.Close()
grpcWarn := c.nodeConfig.ListenGRPCMultiaddr == ""
p := tea.NewProgram(consoleModel(conn, c.nodeConfig, grpcWarn))
if _, err := p.Run(); err != nil {
panic(err)
}
}
func logoVersion(width int) string {
var out string
if width >= 83 {
out = " ..-------..\n"
out += " ..---'''' ''''---..\n"
out += " .---'' ''---.\n"
out += " .-' '-.\n"
out += " ..-' ..--''''''''''''''--.. '-..\n"
out += " .' .--'' ''--. ''.\n"
out += " .'' ..-' ''-. '.\n"
out += " ' ' ''. '.\n"
out += " '' .'' '. '\n"
out += " ' '' '. '\n"
out += " ' ' ########## . '\n"
out += " ' ' ############## ' '\n"
out += " ' ' ############## ' '\n"
out += " ' ' ############## ' '\n"
out += "' ' ########## ' '\n"
out += "' ' ' '\n"
out += "' ' ' '\n"
out += "' ' ####### ####### ' '\n"
out += "' ' &######################### ' '\n"
out += "' ' ##############% ############## ' '\n"
out += " ' ' &############## ############### ' '\n"
out += " ' ' ############### ##############% '. '\n"
out += " ' '. ########## ############### '-. '\n"
out += " '. . ##### ##############% '-.'\n"
out += " ' '. ###############\n"
out += " '. '.. ##############%\n"
out += " '. '-. ###############\n"
out += " '-. ''-.. .. ##############%\n"
out += " '-. ''---............----' '. ###############\n"
out += " '-.. '. ############\n"
out += " ''-.. ..' ########\n"
out += " ''---.. ...---'' ##\n"
out += " ''----------''\n"
out += " \n"
out += " Quilibrium Node - v" + config.GetVersionString() + " Betelgeuse\n"
out += " \n"
out += " DB Console\n"
} else {
out = "Quilibrium Node - v" + config.GetVersionString() + " Betelgeuse - DB Console\n"
}
return out
}