Skip to content

Commit

Permalink
update ncli_db to use Opt (#6575)
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec authored Sep 23, 2024
1 parent 85d7109 commit 71d8fb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ncli/ncli_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type
inactivity_penalty*: Gwei
slashing_outcome*: int64
deposits*: Gwei
inclusion_delay*: Option[uint64]
inclusion_delay*: Opt[uint64]

ParticipationFlags* = object
currentEpochParticipation: EpochParticipationFlags
Expand Down Expand Up @@ -399,13 +399,13 @@ func collectFromAttestations(
forkyState.data, attestation.data, attestation.aggregation_bits,
attestation.committee_bits, cache):
rewardsAndPenalties[index].inclusion_delay =
some(inclusionDelay.uint64)
Opt.some(inclusionDelay.uint64)
else:
for index in get_attesting_indices(
forkyState.data, attestation.data, attestation.aggregation_bits,
cache):
rewardsAndPenalties[index].inclusion_delay =
some(inclusionDelay.uint64)
Opt.some(inclusionDelay.uint64)

from ".."/beacon_chain/validator_bucket_sort import
findValidatorIndex, sortValidatorBuckets
Expand Down Expand Up @@ -433,7 +433,7 @@ proc collectFromDeposits(
if index.isSome:
try:
rewardsAndPenalties[index.get()].deposits += amount
except KeyError as e:
except KeyError:
raiseAssert "rewardsAndPenalties lacks expected index " & $index.get()
elif verify_deposit_signature(cfg, deposit.data):
pubkeyToIndex[pubkey] = ValidatorIndex(rewardsAndPenalties.len)
Expand Down Expand Up @@ -494,7 +494,7 @@ proc collectBlockRewardsAndPenalties*(
func serializeToCsv*(rp: RewardsAndPenalties,
avgInclusionDelay = none(float)): string =
for name, value in fieldPairs(rp):
if value isnot Option:
if value isnot Opt:
result &= $value & ","
if avgInclusionDelay.isSome:
result.addFloat(avgInclusionDelay.get)
Expand Down
4 changes: 2 additions & 2 deletions ncli/ncli_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,9 @@ proc cmdValidatorDb(conf: DbConf, cfg: RuntimeConfig) =
rp.inclusion_delay = block:
let notSlashed = (RewardFlags.isSlashed notin validator.flags)
if notSlashed and validator.is_previous_epoch_attester.isSome():
some(validator.is_previous_epoch_attester.get().delay.uint64)
Opt.some(validator.is_previous_epoch_attester.get().delay.uint64)
else:
none(uint64)
Opt.none(uint64)

if conf.writeUnaggregatedFiles:
csvLines.add rp.serializeToCsv
Expand Down
4 changes: 2 additions & 2 deletions ncli/validator_db_aggregator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func `+=`(lhs: var RewardsAndPenalties, rhs: RewardsAndPenalties) =
lhs.inclusion_delay.get += rhs.inclusion_delay.get
else:
if rhs.inclusion_delay.isSome:
lhs.inclusion_delay = some(rhs.inclusion_delay.get)
lhs.inclusion_delay = Opt.some(rhs.inclusion_delay.get)

func average(rp: var RewardsAndPenalties,
averageInclusionDelay: var Option[float],
Expand Down Expand Up @@ -206,7 +206,7 @@ when isMainModule:
slashing_outcome: parseBiggestInt(csvRow[12]),
deposits: parseBiggestUInt(csvRow[13]).Gwei)
if csvRow[14].len > 0:
result.inclusion_delay = some(parseBiggestUInt(csvRow[14]))
result.inclusion_delay = Opt.some(parseBiggestUInt(csvRow[14]))

proc aggregateEpochs(
startEpoch, endEpoch: Epoch, resolution: uint,
Expand Down

0 comments on commit 71d8fb5

Please sign in to comment.