Skip to content

Commit

Permalink
new object pools view
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jul 25, 2021
1 parent 17f044d commit 06e6b85
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 245 deletions.
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@
[submodule "vendor/eth2-networks"]
path = vendor/eth2-networks
url = https://github.com/eth2-clients/eth2-networks.git

[submodule "vendor/DOtherSide"]
path = vendor/DOtherSide
url = https://github.com/filcuc/DOtherSide.git
branch = master
[submodule "vendor/nimqml"]
path = vendor/nimqml
url = https://github.com/filcuc/nimqml.git
branch = master

2 changes: 1 addition & 1 deletion beacon_chain/rpc/eth2_json_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type
DataRestPoolAttestations* = DataEnclosedObject[seq[Attestation]]
DataRestPoolAttesterSlashings* = DataEnclosedObject[seq[AttesterSlashing]]
DataRestPoolProposerSlashings* = DataEnclosedObject[seq[ProposerSlashing]]
DataRestPoolVoluntaryExits* = DataEnclosedObject[seq[VoluntaryExit]]
DataRestPoolVoluntaryExits* = DataEnclosedObject[seq[SignedVoluntaryExit]]
DataRestProposerDuties* = DataRootEnclosedObject[seq[RestProposerDuty]]
DataRestSignedBeaconBlock* = DataEnclosedObject[phase0.SignedBeaconBlock]
DataRestSyncInfo* = DataEnclosedObject[RestSyncInfo]
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/validator_client/api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ proc checkOnline*(node: BeaconNodeServerRef) {.async.} =
debug "Checking beacon node status"
let agent =
try:
let res = await node.client.getVersion()
let res = await node.client.getNodeVersion()
res.data.data
except CancelledError as exc:
error "Status request was interrupted"
Expand Down
10 changes: 5 additions & 5 deletions ngui/attestationlist.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import
std/[tables],
std/[sequtils, tables],
NimQml,
../beacon_chain/rpc/beacon_rest_client,
../beacon_chain/spec/[datatypes, helpers],
Expand Down Expand Up @@ -39,9 +39,9 @@ QtObject:
proc delete(self: AttestationList) =
self.QAbstractTableModel.delete

proc newAttestationList*(data: seq[AttestationInfo]): AttestationList =
proc newAttestationList*(data: seq[Attestation]): AttestationList =
new(result, delete)
result.data = ObjectTableModelImpl[AttestationInfo](items: data)
result.data = ObjectTableModelImpl[AttestationInfo](items: data.mapIt(it.toAttestationInfo()))
result.setup

method rowCount(self: AttestationList, index: QModelIndex = nil): int =
Expand All @@ -59,8 +59,8 @@ QtObject:
method roleNames(self: AttestationList): Table[int, string] =
self.data.roleNames()

proc setNewData*(self: AttestationList, v: seq[AttestationInfo]) =
self.data.setNewData(self, v)
proc setNewData*(self: AttestationList, v: seq[Attestation]) =
self.data.setNewData(self, v.mapIt(it.toAttestationInfo()))

proc sort*(self: AttestationList, section: int) {.slot.} =
self.data.sort(self, section)
33 changes: 22 additions & 11 deletions ngui/blockmodel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import
NimQml,
../beacon_chain/rpc/beacon_rest_client,
../beacon_chain/spec/[datatypes, crypto],
./attestationlist, ./depositlist, ./utils
"."/[
attestationlist, depositlist, attesterslashinglist, proposerslashinglist,
voluntaryexitlist, utils]

QtObject:
type
BlockModel* = ref object of QObject
blck: SignedBeaconBlock
attestationsx: AttestationList
depositsx: DepositList
attester_slashingsx: AttesterSlashingList
proposer_slashingsx: ProposerSlashingList
voluntary_exitsx: VoluntaryExitList
genesis_time*: uint64

proc delete*(self: BlockModel) =
Expand All @@ -24,17 +29,23 @@ QtObject:
proc newBlockModel*(blck: SignedBeaconBlock, genesis_time: uint64): BlockModel =
let res = BlockModel(
blck: blck,
attestationsx: newAttestationList(blck.message.body.attestations.mapIt(it.toAttestationInfo())),
attestationsx: newAttestationList(blck.message.body.attestations.asSeq()),
depositsx: newDepositList(blck.message.body.deposits.mapIt(it.toDepositInfo())),
attester_slashingsx: newAttesterSlashingList(blck.message.body.attester_slashings.asSeq()),
proposer_slashingsx: newProposerSlashingList(blck.message.body.proposer_slashings.asSeq()),
voluntary_exitsx: newVoluntaryExitList(blck.message.body.voluntary_exits.asSeq()),
genesis_time: genesis_time,
)
res.setup()
res

