@aztec/p2p 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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/interface.d.ts +18 -5
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +10 -13
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +449 -118
- package/dest/config.js +2 -2
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +61 -42
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.js +237 -263
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +21 -18
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +113 -108
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +17 -16
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +89 -128
- package/dest/mem_pools/attestation_pool/mocks.d.ts +9 -6
- package/dest/mem_pools/attestation_pool/mocks.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/mocks.js +16 -12
- package/dest/mem_pools/instrumentation.d.ts +1 -1
- package/dest/mem_pools/instrumentation.d.ts.map +1 -1
- package/dest/mem_pools/instrumentation.js +4 -13
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts +13 -8
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/aztec_kv_tx_pool.js +91 -50
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts +17 -4
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_manager.js +59 -3
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts +77 -4
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/eviction_strategy.js +47 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.js +115 -0
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts +2 -2
- package/dest/mem_pools/tx_pool/eviction/low_priority_eviction_rule.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts +25 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.js +57 -0
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts +4 -4
- package/dest/msg_validators/attestation_validator/attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/attestation_validator.js +12 -10
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +5 -5
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts.map +1 -1
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.js +7 -10
- package/dest/msg_validators/index.d.ts +2 -2
- package/dest/msg_validators/index.d.ts.map +1 -1
- package/dest/msg_validators/index.js +1 -1
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/block_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts +9 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/checkpoint_proposal_validator.js +6 -0
- package/dest/msg_validators/proposal_validator/index.d.ts +4 -0
- package/dest/msg_validators/proposal_validator/index.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/index.js +3 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts +13 -0
- package/dest/msg_validators/proposal_validator/proposal_validator.d.ts.map +1 -0
- package/dest/msg_validators/{block_proposal_validator/block_proposal_validator.js → proposal_validator/proposal_validator.js} +19 -21
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts +23 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.d.ts.map +1 -0
- package/dest/msg_validators/proposal_validator/proposal_validator_test_suite.js +183 -0
- package/dest/msg_validators/tx_validator/data_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/data_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts +10 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.d.ts.map +1 -0
- package/dest/msg_validators/tx_validator/fee_payer_balance.js +20 -0
- package/dest/msg_validators/tx_validator/gas_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.d.ts.map +1 -1
- package/dest/msg_validators/tx_validator/gas_validator.js +8 -14
- 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/timestamp_validator.d.ts +1 -1
- package/dest/msg_validators/tx_validator/timestamp_validator.d.ts.map +1 -1
- package/dest/services/dummy_service.d.ts +6 -2
- package/dest/services/dummy_service.d.ts.map +1 -1
- package/dest/services/dummy_service.js +3 -0
- package/dest/services/encoding.d.ts +1 -1
- package/dest/services/encoding.d.ts.map +1 -1
- package/dest/services/encoding.js +4 -2
- package/dest/services/libp2p/instrumentation.d.ts +1 -1
- package/dest/services/libp2p/instrumentation.d.ts.map +1 -1
- package/dest/services/libp2p/instrumentation.js +20 -73
- package/dest/services/libp2p/libp2p_service.d.ts +27 -10
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +696 -137
- package/dest/services/peer-manager/metrics.d.ts +1 -1
- package/dest/services/peer-manager/metrics.d.ts.map +1 -1
- package/dest/services/peer-manager/metrics.js +6 -26
- package/dest/services/peer-manager/peer_manager.d.ts +2 -2
- package/dest/services/peer-manager/peer_manager.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_manager.js +0 -10
- package/dest/services/peer-manager/peer_scoring.d.ts +1 -1
- package/dest/services/peer-manager/peer_scoring.d.ts.map +1 -1
- package/dest/services/peer-manager/peer_scoring.js +2 -5
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts +1 -1
- package/dest/services/reqresp/connection-sampler/connection_sampler.d.ts.map +1 -1
- package/dest/services/reqresp/constants.d.ts +12 -0
- package/dest/services/reqresp/constants.d.ts.map +1 -0
- package/dest/services/reqresp/constants.js +7 -0
- package/dest/services/reqresp/interface.d.ts +3 -3
- package/dest/services/reqresp/interface.d.ts.map +1 -1
- package/dest/services/reqresp/interface.js +2 -2
- package/dest/services/reqresp/metrics.d.ts +1 -1
- package/dest/services/reqresp/metrics.d.ts.map +1 -1
- package/dest/services/reqresp/metrics.js +5 -21
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/bitvector.js +7 -0
- package/dest/services/reqresp/protocols/status.d.ts +1 -1
- package/dest/services/reqresp/protocols/status.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/status.js +4 -1
- package/dest/services/reqresp/reqresp.js +402 -24
- package/dest/services/service.d.ts +16 -3
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts +1 -1
- package/dest/services/tx_collection/instrumentation.d.ts.map +1 -1
- package/dest/services/tx_collection/instrumentation.js +4 -14
- package/dest/services/tx_provider_instrumentation.d.ts +1 -1
- package/dest/services/tx_provider_instrumentation.d.ts.map +1 -1
- package/dest/services/tx_provider_instrumentation.js +6 -19
- package/dest/testbench/p2p_client_testbench_worker.js +27 -12
- package/dest/testbench/worker_client_manager.d.ts +1 -1
- package/dest/testbench/worker_client_manager.d.ts.map +1 -1
- package/dest/testbench/worker_client_manager.js +6 -1
- package/package.json +16 -16
- package/src/client/interface.ts +19 -4
- package/src/client/p2p_client.ts +78 -128
- package/src/config.ts +2 -2
- package/src/mem_pools/attestation_pool/attestation_pool.ts +68 -41
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +239 -287
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +162 -140
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +141 -164
- package/src/mem_pools/attestation_pool/mocks.ts +19 -13
- package/src/mem_pools/instrumentation.ts +9 -18
- package/src/mem_pools/tx_pool/README.md +28 -13
- package/src/mem_pools/tx_pool/aztec_kv_tx_pool.ts +128 -73
- package/src/mem_pools/tx_pool/eviction/eviction_manager.ts +64 -4
- package/src/mem_pools/tx_pool/eviction/eviction_strategy.ts +117 -3
- package/src/mem_pools/tx_pool/eviction/fee_payer_balance_eviction_rule.ts +159 -0
- package/src/mem_pools/tx_pool/eviction/nullifier_conflict_pre_add_rule.ts +75 -0
- package/src/msg_validators/attestation_validator/attestation_validator.ts +16 -13
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +9 -12
- package/src/msg_validators/index.ts +1 -1
- package/src/msg_validators/proposal_validator/block_proposal_validator.ts +10 -0
- package/src/msg_validators/proposal_validator/checkpoint_proposal_validator.ts +13 -0
- package/src/msg_validators/proposal_validator/index.ts +3 -0
- package/src/msg_validators/{block_proposal_validator/block_proposal_validator.ts → proposal_validator/proposal_validator.ts} +23 -28
- package/src/msg_validators/proposal_validator/proposal_validator_test_suite.ts +206 -0
- package/src/msg_validators/tx_validator/data_validator.ts +12 -4
- package/src/msg_validators/tx_validator/fee_payer_balance.ts +40 -0
- package/src/msg_validators/tx_validator/gas_validator.ts +8 -25
- package/src/msg_validators/tx_validator/metadata_validator.ts +12 -4
- package/src/msg_validators/tx_validator/timestamp_validator.ts +3 -1
- package/src/services/dummy_service.ts +6 -0
- package/src/services/encoding.ts +3 -1
- package/src/services/libp2p/instrumentation.ts +19 -73
- package/src/services/libp2p/libp2p_service.ts +326 -102
- package/src/services/peer-manager/metrics.ts +5 -26
- package/src/services/peer-manager/peer_manager.ts +1 -2
- package/src/services/peer-manager/peer_scoring.ts +1 -5
- package/src/services/reqresp/connection-sampler/connection_sampler.ts +3 -1
- package/src/services/reqresp/constants.ts +14 -0
- package/src/services/reqresp/interface.ts +2 -2
- package/src/services/reqresp/metrics.ts +7 -23
- package/src/services/reqresp/protocols/block_txs/bitvector.ts +9 -0
- package/src/services/reqresp/protocols/status.ts +7 -4
- package/src/services/service.ts +19 -4
- package/src/services/tx_collection/instrumentation.ts +4 -21
- package/src/services/tx_provider_instrumentation.ts +11 -24
- package/src/testbench/p2p_client_testbench_worker.ts +35 -12
- package/src/testbench/worker_client_manager.ts +6 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts +0 -15
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.d.ts.map +0 -1
- package/dest/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.js +0 -88
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts +0 -12
- package/dest/msg_validators/block_proposal_validator/block_proposal_validator.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.d.ts +0 -2
- package/dest/msg_validators/block_proposal_validator/index.d.ts.map +0 -1
- package/dest/msg_validators/block_proposal_validator/index.js +0 -1
- package/src/mem_pools/tx_pool/eviction/insufficient_fee_payer_balance_rule.ts +0 -108
- package/src/msg_validators/block_proposal_validator/index.ts +0 -1
|
@@ -1,71 +1,120 @@
|
|
|
1
1
|
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
BlockProposal,
|
|
5
|
+
CheckpointAttestation,
|
|
6
|
+
CheckpointProposal,
|
|
7
|
+
CheckpointProposalCore,
|
|
8
|
+
} from '@aztec/stdlib/p2p';
|
|
4
9
|
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
5
10
|
|
|
11
|
+
import { ProposalSlotCapExceededError } from '../../errors/attestation-pool.error.js';
|
|
6
12
|
import { PoolInstrumentation, PoolName, type PoolStatsCallback } from '../instrumentation.js';
|
|
7
13
|
import type { AttestationPool } from './attestation_pool.js';
|
|
8
14
|
import { ATTESTATION_CAP_BUFFER, MAX_PROPOSALS_PER_SLOT } from './kv_attestation_pool.js';
|
|
9
15
|
|
|
10
16
|
export class InMemoryAttestationPool implements AttestationPool {
|
|
11
|
-
private metrics: PoolInstrumentation<
|
|
17
|
+
private metrics: PoolInstrumentation<CheckpointAttestation>;
|
|
12
18
|
|
|
19
|
+
private proposals: Map<string, BlockProposal>;
|
|
20
|
+
|
|
21
|
+
// Checkpoint attestations
|
|
13
22
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
14
|
-
private
|
|
23
|
+
private checkpointAttestations: Map<
|
|
15
24
|
/*slot=*/ SlotNumber,
|
|
16
|
-
Map</*proposalId*/ string, Map</*address=*/ string,
|
|
25
|
+
Map</*proposalId*/ string, Map</*address=*/ string, CheckpointAttestation>>
|
|
17
26
|
>;
|
|
18
|
-
private
|
|
27
|
+
private checkpointProposals: Map<string, CheckpointProposalCore>;
|
|
19
28
|
|
|
20
29
|
constructor(
|
|
21
30
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
22
31
|
private log = createLogger('p2p:attestation_pool'),
|
|
23
32
|
) {
|
|
24
|
-
this.attestations = new Map();
|
|
25
33
|
this.proposals = new Map();
|
|
34
|
+
this.checkpointAttestations = new Map();
|
|
35
|
+
this.checkpointProposals = new Map();
|
|
26
36
|
this.metrics = new PoolInstrumentation(telemetry, PoolName.ATTESTATION_POOL, this.poolStats);
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
private poolStats: PoolStatsCallback = () => {
|
|
30
40
|
return Promise.resolve({
|
|
31
|
-
itemCount: this.
|
|
41
|
+
itemCount: this.checkpointAttestations.size,
|
|
32
42
|
});
|
|
33
43
|
};
|
|
34
44
|
|
|
35
45
|
public isEmpty(): Promise<boolean> {
|
|
36
|
-
return Promise.resolve(this.
|
|
46
|
+
return Promise.resolve(this.checkpointAttestations.size === 0 && this.proposals.size === 0);
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
public
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
);
|
|
49
|
+
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
50
|
+
// Strip signedTxs before storing to avoid holding full tx data in memory
|
|
51
|
+
this.proposals.set(blockProposal.archive.toString(), blockProposal.withoutSignedTxs());
|
|
52
|
+
return Promise.resolve();
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
public
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
56
|
+
return Promise.resolve(this.proposals.get(id));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
60
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.archive.toString();
|
|
61
|
+
return Promise.resolve(this.proposals.has(id));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public canAddProposal(_block: BlockProposal): Promise<boolean> {
|
|
65
|
+
// TODO(palla/mbps): See when to allow
|
|
66
|
+
return Promise.resolve(true);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Checkpoint attestation methods
|
|
70
|
+
|
|
71
|
+
public async addCheckpointProposal(proposal: CheckpointProposal): Promise<void> {
|
|
72
|
+
if (!(await this.canAddCheckpointProposal(proposal))) {
|
|
73
|
+
throw new ProposalSlotCapExceededError(
|
|
74
|
+
`Maximum checkpoint proposals per slot reached: slot=${proposal.slotNumber} cap=${MAX_PROPOSALS_PER_SLOT} proposal=${proposal.archive.toString()}`,
|
|
75
|
+
);
|
|
54
76
|
}
|
|
55
|
-
|
|
77
|
+
|
|
78
|
+
// Extract and validate the block proposal if present
|
|
79
|
+
const blockProposal = proposal.getBlockProposal();
|
|
80
|
+
if (blockProposal && !(await this.canAddProposal(blockProposal))) {
|
|
81
|
+
throw new ProposalSlotCapExceededError(
|
|
82
|
+
`Maximum block proposals per slot reached when extracting from checkpoint: slot=${proposal.slotNumber} proposal=${blockProposal.archive.toString()}`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const slotProposalMapping = getCheckpointSlotOrDefault(this.checkpointAttestations, proposal.slotNumber);
|
|
87
|
+
slotProposalMapping.set(proposal.archive.toString(), new Map<string, CheckpointAttestation>());
|
|
88
|
+
|
|
89
|
+
// Store the checkpoint proposal as core (without lastBlock) to avoid duplication
|
|
90
|
+
this.checkpointProposals.set(proposal.archive.toString(), proposal.toCore());
|
|
91
|
+
|
|
92
|
+
// Store the extracted block proposal separately
|
|
93
|
+
if (blockProposal) {
|
|
94
|
+
this.proposals.set(blockProposal.archive.toString(), blockProposal.withoutSignedTxs());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public getCheckpointProposal(id: string): Promise<CheckpointProposalCore | undefined> {
|
|
101
|
+
return Promise.resolve(this.checkpointProposals.get(id));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public hasCheckpointProposal(idOrProposal: string | CheckpointProposal): Promise<boolean> {
|
|
105
|
+
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.archive.toString();
|
|
106
|
+
return Promise.resolve(this.checkpointProposals.has(id));
|
|
56
107
|
}
|
|
57
108
|
|
|
58
|
-
public
|
|
109
|
+
public addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void> {
|
|
59
110
|
for (const attestation of attestations) {
|
|
60
|
-
// Perf: order and group by slot before insertion
|
|
61
111
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
62
|
-
|
|
63
112
|
const proposalId = attestation.archive.toString();
|
|
64
113
|
const sender = attestation.getSender();
|
|
65
114
|
|
|
66
115
|
// Skip attestations with invalid signatures
|
|
67
116
|
if (!sender) {
|
|
68
|
-
this.log.warn(`Skipping attestation with invalid signature for slot ${slotNumber}`, {
|
|
117
|
+
this.log.warn(`Skipping checkpoint attestation with invalid signature for slot ${slotNumber}`, {
|
|
69
118
|
signature: attestation.signature.toString(),
|
|
70
119
|
slotNumber,
|
|
71
120
|
proposalId,
|
|
@@ -73,11 +122,11 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
73
122
|
continue;
|
|
74
123
|
}
|
|
75
124
|
|
|
76
|
-
const slotAttestationMap =
|
|
77
|
-
const proposalAttestationMap =
|
|
125
|
+
const slotAttestationMap = getCheckpointSlotOrDefault(this.checkpointAttestations, slotNumber);
|
|
126
|
+
const proposalAttestationMap = getCheckpointProposalOrDefault(slotAttestationMap, proposalId);
|
|
78
127
|
proposalAttestationMap.set(sender.toString(), attestation);
|
|
79
128
|
|
|
80
|
-
this.log.verbose(`Added attestation for slot ${slotNumber} from ${sender}`, {
|
|
129
|
+
this.log.verbose(`Added checkpoint attestation for slot ${slotNumber} from ${sender}`, {
|
|
81
130
|
signature: attestation.signature.toString(),
|
|
82
131
|
slotNumber,
|
|
83
132
|
address: sender,
|
|
@@ -88,25 +137,32 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
88
137
|
return Promise.resolve();
|
|
89
138
|
}
|
|
90
139
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
140
|
+
public getCheckpointAttestationsForSlot(slot: SlotNumber): Promise<CheckpointAttestation[]> {
|
|
141
|
+
return Promise.resolve(
|
|
142
|
+
Array.from(this.checkpointAttestations.get(slot)?.values() ?? []).flatMap(proposalAttestationMap =>
|
|
143
|
+
Array.from(proposalAttestationMap.values()),
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
94
147
|
|
|
148
|
+
public getCheckpointAttestationsForSlotAndProposal(
|
|
149
|
+
slot: SlotNumber,
|
|
150
|
+
proposalId: string,
|
|
151
|
+
): Promise<CheckpointAttestation[]> {
|
|
152
|
+
const slotAttestationMap = this.checkpointAttestations.get(slot);
|
|
95
153
|
if (slotAttestationMap) {
|
|
96
|
-
|
|
97
|
-
|
|
154
|
+
const proposalAttestationMap = slotAttestationMap.get(proposalId);
|
|
155
|
+
if (proposalAttestationMap) {
|
|
156
|
+
return Promise.resolve(Array.from(proposalAttestationMap.values()));
|
|
98
157
|
}
|
|
99
158
|
}
|
|
100
|
-
return
|
|
159
|
+
return Promise.resolve([]);
|
|
101
160
|
}
|
|
102
161
|
|
|
103
|
-
public
|
|
162
|
+
public deleteCheckpointAttestationsOlderThan(oldestSlot: SlotNumber): Promise<void> {
|
|
104
163
|
const olderThan = [];
|
|
105
164
|
|
|
106
|
-
|
|
107
|
-
// Note: this will only prune correctly if attestations are added in order of rising slot, it is important that we do not allow
|
|
108
|
-
// insertion of attestations that are old. #(https://github.com/AztecProtocol/aztec-packages/issues/10322)
|
|
109
|
-
const slots = this.attestations.keys();
|
|
165
|
+
const slots = this.checkpointAttestations.keys();
|
|
110
166
|
for (const slot of slots) {
|
|
111
167
|
if (slot < oldestSlot) {
|
|
112
168
|
olderThan.push(slot);
|
|
@@ -116,70 +172,51 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
116
172
|
}
|
|
117
173
|
|
|
118
174
|
for (const oldSlot of olderThan) {
|
|
119
|
-
|
|
175
|
+
const proposalIds = this.checkpointAttestations.get(oldSlot)?.keys();
|
|
176
|
+
proposalIds?.forEach(proposalId => this.checkpointProposals.delete(proposalId));
|
|
177
|
+
this.checkpointAttestations.delete(oldSlot);
|
|
120
178
|
}
|
|
121
179
|
return Promise.resolve();
|
|
122
180
|
}
|
|
123
181
|
|
|
124
|
-
public
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
let proposalIdsToDeleteCount = 0;
|
|
129
|
-
proposalIdsToDelete?.forEach(proposalId => {
|
|
130
|
-
this.proposals.delete(proposalId);
|
|
131
|
-
proposalIdsToDeleteCount++;
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
this.attestations.delete(slot);
|
|
135
|
-
this.log.verbose(
|
|
136
|
-
`Removed ${numberOfAttestations} attestations and ${proposalIdsToDeleteCount} proposals for slot ${slot}`,
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
return Promise.resolve();
|
|
182
|
+
public hasReachedCheckpointProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
183
|
+
const slotAttestationMap = this.checkpointAttestations.get(slot);
|
|
184
|
+
const proposalCount = slotAttestationMap?.size ?? 0;
|
|
185
|
+
return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
|
|
140
186
|
}
|
|
141
187
|
|
|
142
|
-
public
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
188
|
+
public hasReachedCheckpointAttestationCap(
|
|
189
|
+
slot: SlotNumber,
|
|
190
|
+
proposalId: string,
|
|
191
|
+
committeeSize: number,
|
|
192
|
+
): Promise<boolean> {
|
|
193
|
+
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
194
|
+
const count = this.checkpointAttestations.get(slot)?.get(proposalId)?.size ?? 0;
|
|
195
|
+
return Promise.resolve(limit <= 0 || count >= limit);
|
|
196
|
+
}
|
|
153
197
|
|
|
154
|
-
|
|
155
|
-
return
|
|
198
|
+
public async canAddCheckpointProposal(proposal: CheckpointProposal): Promise<boolean> {
|
|
199
|
+
return (
|
|
200
|
+
this.checkpointProposals.has(proposal.archive.toString()) ||
|
|
201
|
+
!(await this.hasReachedCheckpointProposalCap(proposal.slotNumber))
|
|
202
|
+
);
|
|
156
203
|
}
|
|
157
204
|
|
|
158
|
-
public
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.log.warn(`Skipping deletion of attestation with invalid signature for slot ${slotNumber}`);
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
proposalAttestationMap.delete(sender.toString());
|
|
175
|
-
this.log.debug(`Deleted attestation for slot ${slotNumber} from ${sender}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return Promise.resolve();
|
|
205
|
+
public async canAddCheckpointAttestation(
|
|
206
|
+
attestation: CheckpointAttestation,
|
|
207
|
+
committeeSize: number,
|
|
208
|
+
): Promise<boolean> {
|
|
209
|
+
const sender = attestation.getSender();
|
|
210
|
+
const slot = attestation.payload.header.slotNumber;
|
|
211
|
+
const pid = attestation.archive.toString();
|
|
212
|
+
return (
|
|
213
|
+
!!sender &&
|
|
214
|
+
((this.checkpointAttestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
|
|
215
|
+
!(await this.hasReachedCheckpointAttestationCap(slot, pid, committeeSize)))
|
|
216
|
+
);
|
|
180
217
|
}
|
|
181
218
|
|
|
182
|
-
public
|
|
219
|
+
public hasCheckpointAttestation(attestation: CheckpointAttestation): Promise<boolean> {
|
|
183
220
|
const slotNumber = attestation.payload.header.slotNumber;
|
|
184
221
|
const proposalId = attestation.archive.toString();
|
|
185
222
|
const sender = attestation.getSender();
|
|
@@ -189,7 +226,7 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
189
226
|
return Promise.resolve(false);
|
|
190
227
|
}
|
|
191
228
|
|
|
192
|
-
const slotAttestationMap = this.
|
|
229
|
+
const slotAttestationMap = this.checkpointAttestations.get(slotNumber);
|
|
193
230
|
if (!slotAttestationMap) {
|
|
194
231
|
return Promise.resolve(false);
|
|
195
232
|
}
|
|
@@ -201,87 +238,27 @@ export class InMemoryAttestationPool implements AttestationPool {
|
|
|
201
238
|
|
|
202
239
|
return Promise.resolve(proposalAttestationMap.has(sender.toString()));
|
|
203
240
|
}
|
|
204
|
-
|
|
205
|
-
public addBlockProposal(blockProposal: BlockProposal): Promise<void> {
|
|
206
|
-
// We initialize slot-proposal mapping if it does not exist
|
|
207
|
-
// This is important to ensure we can delete this proposal if there were not attestations for it
|
|
208
|
-
const slotProposalMapping = getSlotOrDefault(this.attestations, blockProposal.slotNumber);
|
|
209
|
-
slotProposalMapping.set(blockProposal.payload.archive.toString(), new Map<string, BlockAttestation>());
|
|
210
|
-
|
|
211
|
-
this.proposals.set(blockProposal.payload.archive.toString(), blockProposal);
|
|
212
|
-
return Promise.resolve();
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
public getBlockProposal(id: string): Promise<BlockProposal | undefined> {
|
|
216
|
-
return Promise.resolve(this.proposals.get(id));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
public hasBlockProposal(idOrProposal: string | BlockProposal): Promise<boolean> {
|
|
220
|
-
const id = typeof idOrProposal === 'string' ? idOrProposal : idOrProposal.payload.archive.toString();
|
|
221
|
-
return Promise.resolve(this.proposals.has(id));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
public hasReachedProposalCap(slot: SlotNumber): Promise<boolean> {
|
|
225
|
-
const slotAttestationMap = this.attestations.get(slot);
|
|
226
|
-
const proposalCount = slotAttestationMap?.size ?? 0;
|
|
227
|
-
return Promise.resolve(proposalCount >= MAX_PROPOSALS_PER_SLOT);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public hasReachedAttestationCap(slot: SlotNumber, proposalId: string, committeeSize: number): Promise<boolean> {
|
|
231
|
-
const limit = committeeSize + ATTESTATION_CAP_BUFFER;
|
|
232
|
-
const count = this.attestations.get(slot)?.get(proposalId)?.size ?? 0;
|
|
233
|
-
return Promise.resolve(limit <= 0 || count >= limit);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public async canAddProposal(block: BlockProposal): Promise<boolean> {
|
|
237
|
-
return this.proposals.has(block.archive.toString()) || !(await this.hasReachedProposalCap(block.slotNumber));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public async canAddAttestation(attestation: BlockAttestation, committeeSize: number): Promise<boolean> {
|
|
241
|
-
const sender = attestation.getSender();
|
|
242
|
-
const slot = attestation.payload.header.slotNumber;
|
|
243
|
-
const pid = attestation.archive.toString();
|
|
244
|
-
return (
|
|
245
|
-
!!sender &&
|
|
246
|
-
((this.attestations.get(slot)?.get(pid)?.has(sender.toString()) ?? false) ||
|
|
247
|
-
!(await this.hasReachedAttestationCap(slot, pid, committeeSize)))
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
241
|
}
|
|
251
242
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* Fetch the slot mapping, if it does not exist, then create a mapping and return it
|
|
256
|
-
* @param map - The map to fetch from
|
|
257
|
-
* @param slot - The slot to fetch
|
|
258
|
-
* @returns The slot mapping
|
|
259
|
-
*/
|
|
260
|
-
function getSlotOrDefault(
|
|
243
|
+
// Checkpoint attestation helper functions
|
|
244
|
+
|
|
245
|
+
function getCheckpointSlotOrDefault(
|
|
261
246
|
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
262
|
-
map: Map<SlotNumber, Map<string, Map<string,
|
|
247
|
+
map: Map<SlotNumber, Map<string, Map<string, CheckpointAttestation>>>,
|
|
263
248
|
slot: SlotNumber,
|
|
264
|
-
): Map<string, Map<string,
|
|
249
|
+
): Map<string, Map<string, CheckpointAttestation>> {
|
|
265
250
|
if (!map.has(slot)) {
|
|
266
|
-
map.set(slot, new Map<string, Map<string,
|
|
251
|
+
map.set(slot, new Map<string, Map<string, CheckpointAttestation>>());
|
|
267
252
|
}
|
|
268
253
|
return map.get(slot)!;
|
|
269
254
|
}
|
|
270
255
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
*
|
|
274
|
-
* Fetch the proposal mapping, if it does not exist, then create a mapping and return it
|
|
275
|
-
* @param map - The map to fetch from
|
|
276
|
-
* @param proposalId - The proposal id to fetch
|
|
277
|
-
* @returns The proposal mapping
|
|
278
|
-
*/
|
|
279
|
-
function getProposalOrDefault(
|
|
280
|
-
map: Map<string, Map<string, BlockAttestation>>,
|
|
256
|
+
function getCheckpointProposalOrDefault(
|
|
257
|
+
map: Map<string, Map<string, CheckpointAttestation>>,
|
|
281
258
|
proposalId: string,
|
|
282
|
-
): Map<string,
|
|
259
|
+
): Map<string, CheckpointAttestation> {
|
|
283
260
|
if (!map.has(proposalId)) {
|
|
284
|
-
map.set(proposalId, new Map<string,
|
|
261
|
+
map.set(proposalId, new Map<string, CheckpointAttestation>());
|
|
285
262
|
}
|
|
286
263
|
return map.get(proposalId)!;
|
|
287
264
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
2
|
import type { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
+
CheckpointAttestation,
|
|
5
6
|
ConsensusPayload,
|
|
6
7
|
SignatureDomainSeparator,
|
|
7
8
|
getHashedSignaturePayloadEthSignedMessage,
|
|
8
9
|
} from '@aztec/stdlib/p2p';
|
|
9
|
-
import {
|
|
10
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
10
11
|
|
|
11
12
|
import { type LocalAccount, generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
12
13
|
|
|
@@ -20,26 +21,31 @@ export const generateAccount = (): LocalAccount => {
|
|
|
20
21
|
return privateKeyToAccount(privateKey);
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
/** Mock Attestation
|
|
24
|
+
/** Mock Checkpoint Attestation
|
|
24
25
|
*
|
|
25
|
-
* @param signer A
|
|
26
|
+
* @param signer A Secp256k1Signer to create a signature
|
|
26
27
|
* @param slot The slot number the attestation is for
|
|
27
|
-
* @
|
|
28
|
+
* @param archive The archive root (defaults to random)
|
|
29
|
+
* @param header The checkpoint header (defaults to random with given slot)
|
|
30
|
+
* @returns A Checkpoint Attestation
|
|
28
31
|
*/
|
|
29
|
-
export const
|
|
32
|
+
export const mockCheckpointAttestation = (
|
|
30
33
|
signer: Secp256k1Signer,
|
|
31
34
|
slot: number = 0,
|
|
32
35
|
archive: Fr = Fr.random(),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const payload = new ConsensusPayload(header
|
|
36
|
+
header?: CheckpointHeader,
|
|
37
|
+
): CheckpointAttestation => {
|
|
38
|
+
header = header ?? CheckpointHeader.random({ slotNumber: SlotNumber(slot) });
|
|
39
|
+
const payload = new ConsensusPayload(header, archive);
|
|
37
40
|
|
|
38
|
-
const attestationHash = getHashedSignaturePayloadEthSignedMessage(
|
|
41
|
+
const attestationHash = getHashedSignaturePayloadEthSignedMessage(
|
|
42
|
+
payload,
|
|
43
|
+
SignatureDomainSeparator.checkpointAttestation,
|
|
44
|
+
);
|
|
39
45
|
const attestationSignature = signer.sign(attestationHash);
|
|
40
46
|
|
|
41
|
-
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.
|
|
47
|
+
const proposalHash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.checkpointProposal);
|
|
42
48
|
const proposerSignature = signer.sign(proposalHash);
|
|
43
49
|
|
|
44
|
-
return new
|
|
50
|
+
return new CheckpointAttestation(payload, attestationSignature, proposerSignature);
|
|
45
51
|
};
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
LmdbMetrics,
|
|
8
8
|
type LmdbStatsCallback,
|
|
9
9
|
type Meter,
|
|
10
|
+
type MetricDefinition,
|
|
10
11
|
Metrics,
|
|
11
|
-
type MetricsType,
|
|
12
12
|
type ObservableGauge,
|
|
13
13
|
type TelemetryClient,
|
|
14
14
|
type UpDownCounter,
|
|
@@ -20,10 +20,10 @@ export enum PoolName {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
type MetricsLabels = {
|
|
23
|
-
objectInMempool:
|
|
24
|
-
objectSize:
|
|
25
|
-
itemsAdded:
|
|
26
|
-
itemMinedDelay:
|
|
23
|
+
objectInMempool: MetricDefinition;
|
|
24
|
+
objectSize: MetricDefinition;
|
|
25
|
+
itemsAdded: MetricDefinition;
|
|
26
|
+
itemMinedDelay: MetricDefinition;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -85,14 +85,9 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
85
85
|
|
|
86
86
|
const metricsLabels = getMetricsLabels(name);
|
|
87
87
|
|
|
88
|
-
this.objectsInMempool = this.meter.createObservableGauge(metricsLabels.objectInMempool
|
|
89
|
-
description: 'The current number of transactions in the mempool',
|
|
90
|
-
});
|
|
88
|
+
this.objectsInMempool = this.meter.createObservableGauge(metricsLabels.objectInMempool);
|
|
91
89
|
|
|
92
|
-
this.objectSize = this.meter.createHistogram(metricsLabels.objectSize
|
|
93
|
-
unit: 'By',
|
|
94
|
-
description: 'The size of transactions in the mempool',
|
|
95
|
-
});
|
|
90
|
+
this.objectSize = this.meter.createHistogram(metricsLabels.objectSize);
|
|
96
91
|
|
|
97
92
|
this.dbMetrics = new LmdbMetrics(
|
|
98
93
|
this.meter,
|
|
@@ -102,13 +97,9 @@ export class PoolInstrumentation<PoolObject extends Gossipable> {
|
|
|
102
97
|
dbStats,
|
|
103
98
|
);
|
|
104
99
|
|
|
105
|
-
this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded
|
|
106
|
-
description: 'The number of transactions added to the mempool',
|
|
107
|
-
});
|
|
100
|
+
this.addObjectCounter = this.meter.createUpDownCounter(metricsLabels.itemsAdded);
|
|
108
101
|
|
|
109
|
-
this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay
|
|
110
|
-
description: 'Delay between transaction added and evicted from the mempool',
|
|
111
|
-
});
|
|
102
|
+
this.minedDelay = this.meter.createHistogram(metricsLabels.itemMinedDelay);
|
|
112
103
|
|
|
113
104
|
this.meter.addBatchObservableCallback(this.observeStats, [this.objectsInMempool]);
|
|
114
105
|
}
|
|
@@ -24,7 +24,7 @@ The lifecycle of transactions in the pool is summarised in the following table:
|
|
|
24
24
|
|
|
25
25
|
**Note on why Soft Delete:**
|
|
26
26
|
Mined transactions are soft-deleted rather than permanently removed to support:
|
|
27
|
-
1. Reorg handling — If a chain reorganization occurs, soft-deleted transactions are still available in the mempool
|
|
27
|
+
1. Reorg handling — If a chain reorganization occurs, soft-deleted transactions are still available in the mempool
|
|
28
28
|
2. Slash condition detection — The epoch prune watcher needs access to transactions from pruned epochs to correctly identify data withholding slash conditions. Without soft-delete, transactions invalidated by reorgs (e.g., built on removed blocks) would be lost, causing false positives for data withholding violations.
|
|
29
29
|
|
|
30
30
|
Mined transactions are permanently deleted via `cleanupDeletedMinedTxs()` once their original block is finalized on L1, ensuring theyremain available during the uncertainty window.
|
|
@@ -34,7 +34,7 @@ Alternatively, mined transactions can be permanently deleted immediately by pass
|
|
|
34
34
|
|
|
35
35
|
| Method | Description |
|
|
36
36
|
|--------|-------------|
|
|
37
|
-
| `addTxs(txs, opts?)` | Adds transactions to the pool. Duplicates are
|
|
37
|
+
| `addTxs(txs, opts?)` | Adds transactions to the pool. Duplicates and nullifier conflicts are handled. Returns count of newly added txs. |
|
|
38
38
|
| `deleteTxs(txHashes, opts?)` | Removes transactions from the pool. Supports soft-delete for mined txs. |
|
|
39
39
|
| `markAsMined(txHashes, blockHeader)` | Marks transactions as included in a block. |
|
|
40
40
|
| `markMinedAsPending(txHashes, blockNumber)` | Reverts mined transactions to pending (used during reorgs). |
|
|
@@ -91,6 +91,7 @@ The pool maintains several KV maps and indexes:
|
|
|
91
91
|
| `#txHashToHistoricalBlockHeaderHash` | Anchor block reference for each tx |
|
|
92
92
|
| `#historicalHeaderToTxHash` | Index from historical block → tx hashes |
|
|
93
93
|
| `#feePayerToTxHash` | Index from fee payer address → tx hashes |
|
|
94
|
+
| `#pendingNullifierToTxHash` | Index from nullifier → tx hash |
|
|
94
95
|
| `#archivedTxs` | Archived transactions for historical lookup |
|
|
95
96
|
|
|
96
97
|
#### In-Memory Caches
|
|
@@ -117,15 +118,17 @@ The priority is stored as a hex string derived from a 32-byte buffer representat
|
|
|
117
118
|
When `addTxs()` is called:
|
|
118
119
|
|
|
119
120
|
1. Check for duplicates (skip if tx already exists)
|
|
120
|
-
2.
|
|
121
|
-
3.
|
|
122
|
-
4.
|
|
121
|
+
2. Check for nullifier conflicts (see Nullifier Deduplication below)
|
|
122
|
+
3. Store the serialized tx in `#txs`
|
|
123
|
+
4. Index the tx by its anchor block hash
|
|
124
|
+
5. If not already mined, add to pending indexes:
|
|
123
125
|
- Priority-to-hash index (for ordering)
|
|
124
126
|
- Historical header index (for reorg handling)
|
|
125
127
|
- Fee payer index (for balance validation)
|
|
126
|
-
|
|
127
|
-
6.
|
|
128
|
-
7.
|
|
128
|
+
- Nullifier-to-tx-hash index (for conflict detection)
|
|
129
|
+
6. Record metrics
|
|
130
|
+
7. Trigger eviction rules for `TXS_ADDED` event
|
|
131
|
+
8. Emit `txs-added` event
|
|
129
132
|
|
|
130
133
|
### 2. Marking as Mined
|
|
131
134
|
|
|
@@ -152,6 +155,16 @@ The `deleteTxs()` method handles two cases:
|
|
|
152
155
|
|
|
153
156
|
Soft-deleted mined transactions are retained for potential future reference and can be permanently cleaned up later via `cleanupDeletedMinedTxs()`.
|
|
154
157
|
|
|
158
|
+
### Nullifier Deduplication
|
|
159
|
+
|
|
160
|
+
The pool prevents nullifier spam attacks by ensuring only one pending transaction can reference each unique nullifier. When an incoming transaction shares nullifiers with existing pending transactions:
|
|
161
|
+
|
|
162
|
+
- **Higher fee wins**: If the incoming tx has a higher priority fee than ALL conflicting txs, those conflicting txs are replaced
|
|
163
|
+
- **Existing tx wins on tie**: If any conflicting tx has an equal or higher fee, the incoming tx is rejected
|
|
164
|
+
- **Partial overlap counts**: Even a single shared nullifier triggers conflict resolution
|
|
165
|
+
|
|
166
|
+
This is enforced at entry time via the `#pendingNullifierToTxHash` index, which maps each nullifier to the tx hash that references it. The index is maintained atomically with tx additions and removals.
|
|
167
|
+
|
|
155
168
|
## Eviction System
|
|
156
169
|
|
|
157
170
|
The eviction system automatically removes invalid or low-priority transactions based on configurable rules. See the [`eviction/`](eviction/) subdirectory for implementation details.
|
|
@@ -189,7 +202,7 @@ The [`EvictionManager`](eviction/eviction_manager.ts) coordinates eviction by:
|
|
|
189
202
|
|-------|---------|---------|
|
|
190
203
|
| `TXS_ADDED` | New transactions added | Enforce pool size limits |
|
|
191
204
|
| `BLOCK_MINED` | Block finalized | Remove invalidated transactions |
|
|
192
|
-
| `CHAIN_PRUNED` | Chain reorganization | Remove txs referencing pruned blocks |
|
|
205
|
+
| `CHAIN_PRUNED` | Chain reorganization | Remove txs referencing pruned blocks and re-evaluate fee payer balances |
|
|
193
206
|
|
|
194
207
|
### Eviction Rules
|
|
195
208
|
|
|
@@ -211,13 +224,15 @@ Evicts transactions that reference blocks no longer in the canonical chain:
|
|
|
211
224
|
- Checks each pending tx's anchor block hash against the archive tree
|
|
212
225
|
- Removes txs whose anchor blocks are not found (pruned)
|
|
213
226
|
|
|
214
|
-
#### 3. `
|
|
227
|
+
#### 3. `FeePayerBalanceEvictionRule`
|
|
215
228
|
|
|
216
|
-
**Triggers on:** `BLOCK_MINED`, `CHAIN_PRUNED`
|
|
229
|
+
**Triggers on:** `TXS_ADDED`, `BLOCK_MINED`, `CHAIN_PRUNED`
|
|
217
230
|
|
|
218
|
-
Evicts transactions
|
|
231
|
+
Evicts low-priority transactions when a fee payer's pending fee limits exceed their Fee Juice balance:
|
|
219
232
|
|
|
220
|
-
-
|
|
233
|
+
- Evaluates transactions in priority order so higher-priority claims can fund lower-priority spends
|
|
234
|
+
- Accounts for self-funding claims made during setup
|
|
235
|
+
- Removes evictable txs that do not fit within the running balance
|
|
221
236
|
|
|
222
237
|
#### 4. `LowPriorityEvictionRule`
|
|
223
238
|
|