ava-labs / avalanchego

Go implementation of an Avalanche node.
https://avax.network
BSD 3-Clause "New" or "Revised" License
2.09k stars 646 forks source link

Remove block lookup from `deliver` #3130

Closed StephenButtolph closed 1 week ago

StephenButtolph commented 1 week ago

Why this should be merged

This PR is part of the effort to remove the usage of .Status() on the block type.

Additionally, this removes a call to getBlock, which could result in a slow DB read. This check can be performed using in-memory state.

How this works

The checks now being performed are significantly simpler to understand. Previously, the checks would:

  1. Verify that the blk.Height() is greater than the last accepted height.
  2. Verify that the blk.ID() is not currently in the processing block tree.
  3. Verify that the parent.Status() was either accepted or parent.ID() is currently in the processing block tree.

Because the blk.Height() was verified to be greater than the last accepted height, we knew that if parent.Status() was accepted then the parent block was the last accepted block.

We now directly verify that:

  1. The blk.ID() is not currently in the processing block tree.
  2. The parent.ID() is either the last accepted block or is currently in the processing block tree.

How this was tested