-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue advance fcU for builing the EL block
rebaseing to the refactored prepare beacon proposer refac payload id cache as separate class and add pruning issue payload fcus if synced rename issueNext.. to maybeIssueNext...
- Loading branch information
Showing
9 changed files
with
170 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {pruneSetToMax} from "../util/map"; | ||
import {IMetrics} from "../metrics"; | ||
import {SLOTS_PER_EPOCH} from "@chainsafe/lodestar-params"; | ||
import {DATA, QUANTITY} from "../eth1/provider/utils"; | ||
|
||
// Idealy this only need to be set to the max head reorgs number | ||
const MAX_PAYLOAD_IDS = SLOTS_PER_EPOCH; | ||
|
||
// An execution engine can produce a payload id anywhere the the uint64 range | ||
// Since we do no processing with this id, we have no need to deserialize it | ||
export type PayloadId = string; | ||
|
||
export type ApiPayloadAttributes = { | ||
/** QUANTITY, 64 Bits - value for the timestamp field of the new payload */ | ||
timestamp: QUANTITY; | ||
/** DATA, 32 Bytes - value for the prevRandao field of the new payload */ | ||
prevRandao: DATA; | ||
/** DATA, 20 Bytes - suggested value for the coinbase field of the new payload */ | ||
suggestedFeeRecipient: DATA; | ||
}; | ||
|
||
type FcuAttributes = {headBlockHash: DATA; finalizedBlockHash: DATA} & ApiPayloadAttributes; | ||
|
||
export class PayloadIdCache { | ||
private readonly payloadIdByFcuAttributes = new Map<string, PayloadId>(); | ||
constructor(private readonly metrics?: IMetrics | null) {} | ||
|
||
getKey({headBlockHash, finalizedBlockHash, timestamp, prevRandao, suggestedFeeRecipient}: FcuAttributes): string { | ||
return `${headBlockHash}-${finalizedBlockHash}-${timestamp}-${prevRandao}-${suggestedFeeRecipient}`; | ||
} | ||
|
||
add(fcuAttributes: FcuAttributes, payloadId: PayloadId): void { | ||
const key = this.getKey(fcuAttributes); | ||
this.payloadIdByFcuAttributes.set(key, payloadId); | ||
} | ||
|
||
prune(): void { | ||
// This is not so optimized function, but could maintain a 2d array may be? | ||
pruneSetToMax(this.payloadIdByFcuAttributes, MAX_PAYLOAD_IDS); | ||
} | ||
|
||
get(fcuAttributes: FcuAttributes): PayloadId | undefined { | ||
const key = this.getKey(fcuAttributes); | ||
return this.payloadIdByFcuAttributes.get(key); | ||
} | ||
} |