Skip to content

Commit b788a24

Browse files
committed
Artificial checkpoint only for 1st batch
1 parent 6b12336 commit b788a24

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

blockchain/src/blockchain/history_sync.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -196,41 +196,25 @@ impl Blockchain {
196196
let mut block_state = vec![];
197197
let mut block_transactions = vec![];
198198
let mut block_inherents = vec![];
199-
200-
let mut prev_batch = 0;
201199
let mut prev_block = 0;
200+
let mut prev_batch = 0;
202201

203202
for hist_tx in history.iter().skip(first_new_hist_tx) {
204203
if hist_tx.block_number > prev_block {
205-
// If a macro block does not have any history items, we need to add it here so that
206-
// we always commit FinalizeBatch/FinalizeEpoch inherents.
207-
// FIXME We're missing the block timestamp to do this correctly.
208-
// Also, this works only if a single macro block is missing between history items.
209-
let batch_number = Policy::batch_at(hist_tx.block_number);
210-
if batch_number > prev_batch
211-
&& block_state.last().is_some_and(|block_state: &BlockState| {
212-
!Policy::is_macro_block_at(block_state.number)
213-
})
214-
{
215-
debug!(
216-
history_item_block_number = hist_tx.block_number,
217-
prev_block,
218-
history_item_batch = batch_number,
219-
prev_batch,
220-
last_block = ?block_state.last(),
221-
"Inserting macro block"
204+
let new_batch = Policy::batch_at(prev_block);
205+
if prev_batch == 0 && new_batch > 1 {
206+
assert_eq!(
207+
new_batch, 2,
208+
"We cannot skip over macro blocks after batch 1 due to reward payout txs."
222209
);
223-
assert_eq!(batch_number, prev_batch + 1, "Missing batch");
224-
225210
block_state.push(BlockState {
226-
number: Policy::macro_block_of(prev_batch).unwrap(),
227-
time: 0, // FIXME
211+
number: Policy::macro_block_after(hist_tx.block_number),
212+
time: 0, // FIX ME change the response to never skip macro_blocks.
228213
protocol_version: this.state.current_version(), // Cannot change, protocol version upgrades only on election blocks.
229214
});
230215
block_transactions.push(vec![]);
231216
block_inherents.push(vec![]);
232217
}
233-
234218
block_state.push(BlockState {
235219
number: hist_tx.block_number,
236220
time: hist_tx.block_time,
@@ -239,8 +223,8 @@ impl Blockchain {
239223
block_transactions.push(vec![]);
240224
block_inherents.push(vec![]);
241225

242-
prev_batch = batch_number;
243226
prev_block = hist_tx.block_number;
227+
prev_batch = new_batch;
244228
}
245229

246230
match &hist_tx.data {

0 commit comments

Comments
 (0)