66 "time"
77
88 coreda "github.com/rollkit/rollkit/core/da"
9+ coresequencer "github.com/rollkit/rollkit/core/sequencer"
910 "github.com/rollkit/rollkit/types"
1011 "google.golang.org/protobuf/proto"
1112)
@@ -139,43 +140,49 @@ func (m *Manager) BatchSubmissionLoop(ctx context.Context) {
139140 m .logger .Info ("batch submission loop stopped" )
140141 return
141142 case batch := <- m .batchSubmissionChan :
142- data := types.Data {
143- Txs : make (types.Txs , len (batch .Transactions )),
144- }
145- for i , tx := range batch .Transactions {
146- data .Txs [i ] = types .Tx (tx )
147- }
148-
149- signature , err := m .getDataSignature (& data )
143+ signedData , err := m .createSignedDataFromBatch (& batch )
150144 if err != nil {
151- m .logger .Error ("failed to get data signature " , "error" , err )
145+ m .logger .Error ("failed to create signed data from batch " , "error" , err )
152146 continue
153147 }
154148
155- pubKey , err : = m .signer . GetPublic ( )
149+ err = m .submitBatchToDA ( ctx , signedData )
156150 if err != nil {
157- m .logger .Error ("failed to get signer public key" , "error" , err )
158- continue
151+ m .logger .Error ("failed to submit batch to DA" , "error" , err )
159152 }
153+ }
154+ }
155+ }
160156
161- signer := types.Signer {
162- PubKey : pubKey ,
163- Address : m .genesis .ProposerAddress ,
164- }
157+ // createSignedDataFromBatch converts a batch to a SignedData, including signing.
158+ func (m * Manager ) createSignedDataFromBatch (batch * coresequencer.Batch ) (* types.SignedData , error ) {
159+ data := types.Data {
160+ Txs : make (types.Txs , len (batch .Transactions )),
161+ }
162+ for i , tx := range batch .Transactions {
163+ data .Txs [i ] = types .Tx (tx )
164+ }
165165
166- // Create SignedData
167- signedData := types.SignedData {
168- Data : data ,
169- Signature : signature ,
170- Signer : signer ,
171- }
166+ signature , err := m .getDataSignature (& data )
167+ if err != nil {
168+ return nil , err
169+ }
172170
173- err = m .submitBatchToDA (ctx , & signedData )
174- if err != nil {
175- m .logger .Error ("failed to submit batch to DA" , "error" , err )
176- }
177- }
171+ pubKey , err := m .signer .GetPublic ()
172+ if err != nil {
173+ return nil , err
178174 }
175+
176+ signer := types.Signer {
177+ PubKey : pubKey ,
178+ Address : m .genesis .ProposerAddress ,
179+ }
180+
181+ return & types.SignedData {
182+ Data : data ,
183+ Signature : signature ,
184+ Signer : signer ,
185+ }, nil
179186}
180187
181188// submitBatchToDA submits a batch of transactions to the Data Availability (DA) layer.
@@ -195,7 +202,7 @@ func (m *Manager) submitBatchToDA(ctx context.Context, signedData *types.SignedD
195202 currentSignedData := signedData
196203 submittedAllTxs := false
197204 var backoff time.Duration
198- totalTxCount := len (currentSignedData .Data . Txs )
205+ totalTxCount := len (currentSignedData .Txs )
199206 submittedTxCount := 0
200207 attempt := 0
201208
@@ -233,16 +240,16 @@ daSubmitRetryLoop:
233240 "gasPrice" , gasPrice ,
234241 "height" , res .Height ,
235242 "submittedTxs" , submittedTxs ,
236- "remainingTxs" , len (currentSignedData .Data . Txs )- submittedTxs )
243+ "remainingTxs" , len (currentSignedData .Txs )- submittedTxs )
237244
238245 submittedTxCount += submittedTxs
239246
240247 // Check if all transactions in the current batch were submitted
241- if submittedTxs == len (currentSignedData .Data . Txs ) {
248+ if submittedTxs == len (currentSignedData .Txs ) {
242249 submittedAllTxs = true
243250 } else {
244251 // Update the current batch to contain only the remaining transactions
245- currentSignedData .Data . Txs = currentSignedData . Data .Txs [submittedTxs :]
252+ currentSignedData .Txs = currentSignedData .Txs [submittedTxs :]
246253 }
247254
248255 // Reset submission parameters after success
0 commit comments