Implementation of post_v1_beacon_pool_attester_slashings() and post_v1_beacon_pool_proposer_slashings().
Remove doAssert.
This commit is contained in:
parent
6cae25701b
commit
7e4ff7a740
|
@ -247,41 +247,66 @@ proc installBeaconApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
||||||
|
|
||||||
rpcServer.rpc("get_v1_beacon_pool_attester_slashings") do (
|
rpcServer.rpc("get_v1_beacon_pool_attester_slashings") do (
|
||||||
) -> seq[AttesterSlashing]:
|
) -> seq[AttesterSlashing]:
|
||||||
|
var res: seq[AttesterSlashing]
|
||||||
|
if isNil(node.exitPool):
|
||||||
|
return res
|
||||||
let length = len(node.exitPool.attester_slashings)
|
let length = len(node.exitPool.attester_slashings)
|
||||||
var res = newSeqOfCap[AttesterSlashing](length)
|
res = newSeqOfCap[AttesterSlashing](length)
|
||||||
for item in node.exitPool.attester_slashings.items():
|
for item in node.exitPool.attester_slashings.items():
|
||||||
res.add(item)
|
res.add(item)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
rpcServer.rpc("post_v1_beacon_pool_attester_slashings") do () -> JsonNode:
|
rpcServer.rpc("post_v1_beacon_pool_attester_slashings") do (
|
||||||
unimplemented()
|
slashing: AttesterSlashing) -> bool:
|
||||||
|
if isNil(node.exitPool):
|
||||||
|
raise newException(CatchableError, "Exit pool is not yet available!")
|
||||||
|
let validity = node.exitPool[].validateAttesterSlashing(slashing)
|
||||||
|
if validity.isOk:
|
||||||
|
node.sendAttesterSlashing(slashing)
|
||||||
|
else:
|
||||||
|
raise newException(CatchableError, $(validity.error[1]))
|
||||||
|
return true
|
||||||
|
|
||||||
rpcServer.rpc("get_v1_beacon_pool_proposer_slashings") do (
|
rpcServer.rpc("get_v1_beacon_pool_proposer_slashings") do (
|
||||||
) -> seq[ProposerSlashing]:
|
) -> seq[ProposerSlashing]:
|
||||||
|
var res: seq[ProposerSlashing]
|
||||||
|
if isNil(node.exitPool):
|
||||||
|
return res
|
||||||
let length = len(node.exitPool.proposer_slashings)
|
let length = len(node.exitPool.proposer_slashings)
|
||||||
var res = newSeqOfCap[ProposerSlashing](length)
|
res = newSeqOfCap[ProposerSlashing](length)
|
||||||
for item in node.exitPool.proposer_slashings.items():
|
for item in node.exitPool.proposer_slashings.items():
|
||||||
res.add(item)
|
res.add(item)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
rpcServer.rpc("post_v1_beacon_pool_proposer_slashings") do () -> JsonNode:
|
rpcServer.rpc("post_v1_beacon_pool_proposer_slashings") do (
|
||||||
unimplemented()
|
slashing: ProposerSlashing) -> bool:
|
||||||
|
if isNil(node.exitPool):
|
||||||
|
raise newException(CatchableError, "Exit pool is not yet available!")
|
||||||
|
let validity = node.exitPool[].validateProposerSlashing(slashing)
|
||||||
|
if validity.isOk:
|
||||||
|
node.sendProposerSlashing(slashing)
|
||||||
|
else:
|
||||||
|
raise newException(CatchableError, $(validity.error[1]))
|
||||||
|
return true
|
||||||
|
|
||||||
rpcServer.rpc("get_v1_beacon_pool_voluntary_exits") do (
|
rpcServer.rpc("get_v1_beacon_pool_voluntary_exits") do (
|
||||||
) -> seq[SignedVoluntaryExit]:
|
) -> seq[SignedVoluntaryExit]:
|
||||||
|
var res: seq[SignedVoluntaryExit]
|
||||||
|
if isNil(node.exitPool):
|
||||||
|
return res
|
||||||
let length = len(node.exitPool.voluntary_exits)
|
let length = len(node.exitPool.voluntary_exits)
|
||||||
var res = newSeqOfCap[SignedVoluntaryExit](length)
|
res = newSeqOfCap[SignedVoluntaryExit](length)
|
||||||
for item in node.exitPool.voluntary_exits.items():
|
for item in node.exitPool.voluntary_exits.items():
|
||||||
res.add(item)
|
res.add(item)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
rpcServer.rpc("post_v1_beacon_pool_voluntary_exits") do (
|
rpcServer.rpc("post_v1_beacon_pool_voluntary_exits") do (
|
||||||
exit: SignedVoluntaryExit) -> bool:
|
exit: SignedVoluntaryExit) -> bool:
|
||||||
doAssert node.exitPool != nil
|
if isNil(node.exitPool):
|
||||||
|
raise newException(CatchableError, "Exit pool is not yet available!")
|
||||||
let validity = node.exitPool[].validateVoluntaryExit(exit)
|
let validity = node.exitPool[].validateVoluntaryExit(exit)
|
||||||
if validity.isOk:
|
if validity.isOk:
|
||||||
node.sendVoluntaryExit(exit)
|
node.sendVoluntaryExit(exit)
|
||||||
else:
|
else:
|
||||||
raise newException(ValueError, $(validity.error[1]))
|
raise newException(CatchableError, $(validity.error[1]))
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
|
@ -158,9 +158,15 @@ proc sendAttestation*(
|
||||||
beacon_attestations_sent.inc()
|
beacon_attestations_sent.inc()
|
||||||
|
|
||||||
proc sendVoluntaryExit*(node: BeaconNode, exit: SignedVoluntaryExit) =
|
proc sendVoluntaryExit*(node: BeaconNode, exit: SignedVoluntaryExit) =
|
||||||
node.network.broadcast(
|
node.network.broadcast(getVoluntaryExitsTopic(node.forkDigest), exit)
|
||||||
getVoluntaryExitsTopic(node.forkDIgest),
|
|
||||||
exit)
|
proc sendAttesterSlashing*(node: BeaconNode, slashing: AttesterSlashing) =
|
||||||
|
node.network.broadcast(getAttesterSlashingsTopic(node.forkDigest),
|
||||||
|
slashing)
|
||||||
|
|
||||||
|
proc sendProposerSlashing*(node: BeaconNode, slashing: ProposerSlashing) =
|
||||||
|
node.network.broadcast(getProposerSlashingsTopic(node.forkDigest),
|
||||||
|
slashing)
|
||||||
|
|
||||||
proc sendAttestation*(node: BeaconNode, attestation: Attestation) =
|
proc sendAttestation*(node: BeaconNode, attestation: Attestation) =
|
||||||
# For the validator API, which doesn't supply num_active_validators.
|
# For the validator API, which doesn't supply num_active_validators.
|
||||||
|
|
Loading…
Reference in New Issue