proc `blck=`*(self: BlockModel, blck: SignedBeaconBlock) =
self.blck = blck
self.attestationsx.setNewData(blck.message.body.attestations.mapIt(it.toAttestationInfo()))
self.depositsx.setNewData(blck.message.body.deposits.mapIt(it.toDepositInfo()))
self.blck = blck
self.attestationsx.setNewData(blck.message.body.attestations.asSeq())
self.depositsx.setNewData(blck.message.body.deposits.mapIt(it.toDepositInfo()))
self.attester_slashingsx.setNewData(blck.message.body.attester_slashings.asSeq())
self.proposer_slashingsx.setNewData(blck.message.body.proposer_slashings.asSeq())
self.voluntary_exitsx.setNewData(blck.message.body.voluntary_exits.asSeq())

proc slot*(self: BlockModel): int {.slot.} = self.blck.message.slot.int
QtProperty[int] slot: read = slot
Expand Down Expand Up @@ -65,20 +76,20 @@ QtObject:
proc graffiti*(self: BlockModel): string {.slot.} = $self.blck.message.body.graffiti
QtProperty[string] graffiti: read = graffiti

proc proposer_slashings*(self: BlockModel): string {.slot.} = RestJson.encode(self.blck.message.body.proposer_slashings, pretty=true)
QtProperty[string] proposer_slashings: read = proposer_slashings
proc proposer_slashings*(self: BlockModel): QVariant {.slot.} = newQVariant(self.proposer_slashingsx)
QtProperty[QVariant] proposer_slashings: read = proposer_slashings

proc attester_slashings*(self: BlockModel): string {.slot.} = RestJson.encode(self.blck.message.body.attester_slashings.asSeq(), pretty=true)
QtProperty[string] attester_slashings: read = attester_slashings
proc attester_slashings*(self: BlockModel): QVariant {.slot.} = newQVariant(self.attester_slashingsx)
QtProperty[QVariant] attester_slashings: read = attester_slashings

proc attestations*(self: BlockModel): QVariant {.slot.} = newQVariant(self.attestationsx)
QtProperty[QVariant] attestations: read = attestations

proc deposits*(self: BlockModel): QVariant {.slot.} = newQVariant(self.depositsx)
QtProperty[QVariant] deposits: read = deposits

proc voluntary_exits*(self: BlockModel): string {.slot.} = RestJson.encode(self.blck.message.body.voluntary_exits.asSeq(), pretty=true)
QtProperty[string] voluntary_exits: read = voluntary_exits
proc voluntary_exits*(self: BlockModel): QVariant {.slot.} = newQVariant(self.voluntary_exitsx)
QtProperty[QVariant] voluntary_exits: read = voluntary_exits

proc signature*(self: BlockModel): string {.slot.} = toDisplayHex(self.blck.signature)
QtProperty[string] signature: read = signature
19 changes: 15 additions & 4 deletions ngui/mainmodel.nim
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import
NimQml, blockmodel, footermodel, epochmodel, peerlist, slotlist, nodemodel
NimQml,
"."/[
blockmodel, footermodel, epochmodel, peerlist, slotlist, nodemodel,
poolmodel]

import
std/[os, strutils],
chronos, metrics,

# Local modules
../beacon_chain/rpc/[beacon_rest_client, rest_utils],
../beacon_chain/ssz/merkleization,
../beacon_chain/spec/[datatypes, digest, crypto, helpers]

QtObject:
Expand All @@ -18,6 +22,7 @@ QtObject:
peerList: PeerList
epochModel: EpochModel
nodeModel: NodeModel
poolModel: PoolModel

genesis: RestBeaconGenesis
currentIndex: int
Expand All @@ -34,13 +39,13 @@ QtObject:
let
client = RestClientRef.new("http://127.0.0.1:8190").get()

let
var
headBlock = (waitFor client.getBlock(BlockIdent.init(BlockIdentType.Head))).data.data
epoch = headBlock.message.slot.epoch
genesis = (waitFor client.getBeaconGenesis()).data.data
peerList = newPeerList(@[])

# peerList.setNewData(waitFor client.get_v1_node_peers(some(newseq[string]()), some(newseq[string]())))
headBlock.root = hash_tree_root(headBlock.message)

let res = MainModel(
app: app,
Expand All @@ -50,6 +55,7 @@ QtObject:
peerList: peerList,
epochModel: newEpochModel(client, epoch.int),
nodeModel: newNodeModel(client),
poolModel: newPoolModel(client),
genesis: genesis,
)
res.setup()
Expand Down Expand Up @@ -126,10 +132,15 @@ QtObject:
QtProperty[QVariant] nodeModel:
read = getNodeModel

