-
-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider state slot in getDomain #4430
Conversation
Performance Report✔️ no performance regression detected Full benchmark results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this solution is correct. What about doing this?
Pushed the solution only on config package here https://github.com/ChainSafe/lodestar/compare/cayman/getDomain-alternative?expand=1
return {
getDomain(domainType: DomainType, slot: Slot, state?: {slot: Slot}): Uint8Array {
// ```py
// def get_domain(state: BeaconState, domain_type: DomainType, epoch: Epoch=None) -> Domain:
// """
// Return the signature domain (fork version concatenated with domain type) of a message.
// """
// epoch = get_current_epoch(state) if epoch is None else epoch
// fork_version = state.fork.previous_version if epoch < state.fork.epoch else state.fork.current_version
// return compute_domain(domain_type, fork_version, state.genesis_validators_root)
// ```
// If not state argument is passed, assume requested slot is the state slot
const stateSlot = state?.slot ?? slot;
const epoch = Math.floor(slot / SLOTS_PER_EPOCH);
// Get pre-computed fork schedule, which _should_ match the one in the state
const forkInfo = chainForkConfig.getForkInfo(stateSlot);
// Only allow to select either current or previous fork respective of the fork schedule at stateSlot
const forkName = epoch < forkInfo.epoch ? forkInfo.prevForkName : forkInfo.name;
let domainByType = domainCache.get(forkName);
if (!domainByType) {
domainByType = new Map<DomainType, Uint8Array>();
domainCache.set(forkInfo.name, domainByType);
}
let domain = domainByType.get(domainType);
if (!domain) {
domain = computeDomain(domainType, forkInfo.version, genesisValidatorsRoot);
domainByType.set(domainType, domain);
}
return domain;
},
eb987aa
to
8345d05
Compare
refactored similarly to your solution, please rereview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
8345d05
to
44b9216
Compare
869adc2
to
4ddf2ae
Compare
@@ -182,7 +182,7 @@ export class ValidatorStore { | |||
// Duties are filtered before-hard by doppelganger-safe, this assert should never throw | |||
this.assertDoppelgangerSafe(pubkey); | |||
|
|||
const proposerDomain = this.config.getDomain(DOMAIN_BEACON_PROPOSER, blindedOrFull.slot); | |||
const proposerDomain = this.config.getDomain(currentSlot, DOMAIN_BEACON_PROPOSER, blindedOrFull.slot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this really be the currentSlot? Without checking the specs, sounds it should be the state slot, so block's slot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentslot should be same as blindedorfull slot same as state slot for signing block here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should is not enough, this can lead to bad signatures on the fork slot if there are clock issues. There's no solid reason to not use blindedOrFull.slot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated 👍
Resolves #4428
Add a
stateSlot: Slot
parameter togetDomain
. This matches the ergonomics of the consensus function.Note:
getDomain
still relies on the configured fork schedule rather than the on-chain fork schedule (state.fork
)