improve deposit processing performance (#4082)

When there are a lot of deposits, we decompress the public key into a
crypto cache. To avoid having those caches grow unreasonably big,
make sure to operate on the decompressed pubkey instead.
This commit is contained in:
Etan Kissling 2022-09-07 20:49:32 +02:00 committed by GitHub
parent bf3a014287
commit 0191225896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -530,11 +530,9 @@ const
DOMAIN_CONTRIBUTION_AND_PROOF* = DomainType([byte 0x09, 0x00, 0x00, 0x00])
func getImmutableValidatorData*(validator: Validator): ImmutableValidatorData2 =
let cookedKey = validator.pubkey.load() # Loading the pubkey is slow!
doAssert cookedKey.isSome,
"Cannot parse validator key: " & toHex(validator.pubkey)
let cookedKey = validator.pubkey.loadValid() # `Validator` has valid key
ImmutableValidatorData2(
pubkey: cookedKey.get(),
pubkey: cookedKey,
withdrawal_credentials: validator.withdrawal_credentials)
template makeLimitedUInt*(T: untyped, limit: SomeUnsignedInt) =

View File

@ -200,13 +200,24 @@ func get_deposit_signature*(message: DepositMessage, version: Version,
blsSign(privkey, signing_root.data)
proc verify_deposit_signature*(preset: RuntimeConfig,
deposit: DepositData): bool =
deposit: DepositData,
pubkey: CookedPubKey): bool =
let
deposit_message = deposit.getDepositMessage()
signing_root = compute_deposit_signing_root(
preset.GENESIS_FORK_VERSION, deposit_message)
blsVerify(deposit.pubkey, signing_root.data, deposit.signature)
blsVerify(pubkey, signing_root.data, deposit.signature)
proc verify_deposit_signature*(preset: RuntimeConfig,
deposit: DepositData): bool =
# Deposits come with compressed public keys; uncompressing them is expensive.
# `blsVerify` fills an internal cache when using `ValidatorPubKey`.
# To avoid filling this cache unnecessarily, uncompress explicitly here.
let pubkey = deposit.pubkey.load() # Loading the pubkey is slow!
if pubkey.isNone:
return false
verify_deposit_signature(preset, deposit, pubkey.get)
func compute_voluntary_exit_signing_root*(
fork: Fork, genesis_validators_root: Eth2Digest,