proc getPoolModel(self: MainModel): QVariant {.slot.} = newQVariant(self.poolModel)
QtProperty[QVariant] poolModel:
read = getPoolModel

proc onLoadBlock(self: MainModel, root: string) {.slot.} =
try:
let blck = waitFor(self.client.getBlock(
var blck = waitFor(self.client.getBlock(
BlockIdent.decodeString(root).tryGet())).data.data
blck.root = hash_tree_root(blck.message)
self.setBlck(blck)
except CatchableError as exc:
echo exc.msg
Expand Down
64 changes: 9 additions & 55 deletions ngui/nodemodel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ QtObject:
NodeModel* = ref object of QObject
client: RestClientRef
genesis: string
attestations: string
attester_slashings: string
proposer_slashings: string
voluntary_exits: string
heads: string
identity: string
version: string
Expand All @@ -38,56 +34,16 @@ QtObject:
res.setup()
res

proc getGenesis*(self: NodeModel): string {.slot.} = self.genesis
proc getgenesis*(self: NodeModel): string {.slot.} = self.genesis
proc genesisChanged*(self: NodeModel, v: string) {.signal.}
proc setGenesis*(self: NodeModel, v: string) =
proc setgenesis*(self: NodeModel, v: string) =
self.genesis = v
self.genesisChanged(v)
QtProperty[string] genesis:
read = getgenesis
notify = genesisChanged
write = setgenesis

proc getattestations*(self: NodeModel): string {.slot.} = self.attestations
proc attestationsChanged*(self: NodeModel, v: string) {.signal.}
proc setattestations*(self: NodeModel, v: string) =
self.attestations = v
self.attestationsChanged(v)
QtProperty[string] attestations:
read = getattestations
notify = attestationsChanged
write = setattestations

proc getattester_slashings*(self: NodeModel): string {.slot.} = self.attester_slashings
proc attester_slashingsChanged*(self: NodeModel, v: string) {.signal.}
proc setattester_slashings*(self: NodeModel, v: string) =
self.attester_slashings = v
self.attester_slashingsChanged(v)
QtProperty[string] attester_slashings:
read = getattester_slashings
notify = attester_slashingsChanged
write = setattester_slashings

proc getproposer_slashings*(self: NodeModel): string {.slot.} = self.proposer_slashings
proc proposer_slashingsChanged*(self: NodeModel, v: string) {.signal.}
proc setproposer_slashings*(self: NodeModel, v: string) =
self.proposer_slashings = v
self.proposer_slashingsChanged(v)
QtProperty[string] proposer_slashings:
read = getproposer_slashings
notify = proposer_slashingsChanged
write = setproposer_slashings

proc getvoluntary_exits*(self: NodeModel): string {.slot.} = self.voluntary_exits
proc voluntary_exitsChanged*(self: NodeModel, v: string) {.signal.}
proc setvoluntary_exits*(self: NodeModel, v: string) =
self.voluntary_exits = v
self.voluntary_exitsChanged(v)
QtProperty[string] voluntary_exits:
read = getvoluntary_exits
notify = voluntary_exitsChanged
write = setvoluntary_exits

proc getheads*(self: NodeModel): string {.slot.} = self.heads
proc headsChanged*(self: NodeModel, v: string) {.signal.}
proc setheads*(self: NodeModel, v: string) =
Expand Down Expand Up @@ -129,12 +85,10 @@ QtObject:
write = sethealth

proc update*(self: NodeModel) {.slot.} =
self.setgenesis(xxx(waitFor self.client.getBeaconGenesis()))
self.setattestations(xxx(waitFor self.client.getPoolAttestations(none(Slot), none(CommitteeIndex))))
self.setattester_slashings(xxx(waitFor self.client.getPoolAttesterSlashings()))
self.setproposer_slashings(xxx(waitFor self.client.getPoolProposerSlashings()))
self.setvoluntary_exits(xxx(waitFor self.client.getPoolVoluntaryExits()))
self.setheads(xxx(waitFor self.client.getDebugChainHeads()))
self.setidentity(xxx(waitFor self.client.getNetworkIdentity()))
self.setversion(xxx(waitFor self.client.getNodeVersion()))
self.sethealth(xxx(waitFor self.client.getHealth()))
self.setgenesis(xxx(waitFor(self.client.getBeaconGenesis()).data.data))
self.setheads(xxx(waitFor(self.client.getDebugChainHeads()).data.data.mapIt(
toBlockLink(it.root) & " @ " & $it.slot
).join("\n")))
self.setidentity(xxx(waitFor(self.client.getNetworkIdentity()).data.data))
self.setversion(xxx(waitFor(self.client.getNodeVersion()).data.data.version))
self.sethealth(xxx(waitFor(self.client.getHealth())))

0 comments on commit 06e6b85

Please sign in to comment.