-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
156 additions
and
34 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
34 changes: 34 additions & 0 deletions
34
packages/beacon-state-transition/src/merge/upgradeState.ts
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,34 @@ | ||
import {altair, merge, ssz} from "@chainsafe/lodestar-types"; | ||
import {CachedBeaconState, createCachedBeaconState} from "../allForks/util"; | ||
import {getCurrentEpoch} from "../util"; | ||
import {TreeBacked} from "@chainsafe/ssz"; | ||
import {IBeaconConfig} from "@chainsafe/lodestar-config"; | ||
|
||
/** | ||
* Upgrade a state from altair to merge. | ||
*/ | ||
export function upgradeState(state: CachedBeaconState<altair.BeaconState>): CachedBeaconState<merge.BeaconState> { | ||
const {config} = state; | ||
const postTreeBackedState = upgradeTreeBackedState(config, state); | ||
// TODO: This seems very sub-optimal, review | ||
return createCachedBeaconState(config, postTreeBackedState); | ||
} | ||
|
||
function upgradeTreeBackedState( | ||
config: IBeaconConfig, | ||
state: CachedBeaconState<altair.BeaconState> | ||
): TreeBacked<merge.BeaconState> { | ||
const stateTB = ssz.phase0.BeaconState.createTreeBacked(state.tree); | ||
|
||
// TODO: Does this preserve the hashing cache? In altair devnets memory spikes on the fork transition | ||
const postState = ssz.merge.BeaconState.createTreeBacked(stateTB.tree); | ||
postState.fork = { | ||
previousVersion: stateTB.fork.currentVersion, | ||
currentVersion: config.MERGE_FORK_VERSION, | ||
epoch: getCurrentEpoch(stateTB), | ||
}; | ||
// Execution-layer | ||
postState.latestExecutionPayloadHeader = ssz.merge.ExecutionPayloadHeader.defaultTreeBacked(); | ||
|
||
return postState; | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
packages/lodestar/src/db/single/totalTerminalDifficulty.ts
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,33 @@ | ||
import {Type} from "@chainsafe/ssz"; | ||
import {IChainForkConfig} from "@chainsafe/lodestar-config"; | ||
import {ssz} from "@chainsafe/lodestar-types"; | ||
import {IDatabaseController, Bucket, IDbMetrics} from "@chainsafe/lodestar-db"; | ||
|
||
export class TotalTerminalDifficulty { | ||
private readonly bucket = Bucket.merge_totalTerminalDifficulty; | ||
private readonly key = Buffer.from(new Uint8Array([this.bucket])); | ||
private readonly type: Type<bigint>; | ||
private readonly db: IDatabaseController<Buffer, Buffer>; | ||
private readonly metrics?: IDbMetrics; | ||
|
||
constructor(config: IChainForkConfig, db: IDatabaseController<Buffer, Buffer>, metrics?: IDbMetrics) { | ||
this.db = db; | ||
this.type = ssz.Uint256; | ||
this.metrics = metrics; | ||
} | ||
|
||
async put(value: bigint): Promise<void> { | ||
this.metrics?.dbWrites.labels({bucket: "merge_totalTerminalDifficulty"}).inc(); | ||
await this.db.put(this.key, this.type.serialize(value) as Buffer); | ||
} | ||
|
||
async get(): Promise<bigint | null> { | ||
this.metrics?.dbReads.labels({bucket: "merge_totalTerminalDifficulty"}).inc(); | ||
const value = await this.db.get(this.key); | ||
return value ? this.type.deserialize(value) : null; | ||
} | ||
|
||
async delete(): Promise<void> { | ||
await this.db.delete(this.key); | ||
} | ||
} |
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