@@ -16,6 +16,11 @@ import (
1616 pb "github.com/rollkit/rollkit/types/pb/rollkit/v1"
1717)
1818
19+ const (
20+ dAefetcherTimeout = 30 * time .Second
21+ dAFetcherRetries = 10
22+ )
23+
1924// RetrieveLoop is responsible for interacting with DA layer.
2025func (m * Manager ) RetrieveLoop (ctx context.Context ) {
2126 // blockFoundCh is used to track when we successfully found a block so
@@ -55,13 +60,11 @@ func (m *Manager) processNextDAHeader(ctx context.Context) error {
5560 default :
5661 }
5762
58- // TODO(tzdybal): extract configuration option
59- maxRetries := 10
6063 daHeight := atomic .LoadUint64 (& m .daHeight )
6164
6265 var err error
6366 m .logger .Debug ("trying to retrieve block from DA" , "daHeight" , daHeight )
64- for r := 0 ; r < maxRetries ; r ++ {
67+ for r := 0 ; r < dAFetcherRetries ; r ++ {
6568 select {
6669 case <- ctx .Done ():
6770 return ctx .Err ()
@@ -80,6 +83,7 @@ func (m *Manager) processNextDAHeader(ctx context.Context) error {
8083 var headerPb pb.SignedHeader
8184 err := proto .Unmarshal (bz , & headerPb )
8285 if err != nil {
86+ // we can fail to unmarshal the header if the header as we fetch all data from the DA layer, which includes Data as well
8387 m .logger .Debug ("failed to unmarshal header" , "error" , err , "DAHeight" , daHeight )
8488 continue
8589 }
@@ -156,9 +160,10 @@ func (m *Manager) areAllErrorsHeightFromFuture(err error) bool {
156160 return false
157161}
158162
163+ // featchHeaders retrieves headers from the DA layer
159164func (m * Manager ) fetchHeaders (ctx context.Context , daHeight uint64 ) (coreda.ResultRetrieve , error ) {
160165 var err error
161- ctx , cancel := context .WithTimeout (ctx , 60 * time . Second ) //TODO: make this configurable
166+ ctx , cancel := context .WithTimeout (ctx , dAefetcherTimeout )
162167 defer cancel ()
163168 headerRes := m .dalc .Retrieve (ctx , daHeight )
164169 if headerRes .Code == coreda .StatusError {
@@ -167,14 +172,7 @@ func (m *Manager) fetchHeaders(ctx context.Context, daHeight uint64) (coreda.Res
167172 return headerRes , err
168173}
169174
170- func (m * Manager ) getSignature (header types.Header ) (types.Signature , error ) {
171- b , err := header .MarshalBinary ()
172- if err != nil {
173- return nil , err
174- }
175- return m .signer .Sign (b )
176- }
177-
175+ // setDAIncludedHeight sets the DA included height in the store
178176func (m * Manager ) setDAIncludedHeight (ctx context.Context , newHeight uint64 ) error {
179177 for {
180178 currentHeight := m .daIncludedHeight .Load ()
0 commit comments