@aztec/txe 0.0.1-commit.a072138 → 0.0.1-commit.a89ec08
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/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +12 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +144 -58
- package/dest/rpc_translator.d.ts +121 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +394 -159
- package/dest/state_machine/archiver.d.ts +3 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +7 -7
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- package/dest/state_machine/index.d.ts +7 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +19 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +4 -0
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +96 -25
- package/dest/util/encoding.d.ts +40 -41
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +167 -108
- package/src/rpc_translator.ts +450 -176
- package/src/state_machine/archiver.ts +7 -5
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +29 -9
- package/src/state_machine/mock_epoch_cache.ts +5 -0
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +102 -72
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +3 -1
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
|
@@ -17,7 +17,7 @@ export class TXEArchiver extends ArchiverDataSourceBase {
|
|
|
17
17
|
private readonly updater = new ArchiverDataStoreUpdater(this.store);
|
|
18
18
|
|
|
19
19
|
constructor(db: AztecAsyncKVStore) {
|
|
20
|
-
const store = new KVArchiverDataStore(db, 9999
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999);
|
|
21
21
|
super(store);
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -59,6 +59,8 @@ export class TXEArchiver extends ArchiverDataSourceBase {
|
|
|
59
59
|
if (!checkpointedBlock) {
|
|
60
60
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpointed block found for block number ${number}`);
|
|
61
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.
|
|
62
64
|
const checkpoint = await this.store.getRangeOfCheckpoints(CheckpointNumber.fromBlockNumber(number), 1);
|
|
63
65
|
if (checkpoint.length === 0) {
|
|
64
66
|
throw new Error(`L2Tips requested from TXE Archiver but no checkpoint found for block number ${number}`);
|
|
@@ -77,12 +79,12 @@ export class TXEArchiver extends ArchiverDataSourceBase {
|
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
public
|
|
81
|
-
throw new Error('TXE Archiver does not implement "
|
|
82
|
+
public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
83
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
public
|
|
85
|
-
throw new Error('TXE Archiver does not implement "
|
|
86
|
+
public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
87
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
@@ -6,6 +6,8 @@ import type {
|
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
7
|
P2PCheckpointReceivedCallback,
|
|
8
8
|
P2PConfig,
|
|
9
|
+
P2PDuplicateAttestationCallback,
|
|
10
|
+
P2PDuplicateProposalCallback,
|
|
9
11
|
P2PSyncState,
|
|
10
12
|
PeerId,
|
|
11
13
|
ReqRespSubProtocol,
|
|
@@ -14,12 +16,12 @@ import type {
|
|
|
14
16
|
StatusMessage,
|
|
15
17
|
} from '@aztec/p2p';
|
|
16
18
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
17
|
-
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
18
|
-
import type { BlockProposal, CheckpointAttestation, CheckpointProposal } from '@aztec/stdlib/p2p';
|
|
19
|
-
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';
|
|
20
22
|
|
|
21
23
|
export class DummyP2P implements P2P {
|
|
22
|
-
public
|
|
24
|
+
public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
|
|
23
25
|
return Promise.resolve();
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -39,6 +41,10 @@ export class DummyP2P implements P2P {
|
|
|
39
41
|
throw new Error('DummyP2P does not implement "getPeers"');
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
|
|
45
|
+
return Promise.resolve(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
public broadcastProposal(_proposal: BlockProposal): Promise<void> {
|
|
43
49
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
44
50
|
}
|
|
@@ -71,8 +77,8 @@ export class DummyP2P implements P2P {
|
|
|
71
77
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
public
|
|
75
|
-
throw new Error('DummyP2P does not implement "
|
|
80
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
81
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -97,6 +103,10 @@ export class DummyP2P implements P2P {
|
|
|
97
103
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
98
104
|
}
|
|
99
105
|
|
|
106
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
107
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
public getPendingTxCount(): Promise<number> {
|
|
101
111
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
102
112
|
}
|
|
@@ -125,6 +135,10 @@ export class DummyP2P implements P2P {
|
|
|
125
135
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
126
136
|
}
|
|
127
137
|
|
|
138
|
+
public getTxProvider(): ITxProvider {
|
|
139
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
140
|
+
}
|
|
141
|
+
|
|
128
142
|
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
129
143
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
130
144
|
}
|
|
@@ -133,8 +147,8 @@ export class DummyP2P implements P2P {
|
|
|
133
147
|
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
134
148
|
}
|
|
135
149
|
|
|
136
|
-
public
|
|
137
|
-
throw new Error('DummyP2P does not implement "
|
|
150
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -157,14 +171,6 @@ export class DummyP2P implements P2P {
|
|
|
157
171
|
throw new Error('DummyP2P does not implement "sync"');
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
161
|
-
throw new Error('DummyP2P does not implement "requestTxsByHash"');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
165
|
-
throw new Error('DummyP2P does not implement "getTxs"');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
174
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
169
175
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
170
176
|
}
|
|
@@ -173,10 +179,6 @@ export class DummyP2P implements P2P {
|
|
|
173
179
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
174
180
|
}
|
|
175
181
|
|
|
176
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
177
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
182
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
181
183
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
182
184
|
}
|
|
@@ -189,8 +191,12 @@ export class DummyP2P implements P2P {
|
|
|
189
191
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
190
192
|
}
|
|
191
193
|
|
|
192
|
-
|
|
193
|
-
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();
|
|
194
200
|
}
|
|
195
201
|
|
|
196
202
|
addReqRespSubProtocol(
|
|
@@ -206,4 +212,16 @@ export class DummyP2P implements P2P {
|
|
|
206
212
|
|
|
207
213
|
//This is no-op
|
|
208
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
|
+
}
|
|
209
227
|
}
|
|
@@ -3,8 +3,8 @@ import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
|
3
3
|
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
4
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
-
import type
|
|
7
|
-
import {
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
7
|
+
import { MessageContextService } from '@aztec/pxe/simulator';
|
|
8
8
|
import { L2Block } from '@aztec/stdlib/block';
|
|
9
9
|
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
10
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
@@ -26,13 +26,17 @@ export class TXEStateMachine {
|
|
|
26
26
|
public synchronizer: TXESynchronizer,
|
|
27
27
|
public archiver: TXEArchiver,
|
|
28
28
|
public anchorBlockStore: AnchorBlockStore,
|
|
29
|
+
public contractSyncService: ContractSyncService,
|
|
30
|
+
public messageContextService: MessageContextService,
|
|
29
31
|
) {}
|
|
30
32
|
|
|
31
|
-
public static async create(
|
|
32
|
-
|
|
33
|
+
public static async create(
|
|
34
|
+
archiver: TXEArchiver,
|
|
35
|
+
anchorBlockStore: AnchorBlockStore,
|
|
36
|
+
contractStore: ContractStore,
|
|
37
|
+
noteStore: NoteStore,
|
|
38
|
+
) {
|
|
33
39
|
const synchronizer = await TXESynchronizer.create();
|
|
34
|
-
const anchorBlockStore = new AnchorBlockStore(db);
|
|
35
|
-
|
|
36
40
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
37
41
|
|
|
38
42
|
const log = createLogger('txe_node');
|
|
@@ -48,6 +52,7 @@ export class TXEStateMachine {
|
|
|
48
52
|
undefined,
|
|
49
53
|
undefined,
|
|
50
54
|
undefined,
|
|
55
|
+
undefined,
|
|
51
56
|
VERSION,
|
|
52
57
|
CHAIN_ID,
|
|
53
58
|
new TXEGlobalVariablesBuilder(),
|
|
@@ -58,11 +63,23 @@ export class TXEStateMachine {
|
|
|
58
63
|
log,
|
|
59
64
|
);
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
const contractSyncService = new ContractSyncService(
|
|
67
|
+
node,
|
|
68
|
+
contractStore,
|
|
69
|
+
noteStore,
|
|
70
|
+
createLogger('txe:contract_sync'),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const messageContextService = new MessageContextService(node);
|
|
74
|
+
|
|
75
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
public async handleL2Block(block: L2Block) {
|
|
65
|
-
// Create a checkpoint from the block manually
|
|
79
|
+
// Create a checkpoint from the block manually.
|
|
80
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
81
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
82
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
66
83
|
const checkpoint = new Checkpoint(
|
|
67
84
|
block.archive,
|
|
68
85
|
CheckpointHeader.from({
|
|
@@ -79,7 +96,7 @@ export class TXEStateMachine {
|
|
|
79
96
|
totalManaUsed: block.header.totalManaUsed,
|
|
80
97
|
}),
|
|
81
98
|
[block],
|
|
82
|
-
|
|
99
|
+
checkpointNumber,
|
|
83
100
|
);
|
|
84
101
|
|
|
85
102
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
@@ -91,6 +108,9 @@ export class TXEStateMachine {
|
|
|
91
108
|
),
|
|
92
109
|
[],
|
|
93
110
|
);
|
|
111
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
112
|
+
this.contractSyncService.wipe();
|
|
113
|
+
|
|
94
114
|
await Promise.all([
|
|
95
115
|
this.synchronizer.handleL2Block(block),
|
|
96
116
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EpochAndSlot, EpochCacheInterface, EpochCommitteeInfo, SlotTag } from '@aztec/epoch-cache';
|
|
2
2
|
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { EmptyL1RollupConstants, type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Mock implementation of the EpochCacheInterface used to satisfy dependencies of AztecNodeService.
|
|
@@ -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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import type { L2Block } from '@aztec/stdlib/block';
|
|
4
|
+
import type { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import type {
|
|
6
6
|
MerkleTreeReadOperations,
|
|
7
7
|
MerkleTreeWriteOperations,
|
|
@@ -33,12 +33,12 @@ export class TXESynchronizer implements WorldStateSynchronizer {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Forces an immediate sync to an optionally provided minimum block number
|
|
36
|
+
* Forces an immediate sync to an optionally provided minimum block number.
|
|
37
37
|
* @param targetBlockNumber - The target block number that we must sync to. Will download unproven blocks if needed to reach it.
|
|
38
|
-
* @param
|
|
38
|
+
* @param blockHash - If provided, verifies the block at targetBlockNumber matches this hash.
|
|
39
39
|
* @returns A promise that resolves with the block number the world state was synced to
|
|
40
40
|
*/
|
|
41
|
-
public syncImmediate(_minBlockNumber?: BlockNumber,
|
|
41
|
+
public syncImmediate(_minBlockNumber?: BlockNumber, _blockHash?: BlockHash): Promise<BlockNumber> {
|
|
42
42
|
return Promise.resolve(this.blockNumber);
|
|
43
43
|
}
|
|
44
44
|
|
package/src/txe_session.ts
CHANGED
|
@@ -3,10 +3,13 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
7
6
|
import {
|
|
8
7
|
AddressStore,
|
|
8
|
+
AnchorBlockStore,
|
|
9
|
+
CapsuleService,
|
|
9
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
|
+
ContractSyncService,
|
|
10
13
|
JobCoordinator,
|
|
11
14
|
NoteService,
|
|
12
15
|
NoteStore,
|
|
@@ -49,10 +52,10 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
|
|
|
49
52
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
50
53
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
51
54
|
import { RPCTranslator } from './rpc_translator.js';
|
|
55
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
52
56
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
53
57
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
54
58
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
55
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
56
59
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
57
60
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
58
61
|
|
|
@@ -111,6 +114,10 @@ export interface TXESessionStateHandler {
|
|
|
111
114
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
112
115
|
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
113
116
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
117
|
+
|
|
118
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
119
|
+
cycleJob(): Promise<string>;
|
|
120
|
+
getCurrentJob(): string;
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
/**
|
|
@@ -129,7 +136,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
136
|
| IPrivateExecutionOracle
|
|
130
137
|
| IAvmExecutionOracle
|
|
131
138
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
139
|
+
private contractStore: ContractStore,
|
|
133
140
|
private noteStore: NoteStore,
|
|
134
141
|
private keyStore: KeyStore,
|
|
135
142
|
private addressStore: AddressStore,
|
|
@@ -144,14 +151,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
144
151
|
private chainId: Fr,
|
|
145
152
|
private version: Fr,
|
|
146
153
|
private nextBlockTimestamp: bigint,
|
|
154
|
+
private contractSyncService: ContractSyncService,
|
|
147
155
|
) {}
|
|
148
156
|
|
|
149
|
-
static async init(
|
|
157
|
+
static async init(contractStore: ContractStore) {
|
|
150
158
|
const store = await openTmpStore('txe-session');
|
|
151
159
|
|
|
152
160
|
const addressStore = new AddressStore(store);
|
|
153
161
|
const privateEventStore = new PrivateEventStore(store);
|
|
154
|
-
const contractStore = new TXEContractStore(store);
|
|
155
162
|
const noteStore = new NoteStore(store);
|
|
156
163
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
157
164
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
@@ -170,13 +177,9 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
170
177
|
noteStore,
|
|
171
178
|
]);
|
|
172
179
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
await contractStore.addContractInstance(instance);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const stateMachine = await TXEStateMachine.create(store);
|
|
180
|
+
const archiver = new TXEArchiver(store);
|
|
181
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
182
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
180
183
|
|
|
181
184
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
182
185
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
@@ -184,6 +187,9 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
184
187
|
|
|
185
188
|
const initialJobId = jobCoordinator.beginJob();
|
|
186
189
|
|
|
190
|
+
const logger = createLogger('txe:session');
|
|
191
|
+
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
192
|
+
|
|
187
193
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
188
194
|
stateMachine,
|
|
189
195
|
contractStore,
|
|
@@ -196,16 +202,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
196
202
|
senderAddressBookStore,
|
|
197
203
|
capsuleStore,
|
|
198
204
|
privateEventStore,
|
|
199
|
-
initialJobId,
|
|
200
205
|
nextBlockTimestamp,
|
|
201
206
|
version,
|
|
202
207
|
chainId,
|
|
203
208
|
new Map(),
|
|
209
|
+
contractSyncService,
|
|
204
210
|
);
|
|
205
|
-
await topLevelOracleHandler.
|
|
211
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
206
212
|
|
|
207
213
|
return new TXESession(
|
|
208
|
-
|
|
214
|
+
logger,
|
|
209
215
|
stateMachine,
|
|
210
216
|
topLevelOracleHandler,
|
|
211
217
|
contractStore,
|
|
@@ -223,6 +229,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
223
229
|
version,
|
|
224
230
|
chainId,
|
|
225
231
|
nextBlockTimestamp,
|
|
232
|
+
contractSyncService,
|
|
226
233
|
);
|
|
227
234
|
}
|
|
228
235
|
|
|
@@ -257,6 +264,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
257
264
|
}
|
|
258
265
|
}
|
|
259
266
|
|
|
267
|
+
getCurrentJob(): string {
|
|
268
|
+
return this.currentJobId;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
272
|
+
async cycleJob(): Promise<string> {
|
|
273
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
274
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
275
|
+
return this.currentJobId;
|
|
276
|
+
}
|
|
277
|
+
|
|
260
278
|
async enterTopLevelState() {
|
|
261
279
|
switch (this.state.name) {
|
|
262
280
|
case 'PRIVATE': {
|
|
@@ -280,8 +298,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
280
298
|
}
|
|
281
299
|
|
|
282
300
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
283
|
-
await this.
|
|
284
|
-
this.currentJobId = this.jobCoordinator.beginJob();
|
|
301
|
+
await this.cycleJob();
|
|
285
302
|
|
|
286
303
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
287
304
|
this.stateMachine,
|
|
@@ -295,11 +312,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
295
312
|
this.senderAddressBookStore,
|
|
296
313
|
this.capsuleStore,
|
|
297
314
|
this.privateEventStore,
|
|
298
|
-
this.currentJobId,
|
|
299
315
|
this.nextBlockTimestamp,
|
|
300
316
|
this.version,
|
|
301
317
|
this.chainId,
|
|
302
318
|
this.authwits,
|
|
319
|
+
this.contractSyncService,
|
|
303
320
|
);
|
|
304
321
|
|
|
305
322
|
this.state = { name: 'TOP_LEVEL' };
|
|
@@ -319,6 +336,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
319
336
|
|
|
320
337
|
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
321
338
|
contractAddress,
|
|
339
|
+
await this.keyStore.getAccounts(),
|
|
322
340
|
);
|
|
323
341
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
324
342
|
|
|
@@ -335,29 +353,33 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
335
353
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
336
354
|
|
|
337
355
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
338
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
339
|
-
Fr.ZERO,
|
|
340
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
341
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
342
|
-
anchorBlock!,
|
|
356
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
357
|
+
argsHash: Fr.ZERO,
|
|
358
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
359
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
360
|
+
anchorBlockHeader: anchorBlock!,
|
|
343
361
|
utilityExecutor,
|
|
344
|
-
[],
|
|
345
|
-
[],
|
|
346
|
-
new HashedValuesCache(),
|
|
362
|
+
authWitnesses: [],
|
|
363
|
+
capsules: [],
|
|
364
|
+
executionCache: new HashedValuesCache(),
|
|
347
365
|
noteCache,
|
|
348
366
|
taggingIndexCache,
|
|
349
|
-
this.contractStore,
|
|
350
|
-
this.noteStore,
|
|
351
|
-
this.keyStore,
|
|
352
|
-
this.addressStore,
|
|
353
|
-
this.stateMachine.node,
|
|
354
|
-
this.senderTaggingStore,
|
|
355
|
-
this.recipientTaggingStore,
|
|
356
|
-
this.senderAddressBookStore,
|
|
357
|
-
this.capsuleStore,
|
|
358
|
-
this.privateEventStore,
|
|
359
|
-
this.
|
|
360
|
-
|
|
367
|
+
contractStore: this.contractStore,
|
|
368
|
+
noteStore: this.noteStore,
|
|
369
|
+
keyStore: this.keyStore,
|
|
370
|
+
addressStore: this.addressStore,
|
|
371
|
+
aztecNode: this.stateMachine.node,
|
|
372
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
373
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
374
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
375
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
376
|
+
privateEventStore: this.privateEventStore,
|
|
377
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
378
|
+
l2TipsStore: this.stateMachine.node,
|
|
379
|
+
jobId: this.currentJobId,
|
|
380
|
+
scopes: await this.keyStore.getAccounts(),
|
|
381
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
382
|
+
});
|
|
361
383
|
|
|
362
384
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
363
385
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -409,24 +431,28 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
409
431
|
this.stateMachine.node,
|
|
410
432
|
anchorBlockHeader,
|
|
411
433
|
this.currentJobId,
|
|
412
|
-
).syncNoteNullifiers(contractAddress);
|
|
434
|
+
).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
413
435
|
|
|
414
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
436
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
415
437
|
contractAddress,
|
|
416
|
-
[],
|
|
417
|
-
[],
|
|
438
|
+
authWitnesses: [],
|
|
439
|
+
capsules: [],
|
|
418
440
|
anchorBlockHeader,
|
|
419
|
-
this.contractStore,
|
|
420
|
-
this.noteStore,
|
|
421
|
-
this.keyStore,
|
|
422
|
-
this.addressStore,
|
|
423
|
-
this.stateMachine.node,
|
|
424
|
-
this.recipientTaggingStore,
|
|
425
|
-
this.senderAddressBookStore,
|
|
426
|
-
this.capsuleStore,
|
|
427
|
-
this.privateEventStore,
|
|
428
|
-
this.
|
|
429
|
-
|
|
441
|
+
contractStore: this.contractStore,
|
|
442
|
+
noteStore: this.noteStore,
|
|
443
|
+
keyStore: this.keyStore,
|
|
444
|
+
addressStore: this.addressStore,
|
|
445
|
+
aztecNode: this.stateMachine.node,
|
|
446
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
447
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
448
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
449
|
+
privateEventStore: this.privateEventStore,
|
|
450
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
451
|
+
contractSyncService: this.contractSyncService,
|
|
452
|
+
l2TipsStore: this.stateMachine.node,
|
|
453
|
+
jobId: this.currentJobId,
|
|
454
|
+
scopes: await this.keyStore.getAccounts(),
|
|
455
|
+
});
|
|
430
456
|
|
|
431
457
|
this.state = { name: 'UTILITY' };
|
|
432
458
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -439,8 +465,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
439
465
|
|
|
440
466
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
441
467
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
442
|
-
// others, it will create empty blocks (via `
|
|
443
|
-
// `
|
|
468
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
469
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
444
470
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
445
471
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
446
472
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -494,29 +520,33 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
494
520
|
}
|
|
495
521
|
|
|
496
522
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
497
|
-
return async (call: FunctionCall) => {
|
|
523
|
+
return async (call: FunctionCall, scopes: AztecAddress[]) => {
|
|
498
524
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
499
525
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
500
526
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
501
527
|
}
|
|
502
528
|
|
|
503
529
|
try {
|
|
504
|
-
const oracle = new UtilityExecutionOracle(
|
|
505
|
-
call.to,
|
|
506
|
-
[],
|
|
507
|
-
[],
|
|
508
|
-
anchorBlock!,
|
|
509
|
-
this.contractStore,
|
|
510
|
-
this.noteStore,
|
|
511
|
-
this.keyStore,
|
|
512
|
-
this.addressStore,
|
|
513
|
-
this.stateMachine.node,
|
|
514
|
-
this.recipientTaggingStore,
|
|
515
|
-
this.senderAddressBookStore,
|
|
516
|
-
this.capsuleStore,
|
|
517
|
-
this.privateEventStore,
|
|
518
|
-
this.
|
|
519
|
-
|
|
530
|
+
const oracle = new UtilityExecutionOracle({
|
|
531
|
+
contractAddress: call.to,
|
|
532
|
+
authWitnesses: [],
|
|
533
|
+
capsules: [],
|
|
534
|
+
anchorBlockHeader: anchorBlock!,
|
|
535
|
+
contractStore: this.contractStore,
|
|
536
|
+
noteStore: this.noteStore,
|
|
537
|
+
keyStore: this.keyStore,
|
|
538
|
+
addressStore: this.addressStore,
|
|
539
|
+
aztecNode: this.stateMachine.node,
|
|
540
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
541
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
542
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
543
|
+
privateEventStore: this.privateEventStore,
|
|
544
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
545
|
+
contractSyncService: this.contractSyncService,
|
|
546
|
+
l2TipsStore: this.stateMachine.node,
|
|
547
|
+
jobId: this.currentJobId,
|
|
548
|
+
scopes,
|
|
549
|
+
});
|
|
520
550
|
await new WASMSimulator()
|
|
521
551
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
522
552
|
.catch((err: Error) => {
|