-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Add ability to update the fee recipient for execution via beacon and/or validator defaults #3958
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b3f15f1
Add and use a default fee recipient for a validator process
g11tech eec95ff
transfer the proposer cache to beacon chain
g11tech 221884b
mock chain fixes
g11tech 767a403
test and perf fixes
g11tech 034ba93
fee recipient validation change
g11tech 7333596
track and use free recipient as string instead of ExecutionAddress
g11tech d83b5f0
fix unit test
g11tech a8bca31
fix merge test
g11tech b902ef4
use dummy address
g11tech 252f285
refac and add proposer cache pruning
g11tech 8dd5583
tests for beacon proposer cache
g11tech 584c5e0
merge interop fee recipient check
g11tech 244c41e
fix the optional
g11tech 8b3ac03
feeRecipient confirmation and small refac
g11tech 032567b
add the missing map
g11tech 705b83e
add flag to enable strict fee recipient check
g11tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function parseFeeRecipient(feeRecipientHex: string): string { | ||
if (!/^0x[a-fA-F0-9]{40}$/i.test(feeRecipientHex)) { | ||
throw Error(`Invalid feeRecipient= ${feeRecipientHex}, expected format: ^0x[a-fA-F0-9]{40}$`); | ||
} | ||
return feeRecipientHex.toLowerCase(); | ||
} |
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,28 @@ | ||
import {expect} from "chai"; | ||
import {parseFeeRecipient} from "../../../src/util"; | ||
|
||
const feeRecipient = Buffer.from(Array.from({length: 20}, () => Math.round(Math.random() * 255))); | ||
const feeRecipientString = feeRecipient.toString("hex"); | ||
|
||
describe("validator / parseFeeRecipient", () => { | ||
const testCases: string[] = [`0x${feeRecipientString}`, `0X${feeRecipientString}`]; | ||
for (const testCase of testCases) { | ||
it(`parse ${testCase}`, () => { | ||
expect(`0x${feeRecipientString}`).to.be.deep.equal(parseFeeRecipient(testCase)); | ||
}); | ||
} | ||
}); | ||
|
||
describe("validator / invalid feeRecipient", () => { | ||
const testCases: string[] = [ | ||
feeRecipientString, | ||
`X0${feeRecipientString}`, | ||
`0x${feeRecipientString}13`, | ||
`0x${feeRecipientString.substr(0, 38)}`, | ||
]; | ||
for (const testCase of testCases) { | ||
it(`should error on ${testCase}`, () => { | ||
expect(() => parseFeeRecipient(testCase)).to.throw(); | ||
}); | ||
} | ||
}); |
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,37 @@ | ||
import {MapDef} from "../util/map"; | ||
import {Epoch} from "@chainsafe/lodestar-types"; | ||
import {IMetrics} from "../metrics"; | ||
|
||
const PROPOSER_PRESERVE_EPOCHS = 2; | ||
export type ProposerPreparationData = { | ||
validatorIndex: string; | ||
feeRecipient: string; | ||
}; | ||
|
||
export class BeaconProposerCache { | ||
private readonly feeRecipientByValidatorIndex: MapDef<string, {epoch: Epoch; feeRecipient: string}>; | ||
constructor(opts: {defaultFeeRecipient: string}, private readonly metrics?: IMetrics | null) { | ||
this.feeRecipientByValidatorIndex = new MapDef<string, {epoch: Epoch; feeRecipient: string}>(() => ({ | ||
epoch: 0, | ||
feeRecipient: opts.defaultFeeRecipient, | ||
})); | ||
} | ||
|
||
add(epoch: Epoch, {validatorIndex, feeRecipient}: ProposerPreparationData): void { | ||
twoeths marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.feeRecipientByValidatorIndex.set(validatorIndex, {epoch, feeRecipient}); | ||
} | ||
|
||
prune(epoch: Epoch): void { | ||
twoeths marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This is not so optimized function, but could maintain a 2d array may be? | ||
for (const [validatorIndex, feeRecipientEntry] of this.feeRecipientByValidatorIndex.entries()) { | ||
// We only retain an entry for PROPOSER_PRESERVE_EPOCHS epochs | ||
if (feeRecipientEntry.epoch + PROPOSER_PRESERVE_EPOCHS < epoch) { | ||
this.feeRecipientByValidatorIndex.delete(validatorIndex); | ||
} | ||
} | ||
} | ||
|
||
get(proposerIndex: number | string): string { | ||
return this.feeRecipientByValidatorIndex.getOrDefault(`${proposerIndex}`).feeRecipient; | ||
twoeths marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why is
validatorIndex
is typed as string? we have our ownValidatorIndex
typeThere 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.
yea i was using that earlier, but Lion suggested to avoid to/fro conversion between validator<>beacon for beacon proposer data as this is mostly to populate a lookup index at the BN.
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.
👍 so maybe just drop a comment here