@aztec/txe 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6
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 +33 -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 +37 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +211 -98
- package/dest/rpc_translator.d.ts +96 -79
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +362 -173
- 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 +66 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -25
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +44 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +25 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +46 -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 +27 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +170 -55
- package/dest/util/encoding.d.ts +686 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +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 +36 -32
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +256 -138
- package/src/rpc_translator.ts +419 -191
- package/src/state_machine/archiver.ts +62 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -33
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +65 -21
- package/src/state_machine/mock_epoch_cache.ts +57 -14
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +236 -104
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -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,97 @@
|
|
|
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
|
+
};
|
|
99
80
|
}
|
|
100
81
|
|
|
101
|
-
public
|
|
102
|
-
throw new Error('TXE Archiver does not implement "
|
|
82
|
+
public getSyncedL2SlotNumber(): Promise<SlotNumber | undefined> {
|
|
83
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2SlotNumber"');
|
|
103
84
|
}
|
|
104
85
|
|
|
105
|
-
public
|
|
106
|
-
throw new Error('TXE Archiver does not implement "
|
|
86
|
+
public getSyncedL2EpochNumber(): Promise<EpochNumber | undefined> {
|
|
87
|
+
throw new Error('TXE Archiver does not implement "getSyncedL2EpochNumber"');
|
|
107
88
|
}
|
|
108
89
|
|
|
109
90
|
public isEpochComplete(_epochNumber: EpochNumber): Promise<boolean> {
|
|
110
91
|
throw new Error('TXE Archiver does not implement "isEpochComplete"');
|
|
111
92
|
}
|
|
112
93
|
|
|
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
94
|
public syncImmediate(): Promise<void> {
|
|
126
95
|
throw new Error('TXE Archiver does not implement "syncImmediate"');
|
|
127
96
|
}
|
|
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
97
|
}
|
|
@@ -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,30 @@ 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 registerCheckpointProposalHandler(_handler: P2PCheckpointReceivedCallback): void {
|
|
65
|
+
throw new Error('DummyP2P does not implement "registerCheckpointProposalHandler"');
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
public requestTxs(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
54
69
|
throw new Error('DummyP2P does not implement "requestTxs"');
|
|
55
70
|
}
|
|
@@ -62,8 +77,8 @@ export class DummyP2P implements P2P {
|
|
|
62
77
|
throw new Error('DummyP2P does not implement "sendTx"');
|
|
63
78
|
}
|
|
64
79
|
|
|
65
|
-
public
|
|
66
|
-
throw new Error('DummyP2P does not implement "
|
|
80
|
+
public handleFailedExecution(_txHashes: TxHash[]): Promise<void> {
|
|
81
|
+
throw new Error('DummyP2P does not implement "handleFailedExecution"');
|
|
67
82
|
}
|
|
68
83
|
|
|
69
84
|
public getTxByHashFromPool(_txHash: TxHash): Promise<Tx | undefined> {
|
|
@@ -79,13 +94,19 @@ export class DummyP2P implements P2P {
|
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
public getTxStatus(_txHash: TxHash): Promise<'pending' | 'mined' | undefined> {
|
|
82
|
-
|
|
97
|
+
// In TXE there is no concept of transactions but we need to implement this because of tagging. We return 'mined'
|
|
98
|
+
// tx status for any tx hash.
|
|
99
|
+
return Promise.resolve('mined');
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
public iteratePendingTxs(): AsyncIterableIterator<Tx> {
|
|
86
103
|
throw new Error('DummyP2P does not implement "iteratePendingTxs"');
|
|
87
104
|
}
|
|
88
105
|
|
|
106
|
+
public iterateEligiblePendingTxs(): AsyncIterableIterator<Tx> {
|
|
107
|
+
throw new Error('DummyP2P does not implement "iterateEligiblePendingTxs"');
|
|
108
|
+
}
|
|
109
|
+
|
|
89
110
|
public getPendingTxCount(): Promise<number> {
|
|
90
111
|
throw new Error('DummyP2P does not implement "getPendingTxCount"');
|
|
91
112
|
}
|
|
@@ -114,20 +135,20 @@ export class DummyP2P implements P2P {
|
|
|
114
135
|
throw new Error('DummyP2P does not implement "isP2PClient"');
|
|
115
136
|
}
|
|
116
137
|
|
|
138
|
+
public getTxProvider(): ITxProvider {
|
|
139
|
+
throw new Error('DummyP2P does not implement "getTxProvider"');
|
|
140
|
+
}
|
|
141
|
+
|
|
117
142
|
public getTxsByHash(_txHashes: TxHash[]): Promise<Tx[]> {
|
|
118
143
|
throw new Error('DummyP2P does not implement "getTxsByHash"');
|
|
119
144
|
}
|
|
120
145
|
|
|
121
|
-
public
|
|
122
|
-
throw new Error('DummyP2P does not implement "
|
|
146
|
+
public getCheckpointAttestationsForSlot(_slot: SlotNumber, _proposalId?: string): Promise<CheckpointAttestation[]> {
|
|
147
|
+
throw new Error('DummyP2P does not implement "getCheckpointAttestationsForSlot"');
|
|
123
148
|
}
|
|
124
149
|
|
|
125
|
-
public
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public addAttestations(_attestations: BlockAttestation[]): Promise<void> {
|
|
130
|
-
throw new Error('DummyP2P does not implement "addAttestations"');
|
|
150
|
+
public addOwnCheckpointAttestations(_attestations: CheckpointAttestation[]): Promise<void> {
|
|
151
|
+
throw new Error('DummyP2P does not implement "addOwnCheckpointAttestations"');
|
|
131
152
|
}
|
|
132
153
|
|
|
133
154
|
public getL2BlockHash(_number: number): Promise<string | undefined> {
|
|
@@ -150,14 +171,6 @@ export class DummyP2P implements P2P {
|
|
|
150
171
|
throw new Error('DummyP2P does not implement "sync"');
|
|
151
172
|
}
|
|
152
173
|
|
|
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
174
|
public getTxsByHashFromPool(_txHashes: TxHash[]): Promise<(Tx | undefined)[]> {
|
|
162
175
|
throw new Error('DummyP2P does not implement "getTxsByHashFromPool"');
|
|
163
176
|
}
|
|
@@ -166,10 +179,6 @@ export class DummyP2P implements P2P {
|
|
|
166
179
|
throw new Error('DummyP2P does not implement "hasTxsInPool"');
|
|
167
180
|
}
|
|
168
181
|
|
|
169
|
-
public addTxsToPool(_txs: Tx[]): Promise<number> {
|
|
170
|
-
throw new Error('DummyP2P does not implement "addTxs"');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
182
|
public getSyncedLatestBlockNum(): Promise<number> {
|
|
174
183
|
throw new Error('DummyP2P does not implement "getSyncedLatestBlockNum"');
|
|
175
184
|
}
|
|
@@ -182,8 +191,12 @@ export class DummyP2P implements P2P {
|
|
|
182
191
|
throw new Error('DummyP2P does not implement "getSyncedLatestSlot"');
|
|
183
192
|
}
|
|
184
193
|
|
|
185
|
-
|
|
186
|
-
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();
|
|
187
200
|
}
|
|
188
201
|
|
|
189
202
|
addReqRespSubProtocol(
|
|
@@ -199,4 +212,16 @@ export class DummyP2P implements P2P {
|
|
|
199
212
|
|
|
200
213
|
//This is no-op
|
|
201
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
|
+
}
|
|
202
227
|
}
|
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { BlockNumber, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
5
5
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
6
|
-
import { type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
6
|
+
import { type CheckpointGlobalVariables, type GlobalVariableBuilder, GlobalVariables } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
8
|
export class TXEGlobalVariablesBuilder implements GlobalVariableBuilder {
|
|
9
|
-
public
|
|
9
|
+
public getCurrentMinFees(): Promise<GasFees> {
|
|
10
10
|
return Promise.resolve(new GasFees(0, 0));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public buildGlobalVariables(
|
|
14
|
-
_blockNumber:
|
|
14
|
+
_blockNumber: BlockNumber,
|
|
15
15
|
_coinbase: EthAddress,
|
|
16
16
|
_feeRecipient: AztecAddress,
|
|
17
17
|
_slotNumber?: SlotNumber,
|
|
18
18
|
): Promise<GlobalVariables> {
|
|
19
19
|
return Promise.resolve(makeGlobalVariables());
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
public buildCheckpointGlobalVariables(
|
|
23
|
+
_coinbase: EthAddress,
|
|
24
|
+
_feeRecipient: AztecAddress,
|
|
25
|
+
_slotNumber: SlotNumber,
|
|
26
|
+
): Promise<CheckpointGlobalVariables> {
|
|
27
|
+
const vars = makeGlobalVariables();
|
|
28
|
+
return Promise.resolve({
|
|
29
|
+
chainId: vars.chainId,
|
|
30
|
+
version: vars.version,
|
|
31
|
+
slotNumber: vars.slotNumber,
|
|
32
|
+
timestamp: vars.timestamp,
|
|
33
|
+
coinbase: vars.coinbase,
|
|
34
|
+
feeRecipient: vars.feeRecipient,
|
|
35
|
+
gasFees: vars.gasFees,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
21
38
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
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';
|
|
@@ -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,70 @@ export class TXEStateMachine {
|
|
|
44
52
|
undefined,
|
|
45
53
|
undefined,
|
|
46
54
|
undefined,
|
|
55
|
+
undefined,
|
|
47
56
|
VERSION,
|
|
48
57
|
CHAIN_ID,
|
|
49
58
|
new TXEGlobalVariablesBuilder(),
|
|
50
59
|
new MockEpochCache(),
|
|
51
60
|
getPackageVersion() ?? '',
|
|
52
61
|
new TestCircuitVerifier(),
|
|
62
|
+
new TestCircuitVerifier(),
|
|
53
63
|
undefined,
|
|
54
64
|
log,
|
|
55
65
|
);
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
const contractSyncService = new ContractSyncService(
|
|
68
|
+
node,
|
|
69
|
+
contractStore,
|
|
70
|
+
noteStore,
|
|
71
|
+
createLogger('txe:contract_sync'),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const messageContextService = new MessageContextService(node);
|
|
75
|
+
|
|
76
|
+
return new this(node, synchronizer, archiver, anchorBlockStore, contractSyncService, messageContextService);
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
public async handleL2Block(block: L2Block) {
|
|
80
|
+
// Create a checkpoint from the block manually.
|
|
81
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
82
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
83
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(block.number);
|
|
84
|
+
const checkpoint = new Checkpoint(
|
|
85
|
+
block.archive,
|
|
86
|
+
CheckpointHeader.from({
|
|
87
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
88
|
+
inHash: Fr.ZERO,
|
|
89
|
+
blobsHash: Fr.ZERO,
|
|
90
|
+
blockHeadersHash: Fr.ZERO,
|
|
91
|
+
epochOutHash: Fr.ZERO,
|
|
92
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
93
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
94
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
95
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
96
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
97
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
98
|
+
}),
|
|
99
|
+
[block],
|
|
100
|
+
checkpointNumber,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const publishedCheckpoint = new PublishedCheckpoint(
|
|
104
|
+
checkpoint,
|
|
105
|
+
new L1PublishedData(
|
|
106
|
+
BigInt(block.header.globalVariables.blockNumber),
|
|
107
|
+
block.header.globalVariables.timestamp,
|
|
108
|
+
block.header.globalVariables.blockNumber.toString(),
|
|
109
|
+
),
|
|
110
|
+
[],
|
|
111
|
+
);
|
|
112
|
+
// Wipe contract sync cache when anchor block changes (mirrors BlockSynchronizer behavior)
|
|
113
|
+
this.contractSyncService.wipe();
|
|
114
|
+
|
|
61
115
|
await Promise.all([
|
|
62
116
|
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()),
|
|
117
|
+
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
118
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
75
119
|
]);
|
|
76
120
|
}
|
|
77
121
|
}
|