Compare commits

...

3 Commits

Author SHA1 Message Date
Manu NALEPA
aa9e3158b4 Blobs: Refactor. 2024-11-29 12:54:36 +01:00
Manu NALEPA
425a7e327e PeerDASIsActive: Remove tautological condition. 2024-11-29 10:53:53 +01:00
Manu NALEPA
5a7aa3715e Fix typo: 7954 ==> 7594. 2024-11-29 10:51:41 +01:00
3 changed files with 46 additions and 43 deletions

View File

@@ -55,7 +55,7 @@ func HigherEqualThanAltairVersionAndEpoch(s state.BeaconState, e primitives.Epoc
// PeerDASIsActive checks whether peerDAS is active at the provided slot.
func PeerDASIsActive(slot primitives.Slot) bool {
return params.PeerDASEnabled() && slots.ToEpoch(slot) >= params.BeaconConfig().Eip7594ForkEpoch
return slots.ToEpoch(slot) >= params.BeaconConfig().Eip7594ForkEpoch
}
// CanUpgradeToAltair returns true if the input `slot` can upgrade to Altair.

View File

@@ -3,7 +3,6 @@ package lookup
import (
"context"
"fmt"
"math"
"strconv"
"strings"
@@ -470,26 +469,30 @@ func (p *BeaconDbBlocker) Blobs(ctx context.Context, id string, indices map[uint
// Get the slot of the block.
blockSlot := b.Block().Slot()
// Get the first peerDAS epoch.
eip7594ForkEpoch := params.BeaconConfig().Eip7594ForkEpoch
// Compute the first peerDAS slot.
peerDASStartSlot := primitives.Slot(math.MaxUint64)
if eip7594ForkEpoch != primitives.Epoch(math.MaxUint64) {
peerDASStartSlot, err = slots.EpochStart(eip7594ForkEpoch)
if err != nil {
return nil, &core.RpcError{Err: errors.Wrap(err, "could not calculate peerDAS start slot"), Reason: core.Internal}
}
}
// Is peerDAS enabled for this block?
isPeerDASEnabledForBlock := blockSlot >= peerDASStartSlot
// Create indices if needed.
if indices == nil {
indices = make(map[uint64]bool)
}
if !isPeerDASEnabledForBlock {
if params.PeerDASEnabled() {
// Get the first peerDAS epoch.
eip7594ForkEpoch := params.BeaconConfig().Eip7594ForkEpoch
// Calculate the slot at which peerDAS starts.
peerDASStartSlot, err := slots.EpochStart(eip7594ForkEpoch)
if err != nil {
return nil, &core.RpcError{Err: errors.Wrap(err, "could not calculate peerDAS start slot"), Reason: core.Internal}
}
// Is peerDAS active for this block?
isPeerDASActiveForBlock := blockSlot >= peerDASStartSlot
// If peerDAS is active for this block, then the database contains data columns.
if isPeerDASActiveForBlock {
return p.blobsFromStoredDataColumns(indices, root)
}
// Else, the database contains blobs.
return p.blobsFromStoredBlobs(indices, root)
}

View File

@@ -1713,7 +1713,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
// Fork epochs.
denebForkEpoch primitives.Epoch
eip7954ForkEpoch primitives.Epoch
eip7594ForkEpoch primitives.Epoch
// Current slot.
currentSlot uint64
@@ -1753,29 +1753,29 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
isError: false,
},
{
name: "All blocks are before EIP-7954 fork epoch",
name: "All blocks are before EIP-7594 fork epoch",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 25, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 26, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 27, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 28, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 25, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 26, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 27, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 28, hasBlobs: false}, // Before EIP-7594 fork epoch
},
batchSize: 32,
addedRODataColumns: [][]int{nil, nil, nil, nil},
isError: false,
},
{
name: "All blocks with commitments before are EIP-7954 fork epoch",
name: "All blocks with commitments before are EIP-7594 fork epoch",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 25, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 26, hasBlobs: true}, // Before EIP-7954 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7954 fork epoch
{slot: 25, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 26, hasBlobs: true}, // Before EIP-7594 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7594 fork epoch
{slot: 32, hasBlobs: false},
{slot: 33, hasBlobs: false},
},
@@ -1785,12 +1785,12 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs but without any missing data columns",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 25, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 26, hasBlobs: true}, // Before EIP-7954 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7954 fork epoch
{slot: 25, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 26, hasBlobs: true}, // Before EIP-7594 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7594 fork epoch
{slot: 32, hasBlobs: false},
{slot: 33, hasBlobs: true},
},
@@ -1808,11 +1808,11 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - one round needed",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 25, hasBlobs: false}, // Before EIP-7954 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7954 fork epoch
{slot: 25, hasBlobs: false}, // Before EIP-7594 fork epoch
{slot: 27, hasBlobs: true}, // Before EIP-7594 fork epoch
{slot: 32, hasBlobs: false},
{slot: 33, hasBlobs: true},
{slot: 34, hasBlobs: true},
@@ -1916,7 +1916,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - partial responses",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 33, hasBlobs: true},
@@ -1970,7 +1970,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - first response is invalid",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 38, hasBlobs: true},
@@ -2004,7 +2004,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - first response is empty",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{{slot: 38, hasBlobs: true}},
storedDataColumns: []map[int]bool{{38: true, 102: true}},
@@ -2033,7 +2033,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - no response at all",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{{slot: 38, hasBlobs: true}},
storedDataColumns: []map[int]bool{{38: true, 102: true}},
@@ -2056,7 +2056,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
{
name: "Some blocks with blobs with missing data columns - request has to be split",
denebForkEpoch: 0,
eip7954ForkEpoch: 1,
eip7594ForkEpoch: 1,
currentSlot: 40,
blocksParams: []blockParams{
{slot: 32, hasBlobs: true}, {slot: 33, hasBlobs: true}, {slot: 34, hasBlobs: true}, {slot: 35, hasBlobs: true}, // 4
@@ -2177,7 +2177,7 @@ func TestFetchDataColumnsFromPeers(t *testing.T) {
params.BeaconConfig().DenebForkEpoch = tc.denebForkEpoch
// Set the EIP-7594 fork epoch.
params.BeaconConfig().Eip7594ForkEpoch = tc.eip7954ForkEpoch
params.BeaconConfig().Eip7594ForkEpoch = tc.eip7594ForkEpoch
// Save the blocks in the store.
storage := make(map[[fieldparams.RootLength]byte][]int)