Skip to content

Commit

Permalink
Block / REST explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Feb 7, 2024
1 parent 742f151 commit 3de5ef7
Show file tree
Hide file tree
Showing 40 changed files with 1,750 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@
path = vendor/nim-toml-serialization
url = https://github.com/status-im/nim-toml-serialization.git
ignore = untracked
[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/status-im/nimqml.git
branch = master
[submodule "vendor/gnosis-chain-configs"]
path = vendor/gnosis-chain-configs
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ force_build_alone_tools: | $(FORCE_BUILD_ALONE_TOOLS_DEPS)
# https://www.gnu.org/software/make/manual/html_node/Multiple-Rules.html#Multiple-Rules
# Already defined as a reult
nimbus_beacon_node: force_build_alone_tools
ngui/ngui: | build deps
+ echo -e $(BUILD_MSG) "build/$@" && \
MAKE="$(MAKE)" V="$(V)" $(ENV_SCRIPT) scripts/compile_nim_program.sh $@ "ngui.ngui.nim" $(NIM_PARAMS) && \
echo -e $(BUILD_END_MSG) "ngui/ngui"

GOERLI_TESTNETS_PARAMS := \
--tcp-port=$$(( $(BASE_PORT) + $(NODE_ID) )) \
Expand Down
7 changes: 5 additions & 2 deletions beacon_chain/rpc/rest_debug_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
"/eth/v2/debug/beacon/heads") do () -> RestApiResponse:
RestApiResponse.jsonResponse(
node.dag.heads.mapIt(
(root: it.root, slot: it.slot,
execution_optimistic: not it.executionValid)
RestChainHeadV2(
root: it.root,
slot: it.slot,
execution_optimistic: not it.executionValid
)
)
)

