-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the /eth/v1/validator/prepare_beacon_proposer end-point (#3901
- Loading branch information
Showing
9 changed files
with
113 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import | ||
std/tables, | ||
stew/results, | ||
web3/ethtypes, | ||
../datatypes/base | ||
|
||
type | ||
Entry = object | ||
recipient: Eth1Address | ||
addedAt: Epoch | ||
|
||
DynamicFeeRecipientsStore* = object | ||
mappings: Table[ValidatorIndex, Entry] | ||
|
||
func init*(T: type DynamicFeeRecipientsStore): T = | ||
T(mappings: initTable[ValidatorIndex, Entry]()) | ||
|
||
func addMapping*(store: var DynamicFeeRecipientsStore, | ||
validator: ValidatorIndex, | ||
feeRecipient: Eth1Address, | ||
currentEpoch: Epoch) = | ||
store.mappings[validator] = Entry(recipient: feeRecipient, | ||
addedAt: currentEpoch) | ||
|
||
func getDynamicFeeRecipient*(store: var DynamicFeeRecipientsStore, | ||
validator: ValidatorIndex, | ||
currentEpoch: Epoch): Opt[Eth1Address] = | ||
store.mappings.withValue(validator, entry) do: | ||
# https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/prepareBeaconProposer | ||
# | ||
# The information supplied for each validator index will persist | ||
# through the epoch in which the call is submitted and for a further | ||
# two epochs after that, or until the beacon node restarts. | ||
# | ||
# It is expected that validator clients will send this information | ||
# periodically, for example each epoch, to ensure beacon nodes have | ||
# correct and timely fee recipient information. | ||
return if (currentEpoch - entry.addedAt) > 2: | ||
err() | ||
else: | ||
ok entry.recipient | ||
do: | ||
return err() | ||
|
||
func pruneOldMappings*(store: var DynamicFeeRecipientsStore, | ||
currentEpoch: Epoch) = | ||
var toPrune: seq[ValidatorIndex] | ||
|
||
for idx, entry in store.mappings: | ||
if (currentEpoch - entry.addedAt) > 2: | ||
toPrune.add idx | ||
|
||
for idx in toPrune: | ||
store.mappings.del idx |
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