|
15 | 15 | // along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | 17 | use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet}; |
18 | | -use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa}; |
| 18 | +use bp_header_chain::{ |
| 19 | + justification::GrandpaJustification, max_expected_submit_finality_proof_arguments_size, |
| 20 | + ChainWithGrandpa, GrandpaConsensusLogReader, |
| 21 | +}; |
19 | 22 | use bp_runtime::{BlockNumberOf, OwnedBridgeModule}; |
20 | 23 | use codec::Encode; |
21 | 24 | use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight}; |
@@ -169,28 +172,28 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>( |
169 | 172 | Weight::zero() |
170 | 173 | }; |
171 | 174 |
|
| 175 | + // check if the `finality_target` is a mandatory header. If so, we are ready to refund larger |
| 176 | + // size |
| 177 | + let is_mandatory_finality_target = |
| 178 | + GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change( |
| 179 | + finality_target.digest(), |
| 180 | + ) |
| 181 | + .is_some(); |
| 182 | + |
172 | 183 | // we can estimate extra call size easily, without any additional significant overhead |
173 | 184 | let actual_call_size: u32 = finality_target |
174 | 185 | .encoded_size() |
175 | 186 | .saturating_add(justification.encoded_size()) |
176 | 187 | .saturated_into(); |
177 | | - let max_expected_call_size = max_expected_call_size::<T, I>(required_precommits); |
| 188 | + let max_expected_call_size = max_expected_submit_finality_proof_arguments_size::<T::BridgedChain>( |
| 189 | + is_mandatory_finality_target, |
| 190 | + required_precommits, |
| 191 | + ); |
178 | 192 | let extra_size = actual_call_size.saturating_sub(max_expected_call_size); |
179 | 193 |
|
180 | 194 | SubmitFinalityProofInfo { block_number, extra_weight, extra_size } |
181 | 195 | } |
182 | 196 |
|
183 | | -/// Returns maximal expected size of `submit_finality_proof` call arguments. |
184 | | -fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 { |
185 | | - let max_expected_justification_size = |
186 | | - GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>( |
187 | | - required_precommits, |
188 | | - ); |
189 | | - |
190 | | - // call arguments are header and justification |
191 | | - T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size) |
192 | | -} |
193 | | - |
194 | 197 | #[cfg(test)] |
195 | 198 | mod tests { |
196 | 199 | use crate::{ |
|
0 commit comments