@aztec/p2p 0.0.1-commit.e310a4c8 → 0.0.1-commit.e558bd1c
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 +3 -3
- package/dest/client/factory.d.ts.map +1 -1
- package/dest/client/factory.js +5 -3
- package/dest/client/interface.d.ts +9 -2
- package/dest/client/interface.d.ts.map +1 -1
- package/dest/client/p2p_client.d.ts +7 -4
- package/dest/client/p2p_client.d.ts.map +1 -1
- package/dest/client/p2p_client.js +17 -7
- package/dest/client/test/tx_proposal_collector/proposal_tx_collector_worker.js +1 -1
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +3 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts +94 -87
- package/dest/mem_pools/attestation_pool/attestation_pool.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/attestation_pool.js +411 -3
- package/dest/mem_pools/attestation_pool/attestation_pool_test_suite.d.ts +2 -2
- 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 +351 -85
- package/dest/mem_pools/attestation_pool/index.d.ts +2 -3
- package/dest/mem_pools/attestation_pool/index.d.ts.map +1 -1
- package/dest/mem_pools/attestation_pool/index.js +1 -2
- package/dest/mem_pools/index.d.ts +2 -2
- package/dest/mem_pools/index.d.ts.map +1 -1
- package/dest/mem_pools/index.js +1 -1
- package/dest/mem_pools/interface.d.ts +3 -3
- package/dest/mem_pools/interface.d.ts.map +1 -1
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts +2 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/index.js +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts +43 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/archive/tx_archive.js +103 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts +47 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/eviction_manager.js +119 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.js +90 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts +19 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.js +89 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts +10 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/index.js +11 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts +131 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/interfaces.js +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts +17 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.js +91 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts +16 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.js +70 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts +20 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.js +63 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts +15 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.js +19 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts +5 -0
- package/dest/mem_pools/tx_pool_v2/index.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/index.js +4 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts +197 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/interfaces.js +6 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts +71 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_metadata.js +95 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts +26 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_bench_metrics.js +70 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts +99 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_indices.js +332 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts +55 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2.js +156 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts +69 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.d.ts.map +1 -0
- package/dest/mem_pools/tx_pool_v2/tx_pool_v2_impl.js +748 -0
- package/dest/msg_validators/attestation_validator/fisherman_attestation_validator.d.ts +3 -3
- package/dest/msg_validators/attestation_validator/fisherman_attestation_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/index.d.ts +2 -1
- package/dest/services/index.d.ts.map +1 -1
- package/dest/services/index.js +1 -0
- package/dest/services/libp2p/libp2p_service.d.ts +74 -33
- package/dest/services/libp2p/libp2p_service.d.ts.map +1 -1
- package/dest/services/libp2p/libp2p_service.js +299 -228
- package/dest/services/reqresp/batch-tx-requester/batch_tx_requester.d.ts +4 -4
- 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 +8 -8
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts +6 -4
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_handler.js +16 -11
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts +15 -10
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.d.ts.map +1 -1
- package/dest/services/reqresp/protocols/block_txs/block_txs_reqresp.js +12 -11
- package/dest/services/service.d.ts +18 -1
- package/dest/services/service.d.ts.map +1 -1
- package/dest/services/tx_collection/config.d.ts +3 -3
- package/dest/services/tx_collection/config.js +3 -3
- package/dest/services/tx_collection/fast_tx_collection.d.ts +4 -5
- package/dest/services/tx_collection/fast_tx_collection.d.ts.map +1 -1
- package/dest/services/tx_collection/fast_tx_collection.js +10 -14
- package/dest/services/tx_collection/index.d.ts +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.d.ts +12 -12
- package/dest/services/tx_collection/proposal_tx_collector.d.ts.map +1 -1
- package/dest/services/tx_collection/proposal_tx_collector.js +4 -5
- package/dest/services/tx_file_store/config.d.ts +18 -0
- package/dest/services/tx_file_store/config.d.ts.map +1 -0
- package/dest/services/tx_file_store/config.js +26 -0
- package/dest/services/tx_file_store/index.d.ts +4 -0
- package/dest/services/tx_file_store/index.d.ts.map +1 -0
- package/dest/services/tx_file_store/index.js +3 -0
- package/dest/services/tx_file_store/instrumentation.d.ts +15 -0
- package/dest/services/tx_file_store/instrumentation.d.ts.map +1 -0
- package/dest/services/tx_file_store/instrumentation.js +29 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts +47 -0
- package/dest/services/tx_file_store/tx_file_store.d.ts.map +1 -0
- package/dest/services/tx_file_store/tx_file_store.js +149 -0
- package/dest/test-helpers/testbench-utils.d.ts +10 -16
- package/dest/test-helpers/testbench-utils.d.ts.map +1 -1
- package/dest/test-helpers/testbench-utils.js +32 -30
- package/dest/testbench/p2p_client_testbench_worker.js +1 -1
- package/package.json +14 -14
- package/src/client/factory.ts +7 -4
- package/src/client/interface.ts +13 -1
- package/src/client/p2p_client.ts +25 -8
- package/src/client/test/tx_proposal_collector/proposal_tx_collector_worker.ts +1 -1
- package/src/config.ts +8 -1
- package/src/mem_pools/attestation_pool/attestation_pool.ts +444 -90
- package/src/mem_pools/attestation_pool/attestation_pool_test_suite.ts +436 -100
- package/src/mem_pools/attestation_pool/index.ts +9 -2
- package/src/mem_pools/index.ts +1 -1
- package/src/mem_pools/interface.ts +2 -2
- package/src/mem_pools/tx_pool_v2/README.md +209 -0
- package/src/mem_pools/tx_pool_v2/archive/index.ts +1 -0
- package/src/mem_pools/tx_pool_v2/archive/tx_archive.ts +120 -0
- package/src/mem_pools/tx_pool_v2/eviction/eviction_manager.ts +147 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_eviction_rule.ts +118 -0
- package/src/mem_pools/tx_pool_v2/eviction/fee_payer_balance_pre_add_rule.ts +111 -0
- package/src/mem_pools/tx_pool_v2/eviction/index.ts +23 -0
- package/src/mem_pools/tx_pool_v2/eviction/interfaces.ts +164 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_mining_rule.ts +74 -0
- package/src/mem_pools/tx_pool_v2/eviction/invalid_txs_after_reorg_rule.ts +101 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_eviction_rule.ts +86 -0
- package/src/mem_pools/tx_pool_v2/eviction/low_priority_pre_add_rule.ts +72 -0
- package/src/mem_pools/tx_pool_v2/eviction/nullifier_conflict_rule.ts +31 -0
- package/src/mem_pools/tx_pool_v2/index.ts +11 -0
- package/src/mem_pools/tx_pool_v2/interfaces.ts +227 -0
- package/src/mem_pools/tx_pool_v2/tx_metadata.ts +161 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_bench_metrics.ts +77 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_indices.ts +417 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2.ts +212 -0
- package/src/mem_pools/tx_pool_v2/tx_pool_v2_impl.ts +882 -0
- package/src/msg_validators/attestation_validator/fisherman_attestation_validator.ts +2 -2
- package/src/services/dummy_service.ts +6 -0
- package/src/services/index.ts +1 -0
- package/src/services/libp2p/libp2p_service.ts +304 -230
- package/src/services/reqresp/batch-tx-requester/README.md +7 -7
- package/src/services/reqresp/batch-tx-requester/batch_tx_requester.ts +11 -11
- package/src/services/reqresp/protocols/block_txs/block_txs_handler.ts +22 -13
- package/src/services/reqresp/protocols/block_txs/block_txs_reqresp.ts +21 -15
- package/src/services/service.ts +20 -0
- package/src/services/tx_collection/config.ts +6 -6
- package/src/services/tx_collection/fast_tx_collection.ts +14 -24
- package/src/services/tx_collection/index.ts +1 -1
- package/src/services/tx_collection/proposal_tx_collector.ts +12 -14
- package/src/services/tx_file_store/config.ts +43 -0
- package/src/services/tx_file_store/index.ts +3 -0
- package/src/services/tx_file_store/instrumentation.ts +36 -0
- package/src/services/tx_file_store/tx_file_store.ts +173 -0
- package/src/test-helpers/testbench-utils.ts +18 -39
- package/src/testbench/p2p_client_testbench_worker.ts +1 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts +0 -40
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/kv_attestation_pool.js +0 -218
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts +0 -31
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.d.ts.map +0 -1
- package/dest/mem_pools/attestation_pool/memory_attestation_pool.js +0 -180
- package/src/mem_pools/attestation_pool/kv_attestation_pool.ts +0 -320
- package/src/mem_pools/attestation_pool/memory_attestation_pool.ts +0 -264
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
4
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
5
5
|
import { makeBlockHeader, makeBlockProposal, makeCheckpointHeader, makeCheckpointProposal } from '@aztec/stdlib/testing';
|
|
6
|
-
import { MAX_PROPOSALS_PER_SLOT } from './
|
|
6
|
+
import { MAX_PROPOSALS_PER_POSITION, MAX_PROPOSALS_PER_SLOT } from './attestation_pool.js';
|
|
7
7
|
import { mockCheckpointAttestation } from './mocks.js';
|
|
8
8
|
const NUMBER_OF_SIGNERS_PER_TEST = 4;
|
|
9
9
|
export function describeAttestationPool(getAttestationPool) {
|
|
@@ -42,20 +42,16 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
42
42
|
const slotNumber = 420;
|
|
43
43
|
const archive = Fr.random();
|
|
44
44
|
const attestations = signers.slice(0, -1).map((signer)=>mockCheckpointAttestation(signer, slotNumber, archive));
|
|
45
|
-
await ap.
|
|
45
|
+
await ap.addOwnCheckpointAttestations(attestations);
|
|
46
46
|
const retrievedAttestations = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(slotNumber), archive.toString());
|
|
47
47
|
expect(retrievedAttestations.length).toBe(attestations.length);
|
|
48
48
|
compareCheckpointAttestations(retrievedAttestations, attestations);
|
|
49
|
-
// Check hasCheckpointAttestation for added attestations
|
|
50
|
-
for (const attestation of attestations){
|
|
51
|
-
expect(await ap.hasCheckpointAttestation(attestation)).toBe(true);
|
|
52
|
-
}
|
|
53
49
|
const retrievedAttestationsForSlot = await ap.getCheckpointAttestationsForSlot(SlotNumber(slotNumber));
|
|
54
50
|
expect(retrievedAttestationsForSlot.length).toBe(attestations.length);
|
|
55
51
|
compareCheckpointAttestations(retrievedAttestationsForSlot, attestations);
|
|
56
52
|
// Add another one
|
|
57
53
|
const newAttestation = mockCheckpointAttestation(signers[NUMBER_OF_SIGNERS_PER_TEST - 1], slotNumber, archive);
|
|
58
|
-
await ap.
|
|
54
|
+
await ap.addOwnCheckpointAttestations([
|
|
59
55
|
newAttestation
|
|
60
56
|
]);
|
|
61
57
|
const retrievedAttestationsAfterAdd = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(slotNumber), archive.toString());
|
|
@@ -64,7 +60,6 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
64
60
|
...attestations,
|
|
65
61
|
newAttestation
|
|
66
62
|
]);
|
|
67
|
-
expect(await ap.hasCheckpointAttestation(newAttestation)).toBe(true);
|
|
68
63
|
const retrievedAttestationsForSlotAfterAdd = await ap.getCheckpointAttestationsForSlot(SlotNumber(slotNumber));
|
|
69
64
|
expect(retrievedAttestationsForSlotAfterAdd.length).toBe(attestations.length + 1);
|
|
70
65
|
compareCheckpointAttestations(retrievedAttestationsForSlotAfterAdd, [
|
|
@@ -72,14 +67,9 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
72
67
|
newAttestation
|
|
73
68
|
]);
|
|
74
69
|
// Delete by slot
|
|
75
|
-
await ap.
|
|
70
|
+
await ap.deleteOlderThan(SlotNumber(slotNumber + 1));
|
|
76
71
|
const retreivedAttestationsAfterDelete = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(slotNumber), archive.toString());
|
|
77
72
|
expect(retreivedAttestationsAfterDelete.length).toBe(0);
|
|
78
|
-
// Check hasCheckpointAttestation after deletion
|
|
79
|
-
for (const attestation of attestations){
|
|
80
|
-
expect(await ap.hasCheckpointAttestation(attestation)).toBe(false);
|
|
81
|
-
}
|
|
82
|
-
expect(await ap.hasCheckpointAttestation(newAttestation)).toBe(false);
|
|
83
73
|
});
|
|
84
74
|
it('should handle duplicate proposals in a slot', async ()=>{
|
|
85
75
|
const slotNumber = 420;
|
|
@@ -94,13 +84,13 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
94
84
|
attestations.push(mockCheckpointAttestation(signer, slotNumber, archive, header));
|
|
95
85
|
}
|
|
96
86
|
// Add them to store and check we end up with only one
|
|
97
|
-
await ap.
|
|
87
|
+
await ap.addOwnCheckpointAttestations(attestations);
|
|
98
88
|
const retreivedAttestations = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(slotNumber), archive.toString());
|
|
99
89
|
expect(retreivedAttestations.length).toBe(1);
|
|
100
90
|
expect(retreivedAttestations[0].toBuffer()).toEqual(attestations[0].toBuffer());
|
|
101
91
|
expect(retreivedAttestations[0].getSender()?.toString()).toEqual(signer.address.toString());
|
|
102
92
|
// Try adding them on another operation and check they are still not duplicated
|
|
103
|
-
await ap.
|
|
93
|
+
await ap.addOwnCheckpointAttestations([
|
|
104
94
|
attestations[0]
|
|
105
95
|
]);
|
|
106
96
|
expect(await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(slotNumber), archive.toString())).toHaveLength(1);
|
|
@@ -113,7 +103,7 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
113
103
|
4
|
|
114
104
|
];
|
|
115
105
|
const attestations = signers.map((signer, i)=>mockCheckpointAttestation(signer, slotNumbers[i]));
|
|
116
|
-
await ap.
|
|
106
|
+
await ap.addOwnCheckpointAttestations(attestations);
|
|
117
107
|
for (const attestation of attestations){
|
|
118
108
|
const slot = attestation.payload.header.slotNumber;
|
|
119
109
|
const archive = attestation.archive.toString();
|
|
@@ -137,7 +127,7 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
137
127
|
Fr.random()
|
|
138
128
|
];
|
|
139
129
|
const attestations = signers.map((signer, i)=>mockCheckpointAttestation(signer, slotNumbers[i], archives[i]));
|
|
140
|
-
await ap.
|
|
130
|
+
await ap.addOwnCheckpointAttestations(attestations);
|
|
141
131
|
for (const attestation of attestations){
|
|
142
132
|
const slot = attestation.payload.header.slotNumber;
|
|
143
133
|
const proposalId = attestation.archive.toString();
|
|
@@ -160,10 +150,10 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
160
150
|
];
|
|
161
151
|
const attestations = (await Promise.all(slotNumbers.map((slotNumber)=>createCheckpointAttestationsForSlot(slotNumber)))).flat();
|
|
162
152
|
const proposalId = attestations[0].archive.toString();
|
|
163
|
-
await ap.
|
|
153
|
+
await ap.addOwnCheckpointAttestations(attestations);
|
|
164
154
|
const attestationsForSlot1 = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(1), proposalId);
|
|
165
155
|
expect(attestationsForSlot1.length).toBe(signers.length);
|
|
166
|
-
await ap.
|
|
156
|
+
await ap.deleteOlderThan(SlotNumber(73));
|
|
167
157
|
const attestationsForSlot1AfterDelete = await ap.getCheckpointAttestationsForSlotAndProposal(SlotNumber(1), proposalId);
|
|
168
158
|
expect(attestationsForSlot1AfterDelete.length).toBe(0);
|
|
169
159
|
});
|
|
@@ -174,57 +164,46 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
174
164
|
const archive = Fr.random();
|
|
175
165
|
const proposal = await mockBlockProposalForPool(signers[0], slotNumber, archive);
|
|
176
166
|
const proposalId = proposal.archive.toString();
|
|
177
|
-
await ap.
|
|
167
|
+
const result = await ap.tryAddBlockProposal(proposal);
|
|
168
|
+
expect(result.added).toBe(true);
|
|
169
|
+
expect(result.alreadyExists).toBe(false);
|
|
170
|
+
expect(result.totalForPosition).toBe(1);
|
|
178
171
|
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
179
172
|
expect(retrievedProposal).toBeDefined();
|
|
180
173
|
expect(retrievedProposal).toEqual(proposal);
|
|
181
|
-
// Check hasBlockProposal with both id and object
|
|
182
|
-
expect(await ap.hasBlockProposal(proposalId)).toBe(true);
|
|
183
|
-
expect(await ap.hasBlockProposal(proposal)).toBe(true);
|
|
184
174
|
});
|
|
185
175
|
it('should return undefined for non-existent block proposal', async ()=>{
|
|
186
176
|
const nonExistentId = Fr.random().toString();
|
|
187
177
|
const retrievedProposal = await ap.getBlockProposal(nonExistentId);
|
|
188
178
|
expect(retrievedProposal).toBeUndefined();
|
|
189
|
-
// Check hasBlockProposal returns false for non-existent proposal
|
|
190
|
-
expect(await ap.hasBlockProposal(nonExistentId)).toBe(false);
|
|
191
179
|
});
|
|
192
|
-
it('should
|
|
180
|
+
it('should return alreadyExists when adding proposal with same id', async ()=>{
|
|
193
181
|
const slotNumber = 420;
|
|
194
182
|
const archive = Fr.random();
|
|
195
183
|
const proposal1 = await mockBlockProposalForPool(signers[0], slotNumber, archive);
|
|
196
184
|
const proposalId = proposal1.archive.toString();
|
|
197
|
-
await ap.
|
|
185
|
+
const result1 = await ap.tryAddBlockProposal(proposal1);
|
|
186
|
+
expect(result1.added).toBe(true);
|
|
187
|
+
expect(result1.alreadyExists).toBe(false);
|
|
198
188
|
// Create a new proposal with same archive but different signer
|
|
199
189
|
const proposal2 = await mockBlockProposalForPool(signers[1], slotNumber, archive);
|
|
200
|
-
await ap.
|
|
190
|
+
const result2 = await ap.tryAddBlockProposal(proposal2);
|
|
191
|
+
expect(result2.added).toBe(false);
|
|
192
|
+
expect(result2.alreadyExists).toBe(true);
|
|
193
|
+
// Should still have the first proposal
|
|
201
194
|
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
202
195
|
expect(retrievedProposal).toBeDefined();
|
|
203
|
-
|
|
204
|
-
expect(retrievedProposal.
|
|
205
|
-
expect(retrievedProposal.getSender()?.toString()).toBe(signers[1].address.toString());
|
|
206
|
-
});
|
|
207
|
-
it('should handle block proposals with different slots and same archive', async ()=>{
|
|
208
|
-
const archive = Fr.random();
|
|
209
|
-
const proposal1 = await mockBlockProposalForPool(signers[0], 100, archive);
|
|
210
|
-
const proposal2 = await mockBlockProposalForPool(signers[1], 200, archive);
|
|
211
|
-
const proposalId = archive.toString();
|
|
212
|
-
await ap.addBlockProposal(proposal1);
|
|
213
|
-
await ap.addBlockProposal(proposal2);
|
|
214
|
-
// Should get the latest one added
|
|
215
|
-
const retrievedProposal = await ap.getBlockProposal(proposalId);
|
|
216
|
-
expect(retrievedProposal).toBeDefined();
|
|
217
|
-
expect(retrievedProposal.toBuffer()).toEqual(proposal2.toBuffer());
|
|
218
|
-
expect(retrievedProposal.slotNumber).toBe(SlotNumber(200));
|
|
196
|
+
expect(retrievedProposal.toBuffer()).toEqual(proposal1.toBuffer());
|
|
197
|
+
expect(retrievedProposal.getSender()?.toString()).toBe(signers[0].address.toString());
|
|
219
198
|
});
|
|
220
199
|
});
|
|
221
200
|
describe('CheckpointProposal in attestation pool', ()=>{
|
|
222
|
-
const mockCheckpointProposalForPool = (signer, slotNumber, archive = Fr.random())=>{
|
|
201
|
+
const mockCheckpointProposalForPool = async (signer, slotNumber, archive = Fr.random())=>{
|
|
223
202
|
const checkpointHeader = makeCheckpointHeader(1, {
|
|
224
203
|
slotNumber: SlotNumber(slotNumber)
|
|
225
204
|
});
|
|
226
205
|
const blockHeader = makeBlockHeader(1);
|
|
227
|
-
|
|
206
|
+
const proposal = await makeCheckpointProposal({
|
|
228
207
|
signer,
|
|
229
208
|
checkpointHeader,
|
|
230
209
|
archiveRoot: archive,
|
|
@@ -232,37 +211,23 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
232
211
|
blockHeader
|
|
233
212
|
}
|
|
234
213
|
});
|
|
214
|
+
// Return the core version since tryAddCheckpointProposal now takes CheckpointProposalCore
|
|
215
|
+
return proposal.toCore();
|
|
235
216
|
};
|
|
236
|
-
it('should add and retrieve checkpoint proposal
|
|
217
|
+
it('should add and retrieve checkpoint proposal', async ()=>{
|
|
237
218
|
const slotNumber = 420;
|
|
238
219
|
const archive = Fr.random();
|
|
239
220
|
const proposal = await mockCheckpointProposalForPool(signers[0], slotNumber, archive);
|
|
240
221
|
const proposalId = proposal.archive.toString();
|
|
241
|
-
await ap.
|
|
222
|
+
const result = await ap.tryAddCheckpointProposal(proposal);
|
|
223
|
+
expect(result.added).toBe(true);
|
|
224
|
+
expect(result.alreadyExists).toBe(false);
|
|
225
|
+
expect(result.totalForPosition).toBe(1);
|
|
242
226
|
const retrievedProposal = await ap.getCheckpointProposal(proposalId);
|
|
243
227
|
expect(retrievedProposal).toBeDefined();
|
|
244
|
-
|
|
245
|
-
expect(retrievedProposal.toBuffer()).toEqual(proposal.toCore().toBuffer());
|
|
246
|
-
// Check hasCheckpointProposal with both id and object
|
|
247
|
-
expect(await ap.hasCheckpointProposal(proposalId)).toBe(true);
|
|
248
|
-
expect(await ap.hasCheckpointProposal(proposal)).toBe(true);
|
|
249
|
-
});
|
|
250
|
-
it('should extract and store block proposal when adding checkpoint proposal with lastBlock', async ()=>{
|
|
251
|
-
const slotNumber = 420;
|
|
252
|
-
const archive = Fr.random();
|
|
253
|
-
const proposal = await mockCheckpointProposalForPool(signers[0], slotNumber, archive);
|
|
254
|
-
const proposalId = proposal.archive.toString();
|
|
255
|
-
// Verify the proposal has a lastBlock
|
|
256
|
-
const expectedBlockProposal = proposal.getBlockProposal();
|
|
257
|
-
expect(expectedBlockProposal).toBeDefined();
|
|
258
|
-
await ap.addCheckpointProposal(proposal);
|
|
259
|
-
// The block proposal should be stored separately and retrievable
|
|
260
|
-
const retrievedBlockProposal = await ap.getBlockProposal(proposalId);
|
|
261
|
-
expect(retrievedBlockProposal).toBeDefined();
|
|
262
|
-
expect(retrievedBlockProposal.archive.toString()).toBe(archive.toString());
|
|
263
|
-
expect(retrievedBlockProposal.blockHeader.toBuffer()).toEqual(expectedBlockProposal.blockHeader.toBuffer());
|
|
228
|
+
expect(retrievedProposal.toBuffer()).toEqual(proposal.toBuffer());
|
|
264
229
|
});
|
|
265
|
-
it('should
|
|
230
|
+
it('should handle checkpoint proposal without lastBlock (caller extracts and adds block separately)', async ()=>{
|
|
266
231
|
const slotNumber = 420;
|
|
267
232
|
const archive = Fr.random();
|
|
268
233
|
const checkpointHeader = makeCheckpointHeader(1, {
|
|
@@ -275,11 +240,12 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
275
240
|
archiveRoot: archive
|
|
276
241
|
});
|
|
277
242
|
const proposalId = proposal.archive.toString();
|
|
278
|
-
|
|
243
|
+
// Add the checkpoint core - block extraction is now caller responsibility
|
|
244
|
+
await ap.tryAddCheckpointProposal(proposal.toCore());
|
|
279
245
|
// The checkpoint proposal should be stored
|
|
280
246
|
const retrievedCheckpointProposal = await ap.getCheckpointProposal(proposalId);
|
|
281
247
|
expect(retrievedCheckpointProposal).toBeDefined();
|
|
282
|
-
//
|
|
248
|
+
// No block proposal was extracted (it had none anyway)
|
|
283
249
|
const retrievedBlockProposal = await ap.getBlockProposal(proposalId);
|
|
284
250
|
expect(retrievedBlockProposal).toBeUndefined();
|
|
285
251
|
});
|
|
@@ -287,34 +253,334 @@ export function describeAttestationPool(getAttestationPool) {
|
|
|
287
253
|
const nonExistentId = Fr.random().toString();
|
|
288
254
|
const retrievedProposal = await ap.getCheckpointProposal(nonExistentId);
|
|
289
255
|
expect(retrievedProposal).toBeUndefined();
|
|
290
|
-
// Check hasCheckpointProposal returns false for non-existent proposal
|
|
291
|
-
expect(await ap.hasCheckpointProposal(nonExistentId)).toBe(false);
|
|
292
256
|
});
|
|
293
|
-
it('should
|
|
257
|
+
it('should return alreadyExists when adding proposal with same id', async ()=>{
|
|
294
258
|
const slotNumber = 420;
|
|
295
259
|
const archive = Fr.random();
|
|
296
260
|
const proposal1 = await mockCheckpointProposalForPool(signers[0], slotNumber, archive);
|
|
297
261
|
const proposalId = proposal1.archive.toString();
|
|
298
|
-
await ap.
|
|
262
|
+
const result1 = await ap.tryAddCheckpointProposal(proposal1);
|
|
263
|
+
expect(result1.added).toBe(true);
|
|
264
|
+
expect(result1.alreadyExists).toBe(false);
|
|
299
265
|
// Create a new proposal with same archive but different signer
|
|
300
266
|
const proposal2 = await mockCheckpointProposalForPool(signers[1], slotNumber, archive);
|
|
301
|
-
await ap.
|
|
267
|
+
const result2 = await ap.tryAddCheckpointProposal(proposal2);
|
|
268
|
+
expect(result2.added).toBe(false);
|
|
269
|
+
expect(result2.alreadyExists).toBe(true);
|
|
270
|
+
// Should still have the first proposal
|
|
302
271
|
const retrievedProposal = await ap.getCheckpointProposal(proposalId);
|
|
303
272
|
expect(retrievedProposal).toBeDefined();
|
|
304
|
-
|
|
305
|
-
expect(retrievedProposal.
|
|
306
|
-
expect(retrievedProposal.getSender()?.toString()).toBe(signers[1].address.toString());
|
|
273
|
+
expect(retrievedProposal.toBuffer()).toEqual(proposal1.toBuffer());
|
|
274
|
+
expect(retrievedProposal.getSender()?.toString()).toBe(signers[0].address.toString());
|
|
307
275
|
});
|
|
308
|
-
it('should
|
|
276
|
+
it('should return added=false when exceeding capacity', async ()=>{
|
|
309
277
|
const slotNumber = 420;
|
|
310
278
|
// Add MAX_PROPOSALS_PER_SLOT proposals
|
|
311
279
|
for(let i = 0; i < MAX_PROPOSALS_PER_SLOT; i++){
|
|
312
280
|
const proposal = await mockCheckpointProposalForPool(signers[i % NUMBER_OF_SIGNERS_PER_TEST], slotNumber);
|
|
313
|
-
await ap.
|
|
281
|
+
const result = await ap.tryAddCheckpointProposal(proposal);
|
|
282
|
+
expect(result.added).toBe(true);
|
|
283
|
+
expect(result.totalForPosition).toBe(i + 1);
|
|
314
284
|
}
|
|
315
|
-
// The next proposal should
|
|
285
|
+
// The next proposal should not be added
|
|
316
286
|
const extraProposal = await mockCheckpointProposalForPool(signers[0], slotNumber);
|
|
317
|
-
await
|
|
287
|
+
const result = await ap.tryAddCheckpointProposal(extraProposal);
|
|
288
|
+
expect(result.added).toBe(false);
|
|
289
|
+
expect(result.alreadyExists).toBe(false);
|
|
290
|
+
expect(result.totalForPosition).toBe(MAX_PROPOSALS_PER_SLOT);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
describe('Duplicate proposal detection', ()=>{
|
|
294
|
+
const mockBlockProposalWithIndex = (signer, slotNumber, indexWithinCheckpoint, archive = Fr.random())=>{
|
|
295
|
+
const header = makeBlockHeader(1, {
|
|
296
|
+
slotNumber: SlotNumber(slotNumber)
|
|
297
|
+
});
|
|
298
|
+
return makeBlockProposal({
|
|
299
|
+
signer,
|
|
300
|
+
blockHeader: header,
|
|
301
|
+
archiveRoot: archive,
|
|
302
|
+
indexWithinCheckpoint: IndexWithinCheckpoint(indexWithinCheckpoint)
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
describe('tryAddBlockProposal duplicate detection', ()=>{
|
|
306
|
+
it('should return totalForPosition=1 when pool is empty', async ()=>{
|
|
307
|
+
const proposal = await mockBlockProposalWithIndex(signers[0], 100, 0);
|
|
308
|
+
const result = await ap.tryAddBlockProposal(proposal);
|
|
309
|
+
expect(result.added).toBe(true);
|
|
310
|
+
expect(result.alreadyExists).toBe(false);
|
|
311
|
+
expect(result.totalForPosition).toBe(1);
|
|
312
|
+
});
|
|
313
|
+
it('should return alreadyExists when same proposal exists', async ()=>{
|
|
314
|
+
const proposal = await mockBlockProposalWithIndex(signers[0], 100, 0);
|
|
315
|
+
await ap.tryAddBlockProposal(proposal);
|
|
316
|
+
const result = await ap.tryAddBlockProposal(proposal);
|
|
317
|
+
expect(result.added).toBe(false);
|
|
318
|
+
expect(result.alreadyExists).toBe(true);
|
|
319
|
+
expect(result.totalForPosition).toBe(1);
|
|
320
|
+
});
|
|
321
|
+
it('should detect duplicate via totalForPosition when different proposal exists at same position', async ()=>{
|
|
322
|
+
const slotNumber = 100;
|
|
323
|
+
const indexWithinCheckpoint = 2;
|
|
324
|
+
// Add first proposal
|
|
325
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
|
|
326
|
+
const result1 = await ap.tryAddBlockProposal(proposal1);
|
|
327
|
+
expect(result1.totalForPosition).toBe(1);
|
|
328
|
+
// Add a different proposal at same position - this is a duplicate (equivocation)
|
|
329
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
|
|
330
|
+
const result2 = await ap.tryAddBlockProposal(proposal2);
|
|
331
|
+
expect(result2.added).toBe(true);
|
|
332
|
+
expect(result2.alreadyExists).toBe(false);
|
|
333
|
+
// totalForPosition >= 2 indicates duplicate detection
|
|
334
|
+
expect(result2.totalForPosition).toBe(2);
|
|
335
|
+
});
|
|
336
|
+
it('should not detect duplicate for different positions in same slot', async ()=>{
|
|
337
|
+
const slotNumber = 100;
|
|
338
|
+
// Add proposal at index 0
|
|
339
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, 0);
|
|
340
|
+
await ap.tryAddBlockProposal(proposal1);
|
|
341
|
+
// Add proposal at index 1 (different position)
|
|
342
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, 1);
|
|
343
|
+
const result = await ap.tryAddBlockProposal(proposal2);
|
|
344
|
+
expect(result.added).toBe(true);
|
|
345
|
+
// totalForPosition = 1 means no duplicate for this position
|
|
346
|
+
expect(result.totalForPosition).toBe(1);
|
|
347
|
+
});
|
|
348
|
+
it('should not detect duplicate for same position in different slots', async ()=>{
|
|
349
|
+
const indexWithinCheckpoint = 0;
|
|
350
|
+
// Add proposal at slot 100
|
|
351
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[0], 100, indexWithinCheckpoint);
|
|
352
|
+
await ap.tryAddBlockProposal(proposal1);
|
|
353
|
+
// Add proposal at slot 200 (different slot)
|
|
354
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[1], 200, indexWithinCheckpoint);
|
|
355
|
+
const result = await ap.tryAddBlockProposal(proposal2);
|
|
356
|
+
expect(result.added).toBe(true);
|
|
357
|
+
// totalForPosition = 1 means no duplicate for this position
|
|
358
|
+
expect(result.totalForPosition).toBe(1);
|
|
359
|
+
});
|
|
360
|
+
it('should track multiple duplicates correctly via totalForPosition', async ()=>{
|
|
361
|
+
const slotNumber = 100;
|
|
362
|
+
const indexWithinCheckpoint = 0;
|
|
363
|
+
// Add multiple proposals for same position
|
|
364
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
|
|
365
|
+
const result1 = await ap.tryAddBlockProposal(proposal1);
|
|
366
|
+
expect(result1.totalForPosition).toBe(1);
|
|
367
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
|
|
368
|
+
const result2 = await ap.tryAddBlockProposal(proposal2);
|
|
369
|
+
expect(result2.totalForPosition).toBe(2);
|
|
370
|
+
// Add a third proposal for same position
|
|
371
|
+
const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
|
|
372
|
+
const result3 = await ap.tryAddBlockProposal(proposal3);
|
|
373
|
+
expect(result3.added).toBe(true);
|
|
374
|
+
expect(result3.totalForPosition).toBe(3);
|
|
375
|
+
});
|
|
376
|
+
it('should return added=false when exceeding capacity', async ()=>{
|
|
377
|
+
const slotNumber = 100;
|
|
378
|
+
const indexWithinCheckpoint = 0;
|
|
379
|
+
// Add MAX_PROPOSALS_PER_POSITION proposals
|
|
380
|
+
for(let i = 0; i < MAX_PROPOSALS_PER_POSITION; i++){
|
|
381
|
+
const proposal = await mockBlockProposalWithIndex(signers[i % NUMBER_OF_SIGNERS_PER_TEST], slotNumber, indexWithinCheckpoint);
|
|
382
|
+
const result = await ap.tryAddBlockProposal(proposal);
|
|
383
|
+
expect(result.added).toBe(true);
|
|
384
|
+
expect(result.totalForPosition).toBe(i + 1);
|
|
385
|
+
}
|
|
386
|
+
// The next proposal should not be added
|
|
387
|
+
const extraProposal = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
|
|
388
|
+
const result = await ap.tryAddBlockProposal(extraProposal);
|
|
389
|
+
expect(result.added).toBe(false);
|
|
390
|
+
expect(result.alreadyExists).toBe(false);
|
|
391
|
+
expect(result.totalForPosition).toBe(MAX_PROPOSALS_PER_POSITION);
|
|
392
|
+
});
|
|
393
|
+
it('should clean up block position index when deleting old data', async ()=>{
|
|
394
|
+
const slotNumber = 100;
|
|
395
|
+
const indexWithinCheckpoint = 0;
|
|
396
|
+
// Add proposal
|
|
397
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[0], slotNumber, indexWithinCheckpoint);
|
|
398
|
+
await ap.tryAddBlockProposal(proposal1);
|
|
399
|
+
// Verify it's tracked (adding another should show totalForPosition = 2)
|
|
400
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[1], slotNumber, indexWithinCheckpoint);
|
|
401
|
+
let result = await ap.tryAddBlockProposal(proposal2);
|
|
402
|
+
expect(result.totalForPosition).toBe(2);
|
|
403
|
+
// Delete old data
|
|
404
|
+
await ap.deleteOlderThan(SlotNumber(slotNumber + 1));
|
|
405
|
+
// Verify position index is cleaned up (totalForPosition should be 1 now)
|
|
406
|
+
const proposal3 = await mockBlockProposalWithIndex(signers[2], slotNumber, indexWithinCheckpoint);
|
|
407
|
+
result = await ap.tryAddBlockProposal(proposal3);
|
|
408
|
+
expect(result.totalForPosition).toBe(1);
|
|
409
|
+
});
|
|
410
|
+
it('should correctly delete block proposals at slot boundary', async ()=>{
|
|
411
|
+
// Add proposals at slots 99, 100, and 101 with various indices
|
|
412
|
+
const proposalSlot99Idx0 = await mockBlockProposalWithIndex(signers[0], 99, 0);
|
|
413
|
+
const proposalSlot99Idx1 = await mockBlockProposalWithIndex(signers[1], 99, 1);
|
|
414
|
+
const proposalSlot100Idx0 = await mockBlockProposalWithIndex(signers[2], 100, 0);
|
|
415
|
+
const proposalSlot101Idx0 = await mockBlockProposalWithIndex(signers[3], 101, 0);
|
|
416
|
+
await ap.tryAddBlockProposal(proposalSlot99Idx0);
|
|
417
|
+
await ap.tryAddBlockProposal(proposalSlot99Idx1);
|
|
418
|
+
await ap.tryAddBlockProposal(proposalSlot100Idx0);
|
|
419
|
+
await ap.tryAddBlockProposal(proposalSlot101Idx0);
|
|
420
|
+
// Delete slots older than 100 (should delete slot 99 only)
|
|
421
|
+
await ap.deleteOlderThan(SlotNumber(100));
|
|
422
|
+
// Slot 99 proposals should have their index cleaned up
|
|
423
|
+
const newProposal99 = await mockBlockProposalWithIndex(signers[0], 99, 0);
|
|
424
|
+
const result99 = await ap.tryAddBlockProposal(newProposal99);
|
|
425
|
+
expect(result99.totalForPosition).toBe(1); // Index was cleaned up
|
|
426
|
+
// Slot 100 and 101 should still be tracked
|
|
427
|
+
const newProposal100 = await mockBlockProposalWithIndex(signers[1], 100, 0);
|
|
428
|
+
const result100 = await ap.tryAddBlockProposal(newProposal100);
|
|
429
|
+
expect(result100.totalForPosition).toBe(2); // Still has the original
|
|
430
|
+
const newProposal101 = await mockBlockProposalWithIndex(signers[2], 101, 0);
|
|
431
|
+
const result101 = await ap.tryAddBlockProposal(newProposal101);
|
|
432
|
+
expect(result101.totalForPosition).toBe(2); // Still has the original
|
|
433
|
+
});
|
|
434
|
+
it('should delete all indices for a given slot', async ()=>{
|
|
435
|
+
const slotNumber = 50;
|
|
436
|
+
// Add proposals at multiple indices for the same slot
|
|
437
|
+
const proposal0 = await mockBlockProposalWithIndex(signers[0], slotNumber, 0);
|
|
438
|
+
const proposal1 = await mockBlockProposalWithIndex(signers[1], slotNumber, 1);
|
|
439
|
+
const proposal2 = await mockBlockProposalWithIndex(signers[2], slotNumber, 2);
|
|
440
|
+
await ap.tryAddBlockProposal(proposal0);
|
|
441
|
+
await ap.tryAddBlockProposal(proposal1);
|
|
442
|
+
await ap.tryAddBlockProposal(proposal2);
|
|
443
|
+
// Delete slots older than slotNumber + 1
|
|
444
|
+
await ap.deleteOlderThan(SlotNumber(slotNumber + 1));
|
|
445
|
+
// All indices should be cleaned up
|
|
446
|
+
const newProposal0 = await mockBlockProposalWithIndex(signers[0], slotNumber, 0);
|
|
447
|
+
const result0 = await ap.tryAddBlockProposal(newProposal0);
|
|
448
|
+
expect(result0.totalForPosition).toBe(1);
|
|
449
|
+
const newProposal1 = await mockBlockProposalWithIndex(signers[1], slotNumber, 1);
|
|
450
|
+
const result1 = await ap.tryAddBlockProposal(newProposal1);
|
|
451
|
+
expect(result1.totalForPosition).toBe(1);
|
|
452
|
+
const newProposal2 = await mockBlockProposalWithIndex(signers[2], slotNumber, 2);
|
|
453
|
+
const result2 = await ap.tryAddBlockProposal(newProposal2);
|
|
454
|
+
expect(result2.totalForPosition).toBe(1);
|
|
455
|
+
});
|
|
456
|
+
it('should delete block proposals from storage when deleting old data', async ()=>{
|
|
457
|
+
const oldSlot = 50;
|
|
458
|
+
const newSlot = 100;
|
|
459
|
+
// Add proposals at old and new slots
|
|
460
|
+
const oldProposal = await mockBlockProposalWithIndex(signers[0], oldSlot, 0);
|
|
461
|
+
const newProposal = await mockBlockProposalWithIndex(signers[1], newSlot, 0);
|
|
462
|
+
await ap.tryAddBlockProposal(oldProposal);
|
|
463
|
+
await ap.tryAddBlockProposal(newProposal);
|
|
464
|
+
// Verify both proposals exist
|
|
465
|
+
expect(await ap.getBlockProposal(oldProposal.archive.toString())).toBeDefined();
|
|
466
|
+
expect(await ap.getBlockProposal(newProposal.archive.toString())).toBeDefined();
|
|
467
|
+
// Delete slots older than newSlot (should delete oldSlot)
|
|
468
|
+
await ap.deleteOlderThan(SlotNumber(newSlot));
|
|
469
|
+
// Old proposal should be deleted from storage
|
|
470
|
+
expect(await ap.getBlockProposal(oldProposal.archive.toString())).toBeUndefined();
|
|
471
|
+
// New proposal should still exist
|
|
472
|
+
expect(await ap.getBlockProposal(newProposal.archive.toString())).toBeDefined();
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
describe('tryAddCheckpointProposal duplicate detection', ()=>{
|
|
476
|
+
const mockCheckpointProposalCoreForPool = async (signer, slotNumber, archive = Fr.random())=>{
|
|
477
|
+
const checkpointHeader = makeCheckpointHeader(1, {
|
|
478
|
+
slotNumber: SlotNumber(slotNumber)
|
|
479
|
+
});
|
|
480
|
+
const blockHeader = makeBlockHeader(1);
|
|
481
|
+
const proposal = await makeCheckpointProposal({
|
|
482
|
+
signer,
|
|
483
|
+
checkpointHeader,
|
|
484
|
+
archiveRoot: archive,
|
|
485
|
+
lastBlock: {
|
|
486
|
+
blockHeader
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
return proposal.toCore();
|
|
490
|
+
};
|
|
491
|
+
it('should return totalForPosition=1 when pool is empty', async ()=>{
|
|
492
|
+
const proposal = await mockCheckpointProposalCoreForPool(signers[0], 100);
|
|
493
|
+
const result = await ap.tryAddCheckpointProposal(proposal);
|
|
494
|
+
expect(result.added).toBe(true);
|
|
495
|
+
expect(result.alreadyExists).toBe(false);
|
|
496
|
+
expect(result.totalForPosition).toBe(1);
|
|
497
|
+
});
|
|
498
|
+
it('should return alreadyExists when same proposal exists', async ()=>{
|
|
499
|
+
const proposal = await mockCheckpointProposalCoreForPool(signers[0], 100);
|
|
500
|
+
await ap.tryAddCheckpointProposal(proposal);
|
|
501
|
+
const result = await ap.tryAddCheckpointProposal(proposal);
|
|
502
|
+
expect(result.added).toBe(false);
|
|
503
|
+
expect(result.alreadyExists).toBe(true);
|
|
504
|
+
expect(result.totalForPosition).toBe(1);
|
|
505
|
+
});
|
|
506
|
+
it('should detect duplicate via totalForPosition when different proposal exists for same slot', async ()=>{
|
|
507
|
+
const slotNumber = 100;
|
|
508
|
+
// Add first proposal
|
|
509
|
+
const proposal1 = await mockCheckpointProposalCoreForPool(signers[0], slotNumber);
|
|
510
|
+
const result1 = await ap.tryAddCheckpointProposal(proposal1);
|
|
511
|
+
expect(result1.totalForPosition).toBe(1);
|
|
512
|
+
// Add a different proposal for same slot - this is a duplicate (equivocation)
|
|
513
|
+
const proposal2 = await mockCheckpointProposalCoreForPool(signers[1], slotNumber);
|
|
514
|
+
const result2 = await ap.tryAddCheckpointProposal(proposal2);
|
|
515
|
+
expect(result2.added).toBe(true);
|
|
516
|
+
expect(result2.alreadyExists).toBe(false);
|
|
517
|
+
// totalForPosition >= 2 indicates duplicate detection
|
|
518
|
+
expect(result2.totalForPosition).toBe(2);
|
|
519
|
+
});
|
|
520
|
+
it('should not detect duplicate for different slots', async ()=>{
|
|
521
|
+
// Add proposal at slot 100
|
|
522
|
+
const proposal1 = await mockCheckpointProposalCoreForPool(signers[0], 100);
|
|
523
|
+
await ap.tryAddCheckpointProposal(proposal1);
|
|
524
|
+
// Add proposal at slot 200 (different slot)
|
|
525
|
+
const proposal2 = await mockCheckpointProposalCoreForPool(signers[1], 200);
|
|
526
|
+
const result = await ap.tryAddCheckpointProposal(proposal2);
|
|
527
|
+
expect(result.added).toBe(true);
|
|
528
|
+
// totalForPosition = 1 means no duplicate for this slot
|
|
529
|
+
expect(result.totalForPosition).toBe(1);
|
|
530
|
+
});
|
|
531
|
+
it('should track multiple duplicates correctly via totalForPosition', async ()=>{
|
|
532
|
+
const slotNumber = 100;
|
|
533
|
+
// Add multiple proposals for same slot
|
|
534
|
+
const proposal1 = await mockCheckpointProposalCoreForPool(signers[0], slotNumber);
|
|
535
|
+
const result1 = await ap.tryAddCheckpointProposal(proposal1);
|
|
536
|
+
expect(result1.totalForPosition).toBe(1);
|
|
537
|
+
const proposal2 = await mockCheckpointProposalCoreForPool(signers[1], slotNumber);
|
|
538
|
+
const result2 = await ap.tryAddCheckpointProposal(proposal2);
|
|
539
|
+
expect(result2.totalForPosition).toBe(2);
|
|
540
|
+
// Add a third proposal for same slot
|
|
541
|
+
const proposal3 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber);
|
|
542
|
+
const result3 = await ap.tryAddCheckpointProposal(proposal3);
|
|
543
|
+
expect(result3.added).toBe(true);
|
|
544
|
+
expect(result3.totalForPosition).toBe(3);
|
|
545
|
+
});
|
|
546
|
+
it('should not count attestations as proposals for duplicate detection', async ()=>{
|
|
547
|
+
const slotNumber = 100;
|
|
548
|
+
const archive = Fr.random();
|
|
549
|
+
// Attestation arrives BEFORE the checkpoint proposal (race condition in p2p)
|
|
550
|
+
const attestation = mockCheckpointAttestation(signers[0], slotNumber, archive);
|
|
551
|
+
await ap.addOwnCheckpointAttestations([
|
|
552
|
+
attestation
|
|
553
|
+
]);
|
|
554
|
+
// Now the checkpoint proposal arrives - this should NOT be detected as a duplicate
|
|
555
|
+
const proposal = await mockCheckpointProposalCoreForPool(signers[1], slotNumber, archive);
|
|
556
|
+
const result = await ap.tryAddCheckpointProposal(proposal);
|
|
557
|
+
expect(result.added).toBe(true);
|
|
558
|
+
expect(result.alreadyExists).toBe(false);
|
|
559
|
+
// totalForPosition should be 1, NOT 2 - attestations should not count as proposals
|
|
560
|
+
expect(result.totalForPosition).toBe(1);
|
|
561
|
+
});
|
|
562
|
+
it('should not count attestations for different proposals as duplicates', async ()=>{
|
|
563
|
+
const slotNumber = 100;
|
|
564
|
+
const archive1 = Fr.random();
|
|
565
|
+
const archive2 = Fr.random();
|
|
566
|
+
// Add attestations for two different proposals in the same slot
|
|
567
|
+
const attestation1 = mockCheckpointAttestation(signers[0], slotNumber, archive1);
|
|
568
|
+
const attestation2 = mockCheckpointAttestation(signers[1], slotNumber, archive2);
|
|
569
|
+
await ap.addOwnCheckpointAttestations([
|
|
570
|
+
attestation1,
|
|
571
|
+
attestation2
|
|
572
|
+
]);
|
|
573
|
+
// Add the first checkpoint proposal - should not be affected by attestations
|
|
574
|
+
const proposal1 = await mockCheckpointProposalCoreForPool(signers[2], slotNumber, archive1);
|
|
575
|
+
const result1 = await ap.tryAddCheckpointProposal(proposal1);
|
|
576
|
+
expect(result1.added).toBe(true);
|
|
577
|
+
expect(result1.totalForPosition).toBe(1);
|
|
578
|
+
// Add the second checkpoint proposal - this IS a duplicate (different archive, same slot)
|
|
579
|
+
const proposal2 = await mockCheckpointProposalCoreForPool(signers[3], slotNumber, archive2);
|
|
580
|
+
const result2 = await ap.tryAddCheckpointProposal(proposal2);
|
|
581
|
+
expect(result2.added).toBe(true);
|
|
582
|
+
expect(result2.totalForPosition).toBe(2);
|
|
583
|
+
});
|
|
318
584
|
});
|
|
319
585
|
});
|
|
320
586
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvYXR0ZXN0YXRpb25fcG9vbC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHVCQUF1QixDQUFDO0FBQ3RDLGNBQWMsOEJBQThCLENBQUMifQ==
|
|
1
|
+
export { AttestationPool, type AttestationPoolApi, type TryAddResult, createTestAttestationPool, MAX_PROPOSALS_PER_SLOT, MAX_PROPOSALS_PER_POSITION, ATTESTATION_CAP_BUFFER, } from './attestation_pool.js';
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9tZW1fcG9vbHMvYXR0ZXN0YXRpb25fcG9vbC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsZUFBZSxFQUNmLEtBQUssa0JBQWtCLEVBQ3ZCLEtBQUssWUFBWSxFQUNqQix5QkFBeUIsRUFDekIsc0JBQXNCLEVBQ3RCLDBCQUEwQixFQUMxQixzQkFBc0IsR0FDdkIsTUFBTSx1QkFBdUIsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mem_pools/attestation_pool/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './memory_attestation_pool.js';
|
|
1
|
+
export { AttestationPool, createTestAttestationPool, MAX_PROPOSALS_PER_SLOT, MAX_PROPOSALS_PER_POSITION, ATTESTATION_CAP_BUFFER } from './attestation_pool.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { AttestationPool, type AttestationPoolApi } from './attestation_pool/attestation_pool.js';
|
|
2
2
|
export { type MemPools } from './interface.js';
|
|
3
3
|
export { type TxPool } from './tx_pool/tx_pool.js';
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tZW1fcG9vbHMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGVBQWUsRUFBRSxLQUFLLGtCQUFrQixFQUFFLE1BQU0sd0NBQXdDLENBQUM7QUFDbEcsT0FBTyxFQUFFLEtBQUssUUFBUSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDL0MsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLE1BQU0sc0JBQXNCLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mem_pools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mem_pools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAClG,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dest/mem_pools/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { };
|
|
1
|
+
export { AttestationPool } from './attestation_pool/attestation_pool.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AttestationPoolApi } from './attestation_pool/attestation_pool.js';
|
|
2
2
|
import type { TxPool } from './tx_pool/tx_pool.js';
|
|
3
3
|
/**
|
|
4
4
|
* A interface the combines all mempools
|
|
5
5
|
*/
|
|
6
6
|
export type MemPools = {
|
|
7
7
|
txPool: TxPool;
|
|
8
|
-
attestationPool:
|
|
8
|
+
attestationPool: AttestationPoolApi;
|
|
9
9
|
};
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbWVtX3Bvb2xzL2ludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdDQUF3QyxDQUFDO0FBQ2pGLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBRW5EOztHQUVHO0FBQ0gsTUFBTSxNQUFNLFFBQVEsR0FBRztJQUNyQixNQUFNLEVBQUUsTUFBTSxDQUFDO0lBQ2YsZUFBZSxFQUFFLGtCQUFrQixDQUFDO0NBQ3JDLENBQUMifQ==
|