@aztec/p2p 0.0.1-commit.ff7989d6c → 0.0.1-commit.ffe5b04ea
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/client/factory.d.ts +5 -6
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +15 -26
- package/dest/client/interface.d.ts +6 -13
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +5 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +3 -82
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -2
- package/dest/config.d.ts +20 -11
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +66 -32
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +5 -1
- package/dest/mem_pools/instrumentation.d.ts +4 -2
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +16 -14
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +2 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +7 -1
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +8 -6
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/index.js +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +7 -5
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/interfaces.js +2 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +40 -10
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +74 -16
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +26 -44
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +2 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +3 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +3 -2
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +42 -29
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +10 -2
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +6 -4
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +16 -2
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -8
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator.js +48 -36
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/aggregate_tx_validator.js +3 -3
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts +2 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/allowed_public_setup.js +24 -20
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts +17 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/allowed_setup_helpers.js +24 -0
- package/dest/msg_validators/tx_validator/factory.d.ts +114 -6
- package/dest/msg_validators/tx_validator/factory.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/factory.js +219 -58
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +6 -2
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +58 -3
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +73 -36
- package/dest/msg_validators/tx_validator/index.d.ts +3 -1
- package/dest/msg_validators/tx_validator/index.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/index.js +2 -0
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/metadata_validator.js +4 -4
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/nullifier_cache.js +24 -0
- package/dest/msg_validators/tx_validator/phases_validator.d.ts +2 -2
- package/dest/msg_validators/tx_validator/phases_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/phases_validator.js +44 -23
- package/dest/services/dummy_service.d.ts +2 -3
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +1 -4
- package/dest/services/encoding.d.ts +2 -2
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +7 -7
- package/dest/services/libp2p/libp2p_service.d.ts +15 -13
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +79 -89
- package/dest/services/peer-manager/metrics.d.ts +3 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -0
- package/dest/services/peer-manager/peer_manager.d.ts +1 -1
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +2 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.js +14 -37
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts +17 -11
- package/dest/services/reqresp/batch-tx-requester/peer_collection.d.ts.map +1 -1
- package/dest/services/reqresp/batch-tx-requester/peer_collection.js +49 -15
- package/dest/services/reqresp/batch-tx-requester/tx_validator.js +2 -2
- package/dest/services/reqresp/reqresp.d.ts +1 -1
- package/dest/services/reqresp/reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/reqresp.js +2 -1
- package/dest/services/service.d.ts +2 -2
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_provider.d.ts +3 -3
- package/dest/services/tx_provider.d.ts.map +1 -1
- package/dest/services/tx_provider.js +4 -4
- package/dest/test-helpers/make-test-p2p-clients.d.ts +5 -6
- package/dest/test-helpers/make-test-p2p-clients.d.ts.map +1 -1
- package/dest/test-helpers/make-test-p2p-clients.js +1 -2
- package/dest/test-helpers/mock-pubsub.d.ts +2 -3
- package/dest/test-helpers/mock-pubsub.d.ts.map +1 -1
- package/dest/test-helpers/mock-pubsub.js +2 -2
- package/dest/test-helpers/reqresp-nodes.d.ts +2 -3
- package/dest/test-helpers/reqresp-nodes.d.ts.map +1 -1
- package/dest/test-helpers/reqresp-nodes.js +2 -2
- package/dest/test-helpers/testbench-utils.d.ts +2 -2
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/testbench/p2p_client_testbench_worker.js +7 -6
- package/dest/testbench/worker_client_manager.d.ts +3 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -2
- package/dest/util.d.ts +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +23 -47
- package/src/client/interface.ts +5 -19
- package/src/client/p2p_client.ts +4 -110
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +2 -3
- package/src/config.ts +91 -34
- package/src/mem_pools/attestation_pool/attestation_pool.ts +5 -4
- package/src/mem_pools/instrumentation.ts +17 -13
- package/src/mem_pools/tx_pool_v2/README.md +9 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +1 -1
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +3 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +11 -1
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +2 -2
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +15 -6
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +2 -1
- package/src/mem_pools/tx_pool_v2/index.ts +1 -1
- package/src/mem_pools/tx_pool_v2/interfaces.ts +7 -4
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +104 -19
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +29 -43
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +4 -1
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +50 -29
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +14 -4
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +20 -7
- package/src/msg_validators/proposal_validator/proposal_validator.ts +63 -40
- package/src/msg_validators/tx_validator/README.md +115 -0
- package/src/msg_validators/tx_validator/aggregate_tx_validator.ts +3 -3
- package/src/msg_validators/tx_validator/allowed_public_setup.ts +22 -27
- package/src/msg_validators/tx_validator/allowed_setup_helpers.ts +31 -0
- package/src/msg_validators/tx_validator/factory.ts +353 -77
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +6 -2
- package/src/msg_validators/tx_validator/gas_validator.ts +90 -27
- package/src/msg_validators/tx_validator/index.ts +2 -0
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/nullifier_cache.ts +30 -0
- package/src/msg_validators/tx_validator/phases_validator.ts +51 -26
- package/src/services/dummy_service.ts +1 -5
- package/src/services/encoding.ts +5 -6
- package/src/services/libp2p/libp2p_service.ts +90 -96
- package/src/services/peer-manager/metrics.ts +7 -0
- package/src/services/peer-manager/peer_manager.ts +2 -1
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +14 -42
- package/src/services/reqresp/batch-tx-requester/peer_collection.ts +63 -24
- package/src/services/reqresp/batch-tx-requester/tx_validator.ts +2 -2
- package/src/services/reqresp/reqresp.ts +3 -1
- package/src/services/service.ts +1 -1
- package/src/services/tx_provider.ts +2 -2
- package/src/test-helpers/make-test-p2p-clients.ts +1 -3
- package/src/test-helpers/mock-pubsub.ts +3 -6
- package/src/test-helpers/reqresp-nodes.ts +3 -6
- package/src/test-helpers/testbench-utils.ts +1 -1
- package/src/testbench/p2p_client_testbench_worker.ts +4 -7
- package/src/testbench/worker_client_manager.ts +13 -5
- package/src/util.ts +1 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +0 -23
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +0 -1
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +0 -212
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +0 -230
package/src/client/p2p_client.ts
CHANGED
|
@@ -18,15 +18,8 @@ import {
|
|
|
18
18
|
type L2TipsStore,
|
|
19
19
|
} from '@aztec/stdlib/block';
|
|
20
20
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
21
|
-
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
22
21
|
import { type PeerInfo, tryStop } from '@aztec/stdlib/interfaces/server';
|
|
23
|
-
import {
|
|
24
|
-
type BlockProposal,
|
|
25
|
-
CheckpointAttestation,
|
|
26
|
-
type CheckpointProposal,
|
|
27
|
-
type P2PClientType,
|
|
28
|
-
type TopicType,
|
|
29
|
-
} from '@aztec/stdlib/p2p';
|
|
22
|
+
import { type BlockProposal, CheckpointAttestation, type CheckpointProposal, type TopicType } from '@aztec/stdlib/p2p';
|
|
30
23
|
import type { BlockHeader, Tx, TxHash } from '@aztec/stdlib/tx';
|
|
31
24
|
import { Attributes, type TelemetryClient, WithTracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
32
25
|
|
|
@@ -44,7 +37,6 @@ import {
|
|
|
44
37
|
type ReqRespSubProtocolHandler,
|
|
45
38
|
type ReqRespSubProtocolValidators,
|
|
46
39
|
} from '../services/reqresp/interface.js';
|
|
47
|
-
import { chunkTxHashesRequest } from '../services/reqresp/protocols/tx.js';
|
|
48
40
|
import type {
|
|
49
41
|
DuplicateAttestationInfo,
|
|
50
42
|
DuplicateProposalInfo,
|
|
@@ -60,10 +52,7 @@ import { type P2P, P2PClientState, type P2PSyncState } from './interface.js';
|
|
|
60
52
|
/**
|
|
61
53
|
* The P2P client implementation.
|
|
62
54
|
*/
|
|
63
|
-
export class P2PClient
|
|
64
|
-
extends WithTracer
|
|
65
|
-
implements P2P, P2P<P2PClientType.Prover>
|
|
66
|
-
{
|
|
55
|
+
export class P2PClient extends WithTracer implements P2P {
|
|
67
56
|
/** The JS promise that will be running to keep the client's data in sync. Can be interrupted if the client is stopped. */
|
|
68
57
|
private runningPromise!: Promise<void>;
|
|
69
58
|
|
|
@@ -95,7 +84,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
95
84
|
private slotMonitor: RunningPromise | undefined;
|
|
96
85
|
|
|
97
86
|
constructor(
|
|
98
|
-
_clientType: T,
|
|
99
87
|
private store: AztecAsyncKVStore,
|
|
100
88
|
private l2BlockSource: L2BlockSource & ContractDataSource,
|
|
101
89
|
mempools: MemPools,
|
|
@@ -122,27 +110,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
122
110
|
this.telemetry,
|
|
123
111
|
);
|
|
124
112
|
|
|
125
|
-
// Default to collecting all txs when we see a valid proposal
|
|
126
|
-
// This can be overridden by the validator client to validate, and it will call getTxsForBlockProposal on its own
|
|
127
|
-
// Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
128
|
-
// TODO(palla/txs): We should not trigger a request for txs on a proposal before fully validating it. We need to bring
|
|
129
|
-
// validator-client code into here so we can validate a proposal is reasonable.
|
|
130
|
-
this.registerBlockProposalHandler(async (block, sender) => {
|
|
131
|
-
this.log.debug(`Received block proposal from ${sender.toString()}`);
|
|
132
|
-
// TODO(palla/txs): Need to subtract validatorReexecuteDeadlineMs from this deadline (see ValidatorClient.getReexecutionDeadline)
|
|
133
|
-
const constants = this.txCollection.getConstants();
|
|
134
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(block.slotNumber + 1), constants));
|
|
135
|
-
const deadline = new Date(nextSlotTimestampSeconds * 1000);
|
|
136
|
-
const parentBlock = await this.l2BlockSource.getBlockHeaderByArchive(block.blockHeader.lastArchive.root);
|
|
137
|
-
if (!parentBlock) {
|
|
138
|
-
this.log.debug(`Cannot collect txs for proposal as parent block not found`);
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
const blockNumber = BlockNumber(parentBlock.getBlockNumber() + 1);
|
|
142
|
-
await this.txProvider.getTxsForBlockProposal(block, blockNumber, { pinnedPeer: sender, deadline });
|
|
143
|
-
return true;
|
|
144
|
-
});
|
|
145
|
-
|
|
146
113
|
this.l2Tips = new L2TipsKVStore(store, 'p2p_client');
|
|
147
114
|
this.synchedLatestSlot = store.openSingleton('p2p_pool_last_l2_slot');
|
|
148
115
|
}
|
|
@@ -433,36 +400,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
433
400
|
this.p2pService.registerDuplicateAttestationCallback(callback);
|
|
434
401
|
}
|
|
435
402
|
|
|
436
|
-
/**
|
|
437
|
-
* Uses the batched Request Response protocol to request a set of transactions from the network.
|
|
438
|
-
*/
|
|
439
|
-
private async requestTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<Tx[]> {
|
|
440
|
-
const timeoutMs = 8000; // Longer timeout for now
|
|
441
|
-
const maxRetryAttempts = 10; // Keep retrying within the timeout
|
|
442
|
-
const requests = chunkTxHashesRequest(txHashes);
|
|
443
|
-
const maxPeers = Math.min(Math.ceil(requests.length / 3), 10);
|
|
444
|
-
|
|
445
|
-
const txBatches = await this.p2pService.sendBatchRequest(
|
|
446
|
-
ReqRespSubProtocol.TX,
|
|
447
|
-
requests,
|
|
448
|
-
pinnedPeerId,
|
|
449
|
-
timeoutMs,
|
|
450
|
-
maxPeers,
|
|
451
|
-
maxRetryAttempts,
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
const txs = txBatches.flat();
|
|
455
|
-
if (txs.length > 0) {
|
|
456
|
-
await this.txPool.addPendingTxs(txs);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const txHashesStr = txHashes.map(tx => tx.toString()).join(', ');
|
|
460
|
-
this.log.debug(`Requested txs ${txHashesStr} (${txs.length} / ${txHashes.length}) from peers`);
|
|
461
|
-
|
|
462
|
-
// We return all transactions, even the not found ones to the caller, such they can handle missing items themselves.
|
|
463
|
-
return txs;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
403
|
public async getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
467
404
|
if (limit !== undefined && limit <= 0) {
|
|
468
405
|
throw new TypeError('limit must be greater than 0');
|
|
@@ -530,49 +467,6 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
530
467
|
return this.txPool.hasTxs(txHashes);
|
|
531
468
|
}
|
|
532
469
|
|
|
533
|
-
/**
|
|
534
|
-
* Returns transactions in the transaction pool by hash.
|
|
535
|
-
* If a transaction is not in the pool, it will be requested from the network.
|
|
536
|
-
* @param txHashes - Hashes of the transactions to look for.
|
|
537
|
-
* @returns The txs found, or undefined if not found in the order requested.
|
|
538
|
-
*/
|
|
539
|
-
async getTxsByHash(txHashes: TxHash[], pinnedPeerId: PeerId | undefined): Promise<(Tx | undefined)[]> {
|
|
540
|
-
const txs = await Promise.all(txHashes.map(txHash => this.txPool.getTxByHash(txHash)));
|
|
541
|
-
const missingTxHashes = txs
|
|
542
|
-
.map((tx, index) => [tx, index] as const)
|
|
543
|
-
.filter(([tx, _index]) => !tx)
|
|
544
|
-
.map(([_tx, index]) => txHashes[index]);
|
|
545
|
-
|
|
546
|
-
if (missingTxHashes.length === 0) {
|
|
547
|
-
return txs as Tx[];
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
const missingTxs = await this.requestTxsByHash(missingTxHashes, pinnedPeerId);
|
|
551
|
-
// TODO: optimize
|
|
552
|
-
// Merge the found txs in order
|
|
553
|
-
const mergingTxs = txHashes.map(txHash => {
|
|
554
|
-
// Is it in the txs list from the mempool?
|
|
555
|
-
for (const tx of txs) {
|
|
556
|
-
if (tx !== undefined && tx.getTxHash().equals(txHash)) {
|
|
557
|
-
return tx;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// Is it in the fetched missing txs?
|
|
562
|
-
// Note: this is an O(n^2) operation, but we expect the number of missing txs to be small.
|
|
563
|
-
for (const tx of missingTxs) {
|
|
564
|
-
if (tx.getTxHash().equals(txHash)) {
|
|
565
|
-
return tx;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// Otherwise return undefined
|
|
570
|
-
return undefined;
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return mergingTxs;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
470
|
/**
|
|
577
471
|
* Returns an archived transaction in the transaction pool by its hash.
|
|
578
472
|
* @param txHash - Hash of the archived transaction to look for.
|
|
@@ -839,8 +733,8 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
|
|
|
839
733
|
this.log.debug(`Moved from state ${P2PClientState[oldState]} to ${P2PClientState[this.currentState]}`);
|
|
840
734
|
}
|
|
841
735
|
|
|
842
|
-
public
|
|
843
|
-
return this.p2pService.
|
|
736
|
+
public validateTxsReceivedInBlockProposal(txs: Tx[]): Promise<void> {
|
|
737
|
+
return this.p2pService.validateTxsReceivedInBlockProposal(txs);
|
|
844
738
|
}
|
|
845
739
|
|
|
846
740
|
/**
|
|
@@ -3,12 +3,12 @@ import { SecretValue } from '@aztec/foundation/config';
|
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { sleep } from '@aztec/foundation/sleep';
|
|
5
5
|
import { DateProvider, Timer, executeTimeout } from '@aztec/foundation/timer';
|
|
6
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
7
6
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
8
7
|
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
9
8
|
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
10
9
|
import type { ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
|
11
|
-
import {
|
|
10
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
11
|
+
import { PeerErrorSeverity } from '@aztec/stdlib/p2p';
|
|
12
12
|
import type { Tx, TxValidationResult } from '@aztec/stdlib/tx';
|
|
13
13
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
14
14
|
|
|
@@ -114,7 +114,6 @@ async function startClient(config: P2PConfig, clientIndex: number) {
|
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
client = await createP2PClient(
|
|
117
|
-
P2PClientType.Full,
|
|
118
117
|
config as P2PConfig & DataStoreConfig,
|
|
119
118
|
l2BlockSource as L2BlockSource & ContractDataSource,
|
|
120
119
|
proofVerifier as ClientProtocolCircuitVerifier,
|
package/src/config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ConfigMappingsType,
|
|
3
3
|
SecretValue,
|
|
4
|
+
bigintConfigHelper,
|
|
4
5
|
booleanConfigHelper,
|
|
5
6
|
getConfigFromMappings,
|
|
6
7
|
getDefaultConfig,
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
secretStringConfigHelper,
|
|
11
12
|
} from '@aztec/foundation/config';
|
|
12
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
|
-
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
14
14
|
import { FunctionSelector } from '@aztec/stdlib/abi/function-selector';
|
|
15
15
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
16
|
import {
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
chainConfigMappings,
|
|
21
21
|
sharedSequencerConfigMappings,
|
|
22
22
|
} from '@aztec/stdlib/config';
|
|
23
|
+
import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
23
24
|
|
|
24
25
|
import {
|
|
25
26
|
type BatchTxRequesterConfig,
|
|
@@ -38,7 +39,10 @@ export interface P2PConfig
|
|
|
38
39
|
ChainConfig,
|
|
39
40
|
TxCollectionConfig,
|
|
40
41
|
TxFileStoreConfig,
|
|
41
|
-
Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot'> {
|
|
42
|
+
Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot' | 'maxTxsPerBlock'> {
|
|
43
|
+
/** Maximum transactions per block for validation. Overrides maxTxsPerBlock for gossip validation when set. */
|
|
44
|
+
validateMaxTxsPerBlock?: number;
|
|
45
|
+
|
|
42
46
|
/** A flag dictating whether the P2P subsystem should be enabled. */
|
|
43
47
|
p2pEnabled: boolean;
|
|
44
48
|
|
|
@@ -150,8 +154,8 @@ export interface P2PConfig
|
|
|
150
154
|
/** The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKb. */
|
|
151
155
|
p2pStoreMapSizeKb?: number;
|
|
152
156
|
|
|
153
|
-
/**
|
|
154
|
-
|
|
157
|
+
/** Additional entries to extend the default setup allow list. */
|
|
158
|
+
txPublicSetupAllowListExtend: AllowedElement[];
|
|
155
159
|
|
|
156
160
|
/** The maximum number of pending txs before evicting lower priority txs. */
|
|
157
161
|
maxPendingTxCount: number;
|
|
@@ -190,11 +194,20 @@ export interface P2PConfig
|
|
|
190
194
|
|
|
191
195
|
/** Minimum age (ms) a transaction must have been in the pool before it's eligible for block building. */
|
|
192
196
|
minTxPoolAgeMs: number;
|
|
197
|
+
|
|
198
|
+
/** Minimum percentage fee increase required to replace an existing tx via RPC (0 = no bump). */
|
|
199
|
+
priceBumpPercentage: bigint;
|
|
193
200
|
}
|
|
194
201
|
|
|
195
202
|
export const DEFAULT_P2P_PORT = 40400;
|
|
196
203
|
|
|
197
204
|
export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
205
|
+
validateMaxTxsPerBlock: {
|
|
206
|
+
env: 'VALIDATOR_MAX_TX_PER_BLOCK',
|
|
207
|
+
description:
|
|
208
|
+
'Maximum transactions per block for validation. Overrides maxTxsPerBlock for gossip validation when set.',
|
|
209
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
210
|
+
},
|
|
198
211
|
p2pEnabled: {
|
|
199
212
|
env: 'P2P_ENABLED',
|
|
200
213
|
description: 'A flag dictating whether the P2P subsystem should be enabled.',
|
|
@@ -393,12 +406,13 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
393
406
|
parseEnv: (val: string | undefined) => (val ? +val : undefined),
|
|
394
407
|
description: 'The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKb.',
|
|
395
408
|
},
|
|
396
|
-
|
|
409
|
+
txPublicSetupAllowListExtend: {
|
|
397
410
|
env: 'TX_PUBLIC_SETUP_ALLOWLIST',
|
|
398
411
|
parseEnv: (val: string) => parseAllowList(val),
|
|
399
|
-
description:
|
|
412
|
+
description:
|
|
413
|
+
'Additional entries to extend the default setup allow list. Format: I:address:selector[:flags],C:classId:selector[:flags]. Flags: os (onlySelf), rn (rejectNullMsgSender), cl=N (calldataLength), joined with +.',
|
|
400
414
|
printDefault: () =>
|
|
401
|
-
'AuthRegistry
|
|
415
|
+
'Default: AuthRegistry._set_authorized, AuthRegistry.set_authorized, FeeJuice._increase_public_balance',
|
|
402
416
|
},
|
|
403
417
|
maxPendingTxCount: {
|
|
404
418
|
env: 'P2P_MAX_PENDING_TX_COUNT',
|
|
@@ -464,6 +478,12 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
|
|
|
464
478
|
description: 'Minimum age (ms) a transaction must have been in the pool before it is eligible for block building.',
|
|
465
479
|
...numberConfigHelper(2_000),
|
|
466
480
|
},
|
|
481
|
+
priceBumpPercentage: {
|
|
482
|
+
env: 'P2P_RPC_PRICE_BUMP_PERCENTAGE',
|
|
483
|
+
description:
|
|
484
|
+
'Minimum percentage fee increase required to replace an existing tx via RPC. Even at 0%, replacement still requires paying at least 1 unit more.',
|
|
485
|
+
...bigintConfigHelper(10n),
|
|
486
|
+
},
|
|
467
487
|
...sharedSequencerConfigMappings,
|
|
468
488
|
...p2pReqRespConfigMappings,
|
|
469
489
|
...batchTxRequesterConfigMappings,
|
|
@@ -521,13 +541,44 @@ export const bootnodeConfigMappings = pickConfigMappings(
|
|
|
521
541
|
bootnodeConfigKeys,
|
|
522
542
|
);
|
|
523
543
|
|
|
544
|
+
/**
|
|
545
|
+
* Parses a `+`-separated flags string into validation properties for an allow list entry.
|
|
546
|
+
* Supported flags: `os` (onlySelf), `rn` (rejectNullMsgSender), `cl=N` (calldataLength).
|
|
547
|
+
*/
|
|
548
|
+
function parseFlags(
|
|
549
|
+
flags: string,
|
|
550
|
+
entry: string,
|
|
551
|
+
): { onlySelf?: boolean; rejectNullMsgSender?: boolean; calldataLength?: number } {
|
|
552
|
+
const result: { onlySelf?: boolean; rejectNullMsgSender?: boolean; calldataLength?: number } = {};
|
|
553
|
+
for (const flag of flags.split('+')) {
|
|
554
|
+
if (flag === 'os') {
|
|
555
|
+
result.onlySelf = true;
|
|
556
|
+
} else if (flag === 'rn') {
|
|
557
|
+
result.rejectNullMsgSender = true;
|
|
558
|
+
} else if (flag.startsWith('cl=')) {
|
|
559
|
+
const n = parseInt(flag.slice(3), 10);
|
|
560
|
+
if (isNaN(n) || n < 0) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
`Invalid allow list entry "${entry}": invalid calldataLength in flag "${flag}". Expected a non-negative integer.`,
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
result.calldataLength = n;
|
|
566
|
+
} else {
|
|
567
|
+
throw new Error(`Invalid allow list entry "${entry}": unknown flag "${flag}". Supported flags: os, rn, cl=N.`);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return result;
|
|
571
|
+
}
|
|
572
|
+
|
|
524
573
|
/**
|
|
525
574
|
* Parses a string to a list of allowed elements.
|
|
526
|
-
* Each
|
|
527
|
-
* `I:${address}`
|
|
528
|
-
* `
|
|
529
|
-
*
|
|
530
|
-
*
|
|
575
|
+
* Each entry is expected to be of one of the following formats:
|
|
576
|
+
* `I:${address}:${selector}` — instance (contract address) with function selector
|
|
577
|
+
* `C:${classId}:${selector}` — class with function selector
|
|
578
|
+
*
|
|
579
|
+
* An optional flags segment can be appended after the selector:
|
|
580
|
+
* `I:${address}:${selector}:${flags}` or `C:${classId}:${selector}:${flags}`
|
|
581
|
+
* where flags is a `+`-separated list of: `os` (onlySelf), `rn` (rejectNullMsgSender), `cl=N` (calldataLength).
|
|
531
582
|
*
|
|
532
583
|
* @param value The string to parse
|
|
533
584
|
* @returns A list of allowed elements
|
|
@@ -540,31 +591,37 @@ export function parseAllowList(value: string): AllowedElement[] {
|
|
|
540
591
|
}
|
|
541
592
|
|
|
542
593
|
for (const val of value.split(',')) {
|
|
543
|
-
const
|
|
544
|
-
|
|
594
|
+
const trimmed = val.trim();
|
|
595
|
+
if (!trimmed) {
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
const [typeString, identifierString, selectorString, flagsString] = trimmed.split(':');
|
|
599
|
+
|
|
600
|
+
if (!selectorString) {
|
|
601
|
+
throw new Error(
|
|
602
|
+
`Invalid allow list entry "${trimmed}": selector is required. Expected format: I:address:selector or C:classId:selector`,
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const selector = FunctionSelector.fromString(selectorString);
|
|
607
|
+
const flags = flagsString ? parseFlags(flagsString, trimmed) : {};
|
|
545
608
|
|
|
546
609
|
if (typeString === 'I') {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
} else {
|
|
553
|
-
entries.push({
|
|
554
|
-
address: AztecAddress.fromString(identifierString),
|
|
555
|
-
});
|
|
556
|
-
}
|
|
610
|
+
entries.push({
|
|
611
|
+
address: AztecAddress.fromString(identifierString),
|
|
612
|
+
selector,
|
|
613
|
+
...flags,
|
|
614
|
+
});
|
|
557
615
|
} else if (typeString === 'C') {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
616
|
+
entries.push({
|
|
617
|
+
classId: Fr.fromHexString(identifierString),
|
|
618
|
+
selector,
|
|
619
|
+
...flags,
|
|
620
|
+
});
|
|
621
|
+
} else {
|
|
622
|
+
throw new Error(
|
|
623
|
+
`Invalid allow list entry "${trimmed}": unknown type "${typeString}". Expected "I" (instance) or "C" (class).`,
|
|
624
|
+
);
|
|
568
625
|
}
|
|
569
626
|
}
|
|
570
627
|
|
|
@@ -359,11 +359,10 @@ export class AttestationPool {
|
|
|
359
359
|
}
|
|
360
360
|
|
|
361
361
|
const address = sender.toString();
|
|
362
|
+
const ownKey = this.getAttestationKey(slotNumber, proposalId, address);
|
|
362
363
|
|
|
363
|
-
await this.checkpointAttestations.set(
|
|
364
|
-
|
|
365
|
-
attestation.toBuffer(),
|
|
366
|
-
);
|
|
364
|
+
await this.checkpointAttestations.set(ownKey, attestation.toBuffer());
|
|
365
|
+
this.metrics.trackMempoolItemAdded(ownKey);
|
|
367
366
|
|
|
368
367
|
this.log.debug(`Added own checkpoint attestation for slot ${slotNumber} from ${address}`, {
|
|
369
368
|
signature: attestation.signature.toString(),
|
|
@@ -429,6 +428,7 @@ export class AttestationPool {
|
|
|
429
428
|
const attestationEndKey = new Fr(oldestSlot).toString();
|
|
430
429
|
for await (const key of this.checkpointAttestations.keysAsync({ end: attestationEndKey })) {
|
|
431
430
|
await this.checkpointAttestations.delete(key);
|
|
431
|
+
this.metrics.trackMempoolItemRemoved(key);
|
|
432
432
|
numberOfAttestations++;
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -526,6 +526,7 @@ export class AttestationPool {
|
|
|
526
526
|
|
|
527
527
|
// Add the attestation
|
|
528
528
|
await this.checkpointAttestations.set(key, attestation.toBuffer());
|
|
529
|
+
this.metrics.trackMempoolItemAdded(key);
|
|
529
530
|
|
|
530
531
|
// Track this attestation in the per-signer-per-slot index for duplicate detection
|
|
531
532
|
const slotSignerKey = this.getSlotSignerKey(slotNumber, signerAddress);
|
|
@@ -73,7 +73,7 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
73
73
|
private defaultAttributes;
|
|
74
74
|
private meter: Meter;
|
|
75
75
|
|
|
76
|
-
private
|
|
76
|
+
private mempoolItemAddedTimestamp: Map<bigint | string, number> = new Map<bigint | string, number>();
|
|
77
77
|
|
|
78
78
|
constructor(
|
|
79
79
|
telemetry: TelemetryClient,
|
|
@@ -114,22 +114,26 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
public transactionsAdded(transactions: Tx[]) {
|
|
117
|
-
|
|
118
|
-
for (const transaction of transactions) {
|
|
119
|
-
this.txAddedTimestamp.set(transaction.txHash.toBigInt(), timestamp);
|
|
120
|
-
}
|
|
117
|
+
transactions.forEach(tx => this.trackMempoolItemAdded(tx.txHash.toBigInt()));
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
public transactionsRemoved(hashes: Iterable<bigint> | Iterable<string>) {
|
|
124
|
-
const timestamp = Date.now();
|
|
125
121
|
for (const hash of hashes) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
this.trackMempoolItemRemoved(BigInt(hash));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public trackMempoolItemAdded(key: bigint | string): void {
|
|
127
|
+
this.mempoolItemAddedTimestamp.set(key, Date.now());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public trackMempoolItemRemoved(key: bigint | string): void {
|
|
131
|
+
const timestamp = Date.now();
|
|
132
|
+
const addedAt = this.mempoolItemAddedTimestamp.get(key);
|
|
133
|
+
if (addedAt !== undefined) {
|
|
134
|
+
this.mempoolItemAddedTimestamp.delete(key);
|
|
135
|
+
if (addedAt < timestamp) {
|
|
136
|
+
this.minedDelay.record(timestamp - addedAt);
|
|
133
137
|
}
|
|
134
138
|
}
|
|
135
139
|
}
|
|
@@ -158,7 +158,7 @@ Checked before adding a transaction to the pending pool:
|
|
|
158
158
|
|
|
159
159
|
| Rule | Purpose |
|
|
160
160
|
|------|---------|
|
|
161
|
-
| `NullifierConflictRule` | Handles transactions with conflicting nullifiers. Higher priority tx wins. |
|
|
161
|
+
| `NullifierConflictRule` | Handles transactions with conflicting nullifiers. Higher priority tx wins. For RPC submissions, a configurable price bump percentage is required. |
|
|
162
162
|
| `FeePayerBalancePreAddRule` | Ensures fee payer has sufficient balance for all their pending txs. |
|
|
163
163
|
| `LowPriorityPreAddRule` | Rejects txs when pool is full and new tx has lowest priority. |
|
|
164
164
|
|
|
@@ -233,6 +233,14 @@ await pool.updateConfig({
|
|
|
233
233
|
});
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
+
### Price Bump (RPC Transaction Replacement)
|
|
237
|
+
|
|
238
|
+
When a transaction is submitted via RPC and clashes on nullifiers with an existing pool transaction, the incoming tx must pay at least `priceBumpPercentage`% more in priority fee (i.e. `>= existingFee + existingFee * bump / 100`) to replace it. This prevents spam via small fee increments. The same bump applies when the pool is full and the incoming tx needs to evict the lowest-priority tx.
|
|
239
|
+
|
|
240
|
+
- **Env var**: `P2P_RPC_PRICE_BUMP_PERCENTAGE` (default: 10)
|
|
241
|
+
- **Scope**: RPC submissions only. P2P gossip uses `comparePriority` (fee + hash tiebreaker) with no bump.
|
|
242
|
+
- Even with a 0% bump, a replacement tx must pay at least 1 unit more than the existing fee.
|
|
243
|
+
|
|
236
244
|
## Return Values
|
|
237
245
|
|
|
238
246
|
### AddTxsResult
|
|
@@ -34,7 +34,7 @@ export class FeePayerBalanceEvictionRule implements EvictionRule {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (context.event === EvictionEvent.CHAIN_PRUNED) {
|
|
37
|
-
await this.worldState.syncImmediate(
|
|
37
|
+
await this.worldState.syncImmediate();
|
|
38
38
|
const feePayers = pool.getPendingFeePayers();
|
|
39
39
|
return await this.evictForFeePayers(feePayers, this.worldState.getSnapshot(context.blockNumber), pool);
|
|
40
40
|
}
|
|
@@ -35,6 +35,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
|
|
|
35
35
|
// Create combined list with incoming tx
|
|
36
36
|
const allTxs: Array<{
|
|
37
37
|
txHash: string;
|
|
38
|
+
txHashBigInt: bigint;
|
|
38
39
|
priorityFee: bigint;
|
|
39
40
|
feeLimit: bigint;
|
|
40
41
|
claimAmount: bigint;
|
|
@@ -42,6 +43,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
|
|
|
42
43
|
}> = [
|
|
43
44
|
...existingTxs.map(t => ({
|
|
44
45
|
txHash: t.txHash,
|
|
46
|
+
txHashBigInt: t.txHashBigInt,
|
|
45
47
|
priorityFee: t.priorityFee,
|
|
46
48
|
feeLimit: t.feeLimit,
|
|
47
49
|
claimAmount: t.claimAmount,
|
|
@@ -49,6 +51,7 @@ export class FeePayerBalancePreAddRule implements PreAddRule {
|
|
|
49
51
|
})),
|
|
50
52
|
{
|
|
51
53
|
txHash: incomingMeta.txHash,
|
|
54
|
+
txHashBigInt: incomingMeta.txHashBigInt,
|
|
52
55
|
priorityFee: incomingMeta.priorityFee,
|
|
53
56
|
feeLimit: incomingMeta.feeLimit,
|
|
54
57
|
claimAmount: incomingMeta.claimAmount,
|
|
@@ -100,7 +100,15 @@ export type TxPoolRejectionError =
|
|
|
100
100
|
availableBalance: bigint;
|
|
101
101
|
feeLimit: bigint;
|
|
102
102
|
}
|
|
103
|
-
| {
|
|
103
|
+
| {
|
|
104
|
+
code: typeof TxPoolRejectionCode.NULLIFIER_CONFLICT;
|
|
105
|
+
message: string;
|
|
106
|
+
conflictingTxHash: string;
|
|
107
|
+
/** Minimum fee needed to replace the conflicting tx (only set when price bump applies). */
|
|
108
|
+
minimumPriceBumpFee?: bigint;
|
|
109
|
+
/** Incoming tx's priority fee. */
|
|
110
|
+
txPriorityFee?: bigint;
|
|
111
|
+
}
|
|
104
112
|
| { code: typeof TxPoolRejectionCode.INTERNAL_ERROR; message: string };
|
|
105
113
|
|
|
106
114
|
/**
|
|
@@ -121,6 +129,8 @@ export interface PreAddResult {
|
|
|
121
129
|
export interface PreAddContext {
|
|
122
130
|
/** If true, compare priority fee only (no tx hash tiebreaker). Used for RPC submissions. */
|
|
123
131
|
feeComparisonOnly?: boolean;
|
|
132
|
+
/** Percentage-based price bump required for tx replacement. Only set for RPC submissions. */
|
|
133
|
+
priceBumpPercentage?: bigint;
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
/**
|
|
@@ -45,8 +45,8 @@ export class InvalidTxsAfterReorgRule implements EvictionRule {
|
|
|
45
45
|
txsByBlockHash.get(blockHashStr)!.push(meta.txHash);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
await this.worldState.syncImmediate(
|
|
48
|
+
// Sync without a block number to ensure the world state processes the prune event.
|
|
49
|
+
await this.worldState.syncImmediate();
|
|
50
50
|
const db = this.worldState.getSnapshot(context.blockNumber);
|
|
51
51
|
|
|
52
52
|
// Check which blocks exist in the archive
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import { type TxMetaData, comparePriority } from '../tx_metadata.js';
|
|
3
|
+
import { type TxMetaData, comparePriority, getMinimumPriceBumpFee } from '../tx_metadata.js';
|
|
4
4
|
import {
|
|
5
5
|
type EvictionConfig,
|
|
6
6
|
type PreAddContext,
|
|
@@ -48,10 +48,14 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// Compare incoming tx against lowest priority tx.
|
|
51
|
-
// feeOnly mode (RPC): use strict fee comparison only — avoids churn from hash ordering
|
|
52
|
-
//
|
|
51
|
+
// feeOnly mode (RPC): use strict fee comparison only — avoids churn from hash ordering.
|
|
52
|
+
// When price bump is also set, require the bumped fee threshold.
|
|
53
|
+
// Default (gossip): use full comparePriority (fee + tx hash tiebreaker) for determinism.
|
|
53
54
|
const isHigherPriority = context?.feeComparisonOnly
|
|
54
|
-
?
|
|
55
|
+
? context.priceBumpPercentage !== undefined
|
|
56
|
+
? incomingMeta.priorityFee >=
|
|
57
|
+
getMinimumPriceBumpFee(lowestPriorityMeta.priorityFee, context.priceBumpPercentage)
|
|
58
|
+
: incomingMeta.priorityFee > lowestPriorityMeta.priorityFee
|
|
55
59
|
: comparePriority(incomingMeta, lowestPriorityMeta) > 0;
|
|
56
60
|
|
|
57
61
|
if (isHigherPriority) {
|
|
@@ -66,6 +70,11 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
// Incoming tx has equal or lower priority - ignore it (it would be evicted anyway)
|
|
73
|
+
const minimumFee =
|
|
74
|
+
context?.feeComparisonOnly && context.priceBumpPercentage !== undefined
|
|
75
|
+
? getMinimumPriceBumpFee(lowestPriorityMeta.priorityFee, context.priceBumpPercentage)
|
|
76
|
+
: lowestPriorityMeta.priorityFee + 1n;
|
|
77
|
+
|
|
69
78
|
this.log.debug(
|
|
70
79
|
`Pool at capacity (${currentCount}/${this.maxPoolSize}), ignoring ${incomingMeta.txHash} ` +
|
|
71
80
|
`(priority ${incomingMeta.priorityFee}) - lower than existing minimum (priority ${lowestPriorityMeta.priorityFee})`,
|
|
@@ -75,8 +84,8 @@ export class LowPriorityPreAddRule implements PreAddRule {
|
|
|
75
84
|
txHashesToEvict: [],
|
|
76
85
|
reason: {
|
|
77
86
|
code: TxPoolRejectionCode.LOW_PRIORITY_FEE,
|
|
78
|
-
message: `Tx does not meet minimum priority fee. Required: ${
|
|
79
|
-
minimumPriorityFee:
|
|
87
|
+
message: `Tx does not meet minimum priority fee. Required: ${minimumFee}, got: ${incomingMeta.priorityFee}`,
|
|
88
|
+
minimumPriorityFee: minimumFee,
|
|
80
89
|
txPriorityFee: incomingMeta.priorityFee,
|
|
81
90
|
},
|
|
82
91
|
});
|
|
@@ -15,11 +15,12 @@ export class NullifierConflictRule implements PreAddRule {
|
|
|
15
15
|
|
|
16
16
|
private log = createLogger('p2p:tx_pool_v2:nullifier_conflict_rule');
|
|
17
17
|
|
|
18
|
-
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess,
|
|
18
|
+
check(incomingMeta: TxMetaData, poolAccess: PreAddPoolAccess, context?: PreAddContext): Promise<PreAddResult> {
|
|
19
19
|
const result = checkNullifierConflict(
|
|
20
20
|
incomingMeta,
|
|
21
21
|
nullifier => poolAccess.getTxHashByNullifier(nullifier),
|
|
22
22
|
txHash => poolAccess.getMetadata(txHash),
|
|
23
|
+
context?.priceBumpPercentage,
|
|
23
24
|
);
|
|
24
25
|
|
|
25
26
|
if (result.shouldIgnore) {
|
|
@@ -7,6 +7,6 @@ export {
|
|
|
7
7
|
type PoolReadAccess,
|
|
8
8
|
DEFAULT_TX_POOL_V2_CONFIG,
|
|
9
9
|
} from './interfaces.js';
|
|
10
|
-
export { type TxMetaData, type TxState, buildTxMetaData, comparePriority } from './tx_metadata.js';
|
|
10
|
+
export { type TxMetaData, type TxState, buildTxMetaData, comparePriority, stubTxMetaData } from './tx_metadata.js';
|
|
11
11
|
export { TxArchive } from './archive/index.js';
|
|
12
12
|
export { DeletedPool } from './deleted_pool.js';
|