@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2
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/bin/index.d.ts +1 -1
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +85 -52
- package/dest/oracle/interfaces.d.ts +14 -10
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +10 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +24 -15
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +205 -88
- package/dest/rpc_translator.d.ts +35 -20
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +151 -65
- package/dest/state_machine/archiver.d.ts +21 -51
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +21 -14
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -22
- package/dest/state_machine/global_variable_builder.d.ts +6 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +7 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +40 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +21 -13
- package/dest/state_machine/synchronizer.d.ts +3 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +26 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +161 -53
- package/dest/util/encoding.d.ts +615 -16
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -17
- package/src/constants.ts +3 -0
- package/src/index.ts +97 -60
- package/src/oracle/interfaces.ts +16 -8
- package/src/oracle/txe_oracle_public_context.ts +12 -19
- package/src/oracle/txe_oracle_top_level_context.ts +249 -127
- package/src/rpc_translator.ts +179 -68
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +59 -29
- package/src/state_machine/global_variable_builder.ts +22 -4
- package/src/state_machine/index.ts +60 -21
- package/src/state_machine/mock_epoch_cache.ts +25 -20
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +222 -101
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -45
- package/src/utils/block_creation.ts +49 -14
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
|
@@ -1,151 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
+
import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
5
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
|
+
import type { CheckpointId, L2BlockId, L2TipId, L2Tips, ValidateCheckpointResult } from '@aztec/stdlib/block';
|
|
8
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
9
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
10
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
11
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* TXE Archiver implementation.
|
|
13
|
+
* Provides most of the endpoints needed by the node for reading from and writing to state,
|
|
14
|
+
* without needing any of the extra overhead that the Archiver itself requires (i.e. an L1 client).
|
|
15
|
+
*/
|
|
16
|
+
export class TXEArchiver extends ArchiverDataSourceBase {
|
|
17
|
+
private readonly updater = new ArchiverDataStoreUpdater(this.store);
|
|
18
|
+
|
|
17
19
|
constructor(db: AztecAsyncKVStore) {
|
|
18
|
-
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999, { epochDuration: 32 });
|
|
21
|
+
super(store);
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
public
|
|
22
|
-
|
|
23
|
-
this.store.addLogs(blocks.map(block => block.block)),
|
|
24
|
-
this.store.addBlocks(blocks),
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
return opResults.every(Boolean);
|
|
24
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
|
|
25
|
+
await this.updater.addCheckpoints(checkpoints, result);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
33
|
-
*/
|
|
34
|
-
public getBlockNumber(): Promise<number> {
|
|
35
|
-
return this.store.getSynchedL2BlockNumber();
|
|
28
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
29
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
41
|
-
*/
|
|
42
|
-
public getProvenBlockNumber(): Promise<number> {
|
|
43
|
-
return this.store.getSynchedL2BlockNumber();
|
|
32
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* @param number - The block number to return (inclusive).
|
|
49
|
-
* @returns The requested L2 block.
|
|
50
|
-
*/
|
|
51
|
-
public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
52
|
-
// If the number provided is -ve, then return the latest block.
|
|
53
|
-
if (number < 0) {
|
|
54
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
55
|
-
}
|
|
56
|
-
if (number == 0) {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
const blocks = await this.store.getPublishedBlocks(number, 1);
|
|
60
|
-
return blocks.length === 0 ? undefined : blocks[0];
|
|
36
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
61
38
|
}
|
|
62
39
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* @param number - The block number to return (inclusive).
|
|
66
|
-
* @returns The requested L2 block.
|
|
67
|
-
*/
|
|
68
|
-
public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
|
|
69
|
-
return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
|
|
40
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
41
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
70
42
|
}
|
|
71
43
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* @param number - The block number to return or 'latest' for the most recent one.
|
|
75
|
-
* @returns The requested L2 block header.
|
|
76
|
-
*/
|
|
77
|
-
public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
78
|
-
if (number === 'latest') {
|
|
79
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
80
|
-
}
|
|
81
|
-
if (number === 0) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
const headers = await this.store.getBlockHeaders(number, 1);
|
|
85
|
-
return headers.length === 0 ? undefined : headers[0];
|
|
44
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
45
|
+
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
86
46
|
}
|
|
87
47
|
|
|
88
|
-
public
|
|
89
|
-
|
|
90
|
-
|
|
48
|
+
public async getL2Tips(): Promise<L2Tips> {
|
|
49
|
+
// In TXE there is no possibility of reorgs and no blocks are ever getting proven so we just set 'latest', 'proven'
|
|
50
|
+
// and 'finalized' to the latest block.
|
|
51
|
+
const blockHeader = await this.getBlockHeader('latest');
|
|
52
|
+
if (!blockHeader) {
|
|
53
|
+
throw new Error('L2Tips requested from TXE Archiver but no block header found');
|
|
54
|
+
}
|
|
91
55
|
|
|
92
|
-
|
|
56
|
+
const number = blockHeader.globalVariables.blockNumber;
|
|
57
|
+
const hash = (await blockHeader.hash()).toString();
|
|
58
|
+
const checkpointedBlock = await this.getCheckpointedBlock(number);
|
|
59
|
+
if (!checkpointedBlock) {
|
|
60
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
61
|
+
}
|
|
62
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
63
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
64
|
+
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
|
|
65
|
+
if (checkpoint.length === 0) {
|
|
66
|
+
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
67
|
+
}
|
|
68
|
+
const blockId: L2BlockId = { number, hash };
|
|
69
|
+
const checkpointId: CheckpointId = {
|
|
70
|
+
number: checkpoint[0].checkpointNumber,
|
|
71
|
+
hash: checkpoint[0].header.hash().toString(),
|
|
72
|
+
};
|
|
73
|
+
const tipId: L2TipId = { block: blockId, checkpoint: checkpointId };
|
|
74
|
+
return {
|
|
75
|
+
proposed: blockId,
|
|
76
|
+
proven: tipId,
|
|
77
|
+
finalized: tipId,
|
|
78
|
+
checkpointed: tipId,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
93
83
|
throw new Error('TXE Archiver does not implement "getL2SlotNumber"');
|
|
94
84
|
}
|
|
95
85
|
|
|
96
|
-
public getL2EpochNumber(): Promise<
|
|
86
|
+
public getL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
97
87
|
throw new Error('TXE Archiver does not implement "getL2EpochNumber"');
|
|
98
88
|
}
|
|
99
89
|
|
|
100
|
-
public
|
|
101
|
-
throw new Error('TXE Archiver does not implement "getBlocksForEpoch"');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public getBlockHeadersForEpoch(_epochNumber: bigint): Promise<BlockHeader[]> {
|
|
105
|
-
throw new Error('TXE Archiver does not implement "getBlockHeadersForEpoch"');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public isEpochComplete(_epochNumber: bigint): Promise<boolean> {
|
|
90
|
+
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
109
91
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
110
92
|
}
|
|
111
93
|
|
|
112
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
113
|
-
throw new Error('TXE Archiver does not implement "getL2Tips"');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
public getL1Constants(): Promise<L1RollupConstants> {
|
|
117
|
-
throw new Error('TXE Archiver does not implement "getL2Constants"');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
121
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
94
|
public syncImmediate(): Promise<void> {
|
|
125
95
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
126
96
|
}
|
|
127
|
-
|
|
128
|
-
public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
129
|
-
throw new Error('TXE Archiver does not implement "getContract"');
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public getRollupAddress(): Promise<EthAddress> {
|
|
133
|
-
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public getRegistryAddress(): Promise<EthAddress> {
|
|
137
|
-
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
141
|
-
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public isPendingChainInvalid(): Promise<boolean> {
|
|
145
|
-
return Promise.resolve(false);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
|
|
149
|
-
return Promise.resolve({ valid: true });
|
|
150
|
-
}
|
|
151
97
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type {
|
|
2
3
|
AuthRequest,
|
|
3
4
|
ENR,
|
|
4
5
|
P2P,
|
|
5
6
|
P2PBlockReceivedCallback,
|
|
7
|
+
P2PCheckpointReceivedCallback,
|
|
6
8
|
P2PConfig,
|
|
9
|
+
P2PDuplicateAttestationCallback,
|
|
10
|
+
P2PDuplicateProposalCallback,
|
|
7
11
|
P2PSyncState,
|
|
8
12
|
PeerId,
|
|
9
13
|
ReqRespSubProtocol,
|
|
@@ -12,12 +16,12 @@ import type {
|
|
|
12
16
|
StatusMessage,
|
|
13
17
|
} from '@aztec/p2p';
|
|
14
18
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
15
|
-
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
16
|
-
import type {
|
|
17
|
-
import type { Tx, TxHash } from '@aztec/stdlib/tx';
|
|
19
|
+
import type { ITxProvider, PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
20
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposal, TopicType } from '@aztec/stdlib/p2p';
|
|
21
|
+
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
18
22
|
|
|
19
23
|
export class DummyP2P implements P2P {
|
|
20
|
-
public
|
|
24
|
+
public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
|
|
21
25
|
return Promise.resolve();
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -37,14 +41,30 @@ export class DummyP2P implements P2P {
|
|
|
37
41
|
throw new Error('DummyP2P does not implement "getPeers"');
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
|
|
45
|
+
return Promise.resolve(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
public broadcastProposal(_proposal: BlockProposal): Promise<void> {
|
|
41
49
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
42
50
|
}
|
|
43
51
|
|
|
52
|
+
public broadcastCheckpointProposal(_proposal: CheckpointProposal): Promise<void> {
|
|
53
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointProposal"');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public broadcastCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
57
|
+
throw new Error('DummyP2P does not implement "broadcastCheckpointAttestations"');
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
|
|
45
61
|
throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
|
|
46
62
|
}
|
|
47
63
|
|
|
64
|
+
public registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
65
|
+
throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
|
|
66
|
+
}
|
|
67
|
+
|
|
48
68
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
49
69
|
throw new Error('DummyP2P does not implement "requestTxs"');
|
|
50
70
|
}
|
|
@@ -57,8 +77,8 @@ export class DummyP2P implements P2P {
|
|
|
57
77
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
58
78
|
}
|
|
59
79
|
|
|
60
|
-
public
|
|
61
|
-
throw new Error('DummyP2P does not implement "
|
|
80
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
81
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
62
82
|
}
|
|
63
83
|
|
|
64
84
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -74,13 +94,19 @@ export class DummyP2P implements P2P {
|
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
77
|
-
|
|
97
|
+
// In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
|
|
98
|
+
// tx status for any tx hash.
|
|
99
|
+
return Promise.resolve('mined');
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
public iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
81
103
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
82
104
|
}
|
|
83
105
|
|
|
106
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
107
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
108
|
+
}
|
|
109
|
+
|
|
84
110
|
public getPendingTxCount(): Promise<number> {
|
|
85
111
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
86
112
|
}
|
|
@@ -109,20 +135,20 @@ export class DummyP2P implements P2P {
|
|
|
109
135
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
110
136
|
}
|
|
111
137
|
|
|
112
|
-
public
|
|
113
|
-
throw new Error('DummyP2P does not implement "
|
|
138
|
+
public getTxProvider(): ITxProvider {
|
|
139
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
114
140
|
}
|
|
115
141
|
|
|
116
|
-
public
|
|
117
|
-
throw new Error('DummyP2P does not implement "
|
|
142
|
+
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
143
|
+
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
118
144
|
}
|
|
119
145
|
|
|
120
|
-
public
|
|
121
|
-
|
|
146
|
+
public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
|
|
147
|
+
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
122
148
|
}
|
|
123
149
|
|
|
124
|
-
public
|
|
125
|
-
throw new Error('DummyP2P does not implement "
|
|
150
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
126
152
|
}
|
|
127
153
|
|
|
128
154
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -145,14 +171,6 @@ export class DummyP2P implements P2P {
|
|
|
145
171
|
throw new Error('DummyP2P does not implement "sync"');
|
|
146
172
|
}
|
|
147
173
|
|
|
148
|
-
public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
149
|
-
throw new Error('DummyP2P does not implement "requestTxsByHash"');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
153
|
-
throw new Error('DummyP2P does not implement "getTxs"');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
174
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
157
175
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
158
176
|
}
|
|
@@ -161,10 +179,6 @@ export class DummyP2P implements P2P {
|
|
|
161
179
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
162
180
|
}
|
|
163
181
|
|
|
164
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
165
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
182
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
169
183
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
170
184
|
}
|
|
@@ -177,8 +191,12 @@ export class DummyP2P implements P2P {
|
|
|
177
191
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
178
192
|
}
|
|
179
193
|
|
|
180
|
-
|
|
181
|
-
throw new Error('DummyP2P does not implement "
|
|
194
|
+
protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
195
|
+
throw new Error('DummyP2P does not implement "protectTxs".');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
199
|
+
return Promise.resolve();
|
|
182
200
|
}
|
|
183
201
|
|
|
184
202
|
addReqRespSubProtocol(
|
|
@@ -194,4 +212,16 @@ export class DummyP2P implements P2P {
|
|
|
194
212
|
|
|
195
213
|
//This is no-op
|
|
196
214
|
public registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
215
|
+
|
|
216
|
+
public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
|
|
217
|
+
throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
|
|
221
|
+
throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
|
|
225
|
+
throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
|
|
226
|
+
}
|
|
197
227
|
}
|
|
@@ -1,20 +1,38 @@
|
|
|
1
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
4
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
4
5
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
5
|
-
import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
6
|
+
import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
6
7
|
|
|
7
8
|
export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
8
|
-
public
|
|
9
|
+
public getCurrentMinFees(): Promise<GasFees> {
|
|
9
10
|
return Promise.resolve(new GasFees(0, 0));
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
public buildGlobalVariables(
|
|
13
|
-
_blockNumber:
|
|
14
|
+
_blockNumber: BlockNumber,
|
|
14
15
|
_coinbase: EthAddress,
|
|
15
16
|
_feeRecipient: AztecAddress,
|
|
16
|
-
_slotNumber?:
|
|
17
|
+
_slotNumber?: SlotNumber,
|
|
17
18
|
): Promise<GlobalVariables> {
|
|
18
19
|
return Promise.resolve(makeGlobalVariables());
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
public buildCheckpointGlobalVariables(
|
|
23
|
+
_coinbase: EthAddress,
|
|
24
|
+
_feeRecipient: AztecAddress,
|
|
25
|
+
_slotNumber: SlotNumber,
|
|
26
|
+
): Promise<CheckpointGlobalVariables> {
|
|
27
|
+
const vars = makeGlobalVariables();
|
|
28
|
+
return Promise.resolve({
|
|
29
|
+
chainId: vars.chainId,
|
|
30
|
+
version: vars.version,
|
|
31
|
+
slotNumber: vars.slotNumber,
|
|
32
|
+
timestamp: vars.timestamp,
|
|
33
|
+
coinbase: vars.coinbase,
|
|
34
|
+
feeRecipient: vars.feeRecipient,
|
|
35
|
+
gasFees: vars.gasFees,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
20
38
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
|
|
2
2
|
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import type
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
7
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
8
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
9
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
8
11
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
9
12
|
|
|
10
13
|
import { TXEArchiver } from './archiver.js';
|
|
@@ -21,14 +24,17 @@ export class TXEStateMachine {
|
|
|
21
24
|
public node: AztecNode,
|
|
22
25
|
public synchronizer: TXESynchronizer,
|
|
23
26
|
public archiver: TXEArchiver,
|
|
24
|
-
public
|
|
27
|
+
public anchorBlockStore: AnchorBlockStore,
|
|
28
|
+
public contractSyncService: ContractSyncService,
|
|
25
29
|
) {}
|
|
26
30
|
|
|
27
|
-
public static async create(
|
|
28
|
-
|
|
31
|
+
public static async create(
|
|
32
|
+
archiver: TXEArchiver,
|
|
33
|
+
anchorBlockStore: AnchorBlockStore,
|
|
34
|
+
contractStore: ContractStore,
|
|
35
|
+
noteStore: NoteStore,
|
|
36
|
+
) {
|
|
29
37
|
const synchronizer = await TXESynchronizer.create();
|
|
30
|
-
const syncDataProvider = new SyncDataProvider(db);
|
|
31
|
-
|
|
32
38
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
33
39
|
|
|
34
40
|
const log = createLogger('txe_node');
|
|
@@ -44,6 +50,7 @@ export class TXEStateMachine {
|
|
|
44
50
|
undefined,
|
|
45
51
|
undefined,
|
|
46
52
|
undefined,
|
|
53
|
+
undefined,
|
|
47
54
|
VERSION,
|
|
48
55
|
CHAIN_ID,
|
|
49
56
|
new TXEGlobalVariablesBuilder(),
|
|
@@ -54,24 +61,56 @@ export class TXEStateMachine {
|
|
|
54
61
|
log,
|
|
55
62
|
);
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
const contractSyncService = new ContractSyncService(
|
|
65
|
+
node,
|
|
66
|
+
contractStore,
|
|
67
|
+
noteStore,
|
|
68
|
+
createLogger('txe:contract_sync'),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
74
|
public async handleL2Block(block: L2Block) {
|
|
75
|
+
// Create a checkpoint from the block manually.
|
|
76
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
77
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
78
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
79
|
+
const checkpoint = new Checkpoint(
|
|
80
|
+
block.archive,
|
|
81
|
+
CheckpointHeader.from({
|
|
82
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
83
|
+
inHash: Fr.ZERO,
|
|
84
|
+
blobsHash: Fr.ZERO,
|
|
85
|
+
blockHeadersHash: Fr.ZERO,
|
|
86
|
+
epochOutHash: Fr.ZERO,
|
|
87
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
88
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
89
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
90
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
91
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
92
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
93
|
+
}),
|
|
94
|
+
[block],
|
|
95
|
+
checkpointNumber,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const publishedCheckpoint = new PublishedCheckpoint(
|
|
99
|
+
checkpoint,
|
|
100
|
+
new L1PublishedData(
|
|
101
|
+
BigInt(block.header.globalVariables.blockNumber),
|
|
102
|
+
block.header.globalVariables.timestamp,
|
|
103
|
+
block.header.globalVariables.blockNumber.toString(),
|
|
104
|
+
),
|
|
105
|
+
[],
|
|
106
|
+
);
|
|
107
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
108
|
+
this.contractSyncService.wipe();
|
|
109
|
+
|
|
61
110
|
await Promise.all([
|
|
62
111
|
this.synchronizer.handleL2Block(block),
|
|
63
|
-
this.archiver.
|
|
64
|
-
|
|
65
|
-
block,
|
|
66
|
-
l1: {
|
|
67
|
-
blockHash: block.header.globalVariables.blockNumber.toString(),
|
|
68
|
-
blockNumber: BigInt(block.header.globalVariables.blockNumber),
|
|
69
|
-
timestamp: block.header.globalVariables.timestamp,
|
|
70
|
-
},
|
|
71
|
-
attestations: [],
|
|
72
|
-
}),
|
|
73
|
-
]),
|
|
74
|
-
this.syncDataProvider.setHeader(block.getBlockHeader()),
|
|
112
|
+
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
113
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
75
114
|
]);
|
|
76
115
|
}
|
|
77
116
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
|
|
2
|
+
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
|
|
@@ -10,47 +12,46 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
10
12
|
return Promise.resolve({
|
|
11
13
|
committee: undefined,
|
|
12
14
|
seed: 0n,
|
|
13
|
-
epoch:
|
|
15
|
+
epoch: EpochNumber.ZERO,
|
|
16
|
+
isEscapeHatchOpen: false,
|
|
14
17
|
});
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
getEpochAndSlotNow(): EpochAndSlot {
|
|
20
|
+
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
18
21
|
return {
|
|
19
|
-
epoch:
|
|
20
|
-
slot:
|
|
22
|
+
epoch: EpochNumber.ZERO,
|
|
23
|
+
slot: SlotNumber(0),
|
|
21
24
|
ts: 0n,
|
|
25
|
+
nowMs: 0n,
|
|
22
26
|
};
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
getEpochAndSlotInNextL1Slot(): EpochAndSlot & { now: bigint } {
|
|
26
30
|
return {
|
|
27
|
-
epoch:
|
|
28
|
-
slot:
|
|
31
|
+
epoch: EpochNumber.ZERO,
|
|
32
|
+
slot: SlotNumber(0),
|
|
29
33
|
ts: 0n,
|
|
30
34
|
now: 0n,
|
|
31
35
|
};
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
getProposerIndexEncoding(_epoch:
|
|
38
|
+
getProposerIndexEncoding(_epoch: EpochNumber, _slot: SlotNumber, _seed: bigint): `0x${string}` {
|
|
35
39
|
return '0x00';
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
computeProposerIndex(_slot:
|
|
42
|
+
computeProposerIndex(_slot: SlotNumber, _epoch: EpochNumber, _seed: bigint, _size: bigint): bigint {
|
|
39
43
|
return 0n;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
currentSlot: 0n,
|
|
52
|
-
nextSlot: 0n,
|
|
53
|
-
});
|
|
46
|
+
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
47
|
+
return {
|
|
48
|
+
currentSlot: SlotNumber(0),
|
|
49
|
+
nextSlot: SlotNumber(0),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
|
|
54
|
+
return Promise.resolve(undefined);
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
|
|
@@ -64,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
64
65
|
filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
|
|
65
66
|
return Promise.resolve([]);
|
|
66
67
|
}
|
|
68
|
+
|
|
69
|
+
getL1Constants(): L1RollupConstants {
|
|
70
|
+
return EmptyL1RollupConstants;
|
|
71
|
+
}
|
|
67
72
|
}
|