@aztec/txe 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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/constants.d.ts +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +82 -50
- package/dest/oracle/interfaces.d.ts +6 -5
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +118 -41
- package/dest/rpc_translator.d.ts +21 -15
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +91 -54
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +36 -178
- 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 +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +35 -12
- package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +11 -7
- package/dest/state_machine/synchronizer.d.ts +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/txe_session.d.ts +11 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +98 -23
- package/dest/util/encoding.d.ts +17 -17
- 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 +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +83 -49
- package/src/oracle/interfaces.ts +8 -3
- package/src/oracle/txe_oracle_public_context.ts +6 -8
- package/src/oracle/txe_oracle_top_level_context.ts +152 -90
- package/src/rpc_translator.ts +96 -55
- package/src/state_machine/archiver.ts +37 -234
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +49 -11
- package/src/state_machine/mock_epoch_cache.ts +11 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +112 -84
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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
|
@@ -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
|
}
|
|
@@ -1,11 +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 { AnchorBlockStore } from '@aztec/pxe/server';
|
|
6
|
+
import { type AnchorBlockStore, type ContractStore, ContractSyncService, type NoteStore } from '@aztec/pxe/server';
|
|
6
7
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
|
-
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
9
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
10
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
9
11
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
10
12
|
|
|
11
13
|
import { TXEArchiver } from './archiver.js';
|
|
@@ -23,13 +25,16 @@ export class TXEStateMachine {
|
|
|
23
25
|
public synchronizer: TXESynchronizer,
|
|
24
26
|
public archiver: TXEArchiver,
|
|
25
27
|
public anchorBlockStore: AnchorBlockStore,
|
|
28
|
+
public contractSyncService: ContractSyncService,
|
|
26
29
|
) {}
|
|
27
30
|
|
|
28
|
-
public static async create(
|
|
29
|
-
|
|
31
|
+
public static async create(
|
|
32
|
+
archiver: TXEArchiver,
|
|
33
|
+
anchorBlockStore: AnchorBlockStore,
|
|
34
|
+
contractStore: ContractStore,
|
|
35
|
+
noteStore: NoteStore,
|
|
36
|
+
) {
|
|
30
37
|
const synchronizer = await TXESynchronizer.create();
|
|
31
|
-
const anchorBlockStore = new AnchorBlockStore(db);
|
|
32
|
-
|
|
33
38
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
34
39
|
|
|
35
40
|
const log = createLogger('txe_node');
|
|
@@ -45,6 +50,7 @@ export class TXEStateMachine {
|
|
|
45
50
|
undefined,
|
|
46
51
|
undefined,
|
|
47
52
|
undefined,
|
|
53
|
+
undefined,
|
|
48
54
|
VERSION,
|
|
49
55
|
CHAIN_ID,
|
|
50
56
|
new TXEGlobalVariablesBuilder(),
|
|
@@ -55,11 +61,40 @@ export class TXEStateMachine {
|
|
|
55
61
|
log,
|
|
56
62
|
);
|
|
57
63
|
|
|
58
|
-
|
|
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);
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
public async handleL2Block(block: L2Block) {
|
|
62
|
-
|
|
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
|
+
|
|
63
98
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
64
99
|
checkpoint,
|
|
65
100
|
new L1PublishedData(
|
|
@@ -69,10 +104,13 @@ export class TXEStateMachine {
|
|
|
69
104
|
),
|
|
70
105
|
[],
|
|
71
106
|
);
|
|
107
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
108
|
+
this.contractSyncService.wipe();
|
|
109
|
+
|
|
72
110
|
await Promise.all([
|
|
73
|
-
this.synchronizer.handleL2Block(block
|
|
111
|
+
this.synchronizer.handleL2Block(block),
|
|
74
112
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
75
|
-
this.anchorBlockStore.setHeader(block.
|
|
113
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
76
114
|
]);
|
|
77
115
|
}
|
|
78
116
|
}
|
|
@@ -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.
|
|
@@ -12,14 +13,16 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
12
13
|
committee: undefined,
|
|
13
14
|
seed: 0n,
|
|
14
15
|
epoch: EpochNumber.ZERO,
|
|
16
|
+
isEscapeHatchOpen: false,
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
getEpochAndSlotNow(): EpochAndSlot {
|
|
20
|
+
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
19
21
|
return {
|
|
20
22
|
epoch: EpochNumber.ZERO,
|
|
21
23
|
slot: SlotNumber(0),
|
|
22
24
|
ts: 0n,
|
|
25
|
+
nowMs: 0n,
|
|
23
26
|
};
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -40,18 +43,11 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
40
43
|
return 0n;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
nextProposer: EthAddress | undefined;
|
|
46
|
-
currentSlot: SlotNumber;
|
|
47
|
-
nextSlot: SlotNumber;
|
|
48
|
-
}> {
|
|
49
|
-
return Promise.resolve({
|
|
50
|
-
currentProposer: undefined,
|
|
51
|
-
nextProposer: undefined,
|
|
46
|
+
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
47
|
+
return {
|
|
52
48
|
currentSlot: SlotNumber(0),
|
|
53
49
|
nextSlot: SlotNumber(0),
|
|
54
|
-
}
|
|
50
|
+
};
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
|
|
@@ -69,4 +65,8 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
69
65
|
filterInCommittee(_slot: SlotTag, _validators: EthAddress[]): Promise<EthAddress[]> {
|
|
70
66
|
return Promise.resolve([]);
|
|
71
67
|
}
|
|
68
|
+
|
|
69
|
+
getL1Constants(): L1RollupConstants {
|
|
70
|
+
return EmptyL1RollupConstants;
|
|
71
|
+
}
|
|
72
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 {
|
|
4
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import type {
|
|
6
6
|
MerkleTreeReadOperations,
|
|
7
7
|
MerkleTreeWriteOperations,
|
|
@@ -23,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
|
|
|
23
23
|
return new this(nativeWorldStateService);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public async handleL2Block(block:
|
|
26
|
+
public async handleL2Block(block: L2Block) {
|
|
27
27
|
await this.nativeWorldStateService.handleL2BlockAndMessages(
|
|
28
28
|
block,
|
|
29
29
|
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
|
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 {
|
|
6
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
7
7
|
import {
|
|
8
8
|
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
9
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
|
+
JobCoordinator,
|
|
10
13
|
NoteService,
|
|
11
14
|
NoteStore,
|
|
12
15
|
PrivateEventStore,
|
|
@@ -43,15 +46,15 @@ import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
|
43
46
|
|
|
44
47
|
import { z } from 'zod';
|
|
45
48
|
|
|
46
|
-
import { DEFAULT_ADDRESS
|
|
49
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
47
50
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
48
51
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
49
52
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
50
53
|
import { RPCTranslator } from './rpc_translator.js';
|
|
54
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
51
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
52
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
53
57
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
54
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
55
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
56
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
57
60
|
|
|
@@ -74,7 +77,6 @@ type SessionState =
|
|
|
74
77
|
| {
|
|
75
78
|
name: 'PRIVATE';
|
|
76
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
77
|
-
protocolNullifier: Fr;
|
|
78
80
|
noteCache: ExecutionNoteCache;
|
|
79
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
80
82
|
}
|
|
@@ -111,6 +113,10 @@ export interface TXESessionStateHandler {
|
|
|
111
113
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
112
114
|
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
113
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
116
|
+
|
|
117
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
118
|
+
cycleJob(): Promise<string>;
|
|
119
|
+
getCurrentJob(): string;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
/**
|
|
@@ -129,7 +135,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
135
|
| IPrivateExecutionOracle
|
|
130
136
|
| IAvmExecutionOracle
|
|
131
137
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
138
|
+
private contractStore: ContractStore,
|
|
133
139
|
private noteStore: NoteStore,
|
|
134
140
|
private keyStore: KeyStore,
|
|
135
141
|
private addressStore: AddressStore,
|
|
@@ -139,18 +145,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
139
145
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
140
146
|
private capsuleStore: CapsuleStore,
|
|
141
147
|
private privateEventStore: PrivateEventStore,
|
|
148
|
+
private jobCoordinator: JobCoordinator,
|
|
149
|
+
private currentJobId: string,
|
|
142
150
|
private chainId: Fr,
|
|
143
151
|
private version: Fr,
|
|
144
152
|
private nextBlockTimestamp: bigint,
|
|
145
153
|
) {}
|
|
146
154
|
|
|
147
|
-
static async init(
|
|
155
|
+
static async init(contractStore: ContractStore) {
|
|
148
156
|
const store = await openTmpStore('txe-session');
|
|
149
157
|
|
|
150
158
|
const addressStore = new AddressStore(store);
|
|
151
159
|
const privateEventStore = new PrivateEventStore(store);
|
|
152
|
-
const
|
|
153
|
-
const noteStore = await NoteStore.create(store);
|
|
160
|
+
const noteStore = new NoteStore(store);
|
|
154
161
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
155
162
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
156
163
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -158,18 +165,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
158
165
|
const keyStore = new KeyStore(store);
|
|
159
166
|
const accountStore = new TXEAccountStore(store);
|
|
160
167
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
// Create job coordinator and register staged stores
|
|
169
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
170
|
+
jobCoordinator.registerStores([
|
|
171
|
+
capsuleStore,
|
|
172
|
+
senderTaggingStore,
|
|
173
|
+
recipientTaggingStore,
|
|
174
|
+
privateEventStore,
|
|
175
|
+
noteStore,
|
|
176
|
+
]);
|
|
166
177
|
|
|
167
|
-
const
|
|
178
|
+
const archiver = new TXEArchiver(store);
|
|
179
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
180
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
168
181
|
|
|
169
182
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
170
183
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
171
184
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
172
185
|
|
|
186
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
187
|
+
|
|
173
188
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
189
|
stateMachine,
|
|
175
190
|
contractStore,
|
|
@@ -203,6 +218,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
203
218
|
senderAddressBookStore,
|
|
204
219
|
capsuleStore,
|
|
205
220
|
privateEventStore,
|
|
221
|
+
jobCoordinator,
|
|
222
|
+
initialJobId,
|
|
206
223
|
version,
|
|
207
224
|
chainId,
|
|
208
225
|
nextBlockTimestamp,
|
|
@@ -240,6 +257,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
240
257
|
}
|
|
241
258
|
}
|
|
242
259
|
|
|
260
|
+
getCurrentJob(): string {
|
|
261
|
+
return this.currentJobId;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
265
|
+
async cycleJob(): Promise<string> {
|
|
266
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
267
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
268
|
+
return this.currentJobId;
|
|
269
|
+
}
|
|
270
|
+
|
|
243
271
|
async enterTopLevelState() {
|
|
244
272
|
switch (this.state.name) {
|
|
245
273
|
case 'PRIVATE': {
|
|
@@ -262,6 +290,9 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
262
290
|
}
|
|
263
291
|
}
|
|
264
292
|
|
|
293
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
294
|
+
await this.cycleJob();
|
|
295
|
+
|
|
265
296
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
266
297
|
this.stateMachine,
|
|
267
298
|
this.contractStore,
|
|
@@ -290,16 +321,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
290
321
|
): Promise<PrivateContextInputs> {
|
|
291
322
|
this.exitTopLevelState();
|
|
292
323
|
|
|
293
|
-
await new NoteService(
|
|
294
|
-
this.noteStore,
|
|
295
|
-
this.stateMachine.node,
|
|
296
|
-
this.stateMachine.anchorBlockStore,
|
|
297
|
-
).syncNoteNullifiers(contractAddress);
|
|
298
|
-
|
|
299
324
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
300
325
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
301
326
|
// a single transaction with the effects of what was done in the test.
|
|
302
327
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
328
|
+
|
|
329
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
330
|
+
contractAddress,
|
|
331
|
+
'ALL_SCOPES',
|
|
332
|
+
);
|
|
303
333
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
304
334
|
|
|
305
335
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -315,37 +345,38 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
315
345
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
316
346
|
|
|
317
347
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
318
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
319
|
-
Fr.ZERO,
|
|
320
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
321
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
322
|
-
anchorBlock!,
|
|
348
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
349
|
+
argsHash: Fr.ZERO,
|
|
350
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
351
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
352
|
+
anchorBlockHeader: anchorBlock!,
|
|
323
353
|
utilityExecutor,
|
|
324
|
-
[],
|
|
325
|
-
[],
|
|
326
|
-
new HashedValuesCache(),
|
|
354
|
+
authWitnesses: [],
|
|
355
|
+
capsules: [],
|
|
356
|
+
executionCache: new HashedValuesCache(),
|
|
327
357
|
noteCache,
|
|
328
358
|
taggingIndexCache,
|
|
329
|
-
this.contractStore,
|
|
330
|
-
this.noteStore,
|
|
331
|
-
this.keyStore,
|
|
332
|
-
this.addressStore,
|
|
333
|
-
this.stateMachine.node,
|
|
334
|
-
this.
|
|
335
|
-
this.
|
|
336
|
-
this.
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
340
|
-
|
|
341
|
-
|
|
359
|
+
contractStore: this.contractStore,
|
|
360
|
+
noteStore: this.noteStore,
|
|
361
|
+
keyStore: this.keyStore,
|
|
362
|
+
addressStore: this.addressStore,
|
|
363
|
+
aztecNode: this.stateMachine.node,
|
|
364
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
365
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
366
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
367
|
+
capsuleStore: this.capsuleStore,
|
|
368
|
+
privateEventStore: this.privateEventStore,
|
|
369
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
370
|
+
jobId: this.currentJobId,
|
|
371
|
+
scopes: 'ALL_SCOPES',
|
|
372
|
+
});
|
|
342
373
|
|
|
343
374
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
344
375
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
345
376
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
346
377
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
347
378
|
// execution finishes.
|
|
348
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
379
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
349
380
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
350
381
|
|
|
351
382
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -378,6 +409,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
378
409
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
379
410
|
this.exitTopLevelState();
|
|
380
411
|
|
|
412
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
413
|
+
|
|
381
414
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
382
415
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
383
416
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
@@ -386,28 +419,27 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
386
419
|
await new NoteService(
|
|
387
420
|
this.noteStore,
|
|
388
421
|
this.stateMachine.node,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
422
|
+
anchorBlockHeader,
|
|
423
|
+
this.currentJobId,
|
|
424
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
393
425
|
|
|
394
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
426
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
395
427
|
contractAddress,
|
|
396
|
-
[],
|
|
397
|
-
[],
|
|
428
|
+
authWitnesses: [],
|
|
429
|
+
capsules: [],
|
|
398
430
|
anchorBlockHeader,
|
|
399
|
-
this.contractStore,
|
|
400
|
-
this.noteStore,
|
|
401
|
-
this.keyStore,
|
|
402
|
-
this.addressStore,
|
|
403
|
-
this.stateMachine.node,
|
|
404
|
-
this.
|
|
405
|
-
this.
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
);
|
|
431
|
+
contractStore: this.contractStore,
|
|
432
|
+
noteStore: this.noteStore,
|
|
433
|
+
keyStore: this.keyStore,
|
|
434
|
+
addressStore: this.addressStore,
|
|
435
|
+
aztecNode: this.stateMachine.node,
|
|
436
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
437
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
438
|
+
capsuleStore: this.capsuleStore,
|
|
439
|
+
privateEventStore: this.privateEventStore,
|
|
440
|
+
jobId: this.currentJobId,
|
|
441
|
+
scopes: 'ALL_SCOPES',
|
|
442
|
+
});
|
|
411
443
|
|
|
412
444
|
this.state = { name: 'UTILITY' };
|
|
413
445
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -442,11 +474,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
442
474
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
443
475
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
444
476
|
|
|
445
|
-
const txEffect = await makeTxEffect(
|
|
446
|
-
this.state.noteCache,
|
|
447
|
-
this.state.protocolNullifier,
|
|
448
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
449
|
-
);
|
|
477
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
450
478
|
|
|
451
479
|
// We build a block holding just this transaction
|
|
452
480
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
@@ -479,30 +507,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
479
507
|
}
|
|
480
508
|
|
|
481
509
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
482
|
-
return async (call: FunctionCall) => {
|
|
510
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
483
511
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
484
512
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
485
513
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
486
514
|
}
|
|
487
515
|
|
|
488
516
|
try {
|
|
489
|
-
const oracle = new UtilityExecutionOracle(
|
|
490
|
-
call.to,
|
|
491
|
-
[],
|
|
492
|
-
[],
|
|
493
|
-
anchorBlock!,
|
|
494
|
-
this.contractStore,
|
|
495
|
-
this.noteStore,
|
|
496
|
-
this.keyStore,
|
|
497
|
-
this.addressStore,
|
|
498
|
-
this.stateMachine.node,
|
|
499
|
-
this.
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
this.
|
|
503
|
-
this.
|
|
504
|
-
|
|
505
|
-
);
|
|
517
|
+
const oracle = new UtilityExecutionOracle({
|
|
518
|
+
contractAddress: call.to,
|
|
519
|
+
authWitnesses: [],
|
|
520
|
+
capsules: [],
|
|
521
|
+
anchorBlockHeader: anchorBlock!,
|
|
522
|
+
contractStore: this.contractStore,
|
|
523
|
+
noteStore: this.noteStore,
|
|
524
|
+
keyStore: this.keyStore,
|
|
525
|
+
addressStore: this.addressStore,
|
|
526
|
+
aztecNode: this.stateMachine.node,
|
|
527
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
528
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
529
|
+
capsuleStore: this.capsuleStore,
|
|
530
|
+
privateEventStore: this.privateEventStore,
|
|
531
|
+
jobId: this.currentJobId,
|
|
532
|
+
scopes,
|
|
533
|
+
});
|
|
506
534
|
await new WASMSimulator()
|
|
507
535
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
508
536
|
.catch((err: Error) => {
|