Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/state-transition/src/stateView/beaconStateView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export class BeaconStateView implements IBeaconStateViewLatestFork {
return this.config.getForkName(this.cachedState.slot);
}

get forkSeq(): ForkSeq {
return this.config.getForkSeq(this.cachedState.slot);
}

get slot(): number {
return this.cachedState.slot;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/state-transition/src/stateView/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ForkPostFulu,
ForkPostGloas,
ForkPostHeze,
ForkSeq,
isForkPostAltair,
isForkPostBellatrix,
isForkPostCapella,
Expand Down Expand Up @@ -62,6 +63,7 @@ export interface IBeaconStateView {

// phase0
forkName: ForkName;
forkSeq: ForkSeq;
slot: Slot;
fork: Fork;
epoch: Epoch;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CompactMultiProof} from "@chainsafe/persistent-merkle-tree";
import {BitArray, ByteViews} from "@chainsafe/ssz";
import {ForkName} from "@lodestar/params";
import {ForkName, ForkSeq} from "@lodestar/params";
import {
BeaconBlock,
BeaconState,
Expand Down Expand Up @@ -63,6 +63,7 @@ import {
export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
// phase0
private _forkName: ForkName | null = null;
private _forkSeq: ForkSeq | null = null;
private _slot: Slot | null = null;
private _fork: Fork | null = null;
private _epoch: Epoch | null = null;
Expand Down Expand Up @@ -191,6 +192,13 @@ export class NativeBeaconStateView implements IBeaconStateViewLatestFork {
return this._forkName;
}

get forkSeq(): ForkSeq {
if (this._forkSeq === null) {
this._forkSeq = this.binding.forkSeq;
}
return this._forkSeq;
}

get slot(): Slot {
if (this._slot === null) {
this._slot = this.binding.slot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {describe, expect, it} from "vitest";
import {BitArray} from "@chainsafe/ssz";
import {ForkSeq} from "@lodestar/params";
import {IBeaconStateViewNative} from "../../../src/stateView/interface.js";
import {NativeBeaconStateView} from "../../../src/stateView/nativeBeaconStateView.js";

Expand Down Expand Up @@ -37,6 +38,7 @@ describe("NativeBeaconStateView", () => {
it("caches forwarded properties so the binding is hit once", () => {
let forkAccessCount = 0;
let latestBlockHeaderAccessCount = 0;
let forkSeqAccessCount = 0;
const fakeFork = {previousVersion: new Uint8Array(4), currentVersion: new Uint8Array(4), epoch: 0};
const fakeHeader = {
slot: 0,
Expand All @@ -55,15 +57,22 @@ describe("NativeBeaconStateView", () => {
latestBlockHeaderAccessCount++;
return fakeHeader;
},
get forkSeq() {
forkSeqAccessCount++;
return ForkSeq.electra;
},
} as unknown as IBeaconStateViewNative;

const view = new NativeBeaconStateView(binding);
expect(view.fork).toBe(fakeFork);
expect(view.fork).toBe(fakeFork);
expect(view.latestBlockHeader).toBe(fakeHeader);
expect(view.latestBlockHeader).toBe(fakeHeader);
expect(view.forkSeq).toBe(ForkSeq.electra);
expect(view.forkSeq).toBe(ForkSeq.electra);
expect(forkAccessCount).toBe(1);
expect(latestBlockHeaderAccessCount).toBe(1);
expect(forkSeqAccessCount).toBe(1);
});

it("delegates pass-through getters and methods to the binding", () => {
Expand Down
Loading