@aztec/epoch-cache 0.0.1-commit.fffb133c → 0.0.1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/epoch_cache.d.ts +2 -2
- package/dest/epoch_cache.d.ts.map +1 -1
- package/dest/epoch_cache.js +19 -16
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/test_epoch_cache.d.ts +76 -0
- package/dest/test/test_epoch_cache.d.ts.map +1 -0
- package/dest/test/test_epoch_cache.js +152 -0
- package/package.json +5 -5
- package/src/config.ts +1 -1
- package/src/epoch_cache.ts +17 -11
- package/src/test/index.ts +1 -0
- package/src/test/test_epoch_cache.ts +171 -0
package/dest/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type L1ContractsConfig } from '@aztec/ethereum/config';
|
|
2
2
|
import { type L1ReaderConfig } from '@aztec/ethereum/l1-reader';
|
|
3
|
-
export type EpochCacheConfig = Pick<L1ReaderConfig & L1ContractsConfig, 'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'>;
|
|
3
|
+
export type EpochCacheConfig = Pick<L1ReaderConfig & L1ContractsConfig, 'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'l1HttpTimeoutMS' | 'ethereumSlotDuration'>;
|
|
4
4
|
export declare function getEpochCacheConfigEnvVars(): EpochCacheConfig;
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxLQUFLLGlCQUFpQixFQUErQixNQUFNLHdCQUF3QixDQUFDO0FBQzdGLE9BQU8sRUFBRSxLQUFLLGNBQWMsRUFBNEIsTUFBTSwyQkFBMkIsQ0FBQztBQUUxRixNQUFNLE1BQU0sZ0JBQWdCLEdBQUcsSUFBSSxDQUNqQyxjQUFjLEdBQUcsaUJBQWlCLEVBQ2xDLFdBQVcsR0FBRyxXQUFXLEdBQUcsdUJBQXVCLEdBQUcsaUJBQWlCLEdBQUcsc0JBQXNCLENBQ2pHLENBQUM7QUFFRix3QkFBZ0IsMEJBQTBCLElBQUksZ0JBQWdCLENBRTdEIn0=
|
package/dest/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAA+B,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,KAAK,cAAc,EAA4B,MAAM,2BAA2B,CAAC;AAE1F,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,cAAc,GAAG,iBAAiB,EAClC,WAAW,GAAG,WAAW,GAAG,uBAAuB,GAAG,sBAAsB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAA+B,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,KAAK,cAAc,EAA4B,MAAM,2BAA2B,CAAC;AAE1F,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,cAAc,GAAG,iBAAiB,EAClC,WAAW,GAAG,WAAW,GAAG,uBAAuB,GAAG,iBAAiB,GAAG,sBAAsB,CACjG,CAAC;AAEF,wBAAgB,0BAA0B,IAAI,gBAAgB,CAE7D"}
|
package/dest/epoch_cache.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface EpochCacheInterface {
|
|
|
35
35
|
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
36
36
|
isInCommittee(slot: SlotTag, validator: EthAddress): Promise<boolean>;
|
|
37
37
|
filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
38
|
+
getL1Constants(): L1RollupConstants;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Epoch cache
|
|
@@ -71,7 +72,6 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
71
72
|
getEpochAndSlotNow(): EpochAndSlot & {
|
|
72
73
|
nowMs: bigint;
|
|
73
74
|
};
|
|
74
|
-
nowInSeconds(): bigint;
|
|
75
75
|
private getEpochAndSlotAtSlot;
|
|
76
76
|
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
77
77
|
now: bigint;
|
|
@@ -130,4 +130,4 @@ export declare class EpochCache implements EpochCacheInterface {
|
|
|
130
130
|
filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
131
131
|
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
132
132
|
}
|
|
133
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
133
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfY2FjaGUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9lcG9jaF9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQW9CLGNBQWMsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBQzdFLE9BQU8sRUFBRSxXQUFXLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDMUUsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRTNELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN2RCxPQUFPLEVBQ0wsS0FBSyxpQkFBaUI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0FBRyxPQUFPLENBQUMsVUFBVSxFQUFFLENBQUMsQ0FPdEY7SUFFSyx1QkFBdUIsSUFBSSxPQUFPLENBQUMsVUFBVSxFQUFFLENBQUMsQ0FVckQ7Q0FDRiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"epoch_cache.d.ts","sourceRoot":"","sources":["../src/epoch_cache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,KAAK,iBAAiB,EAQvB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,KAAK,gBAAgB,EAA8B,MAAM,aAAa,CAAC;AAEhF,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,+DAA+D;IAC/D,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAElD,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrE,kBAAkB,IAAI,YAAY,GAAG;QAAE,KAAK,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IAC7C,qBAAqB,IAAI;QAAE,WAAW,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,UAAU,CAAA;KAAE,CAQhF;IAED;;;;OAIG;IACI,gCAAgC,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAGzF;IAED;;;;OAIG;IACI,oCAAoC,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAG7E;YAQa,4BAA4B;IAanC,6BAA6B,CAClC,kBAAkB,EAAE,kBAAkB,EACtC,IAAI,EAAE,UAAU,GACf,UAAU,GAAG,SAAS,CAYxB;IAED,4DAA4D;IACtD,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAM1E;IAED,+FAA+F;IACzF,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAOtF;IAEK,uBAAuB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAUrD;CACF"}
|
package/dest/epoch_cache.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
2
3
|
import { NoCommitteeError, RollupContract } from '@aztec/ethereum/contracts';
|
|
3
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import { getEpochAtSlot, getEpochNumberAtTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
7
|
-
import { createPublicClient, encodeAbiParameters,
|
|
7
|
+
import { getEpochAtSlot, getEpochNumberAtTimestamp, getNextL1SlotTimestamp, getSlotAtTimestamp, getSlotRangeForEpoch, getTimestampForSlot, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
8
|
+
import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';
|
|
8
9
|
import { getEpochCacheConfigEnvVars } from './config.js';
|
|
9
10
|
/**
|
|
10
11
|
* Epoch cache
|
|
@@ -50,21 +51,23 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
50
51
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
51
52
|
const publicClient = createPublicClient({
|
|
52
53
|
chain: chain.chainInfo,
|
|
53
|
-
transport:
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
55
|
+
timeout: config.l1HttpTimeoutMS
|
|
56
|
+
}),
|
|
56
57
|
pollingInterval: config.viemPollingIntervalMS
|
|
57
58
|
});
|
|
58
59
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
59
60
|
}
|
|
60
|
-
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochsForValidatorSet, lagInEpochsForRandao] = await Promise.all([
|
|
61
|
+
const [l1StartBlock, l1GenesisTime, proofSubmissionEpochs, slotDuration, epochDuration, lagInEpochsForValidatorSet, lagInEpochsForRandao, targetCommitteeSize, rollupManaLimit] = await Promise.all([
|
|
61
62
|
rollup.getL1StartBlock(),
|
|
62
63
|
rollup.getL1GenesisTime(),
|
|
63
64
|
rollup.getProofSubmissionEpochs(),
|
|
64
65
|
rollup.getSlotDuration(),
|
|
65
66
|
rollup.getEpochDuration(),
|
|
66
67
|
rollup.getLagInEpochsForValidatorSet(),
|
|
67
|
-
rollup.getLagInEpochsForRandao()
|
|
68
|
+
rollup.getLagInEpochsForRandao(),
|
|
69
|
+
rollup.getTargetCommitteeSize(),
|
|
70
|
+
rollup.getManaLimit()
|
|
68
71
|
]);
|
|
69
72
|
const l1RollupConstants = {
|
|
70
73
|
l1StartBlock,
|
|
@@ -74,7 +77,9 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
74
77
|
epochDuration: Number(epochDuration),
|
|
75
78
|
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
76
79
|
lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
|
|
77
|
-
lagInEpochsForRandao: Number(lagInEpochsForRandao)
|
|
80
|
+
lagInEpochsForRandao: Number(lagInEpochsForRandao),
|
|
81
|
+
targetCommitteeSize: Number(targetCommitteeSize),
|
|
82
|
+
rollupManaLimit: Number(rollupManaLimit)
|
|
78
83
|
};
|
|
79
84
|
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
|
|
80
85
|
}
|
|
@@ -89,9 +94,6 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
89
94
|
nowMs
|
|
90
95
|
};
|
|
91
96
|
}
|
|
92
|
-
nowInSeconds() {
|
|
93
|
-
return BigInt(Math.floor(this.dateProvider.now() / 1000));
|
|
94
|
-
}
|
|
95
97
|
getEpochAndSlotAtSlot(slot) {
|
|
96
98
|
const epoch = getEpochAtSlot(slot, this.l1constants);
|
|
97
99
|
const ts = getTimestampRangeForEpoch(epoch, this.l1constants)[0];
|
|
@@ -102,8 +104,8 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
106
|
getEpochAndSlotInNextL1Slot() {
|
|
105
|
-
const now = this.nowInSeconds();
|
|
106
|
-
const nextSlotTs = now
|
|
107
|
+
const now = BigInt(this.dateProvider.nowInSeconds());
|
|
108
|
+
const nextSlotTs = getNextL1SlotTimestamp(Number(now), this.l1constants);
|
|
107
109
|
return {
|
|
108
110
|
...this.getEpochAndSlotAtTimestamp(nextSlotTs),
|
|
109
111
|
now
|
|
@@ -290,10 +292,11 @@ import { getEpochCacheConfigEnvVars } from './config.js';
|
|
|
290
292
|
async getRegisteredValidators() {
|
|
291
293
|
const validatorRefreshIntervalMs = this.config.validatorRefreshIntervalSeconds * 1000;
|
|
292
294
|
const validatorRefreshTime = this.lastValidatorRefresh + validatorRefreshIntervalMs;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
const now = this.dateProvider.now();
|
|
296
|
+
if (validatorRefreshTime < now) {
|
|
297
|
+
const currentSet = await this.rollup.getAttesters(BigInt(Math.floor(now / 1000)));
|
|
295
298
|
this.allValidators = new Set(currentSet.map((v)=>v.toString()));
|
|
296
|
-
this.lastValidatorRefresh =
|
|
299
|
+
this.lastValidatorRefresh = now;
|
|
297
300
|
}
|
|
298
301
|
return Array.from(this.allValidators.keys()).map((v)=>EthAddress.fromString(v));
|
|
299
302
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './test_epoch_cache.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
|
+
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '../epoch_cache.js';
|
|
5
|
+
/**
|
|
6
|
+
* A test implementation of EpochCacheInterface that allows manual configuration
|
|
7
|
+
* of committee, proposer, slot, and escape hatch state for use in tests.
|
|
8
|
+
*
|
|
9
|
+
* Unlike the real EpochCache, this class doesn't require any RPC connections
|
|
10
|
+
* or mock setup. Simply use the setter methods to configure the test state.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TestEpochCache implements EpochCacheInterface {
|
|
13
|
+
private committee;
|
|
14
|
+
private proposerAddress;
|
|
15
|
+
private currentSlot;
|
|
16
|
+
private escapeHatchOpen;
|
|
17
|
+
private seed;
|
|
18
|
+
private registeredValidators;
|
|
19
|
+
private l1Constants;
|
|
20
|
+
constructor(l1Constants?: Partial<L1RollupConstants>);
|
|
21
|
+
/**
|
|
22
|
+
* Sets the committee members. Used in validation and attestation flows.
|
|
23
|
+
* @param committee - Array of committee member addresses.
|
|
24
|
+
*/
|
|
25
|
+
setCommittee(committee: EthAddress[]): this;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the proposer address returned by getProposerAttesterAddressInSlot.
|
|
28
|
+
* @param proposer - The address of the current proposer.
|
|
29
|
+
*/
|
|
30
|
+
setProposer(proposer: EthAddress | undefined): this;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the current slot number.
|
|
33
|
+
* @param slot - The slot number to set.
|
|
34
|
+
*/
|
|
35
|
+
setCurrentSlot(slot: SlotNumber): this;
|
|
36
|
+
/**
|
|
37
|
+
* Sets whether the escape hatch is open.
|
|
38
|
+
* @param open - True if escape hatch should be open.
|
|
39
|
+
*/
|
|
40
|
+
setEscapeHatchOpen(open: boolean): this;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the randomness seed used for proposer selection.
|
|
43
|
+
* @param seed - The seed value.
|
|
44
|
+
*/
|
|
45
|
+
setSeed(seed: bigint): this;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the list of registered validators (all validators, not just committee).
|
|
48
|
+
* @param validators - Array of validator addresses.
|
|
49
|
+
*/
|
|
50
|
+
setRegisteredValidators(validators: EthAddress[]): this;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the L1 constants used for epoch/slot calculations.
|
|
53
|
+
* @param constants - Partial constants to override defaults.
|
|
54
|
+
*/
|
|
55
|
+
setL1Constants(constants: Partial<L1RollupConstants>): this;
|
|
56
|
+
getL1Constants(): L1RollupConstants;
|
|
57
|
+
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo>;
|
|
58
|
+
getEpochAndSlotNow(): EpochAndSlot & {
|
|
59
|
+
nowMs: bigint;
|
|
60
|
+
};
|
|
61
|
+
getEpochAndSlotInNextL1Slot(): EpochAndSlot & {
|
|
62
|
+
now: bigint;
|
|
63
|
+
};
|
|
64
|
+
getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}`;
|
|
65
|
+
computeProposerIndex(slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, size: bigint): bigint;
|
|
66
|
+
getCurrentAndNextSlot(): {
|
|
67
|
+
currentSlot: SlotNumber;
|
|
68
|
+
nextSlot: SlotNumber;
|
|
69
|
+
};
|
|
70
|
+
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined>;
|
|
71
|
+
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
72
|
+
isInCommittee(_slot: SlotTag, validator: EthAddress): Promise<boolean>;
|
|
73
|
+
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
74
|
+
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF9lcG9jaF9jYWNoZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3QvdGVzdF9lcG9jaF9jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQzFFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUMzRCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBR3JFLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxtQkFBbUIsRUFBRSxrQkFBa0IsRUFBRSxPQUFPLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQWN4Rzs7Ozs7O0dBTUc7QUFDSCxxQk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/epoch-helpers';
|
|
3
|
+
/** Default L1 constants for testing. */ const DEFAULT_L1_CONSTANTS = {
|
|
4
|
+
l1StartBlock: 0n,
|
|
5
|
+
l1GenesisTime: 0n,
|
|
6
|
+
slotDuration: 24,
|
|
7
|
+
epochDuration: 16,
|
|
8
|
+
ethereumSlotDuration: 12,
|
|
9
|
+
proofSubmissionEpochs: 2,
|
|
10
|
+
targetCommitteeSize: 48,
|
|
11
|
+
rollupManaLimit: Number.MAX_SAFE_INTEGER
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A test implementation of EpochCacheInterface that allows manual configuration
|
|
15
|
+
* of committee, proposer, slot, and escape hatch state for use in tests.
|
|
16
|
+
*
|
|
17
|
+
* Unlike the real EpochCache, this class doesn't require any RPC connections
|
|
18
|
+
* or mock setup. Simply use the setter methods to configure the test state.
|
|
19
|
+
*/ export class TestEpochCache {
|
|
20
|
+
committee = [];
|
|
21
|
+
proposerAddress;
|
|
22
|
+
currentSlot = SlotNumber(0);
|
|
23
|
+
escapeHatchOpen = false;
|
|
24
|
+
seed = 0n;
|
|
25
|
+
registeredValidators = [];
|
|
26
|
+
l1Constants;
|
|
27
|
+
constructor(l1Constants = {}){
|
|
28
|
+
this.l1Constants = {
|
|
29
|
+
...DEFAULT_L1_CONSTANTS,
|
|
30
|
+
...l1Constants
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the committee members. Used in validation and attestation flows.
|
|
35
|
+
* @param committee - Array of committee member addresses.
|
|
36
|
+
*/ setCommittee(committee) {
|
|
37
|
+
this.committee = committee;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets the proposer address returned by getProposerAttesterAddressInSlot.
|
|
42
|
+
* @param proposer - The address of the current proposer.
|
|
43
|
+
*/ setProposer(proposer) {
|
|
44
|
+
this.proposerAddress = proposer;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the current slot number.
|
|
49
|
+
* @param slot - The slot number to set.
|
|
50
|
+
*/ setCurrentSlot(slot) {
|
|
51
|
+
this.currentSlot = slot;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets whether the escape hatch is open.
|
|
56
|
+
* @param open - True if escape hatch should be open.
|
|
57
|
+
*/ setEscapeHatchOpen(open) {
|
|
58
|
+
this.escapeHatchOpen = open;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sets the randomness seed used for proposer selection.
|
|
63
|
+
* @param seed - The seed value.
|
|
64
|
+
*/ setSeed(seed) {
|
|
65
|
+
this.seed = seed;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sets the list of registered validators (all validators, not just committee).
|
|
70
|
+
* @param validators - Array of validator addresses.
|
|
71
|
+
*/ setRegisteredValidators(validators) {
|
|
72
|
+
this.registeredValidators = validators;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets the L1 constants used for epoch/slot calculations.
|
|
77
|
+
* @param constants - Partial constants to override defaults.
|
|
78
|
+
*/ setL1Constants(constants) {
|
|
79
|
+
this.l1Constants = {
|
|
80
|
+
...this.l1Constants,
|
|
81
|
+
...constants
|
|
82
|
+
};
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
getL1Constants() {
|
|
86
|
+
return this.l1Constants;
|
|
87
|
+
}
|
|
88
|
+
getCommittee(_slot) {
|
|
89
|
+
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
90
|
+
return Promise.resolve({
|
|
91
|
+
committee: this.committee,
|
|
92
|
+
epoch,
|
|
93
|
+
seed: this.seed,
|
|
94
|
+
isEscapeHatchOpen: this.escapeHatchOpen
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
getEpochAndSlotNow() {
|
|
98
|
+
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
99
|
+
const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
|
|
100
|
+
return {
|
|
101
|
+
epoch,
|
|
102
|
+
slot: this.currentSlot,
|
|
103
|
+
ts,
|
|
104
|
+
nowMs: ts * 1000n
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
getEpochAndSlotInNextL1Slot() {
|
|
108
|
+
const now = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
|
|
109
|
+
const nextSlotTs = now + BigInt(this.l1Constants.ethereumSlotDuration);
|
|
110
|
+
const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
|
|
111
|
+
const epoch = getEpochAtSlot(nextSlot, this.l1Constants);
|
|
112
|
+
const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
|
|
113
|
+
return {
|
|
114
|
+
epoch,
|
|
115
|
+
slot: nextSlot,
|
|
116
|
+
ts,
|
|
117
|
+
now
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
getProposerIndexEncoding(epoch, slot, seed) {
|
|
121
|
+
// Simple encoding for testing purposes
|
|
122
|
+
return `0x${epoch.toString(16).padStart(64, '0')}${slot.toString(16).padStart(64, '0')}${seed.toString(16).padStart(64, '0')}`;
|
|
123
|
+
}
|
|
124
|
+
computeProposerIndex(slot, _epoch, _seed, size) {
|
|
125
|
+
if (size === 0n) {
|
|
126
|
+
return 0n;
|
|
127
|
+
}
|
|
128
|
+
return BigInt(slot) % size;
|
|
129
|
+
}
|
|
130
|
+
getCurrentAndNextSlot() {
|
|
131
|
+
return {
|
|
132
|
+
currentSlot: this.currentSlot,
|
|
133
|
+
nextSlot: SlotNumber(this.currentSlot + 1)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
getProposerAttesterAddressInSlot(_slot) {
|
|
137
|
+
return Promise.resolve(this.proposerAddress);
|
|
138
|
+
}
|
|
139
|
+
getRegisteredValidators() {
|
|
140
|
+
return Promise.resolve(this.registeredValidators);
|
|
141
|
+
}
|
|
142
|
+
isInCommittee(_slot, validator) {
|
|
143
|
+
return Promise.resolve(this.committee.some((v)=>v.equals(validator)));
|
|
144
|
+
}
|
|
145
|
+
filterInCommittee(_slot, validators) {
|
|
146
|
+
const committeeSet = new Set(this.committee.map((v)=>v.toString()));
|
|
147
|
+
return Promise.resolve(validators.filter((v)=>committeeSet.has(v.toString())));
|
|
148
|
+
}
|
|
149
|
+
isEscapeHatchOpenAtSlot(_slot) {
|
|
150
|
+
return Promise.resolve(this.escapeHatchOpen);
|
|
151
|
+
}
|
|
152
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/epoch-cache",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-dev",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"../package.common.json"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@aztec/ethereum": "0.0.1-
|
|
30
|
-
"@aztec/foundation": "0.0.1-
|
|
31
|
-
"@aztec/l1-artifacts": "0.0.1-
|
|
32
|
-
"@aztec/stdlib": "0.0.1-
|
|
29
|
+
"@aztec/ethereum": "0.0.1-dev",
|
|
30
|
+
"@aztec/foundation": "0.0.1-dev",
|
|
31
|
+
"@aztec/l1-artifacts": "0.0.1-dev",
|
|
32
|
+
"@aztec/stdlib": "0.0.1-dev",
|
|
33
33
|
"@viem/anvil": "^0.0.10",
|
|
34
34
|
"dotenv": "^16.0.3",
|
|
35
35
|
"get-port": "^7.1.0",
|
package/src/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type L1ReaderConfig, getL1ReaderConfigFromEnv } from '@aztec/ethereum/l
|
|
|
3
3
|
|
|
4
4
|
export type EpochCacheConfig = Pick<
|
|
5
5
|
L1ReaderConfig & L1ContractsConfig,
|
|
6
|
-
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'ethereumSlotDuration'
|
|
6
|
+
'l1RpcUrls' | 'l1ChainId' | 'viemPollingIntervalMS' | 'l1HttpTimeoutMS' | 'ethereumSlotDuration'
|
|
7
7
|
>;
|
|
8
8
|
|
|
9
9
|
export function getEpochCacheConfigEnvVars(): EpochCacheConfig {
|
package/src/epoch_cache.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
2
|
+
import { makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
2
3
|
import { NoCommitteeError, RollupContract } from '@aztec/ethereum/contracts';
|
|
3
4
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -8,13 +9,14 @@ import {
|
|
|
8
9
|
type L1RollupConstants,
|
|
9
10
|
getEpochAtSlot,
|
|
10
11
|
getEpochNumberAtTimestamp,
|
|
12
|
+
getNextL1SlotTimestamp,
|
|
11
13
|
getSlotAtTimestamp,
|
|
12
14
|
getSlotRangeForEpoch,
|
|
13
15
|
getTimestampForSlot,
|
|
14
16
|
getTimestampRangeForEpoch,
|
|
15
17
|
} from '@aztec/stdlib/epoch-helpers';
|
|
16
18
|
|
|
17
|
-
import { createPublicClient, encodeAbiParameters,
|
|
19
|
+
import { createPublicClient, encodeAbiParameters, keccak256 } from 'viem';
|
|
18
20
|
|
|
19
21
|
import { type EpochCacheConfig, getEpochCacheConfigEnvVars } from './config.js';
|
|
20
22
|
|
|
@@ -45,6 +47,7 @@ export interface EpochCacheInterface {
|
|
|
45
47
|
getRegisteredValidators(): Promise<EthAddress[]>;
|
|
46
48
|
isInCommittee(slot: SlotTag, validator: EthAddress): Promise<boolean>;
|
|
47
49
|
filterInCommittee(slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]>;
|
|
50
|
+
getL1Constants(): L1RollupConstants;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/**
|
|
@@ -92,7 +95,7 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
92
95
|
const chain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
93
96
|
const publicClient = createPublicClient({
|
|
94
97
|
chain: chain.chainInfo,
|
|
95
|
-
transport:
|
|
98
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
96
99
|
pollingInterval: config.viemPollingIntervalMS,
|
|
97
100
|
});
|
|
98
101
|
rollup = new RollupContract(publicClient, rollupOrAddress.toString());
|
|
@@ -106,6 +109,8 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
106
109
|
epochDuration,
|
|
107
110
|
lagInEpochsForValidatorSet,
|
|
108
111
|
lagInEpochsForRandao,
|
|
112
|
+
targetCommitteeSize,
|
|
113
|
+
rollupManaLimit,
|
|
109
114
|
] = await Promise.all([
|
|
110
115
|
rollup.getL1StartBlock(),
|
|
111
116
|
rollup.getL1GenesisTime(),
|
|
@@ -114,6 +119,8 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
114
119
|
rollup.getEpochDuration(),
|
|
115
120
|
rollup.getLagInEpochsForValidatorSet(),
|
|
116
121
|
rollup.getLagInEpochsForRandao(),
|
|
122
|
+
rollup.getTargetCommitteeSize(),
|
|
123
|
+
rollup.getManaLimit(),
|
|
117
124
|
] as const);
|
|
118
125
|
|
|
119
126
|
const l1RollupConstants = {
|
|
@@ -125,6 +132,8 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
125
132
|
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
126
133
|
lagInEpochsForValidatorSet: Number(lagInEpochsForValidatorSet),
|
|
127
134
|
lagInEpochsForRandao: Number(lagInEpochsForRandao),
|
|
135
|
+
targetCommitteeSize: Number(targetCommitteeSize),
|
|
136
|
+
rollupManaLimit: Number(rollupManaLimit),
|
|
128
137
|
};
|
|
129
138
|
|
|
130
139
|
return new EpochCache(rollup, l1RollupConstants, deps.dateProvider);
|
|
@@ -140,10 +149,6 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
140
149
|
return { ...this.getEpochAndSlotAtTimestamp(nowSeconds), nowMs };
|
|
141
150
|
}
|
|
142
151
|
|
|
143
|
-
public nowInSeconds(): bigint {
|
|
144
|
-
return BigInt(Math.floor(this.dateProvider.now() / 1000));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
152
|
private getEpochAndSlotAtSlot(slot: SlotNumber): EpochAndSlot {
|
|
148
153
|
const epoch = getEpochAtSlot(slot, this.l1constants);
|
|
149
154
|
const ts = getTimestampRangeForEpoch(epoch, this.l1constants)[0];
|
|
@@ -151,8 +156,8 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
public getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
|
|
154
|
-
const now = this.nowInSeconds();
|
|
155
|
-
const nextSlotTs = now
|
|
159
|
+
const now = BigInt(this.dateProvider.nowInSeconds());
|
|
160
|
+
const nextSlotTs = getNextL1SlotTimestamp(Number(now), this.l1constants);
|
|
156
161
|
return { ...this.getEpochAndSlotAtTimestamp(nextSlotTs), now };
|
|
157
162
|
}
|
|
158
163
|
|
|
@@ -368,10 +373,11 @@ export class EpochCache implements EpochCacheInterface {
|
|
|
368
373
|
async getRegisteredValidators(): Promise<EthAddress[]> {
|
|
369
374
|
const validatorRefreshIntervalMs = this.config.validatorRefreshIntervalSeconds * 1000;
|
|
370
375
|
const validatorRefreshTime = this.lastValidatorRefresh + validatorRefreshIntervalMs;
|
|
371
|
-
|
|
372
|
-
|
|
376
|
+
const now = this.dateProvider.now();
|
|
377
|
+
if (validatorRefreshTime < now) {
|
|
378
|
+
const currentSet = await this.rollup.getAttesters(BigInt(Math.floor(now / 1000)));
|
|
373
379
|
this.allValidators = new Set(currentSet.map(v => v.toString()));
|
|
374
|
-
this.lastValidatorRefresh =
|
|
380
|
+
this.lastValidatorRefresh = now;
|
|
375
381
|
}
|
|
376
382
|
return Array.from(this.allValidators.keys()).map(v => EthAddress.fromString(v));
|
|
377
383
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './test_epoch_cache.js';
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
|
+
import { getEpochAtSlot, getSlotAtTimestamp, getTimestampRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
|
|
5
|
+
|
|
6
|
+
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '../epoch_cache.js';
|
|
7
|
+
|
|
8
|
+
/** Default L1 constants for testing. */
|
|
9
|
+
const DEFAULT_L1_CONSTANTS: L1RollupConstants = {
|
|
10
|
+
l1StartBlock: 0n,
|
|
11
|
+
l1GenesisTime: 0n,
|
|
12
|
+
slotDuration: 24,
|
|
13
|
+
epochDuration: 16,
|
|
14
|
+
ethereumSlotDuration: 12,
|
|
15
|
+
proofSubmissionEpochs: 2,
|
|
16
|
+
targetCommitteeSize: 48,
|
|
17
|
+
rollupManaLimit: Number.MAX_SAFE_INTEGER,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A test implementation of EpochCacheInterface that allows manual configuration
|
|
22
|
+
* of committee, proposer, slot, and escape hatch state for use in tests.
|
|
23
|
+
*
|
|
24
|
+
* Unlike the real EpochCache, this class doesn't require any RPC connections
|
|
25
|
+
* or mock setup. Simply use the setter methods to configure the test state.
|
|
26
|
+
*/
|
|
27
|
+
export class TestEpochCache implements EpochCacheInterface {
|
|
28
|
+
private committee: EthAddress[] = [];
|
|
29
|
+
private proposerAddress: EthAddress | undefined;
|
|
30
|
+
private currentSlot: SlotNumber = SlotNumber(0);
|
|
31
|
+
private escapeHatchOpen: boolean = false;
|
|
32
|
+
private seed: bigint = 0n;
|
|
33
|
+
private registeredValidators: EthAddress[] = [];
|
|
34
|
+
private l1Constants: L1RollupConstants;
|
|
35
|
+
|
|
36
|
+
constructor(l1Constants: Partial<L1RollupConstants> = {}) {
|
|
37
|
+
this.l1Constants = { ...DEFAULT_L1_CONSTANTS, ...l1Constants };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sets the committee members. Used in validation and attestation flows.
|
|
42
|
+
* @param committee - Array of committee member addresses.
|
|
43
|
+
*/
|
|
44
|
+
setCommittee(committee: EthAddress[]): this {
|
|
45
|
+
this.committee = committee;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sets the proposer address returned by getProposerAttesterAddressInSlot.
|
|
51
|
+
* @param proposer - The address of the current proposer.
|
|
52
|
+
*/
|
|
53
|
+
setProposer(proposer: EthAddress | undefined): this {
|
|
54
|
+
this.proposerAddress = proposer;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets the current slot number.
|
|
60
|
+
* @param slot - The slot number to set.
|
|
61
|
+
*/
|
|
62
|
+
setCurrentSlot(slot: SlotNumber): this {
|
|
63
|
+
this.currentSlot = slot;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sets whether the escape hatch is open.
|
|
69
|
+
* @param open - True if escape hatch should be open.
|
|
70
|
+
*/
|
|
71
|
+
setEscapeHatchOpen(open: boolean): this {
|
|
72
|
+
this.escapeHatchOpen = open;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Sets the randomness seed used for proposer selection.
|
|
78
|
+
* @param seed - The seed value.
|
|
79
|
+
*/
|
|
80
|
+
setSeed(seed: bigint): this {
|
|
81
|
+
this.seed = seed;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Sets the list of registered validators (all validators, not just committee).
|
|
87
|
+
* @param validators - Array of validator addresses.
|
|
88
|
+
*/
|
|
89
|
+
setRegisteredValidators(validators: EthAddress[]): this {
|
|
90
|
+
this.registeredValidators = validators;
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Sets the L1 constants used for epoch/slot calculations.
|
|
96
|
+
* @param constants - Partial constants to override defaults.
|
|
97
|
+
*/
|
|
98
|
+
setL1Constants(constants: Partial<L1RollupConstants>): this {
|
|
99
|
+
this.l1Constants = { ...this.l1Constants, ...constants };
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getL1Constants(): L1RollupConstants {
|
|
104
|
+
return this.l1Constants;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getCommittee(_slot?: SlotTag): Promise<EpochCommitteeInfo> {
|
|
108
|
+
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
109
|
+
return Promise.resolve({
|
|
110
|
+
committee: this.committee,
|
|
111
|
+
epoch,
|
|
112
|
+
seed: this.seed,
|
|
113
|
+
isEscapeHatchOpen: this.escapeHatchOpen,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
118
|
+
const epoch = getEpochAtSlot(this.currentSlot, this.l1Constants);
|
|
119
|
+
const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
|
|
120
|
+
return { epoch, slot: this.currentSlot, ts, nowMs: ts * 1000n };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
|
|
124
|
+
const now = getTimestampRangeForEpoch(getEpochAtSlot(this.currentSlot, this.l1Constants), this.l1Constants)[0];
|
|
125
|
+
const nextSlotTs = now + BigInt(this.l1Constants.ethereumSlotDuration);
|
|
126
|
+
const nextSlot = getSlotAtTimestamp(nextSlotTs, this.l1Constants);
|
|
127
|
+
const epoch = getEpochAtSlot(nextSlot, this.l1Constants);
|
|
128
|
+
const ts = getTimestampRangeForEpoch(epoch, this.l1Constants)[0];
|
|
129
|
+
return { epoch, slot: nextSlot, ts, now };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getProposerIndexEncoding(epoch: EpochNumber, slot: SlotNumber, seed: bigint): `0x${string}` {
|
|
133
|
+
// Simple encoding for testing purposes
|
|
134
|
+
return `0x${epoch.toString(16).padStart(64, '0')}${slot.toString(16).padStart(64, '0')}${seed.toString(16).padStart(64, '0')}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
computeProposerIndex(slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, size: bigint): bigint {
|
|
138
|
+
if (size === 0n) {
|
|
139
|
+
return 0n;
|
|
140
|
+
}
|
|
141
|
+
return BigInt(slot) % size;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
145
|
+
return {
|
|
146
|
+
currentSlot: this.currentSlot,
|
|
147
|
+
nextSlot: SlotNumber(this.currentSlot + 1),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
|
|
152
|
+
return Promise.resolve(this.proposerAddress);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getRegisteredValidators(): Promise<EthAddress[]> {
|
|
156
|
+
return Promise.resolve(this.registeredValidators);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
isInCommittee(_slot: SlotTag, validator: EthAddress): Promise<boolean> {
|
|
160
|
+
return Promise.resolve(this.committee.some(v => v.equals(validator)));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
filterInCommittee(_slot: SlotTag, validators: EthAddress[]): Promise<EthAddress[]> {
|
|
164
|
+
const committeeSet = new Set(this.committee.map(v => v.toString()));
|
|
165
|
+
return Promise.resolve(validators.filter(v => committeeSet.has(v.toString())));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
isEscapeHatchOpenAtSlot(_slot?: SlotTag): Promise<boolean> {
|
|
169
|
+
return Promise.resolve(this.escapeHatchOpen);
|
|
170
|
+
}
|
|
171
|
+
}
|