Expand Down
1 change: 1 addition & 0 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ RestJson.useDefaultSerializationFor(
RestBeaconStatesFinalityCheckpoints,
RestBlockHeader,
RestBlockHeaderInfo,
RestChainHeadV2,
RestCommitteeSubscription,
RestContributionAndProof,
RestDepositContract,
Expand Down
6 changes: 6 additions & 0 deletions beacon_chain/spec/eth2_apis/rest_debug_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import

export chronos, client, rest_types, eth2_rest_serialization

proc getDebugChainHeadsV2*(): RestResponse[GetDebugChainHeadsV2Response] {.
rest, endpoint: "/eth/v2/debug/beacon/heads",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Beacon/getDebugChainHeadsV2


proc getStateV2Plain*(state_id: StateIdent): RestPlainResponse {.
rest, endpoint: "/eth/v2/debug/beacon/states/{state_id}",
accept: preferSSZ,
Expand Down
5 changes: 3 additions & 2 deletions beacon_chain/spec/eth2_apis/rest_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,10 @@ type
connected*: uint64
disconnecting*: uint64

RestChainHead* = object
RestChainHeadV2* = object
root*: Eth2Digest
slot*: Slot
execution_optmistic*: bool

RestMetadata* = object
seq_number*: string
Expand Down Expand Up @@ -539,7 +540,7 @@ type
GetBlockHeaderResponse* = DataOptimisticAndFinalizedObject[RestBlockHeaderInfo]
GetBlockHeadersResponse* = DataEnclosedObject[seq[RestBlockHeaderInfo]]
GetBlockRootResponse* = DataOptimisticObject[RestRoot]
GetDebugChainHeadsResponse* = DataEnclosedObject[seq[RestChainHead]]
GetDebugChainHeadsV2Response* = DataEnclosedObject[seq[RestChainHeadV2]]
GetDepositContractResponse* = DataEnclosedObject[RestDepositContract]
GetDepositSnapshotResponse* = DataEnclosedObject[RestDepositSnapshot]
GetEpochCommitteesResponse* = DataEnclosedObject[seq[RestBeaconStatesCommittees]]
Expand Down
23 changes: 23 additions & 0 deletions beacon_chain/spec/eth2_apis/rest_validator_calls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import

export client, rest_types, eth2_rest_serialization

proc getAttesterDuties*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetAttesterDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/attester/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties

proc getAttesterDutiesPlain*(
epoch: Epoch,
body: seq[ValidatorIndex]
Expand All @@ -20,13 +28,28 @@ proc getAttesterDutiesPlain*(
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties

proc getProposerDuties*(
epoch: Epoch
): RestResponse[GetProposerDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/proposer/{epoch}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties

proc getProposerDutiesPlain*(
epoch: Epoch
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/duties/proposer/{epoch}",
meth: MethodGet.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties

proc getSyncCommitteeDuties*(
epoch: Epoch,
body: seq[ValidatorIndex]
): RestResponse[GetSyncCommitteeDutiesResponse] {.
rest, endpoint: "/eth/v1/validator/duties/sync/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties

proc getSyncCommitteeDutiesPlain*(
epoch: Epoch,
body: seq[ValidatorIndex]
Expand Down
25 changes: 19 additions & 6 deletions beacon_chain/spec/forks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -971,28 +971,41 @@ template getForkedBlockField*(
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.y
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y)[]

template signature*(x: ForkedSignedBeaconBlock |
template getForkedBodyField*(
x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
ForkedTrustedSignedBeaconBlock,
y: untyped): untyped =
# unsafeAddr avoids a copy of the field in some cases
(case x.kind
of ConsensusFork.Phase0: unsafeAddr x.phase0Data.message.body.y
of ConsensusFork.Altair: unsafeAddr x.altairData.message.body.y
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.message.body.y
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.body.y
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.body.y)[]

func signature*(x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
ForkedSignedBlindedBeaconBlock): ValidatorSig =
withBlck(x): forkyBlck.signature

template signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
func signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
withBlck(x): forkyBlck.signature

template root*(x: ForkedSignedBeaconBlock |
func root*(x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
ForkedTrustedSignedBeaconBlock): Eth2Digest =
withBlck(x): forkyBlck.root

template slot*(x: ForkedSignedBeaconBlock |
func slot*(x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
ForkedTrustedSignedBeaconBlock): Slot =
withBlck(x): forkyBlck.message.slot

template shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
func shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
withBlck(x): shortLog(forkyBlck)

template shortLog*(x: ForkedSignedBeaconBlock |
func shortLog*(x: ForkedSignedBeaconBlock |
ForkedMsgTrustedSignedBeaconBlock |
ForkedTrustedSignedBeaconBlock |
ForkedSignedBlindedBeaconBlock): auto =
Expand Down
1 change: 1 addition & 0 deletions beacon_chain/spec/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import
# Status libraries
std/times,
stew/[byteutils, endians2, objects, saturation_arith],
chronicles,
eth/common/[eth_types, eth_types_rlp],
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/keystore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ proc validateMnemonic*(inputWords: string,

# TODO consider using a SecretString type for inputWords

let words = strutils.strip(inputWords.string.toNFKD).split(Whitespace)
let words = strutils.strip(inputWords.toNFKD).split(Whitespace)
if words.len < 12 or words.len > 24 or words.len mod 3 != 0:
return false

Expand Down
1 change: 1 addition & 0 deletions ngui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resources.cpp
65 changes: 65 additions & 0 deletions ngui/attestationlist.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import
std/[sequtils, tables],
NimQml,
../beacon_chain/spec/eth2_apis/rest_beacon_client,
../beacon_chain/spec/[eth2_merkleization, helpers],
./objecttablemodel, ./utils

type
AttestationInfo* = object
slot*: int
index*: int
beacon_block_root*: string
source_epoch*: int
source_root*: string
target_epoch*: int
target_root*: string
aggregation_bits*: string

proc toAttestationInfo*(v: Attestation): AttestationInfo =
AttestationInfo(
slot: v.data.slot.int,
index: v.data.index.int,
beacon_block_root: toBlockLink(v.data.beacon_block_root),
source_epoch: v.data.source.epoch.int,
source_root: toBlockLink(v.data.source.root),
target_epoch: v.data.target.epoch.int,
target_root: toBlockLink(v.data.target.root),
aggregation_bits: $v.aggregation_bits,
)

QtObject:
type AttestationList* = ref object of QAbstractTableModel
# TODO this could be a generic ObjectTableModel, except generics + method don't work..
data: ObjectTableModelImpl[AttestationInfo]

proc setup(self: AttestationList) = self.QAbstractTableModel.setup

proc delete(self: AttestationList) =
self.QAbstractTableModel.delete

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

method rowCount(self: AttestationList, index: QModelIndex = nil): int =
self.data.rowCount(index)

method columnCount(self: AttestationList, index: QModelIndex = nil): int =
self.data.columnCount(index)

method headerData*(self: AttestationList, section: int, orientation: QtOrientation, role: int): QVariant =
self.data.headerData(section, orientation, role)

method data(self: AttestationList, index: QModelIndex, role: int): QVariant =
self.data.data(index, role)

method roleNames(self: AttestationList): Table[int, string] =
self.data.roleNames()

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)
51 changes: 51 additions & 0 deletions ngui/attesterslashinglist.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import
std/[sequtils, tables],
NimQml,
../beacon_chain/spec/eth2_apis/rest_beacon_client,
../beacon_chain/spec/[helpers],
./objecttablemodel, ./utils

type
AttesterSlashingInfo* = object
info*: string

proc toAttesterSlashingInfo*(v: AttesterSlashing): AttesterSlashingInfo =
AttesterSlashingInfo(
info: $v
)

QtObject:
type AttesterSlashingList* = ref object of QAbstractTableModel
# TODO this could be a generic ObjectTableModel, except generics + method don't work..
data: ObjectTableModelImpl[AttesterSlashingInfo]

proc setup(self: AttesterSlashingList) = self.QAbstractTableModel.setup

proc delete(self: AttesterSlashingList) =
self.QAbstractTableModel.delete

proc newAttesterSlashingList*(data: openArray[AttesterSlashing]): AttesterSlashingList =
new(result, delete)
result.data = ObjectTableModelImpl[AttesterSlashingInfo](items: data.mapIt(it.toAttesterSlashingInfo()))
result.setup

method rowCount(self: AttesterSlashingList, index: QModelIndex = nil): int =
self.data.rowCount(index)

method columnCount(self: AttesterSlashingList, index: QModelIndex = nil): int =
self.data.columnCount(index)

method headerData*(self: AttesterSlashingList, section: int, orientation: QtOrientation, role: int): QVariant =
self.data.headerData(section, orientation, role)

method data(self: AttesterSlashingList, index: QModelIndex, role: int): QVariant =
self.data.data(index, role)

method roleNames(self: AttesterSlashingList): Table[int, string] =
self.data.roleNames()

proc setNewData*(self: AttesterSlashingList, v: openArray[AttesterSlashing]) =
self.data.setNewData(self, v.mapIt(it.toAttesterSlashingInfo()))

proc sort*(self: AttesterSlashingList, section: int) {.slot.} =
self.data.sort(self, section)

0 comments on commit 3de5ef7

Please sign in to comment.