Skip to content
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

feat: implement maxEB EIP-7251 #6539

Merged
merged 41 commits into from May 7, 2024
Merged

feat: implement maxEB EIP-7251 #6539

merged 41 commits into from May 7, 2024

Conversation

ensi321
Copy link
Contributor

@ensi321 ensi321 commented Mar 13, 2024

maxeb impl for devnet0

index: cachedIndex,
amount: BigInt(amount),
});
stateElectra.pendingBalanceDeposits.push(pendingBalanceDeposit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we add new PendingBalanceDeposit with amount but inside switchToCompoundingValidator() we also add another excess PendingBalanceDeposit with balance - MIN_ACTIVATION_BALANCE

is it correct to add 2 PendingBalanceDeposit for a single deposit? it's not an issue of our implementation just a question for the spec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be correct, so balance - MIN_ACTIVATION_BALANCE is the excess which would have been partially withdrawan, but is not queued to add to balance deposits

withdrawals.push({
index: withdrawalIndex,
validatorIndex: withdrawal.index,
address: validator.withdrawalCredentials.slice(12),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use subarray() instead

ensi321 and others added 9 commits May 6, 2024 13:45
* Add immutable in the dependencies

* Initial change to pubkeyCache

* Added todos

* Moved unfinalized cache to epochCache

* Move populating finalized cache to afterProcessEpoch

* Specify unfinalized cache during state cloning

* Move from unfinalized to finalized cache in afterProcessEpoch

* Confused myself

* Clean up

* Change logic

* Fix cloning issue

* Clean up redundant code

* Add CarryoverData in epochCtx.createFromState

* Fix typo

* Update usage of pubkeyCache

* Update pubkeyCache usage

* Fix lint

* Fix lint

* Add 6110 to ChainConfig

* Add 6110 to BeaconPreset

* Define 6110 fork and container

* Add V6110 api to execution engine

* Update test

* Add depositReceiptsRoot to process_execution_payload

* State transitioning to EIP6110

* State transitioning to EIP6110

* Light client change in EIP-6110

* Update tests

* produceBlock

* Refactor processDeposit to match the spec

* Implement processDepositReceipt

* Implement 6110 fork guard for pubkeyCache

* Handle changes in eth1 deposit

* Update eth1 deposit test

* Fix typo

* Lint

* Remove embarassing comments

* Address comments

* Modify applyDeposit signature

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/pubkeyCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Remove old code

* Rename fields in epochCache and immutableData

* Remove CarryoverData

* Move isAfter6110 from var to method

* Fix cyclic import

* Fix operations spec runner

* Fix for spec test

* Fix spec test

* state.depositReceiptsStartIndex to BigInt

* getDeposit requires cached state

* default depositReceiptsStartIndex value in genesis

* Fix pubkeyCache bug

* newUnfinalizedPubkeyIndexMap in createCachedBeaconState

* Lint

* Pass epochCache instead of pubkey2IndexFn in apis

* Address comments

* Add unit test on pubkey cache cloning

* Add unfinalizedPubkeyCacheSize to metrics

* Add unfinalizedPubkeyCacheSize to metrics

* Clean up code

* Add besu to el-interop

* Add 6110 genesis file

* Template for sim test

* Add unit test for getEth1DepositCount

* Update sim test

* Update besudocker

* Finish beacon api calls in sim test

* Update epochCache.createFromState()

* Fix bug unfinalized validators are not finalized

* Add sim test to run a few blocks

* Lint

* Merge branch 'unstable' into 611

* Add more check to sim test

* Update besu docker image instruction

* Update sim test with correct tx

* Address comment + cleanup

* Clean up code

* Properly handle promise rejection

* Lint

* Update packages/beacon-node/src/execution/engine/types.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update comments

* Accept type undefined in ExecutionPayloadBodyRpc

* Update comment and semantic

* Remove if statement when adding finalized validator

* Comment on repeated insert on finalized cache

* rename createFromState

* Add comment on getPubkey()

* Stash change to reduce diffs

* Stash change to reduce diffs

* Lint

* addFinalizedPubkey on finalized checkpoint

* Update comment

* Use OrderedMap for unfinalized cache

* Pull out logic of deleting pubkeys for batch op

* Add updateUnfinalizedPubkeys in regen

* Update updateUnfinalizedPubkeys logic

* Add comment

* Add metrics for state context caches

* Address comment

* Address comment

* Deprecate eth1Data polling when condition is reached

* Fix conflicts

* Fix sim test

* Lint

* Fix type

* Fix test

* Fix test

* Lint

* Update packages/light-client/src/spec/utils.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Fix spec test

* Address comments

* Improve cache logic on checkpoint finalized

* Update sim test according to new cache logic

* Update comment

* Lint

* Finalized pubkey cache only update once per checkpoint

* Add perf test for updateUnfinalizedPubkeys

* Add perf test for updateUnfinalizedPubkeys

* Tweak params for perf test

* Freeze besu docker image version for 6110

* Add benchmark result

* Use Map instead of OrderedMap. Update benchmark

* Minor optimization

* Minor optimization

* Add memory test for immutable.js

* Update test

* Reduce code duplication

* Lint

* Remove try/catch in updateUnfinalizedPubkeys

* Introduce EpochCache metric

* Add historicalValidatorLengths

* Polish code

* Migrate state-transition unit tests to vitest

* Fix calculation of pivot index

* `historicalValidatorLengths` only activate post 6110

* Update sim test

* Lint

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Improve readability on historicalValidatorLengths

* Update types

* Fix calculation

* Add eth1data poll todo

* Add epochCache.getValidatorCountAtEpoch

* Add todo

* Add getStateIterator for state cache

* Partial commit

* Update perf test

* updateUnfinalizedPubkeys directly modify states from regen

* Update sim test. Lint

* Add todo

* some improvements and a fix for effectiveBalanceIncrements fork safeness

* rename eip6110 to elctra

* fix electra-interop.test.ts

---------

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: gajinder <develop@g11tech.io>

lint and tsc

small cleanup

fix rebase issue
* Add immutable in the dependencies

* Initial change to pubkeyCache

* Added todos

* Moved unfinalized cache to epochCache

* Move populating finalized cache to afterProcessEpoch

* Specify unfinalized cache during state cloning

* Move from unfinalized to finalized cache in afterProcessEpoch

* Confused myself

* Clean up

* Change logic

* Fix cloning issue

* Clean up redundant code

* Add CarryoverData in epochCtx.createFromState

* Fix typo

* Update usage of pubkeyCache

* Update pubkeyCache usage

* Fix lint

* Fix lint

* Add 6110 to ChainConfig

* Add 6110 to BeaconPreset

* Define 6110 fork and container

* Add V6110 api to execution engine

* Update test

* Add depositReceiptsRoot to process_execution_payload

* State transitioning to EIP6110

* State transitioning to EIP6110

* Light client change in EIP-6110

* Update tests

* produceBlock

* Refactor processDeposit to match the spec

* Implement processDepositReceipt

* Implement 6110 fork guard for pubkeyCache

* Handle changes in eth1 deposit

* Update eth1 deposit test

* Fix typo

* Lint

* Remove embarassing comments

* Address comments

* Modify applyDeposit signature

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update packages/state-transition/src/cache/pubkeyCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Remove old code

* Rename fields in epochCache and immutableData

* Remove CarryoverData

* Move isAfter6110 from var to method

* Fix cyclic import

* Fix operations spec runner

* Fix for spec test

* Fix spec test

* state.depositReceiptsStartIndex to BigInt

* getDeposit requires cached state

* default depositReceiptsStartIndex value in genesis

* Fix pubkeyCache bug

* newUnfinalizedPubkeyIndexMap in createCachedBeaconState

* Lint

* Pass epochCache instead of pubkey2IndexFn in apis

* Address comments

* Add unit test on pubkey cache cloning

* Add unfinalizedPubkeyCacheSize to metrics

* Add unfinalizedPubkeyCacheSize to metrics

* Clean up code

* Add besu to el-interop

* Add 6110 genesis file

* Template for sim test

* Add unit test for getEth1DepositCount

* Update sim test

* Update besudocker

* Finish beacon api calls in sim test

* Update epochCache.createFromState()

* Fix bug unfinalized validators are not finalized

* Add sim test to run a few blocks

* Lint

* Merge branch 'unstable' into 611

* Add more check to sim test

* Update besu docker image instruction

* Update sim test with correct tx

* Address comment + cleanup

* Clean up code

* Properly handle promise rejection

* Lint

* Update packages/beacon-node/src/execution/engine/types.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Update comments

* Accept type undefined in ExecutionPayloadBodyRpc

* Update comment and semantic

* Remove if statement when adding finalized validator

* Comment on repeated insert on finalized cache

* rename createFromState

* Add comment on getPubkey()

* Stash change to reduce diffs

* Stash change to reduce diffs

* Lint

* addFinalizedPubkey on finalized checkpoint

* Update comment

* Use OrderedMap for unfinalized cache

* Pull out logic of deleting pubkeys for batch op

* Add updateUnfinalizedPubkeys in regen

* Update updateUnfinalizedPubkeys logic

* Add comment

* Add metrics for state context caches

* Address comment

* Address comment

* Deprecate eth1Data polling when condition is reached

* Fix conflicts

* Fix sim test

* Lint

* Fix type

* Fix test

* Fix test

* Lint

* Update packages/light-client/src/spec/utils.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Fix spec test

* Address comments

* Improve cache logic on checkpoint finalized

* Update sim test according to new cache logic

* Update comment

* Lint

* Finalized pubkey cache only update once per checkpoint

* Add perf test for updateUnfinalizedPubkeys

* Add perf test for updateUnfinalizedPubkeys

* Tweak params for perf test

* Freeze besu docker image version for 6110

* Add benchmark result

* Use Map instead of OrderedMap. Update benchmark

* Minor optimization

* Minor optimization

* Add memory test for immutable.js

* Update test

* Reduce code duplication

* Lint

* Remove try/catch in updateUnfinalizedPubkeys

* Introduce EpochCache metric

* Add historicalValidatorLengths

* Polish code

* Migrate state-transition unit tests to vitest

* Fix calculation of pivot index

* `historicalValidatorLengths` only activate post 6110

* Update sim test

* Lint

* Update packages/state-transition/src/cache/epochCache.ts

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>

* Improve readability on historicalValidatorLengths

* Update types

* Fix calculation

* Add eth1data poll todo

* Add epochCache.getValidatorCountAtEpoch

* Add todo

* Add getStateIterator for state cache

* Partial commit

* Update perf test

* updateUnfinalizedPubkeys directly modify states from regen

* Update sim test. Lint

* Add todo

* some improvements and a fix for effectiveBalanceIncrements fork safeness

* rename eip6110 to elctra

* fix electra-interop.test.ts

---------

Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: gajinder <develop@g11tech.io>

lint and tsc

small cleanup
const stateElectra = state as CachedBeaconStateElectra;
const pendingBalanceDeposit = ssz.electra.PendingBalanceDeposit.toViewDU({
index: validatorIndex,
amount: BigInt(amount),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed to model amount as BigInt? in processPendingBalanceDeposits() we need to cast it to Number anyway:

for (const deposit of state.pendingBalanceDeposits.getAllReadonly()) {
    const {amount} = deposit;
    if (processedAmount + amount > availableForProcessing) {
      break;
    }
    increaseBalance(state, deposit.index, Number(amount));
    processedAmount = processedAmount + amount;
    nextDepositIndex++;
  }

depositReceipt: electra.DepositReceipt
): void {
if (state.depositReceiptsStartIndex === UNSET_DEPOSIT_RECEIPTS_START_INDEX) {
state.depositReceiptsStartIndex = BigInt(depositReceipt.index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use BigInt unless it's really necessary due to performance reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will review and do a followup of the the new amount types and indexes

@g11tech g11tech force-pushed the nc/maxeb branch 4 times, most recently from 33c153c to 57c8aaa Compare May 6, 2024 11:04
@g11tech g11tech removed the status-do-not-merge Merging this issue will break the build. Do not merge! label May 6, 2024
@ensi321 ensi321 marked this pull request as ready for review May 7, 2024 17:56
@ensi321 ensi321 requested a review from a team as a code owner May 7, 2024 17:56
Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for the electra fork branch, any issues to be fixed will followup PRs on debugging or observations

@g11tech g11tech merged commit b1efc6e into electra-fork May 7, 2024
13 of 17 checks passed
@g11tech g11tech deleted the nc/maxeb branch May 7, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants