@@ -82,7 +82,7 @@ type blocksFetcherConfig struct {
8282 mode syncMode
8383 bs filesystem.BlobStorageSummarizer
8484 bv verification.NewBlobVerifier
85- cv verification.NewColumnVerifier
85+ cv verification.NewDataColumnsVerifier
8686}
8787
8888// blocksFetcher is a service to fetch chain data from peers.
@@ -100,7 +100,7 @@ type blocksFetcher struct {
100100 db db.ReadOnlyDatabase
101101 bs filesystem.BlobStorageSummarizer
102102 bv verification.NewBlobVerifier
103- cv verification.NewColumnVerifier
103+ cv verification.NewDataColumnsVerifier
104104 blocksPerPeriod uint64
105105 rateLimiter * leakybucket.Collector
106106 peerLocks map [peer.ID ]* peerLock
@@ -1155,67 +1155,91 @@ func (f *blocksFetcher) waitForPeersForDataColumns(
11551155 return dataColumnsByAdmissiblePeer , nil
11561156}
11571157
1158- // processDataColumn mutates `bwbs` argument by adding the data column,
1158+ // processDataColumns mutates `bwbs` argument by adding the data column,
11591159// and mutates `missingColumnsByRoot` by removing the data column if the
11601160// data column passes all the check.
1161- func processDataColumn (
1161+ func ( f * blocksFetcher ) processDataColumns (
11621162 wrappedBwbsMissingColumns * bwbsMissingColumns ,
1163- columnVerifier verification.NewColumnVerifier ,
1164- blocksByRoot map [[fieldparams .RootLength ]byte ]blocks.ROBlock ,
1163+ blockByRoot map [[fieldparams .RootLength ]byte ]blocks.ROBlock ,
11651164 indicesByRoot map [[fieldparams .RootLength ]byte ][]int ,
1166- dataColumn blocks.RODataColumn ,
1165+ dataColumns [] blocks.RODataColumn ,
11671166) bool {
1168- // Extract the block root from the data column.
1169- blockRoot := dataColumn .BlockRoot ()
1170-
1171- // Find the position of the block in `bwbs` that corresponds to this block root.
1172- indices , ok := indicesByRoot [blockRoot ]
1173- if ! ok {
1174- // The peer returned a data column that we did not expect.
1175- // This is among others possible when the peer is not on the same fork.
1176- return false
1177- }
1167+ // Fiter out data columns:
1168+ // - that are not expected and,
1169+ // - which correspond to blocks before Deneb.
1170+
1171+ // Not expected data columns are among others possible when
1172+ // the peer is not on the same fork, due to the nature of
1173+ // data columns by range requests.
1174+ wrappedBlockDataColumns := make ([]verify.WrappedBlockDataColumn , 0 , len (dataColumns ))
1175+ for _ , dataColumn := range dataColumns {
1176+ // Extract the block root from the data column.
1177+ blockRoot := dataColumn .BlockRoot ()
1178+
1179+ // Skip if the block root is not expected.
1180+ // This is possible when the peer is not on the same fork.
1181+ _ , ok := indicesByRoot [blockRoot ]
1182+ if ! ok {
1183+ continue
1184+ }
11781185
1179- // Extract the block from the block root.
1180- block , ok := blocksByRoot [blockRoot ]
1181- if ! ok {
1182- // This should never happen.
1183- log .WithField ("blockRoot" , fmt .Sprintf ("%#x" , blockRoot )).Error ("Fetch data columns from peers - block not found" )
1184- return false
1185- }
1186+ // Retrieve the block from the block root.
1187+ block , ok := blockByRoot [blockRoot ]
1188+ if ! ok {
1189+ // This should never happen.
1190+ log .WithField ("blockRoot" , fmt .Sprintf ("%#x" , blockRoot )).Error ("Fetch data columns from peers - block not found for root" )
1191+ return false
1192+ }
1193+
1194+ // Skip if the block is before Deneb.
1195+ if block .Version () < version .Deneb {
1196+ continue
1197+ }
11861198
1187- // Verify the data column.
1188- if err := verify . ColumnAlignsWithBlock ( dataColumn , block , columnVerifier ); err != nil {
1189- log . WithError ( err ). WithFields (logrus. Fields {
1190- "root" : fmt . Sprintf ( "%#x" , blockRoot ),
1191- "slot" : block . Block (). Slot (),
1192- "column" : dataColumn . ColumnIndex ,
1193- }). Warning ( "Fetch data columns from peers - fetched data column does not align with block" )
1199+ wrappedBlockDataColumn := verify. WrappedBlockDataColumn {
1200+ ROBlock : block ,
1201+ DataColumn : dataColumn ,
1202+ }
1203+
1204+ wrappedBlockDataColumns = append ( wrappedBlockDataColumns , wrappedBlockDataColumn )
1205+ }
11941206
1207+ // Verify the data columns.
1208+ if err := verify .DataColumnsAlignWithBlock (wrappedBlockDataColumns , f .cv ); err != nil {
11951209 // TODO: Should we downscore the peer for that?
11961210 return false
11971211 }
11981212
1199- // Populate the corresponding items in `bwbs`.
1200- func () {
1201- mu := & wrappedBwbsMissingColumns .mu
1213+ wrappedBwbsMissingColumns .mu .Lock ()
1214+ defer wrappedBwbsMissingColumns .mu .Unlock ()
1215+
1216+ bwbs := wrappedBwbsMissingColumns .bwbs
1217+ missingColumnsByRoot := wrappedBwbsMissingColumns .missingColumnsByRoot
12021218
1203- mu . Lock ()
1204- defer mu . Unlock ()
1219+ for _ , wrappedBlockDataColumn := range wrappedBlockDataColumns {
1220+ dataColumn := wrappedBlockDataColumn . DataColumn
12051221
1206- bwbs := wrappedBwbsMissingColumns .bwbs
1207- missingColumnsByRoot := wrappedBwbsMissingColumns .missingColumnsByRoot
1222+ // Extract the block root from the data column.
1223+ blockRoot := dataColumn .BlockRoot ()
1224+
1225+ // Extract the indices in bwb corresponding to the block root.
1226+ indices , ok := indicesByRoot [blockRoot ]
1227+ if ! ok {
1228+ // This should never happen.
1229+ log .WithField ("blockRoot" , fmt .Sprintf ("%#x" , blockRoot )).Error ("Fetch data columns from peers - indices not found for root" )
1230+ return false
1231+ }
12081232
1233+ // Populate the corresponding items in `bwbs`.
12091234 for _ , index := range indices {
12101235 bwbs [index ].Columns = append (bwbs [index ].Columns , dataColumn )
12111236 }
1212-
12131237 // Remove the column from the missing columns.
12141238 delete (missingColumnsByRoot [blockRoot ], dataColumn .ColumnIndex )
12151239 if len (missingColumnsByRoot [blockRoot ]) == 0 {
12161240 delete (missingColumnsByRoot , blockRoot )
12171241 }
1218- }()
1242+ }
12191243
12201244 return true
12211245}
@@ -1299,17 +1323,8 @@ func (f *blocksFetcher) fetchDataColumnFromPeer(
12991323 return
13001324 }
13011325
1302- globalSuccess := false
1303-
1304- for _ , dataColumn := range roDataColumns {
1305- success := processDataColumn (wrappedBwbsMissingColumns , f .cv , blocksByRoot , indicesByRoot , dataColumn )
1306- if success {
1307- globalSuccess = true
1308- }
1309- }
1310-
1311- if ! globalSuccess {
1312- log .Debug ("Fetch data columns from peers - no valid data column returned" )
1326+ if ! f .processDataColumns (wrappedBwbsMissingColumns , blocksByRoot , indicesByRoot , roDataColumns ) {
1327+ log .Warning ("Fetch data columns from peers - at least one data column is invalid" )
13131328 return
13141329 }
13151330
0 commit comments