@@ -75,6 +75,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
75
75
return new_tx;
76
76
}();
77
77
78
+ const auto wtxid{tx->GetWitnessHash ()};
79
+
78
80
// Trigger orphanage functions that are called using parents. ptx_potential_parent is a tx we constructed in a
79
81
// previous loop and potentially the parent of this tx.
80
82
if (ptx_potential_parent) {
@@ -94,6 +96,9 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
94
96
LIMITED_WHILE (fuzzed_data_provider.ConsumeBool (), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
95
97
{
96
98
NodeId peer_id = fuzzed_data_provider.ConsumeIntegral <NodeId>();
99
+ const auto total_bytes_start{orphanage.TotalOrphanUsage ()};
100
+ const auto total_peer_bytes_start{orphanage.UsageByPeer (peer_id)};
101
+ const auto tx_weight{GetTransactionWeight (*tx)};
97
102
98
103
CallOneOf (
99
104
fuzzed_data_provider,
@@ -113,12 +118,29 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
113
118
bool add_tx = orphanage.AddTx (tx, peer_id);
114
119
// have_tx == true -> add_tx == false
115
120
Assert (!have_tx || !add_tx);
121
+
122
+ if (add_tx) {
123
+ Assert (orphanage.UsageByPeer (peer_id) == tx_weight + total_peer_bytes_start);
124
+ Assert (orphanage.TotalOrphanUsage () == tx_weight + total_bytes_start);
125
+ Assert (tx_weight <= MAX_STANDARD_TX_WEIGHT);
126
+ } else {
127
+ // Peer may have been added as an announcer.
128
+ if (orphanage.UsageByPeer (peer_id) == tx_weight + total_peer_bytes_start) {
129
+ Assert (orphanage.HaveTxFromPeer (wtxid, peer_id));
130
+ } else {
131
+ // Otherwise, there must not be any change to the peer byte count.
132
+ Assert (orphanage.UsageByPeer (peer_id) == total_peer_bytes_start);
133
+ }
134
+
135
+ // Regardless, total bytes should not have changed.
136
+ Assert (orphanage.TotalOrphanUsage () == total_bytes_start);
137
+ }
116
138
}
117
139
have_tx = orphanage.HaveTx (tx->GetWitnessHash ());
118
140
{
119
141
bool add_tx = orphanage.AddTx (tx, peer_id);
120
142
// if have_tx is still false, it must be too big
121
- Assert (!have_tx == (GetTransactionWeight (*tx) > MAX_STANDARD_TX_WEIGHT));
143
+ Assert (!have_tx == (tx_weight > MAX_STANDARD_TX_WEIGHT));
122
144
Assert (!have_tx || !add_tx);
123
145
}
124
146
},
@@ -132,23 +154,46 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
132
154
Assert (have_tx || !added_announcer);
133
155
// have_tx_and_peer == true -> added_announcer == false
134
156
Assert (!have_tx_and_peer || !added_announcer);
157
+
158
+ // Total bytes should not have changed. If peer was added as announcer, byte
159
+ // accounting must have been updated.
160
+ Assert (orphanage.TotalOrphanUsage () == total_bytes_start);
161
+ if (added_announcer) {
162
+ Assert (orphanage.UsageByPeer (peer_id) == tx_weight + total_peer_bytes_start);
163
+ } else {
164
+ Assert (orphanage.UsageByPeer (peer_id) == total_peer_bytes_start);
165
+ }
135
166
}
136
167
},
137
168
[&] {
138
169
bool have_tx = orphanage.HaveTx (tx->GetWitnessHash ());
170
+ bool have_tx_and_peer{orphanage.HaveTxFromPeer (wtxid, peer_id)};
139
171
// EraseTx should return 0 if m_orphans doesn't have the tx
140
172
{
173
+ auto bytes_from_peer_before{orphanage.UsageByPeer (peer_id)};
141
174
Assert (have_tx == orphanage.EraseTx (tx->GetWitnessHash ()));
175
+ if (have_tx) {
176
+ Assert (orphanage.TotalOrphanUsage () == total_bytes_start - tx_weight);
177
+ if (have_tx_and_peer) {
178
+ Assert (orphanage.UsageByPeer (peer_id) == bytes_from_peer_before - tx_weight);
179
+ } else {
180
+ Assert (orphanage.UsageByPeer (peer_id) == bytes_from_peer_before);
181
+ }
182
+ } else {
183
+ Assert (orphanage.TotalOrphanUsage () == total_bytes_start);
184
+ }
142
185
}
143
186
have_tx = orphanage.HaveTx (tx->GetWitnessHash ());
187
+ have_tx_and_peer = orphanage.HaveTxFromPeer (wtxid, peer_id);
144
188
// have_tx should be false and EraseTx should fail
145
189
{
146
- Assert (!have_tx && !orphanage.EraseTx (tx-> GetWitnessHash () ));
190
+ Assert (!have_tx && !have_tx_and_peer && ! orphanage.EraseTx (wtxid ));
147
191
}
148
192
},
149
193
[&] {
150
194
orphanage.EraseForPeer (peer_id);
151
195
Assert (!orphanage.HaveTxFromPeer (tx->GetWitnessHash (), peer_id));
196
+ Assert (orphanage.UsageByPeer (peer_id) == 0 );
152
197
},
153
198
[&] {
154
199
// test mocktime and expiry
0 commit comments