@aztec/txe 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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 +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 +91 -56
- package/dest/oracle/interfaces.d.ts +36 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +44 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +245 -109
- package/dest/rpc_translator.d.ts +136 -78
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +545 -178
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +67 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +21 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +45 -25
- package/dest/state_machine/global_variable_builder.d.ts +11 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +21 -3
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +45 -24
- package/dest/state_machine/mock_epoch_cache.d.ts +26 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +49 -9
- package/dest/state_machine/synchronizer.d.ts +6 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +8 -7
- package/dest/txe_session.d.ts +71 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +228 -57
- package/dest/util/encoding.d.ts +688 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +5 -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 +13 -32
- 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 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +103 -63
- package/src/oracle/interfaces.ts +37 -33
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +291 -151
- package/src/rpc_translator.ts +645 -206
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +62 -33
- package/src/state_machine/global_variable_builder.ts +38 -6
- package/src/state_machine/index.ts +68 -22
- package/src/state_machine/mock_epoch_cache.ts +61 -14
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +351 -105
- package/src/util/encoding.ts +6 -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 -47
- package/src/utils/block_creation.ts +49 -15
- 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,152 +1,98 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArchiverDataSourceBase, ArchiverDataStoreUpdater, KVArchiverDataStore } from '@aztec/archiver';
|
|
2
2
|
import { GENESIS_ARCHIVE_ROOT } from '@aztec/constants';
|
|
3
|
-
import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { CheckpointNumber, type EpochNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
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';
|
|
10
9
|
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
12
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
public override async addBlocks(blocks: PublishedL2Block[]): Promise<boolean> {
|
|
23
|
-
const opResults = await Promise.all([
|
|
24
|
-
this.store.addLogs(blocks.map(block => block.block)),
|
|
25
|
-
this.store.addBlocks(blocks),
|
|
26
|
-
]);
|
|
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);
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
constructor(db: AztecAsyncKVStore) {
|
|
20
|
+
const store = new KVArchiverDataStore(db, 9999);
|
|
21
|
+
super(store);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @returns The number of the latest L2 block processed by the block source implementation.
|
|
34
|
-
*/
|
|
35
|
-
public getBlockNumber(): Promise<number> {
|
|
36
|
-
return this.store.getSynchedL2BlockNumber();
|
|
24
|
+
public async addCheckpoints(checkpoints: PublishedCheckpoint[], result?: ValidateCheckpointResult): Promise<void> {
|
|
25
|
+
await this.updater.addCheckpoints(checkpoints, result);
|
|
37
26
|
}
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @returns The number of the latest L2 block proven seen by the block source implementation.
|
|
42
|
-
*/
|
|
43
|
-
public getProvenBlockNumber(): Promise<number> {
|
|
44
|
-
return this.store.getSynchedL2BlockNumber();
|
|
28
|
+
public getRollupAddress(): Promise<EthAddress> {
|
|
29
|
+
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
45
30
|
}
|
|
46
31
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* @param number - The block number to return (inclusive).
|
|
50
|
-
* @returns The requested L2 block.
|
|
51
|
-
*/
|
|
52
|
-
public override async getPublishedBlock(number: number): Promise<PublishedL2Block | undefined> {
|
|
53
|
-
// If the number provided is -ve, then return the latest block.
|
|
54
|
-
if (number < 0) {
|
|
55
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
56
|
-
}
|
|
57
|
-
if (number == 0) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const blocks = await this.store.getPublishedBlocks(number, 1);
|
|
61
|
-
return blocks.length === 0 ? undefined : blocks[0];
|
|
32
|
+
public getRegistryAddress(): Promise<EthAddress> {
|
|
33
|
+
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
62
34
|
}
|
|
63
35
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param number - The block number to return (inclusive).
|
|
67
|
-
* @returns The requested L2 block.
|
|
68
|
-
*/
|
|
69
|
-
public getBlock(number: number | 'latest'): Promise<L2Block | undefined> {
|
|
70
|
-
return this.getPublishedBlock(number != 'latest' ? number : -1).then(block => block?.block);
|
|
36
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
37
|
+
throw new Error('TXE Archiver does not implement "getL1Constants"');
|
|
71
38
|
}
|
|
72
39
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* @param number - The block number to return or 'latest' for the most recent one.
|
|
76
|
-
* @returns The requested L2 block header.
|
|
77
|
-
*/
|
|
78
|
-
public async getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined> {
|
|
79
|
-
if (number === 'latest') {
|
|
80
|
-
number = await this.store.getSynchedL2BlockNumber();
|
|
81
|
-
}
|
|
82
|
-
if (number === 0) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
const headers = await this.store.getBlockHeaders(number, 1);
|
|
86
|
-
return headers.length === 0 ? undefined : headers[0];
|
|
40
|
+
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
41
|
+
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
87
42
|
}
|
|
88
43
|
|
|
89
|
-
public
|
|
90
|
-
|
|
44
|
+
public getL1Timestamp(): Promise<bigint | undefined> {
|
|
45
|
+
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
91
46
|
}
|
|
92
47
|
|
|
93
|
-
public
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
}
|
|
96
55
|
|
|
97
|
-
|
|
98
|
-
|
|
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
|
+
proposedCheckpoint: tipId,
|
|
80
|
+
};
|
|
99
81
|
}
|
|
100
82
|
|
|
101
|
-
public
|
|
102
|
-
throw new Error('TXE Archiver does not implement "
|
|
83
|
+
public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
84
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
|
|
103
85
|
}
|
|
104
86
|
|
|
105
|
-
public
|
|
106
|
-
throw new Error('TXE Archiver does not implement "
|
|
87
|
+
public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
88
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
|
|
107
89
|
}
|
|
108
90
|
|
|
109
91
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
110
92
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
111
93
|
}
|
|
112
94
|
|
|
113
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
114
|
-
throw new Error('TXE Archiver does not implement "getL2Tips"');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public getL1Constants(): Promise<L1RollupConstants> {
|
|
118
|
-
throw new Error('TXE Archiver does not implement "getL2Constants"');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public getGenesisValues(): Promise<{ genesisArchiveRoot: Fr }> {
|
|
122
|
-
return Promise.resolve({ genesisArchiveRoot: new Fr(GENESIS_ARCHIVE_ROOT) });
|
|
123
|
-
}
|
|
124
|
-
|
|
125
95
|
public syncImmediate(): Promise<void> {
|
|
126
96
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
127
97
|
}
|
|
128
|
-
|
|
129
|
-
public getContract(_address: AztecAddress, _timestamp?: UInt64): Promise<ContractInstanceWithAddress | undefined> {
|
|
130
|
-
throw new Error('TXE Archiver does not implement "getContract"');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public getRollupAddress(): Promise<EthAddress> {
|
|
134
|
-
throw new Error('TXE Archiver does not implement "getRollupAddress"');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public getRegistryAddress(): Promise<EthAddress> {
|
|
138
|
-
throw new Error('TXE Archiver does not implement "getRegistryAddress"');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public getL1Timestamp(): Promise<bigint> {
|
|
142
|
-
throw new Error('TXE Archiver does not implement "getL1Timestamp"');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
public isPendingChainInvalid(): Promise<boolean> {
|
|
146
|
-
return Promise.resolve(false);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
public override getPendingChainValidationStatus(): Promise<ValidateBlockResult> {
|
|
150
|
-
return Promise.resolve({ valid: true });
|
|
151
|
-
}
|
|
152
98
|
}
|
|
@@ -4,7 +4,10 @@ import type {
|
|
|
4
4
|
ENR,
|
|
5
5
|
P2P,
|
|
6
6
|
P2PBlockReceivedCallback,
|
|
7
|
+
P2PCheckpointReceivedCallback,
|
|
7
8
|
P2PConfig,
|
|
9
|
+
P2PDuplicateAttestationCallback,
|
|
10
|
+
P2PDuplicateProposalCallback,
|
|
8
11
|
P2PSyncState,
|
|
9
12
|
PeerId,
|
|
10
13
|
ReqRespSubProtocol,
|
|
@@ -13,16 +16,12 @@ import type {
|
|
|
13
16
|
StatusMessage,
|
|
14
17
|
} from '@aztec/p2p';
|
|
15
18
|
import type { EthAddress, L2BlockStreamEvent, L2Tips } from '@aztec/stdlib/block';
|
|
16
|
-
import type { PeerInfo } from '@aztec/stdlib/interfaces/server';
|
|
17
|
-
import type {
|
|
18
|
-
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';
|
|
19
22
|
|
|
20
23
|
export class DummyP2P implements P2P {
|
|
21
|
-
public
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public validate(_txs: Tx[]): Promise<void> {
|
|
24
|
+
public validateTxsReceivedInBlockProposal(_txs: Tx[]): Promise<void> {
|
|
26
25
|
return Promise.resolve();
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -42,14 +41,34 @@ export class DummyP2P implements P2P {
|
|
|
42
41
|
throw new Error('DummyP2P does not implement "getPeers"');
|
|
43
42
|
}
|
|
44
43
|
|
|
44
|
+
public getGossipMeshPeerCount(_topicType: TopicType): Promise<number> {
|
|
45
|
+
return Promise.resolve(0);
|
|
46
|
+
}
|
|
47
|
+
|
|
45
48
|
public broadcastProposal(_proposal: BlockProposal): Promise<void> {
|
|
46
49
|
throw new Error('DummyP2P does not implement "broadcastProposal"');
|
|
47
50
|
}
|
|
48
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
|
+
|
|
49
60
|
public registerBlockProposalHandler(_handler: P2PBlockReceivedCallback): void {
|
|
50
61
|
throw new Error('DummyP2P does not implement "registerBlockProposalHandler"');
|
|
51
62
|
}
|
|
52
63
|
|
|
64
|
+
public registerValidatorCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
65
|
+
throw new Error('DummyP2P does not implement "registerValidatorCheckpointProposalHandler"');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public registerAllNodesCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
69
|
+
throw new Error('DummyP2P does not implement "registerAllNodesCheckpointProposalHandler"');
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
54
73
|
throw new Error('DummyP2P does not implement "requestTxs"');
|
|
55
74
|
}
|
|
@@ -62,8 +81,8 @@ export class DummyP2P implements P2P {
|
|
|
62
81
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
63
82
|
}
|
|
64
83
|
|
|
65
|
-
public
|
|
66
|
-
throw new Error('DummyP2P does not implement "
|
|
84
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
85
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
67
86
|
}
|
|
68
87
|
|
|
69
88
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -79,13 +98,19 @@ export class DummyP2P implements P2P {
|
|
|
79
98
|
}
|
|
80
99
|
|
|
81
100
|
public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
82
|
-
|
|
101
|
+
// In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
|
|
102
|
+
// tx status for any tx hash.
|
|
103
|
+
return Promise.resolve('mined');
|
|
83
104
|
}
|
|
84
105
|
|
|
85
106
|
public iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
86
107
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
111
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
112
|
+
}
|
|
113
|
+
|
|
89
114
|
public getPendingTxCount(): Promise<number> {
|
|
90
115
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
91
116
|
}
|
|
@@ -114,20 +139,20 @@ export class DummyP2P implements P2P {
|
|
|
114
139
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
115
140
|
}
|
|
116
141
|
|
|
117
|
-
public
|
|
118
|
-
throw new Error('DummyP2P does not implement "
|
|
142
|
+
public getTxProvider(): ITxProvider {
|
|
143
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
119
144
|
}
|
|
120
145
|
|
|
121
|
-
public
|
|
122
|
-
throw new Error('DummyP2P does not implement "
|
|
146
|
+
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
147
|
+
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
123
148
|
}
|
|
124
149
|
|
|
125
|
-
public
|
|
126
|
-
|
|
150
|
+
public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
127
152
|
}
|
|
128
153
|
|
|
129
|
-
public
|
|
130
|
-
throw new Error('DummyP2P does not implement "
|
|
154
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
155
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
131
156
|
}
|
|
132
157
|
|
|
133
158
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -150,14 +175,6 @@ export class DummyP2P implements P2P {
|
|
|
150
175
|
throw new Error('DummyP2P does not implement "sync"');
|
|
151
176
|
}
|
|
152
177
|
|
|
153
|
-
public requestTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
154
|
-
throw new Error('DummyP2P does not implement "requestTxsByHash"');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public getTxs(_filter: 'all' | 'pending' | 'mined'): Promise<Tx[]> {
|
|
158
|
-
throw new Error('DummyP2P does not implement "getTxs"');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
178
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
162
179
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
163
180
|
}
|
|
@@ -166,10 +183,6 @@ export class DummyP2P implements P2P {
|
|
|
166
183
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
167
184
|
}
|
|
168
185
|
|
|
169
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
170
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
186
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
174
187
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
175
188
|
}
|
|
@@ -182,8 +195,12 @@ export class DummyP2P implements P2P {
|
|
|
182
195
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
183
196
|
}
|
|
184
197
|
|
|
185
|
-
|
|
186
|
-
throw new Error('DummyP2P does not implement "
|
|
198
|
+
protectTxs(_txHashes: TxHash[], _blockHeader: BlockHeader): Promise<TxHash[]> {
|
|
199
|
+
throw new Error('DummyP2P does not implement "protectTxs".');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
prepareForSlot(_slotNumber: SlotNumber): Promise<void> {
|
|
203
|
+
return Promise.resolve();
|
|
187
204
|
}
|
|
188
205
|
|
|
189
206
|
addReqRespSubProtocol(
|
|
@@ -199,4 +216,16 @@ export class DummyP2P implements P2P {
|
|
|
199
216
|
|
|
200
217
|
//This is no-op
|
|
201
218
|
public registerThisValidatorAddresses(_address: EthAddress[]): void {}
|
|
219
|
+
|
|
220
|
+
public registerDuplicateProposalCallback(_callback: P2PDuplicateProposalCallback): void {
|
|
221
|
+
throw new Error('DummyP2P does not implement "registerDuplicateProposalCallback"');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public registerDuplicateAttestationCallback(_callback: P2PDuplicateAttestationCallback): void {
|
|
225
|
+
throw new Error('DummyP2P does not implement "registerDuplicateAttestationCallback"');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public hasBlockProposalsForSlot(_slot: SlotNumber): Promise<boolean> {
|
|
229
|
+
throw new Error('DummyP2P does not implement "hasBlockProposalsForSlot"');
|
|
230
|
+
}
|
|
202
231
|
}
|
|
@@ -1,21 +1,53 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SimulationOverridesPlan } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
2
4
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
6
|
+
import { FEE_ORACLE_LAG, GasFees } from '@aztec/stdlib/gas';
|
|
5
7
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
6
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type CheckpointGlobalVariables,
|
|
10
|
+
type FeeProvider,
|
|
11
|
+
type GlobalVariableBuilder,
|
|
12
|
+
GlobalVariables,
|
|
13
|
+
} from '@aztec/stdlib/tx';
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
/** Simple FeeProvider for TXE that returns zero fees. */
|
|
16
|
+
export class TXEFeeProvider implements FeeProvider {
|
|
17
|
+
public getCurrentMinFees(): Promise<GasFees> {
|
|
10
18
|
return Promise.resolve(new GasFees(0, 0));
|
|
11
19
|
}
|
|
12
20
|
|
|
21
|
+
public getPredictedMinFees(): Promise<GasFees[]> {
|
|
22
|
+
return Promise.resolve(times(FEE_ORACLE_LAG, () => new GasFees(0, 0)));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
13
27
|
public buildGlobalVariables(
|
|
14
|
-
_blockNumber:
|
|
28
|
+
_blockNumber: BlockNumber,
|
|
15
29
|
_coinbase: EthAddress,
|
|
16
30
|
_feeRecipient: AztecAddress,
|
|
17
31
|
_slotNumber?: SlotNumber,
|
|
18
32
|
): Promise<GlobalVariables> {
|
|
19
33
|
return Promise.resolve(makeGlobalVariables());
|
|
20
34
|
}
|
|
35
|
+
|
|
36
|
+
public buildCheckpointGlobalVariables(
|
|
37
|
+
_coinbase: EthAddress,
|
|
38
|
+
_feeRecipient: AztecAddress,
|
|
39
|
+
_slotNumber: SlotNumber,
|
|
40
|
+
_simulationOverridesPlan?: SimulationOverridesPlan,
|
|
41
|
+
): Promise<CheckpointGlobalVariables> {
|
|
42
|
+
const vars = makeGlobalVariables();
|
|
43
|
+
return Promise.resolve({
|
|
44
|
+
chainId: vars.chainId,
|
|
45
|
+
version: vars.version,
|
|
46
|
+
slotNumber: vars.slotNumber,
|
|
47
|
+
timestamp: vars.timestamp,
|
|
48
|
+
coinbase: vars.coinbase,
|
|
49
|
+
feeRecipient: vars.feeRecipient,
|
|
50
|
+
gasFees: vars.gasFees,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
21
53
|
}
|
|
@@ -1,15 +1,19 @@
|
|
|
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 { MessageContextService } from '@aztec/pxe/simulator';
|
|
8
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
9
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
7
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
11
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
8
12
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
9
13
|
|
|
10
14
|
import { TXEArchiver } from './archiver.js';
|
|
11
15
|
import { DummyP2P } from './dummy_p2p_client.js';
|
|
12
|
-
import { TXEGlobalVariablesBuilder } from './global_variable_builder.js';
|
|
16
|
+
import { TXEFeeProvider, TXEGlobalVariablesBuilder } from './global_variable_builder.js';
|
|
13
17
|
import { MockEpochCache } from './mock_epoch_cache.js';
|
|
14
18
|
import { TXESynchronizer } from './synchronizer.js';
|
|
15
19
|
|
|
@@ -21,14 +25,18 @@ export class TXEStateMachine {
|
|
|
21
25
|
public node: AztecNode,
|
|
22
26
|
public synchronizer: TXESynchronizer,
|
|
23
27
|
public archiver: TXEArchiver,
|
|
24
|
-
public
|
|
28
|
+
public anchorBlockStore: AnchorBlockStore,
|
|
29
|
+
public contractSyncService: ContractSyncService,
|
|
30
|
+
public messageContextService: MessageContextService,
|
|
25
31
|
) {}
|
|
26
32
|
|
|
27
|
-
public static async create(
|
|
28
|
-
|
|
33
|
+
public static async create(
|
|
34
|
+
archiver: TXEArchiver,
|
|
35
|
+
anchorBlockStore: AnchorBlockStore,
|
|
36
|
+
contractStore: ContractStore,
|
|
37
|
+
noteStore: NoteStore,
|
|
38
|
+
) {
|
|
29
39
|
const synchronizer = await TXESynchronizer.create();
|
|
30
|
-
const syncDataProvider = new SyncDataProvider(db);
|
|
31
|
-
|
|
32
40
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
33
41
|
|
|
34
42
|
const log = createLogger('txe_node');
|
|
@@ -44,34 +52,72 @@ export class TXEStateMachine {
|
|
|
44
52
|
undefined,
|
|
45
53
|
undefined,
|
|
46
54
|
undefined,
|
|
55
|
+
undefined,
|
|
56
|
+
undefined,
|
|
47
57
|
VERSION,
|
|
48
58
|
CHAIN_ID,
|
|
49
59
|
new TXEGlobalVariablesBuilder(),
|
|
60
|
+
new TXEFeeProvider(),
|
|
50
61
|
new MockEpochCache(),
|
|
51
62
|
getPackageVersion() ?? '',
|
|
52
63
|
new TestCircuitVerifier(),
|
|
64
|
+
new TestCircuitVerifier(),
|
|
53
65
|
undefined,
|
|
54
66
|
log,
|
|
55
67
|
);
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
const contractSyncService = new ContractSyncService(
|
|
70
|
+
node,
|
|
71
|
+
contractStore,
|
|
72
|
+
noteStore,
|
|
73
|
+
createLogger('txe:contract_sync'),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const messageContextService = new MessageContextService(node);
|
|
77
|
+
|
|
78
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
public async handleL2Block(block: L2Block) {
|
|
82
|
+
// Create a checkpoint from the block manually.
|
|
83
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
84
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
85
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
86
|
+
const checkpoint = new Checkpoint(
|
|
87
|
+
block.archive,
|
|
88
|
+
CheckpointHeader.from({
|
|
89
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
90
|
+
inHash: Fr.ZERO,
|
|
91
|
+
blobsHash: Fr.ZERO,
|
|
92
|
+
blockHeadersHash: Fr.ZERO,
|
|
93
|
+
epochOutHash: Fr.ZERO,
|
|
94
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
95
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
96
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
97
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
98
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
99
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
100
|
+
}),
|
|
101
|
+
[block],
|
|
102
|
+
checkpointNumber,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const publishedCheckpoint = new PublishedCheckpoint(
|
|
106
|
+
checkpoint,
|
|
107
|
+
new L1PublishedData(
|
|
108
|
+
BigInt(block.header.globalVariables.blockNumber),
|
|
109
|
+
block.header.globalVariables.timestamp,
|
|
110
|
+
block.header.globalVariables.blockNumber.toString(),
|
|
111
|
+
),
|
|
112
|
+
[],
|
|
113
|
+
);
|
|
114
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
115
|
+
this.contractSyncService.wipe();
|
|
116
|
+
|
|
61
117
|
await Promise.all([
|
|
62
118
|
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()),
|
|
119
|
+
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
120
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
75
121
|
]);
|
|
76
122
|
}
|
|
77
123
|
}
|