Skip to content

Commit be53cf5

Browse files
fix lint and refactor
1 parent c3a128c commit be53cf5

5 files changed

Lines changed: 45 additions & 41 deletions

File tree

block/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ func (m *Manager) SaveCache() error {
991991

992992
// isValidSignedData returns true if the data signature is valid for the expected sequencer.
993993
func (m *Manager) isValidSignedData(signedData *types.SignedData) bool {
994-
if signedData == nil || signedData.Data.Txs == nil {
994+
if signedData == nil || signedData.Txs == nil {
995995
return false
996996
}
997997
if !bytes.Equal(signedData.Signer.Address, m.genesis.ProposerAddress) {

block/retriever.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (m *Manager) handlePotentialData(ctx context.Context, bz []byte, daHeight u
153153
m.logger.Debug("failed to unmarshal signed data", "error", err)
154154
return
155155
}
156-
if signedData.Data.Txs == nil || len(signedData.Data.Txs) == 0 {
156+
if len(signedData.Txs) == 0 {
157157
m.logger.Debug("ignoring empty signed data", "daHeight", daHeight)
158158
return
159159
}

block/submitter.go

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
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

block/submitter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func TestSubmitBatchToDA_Success(t *testing.T) {
6868
},
6969
}
7070

71-
signedData.Data.Txs = make(types.Txs, len(batch.Transactions))
71+
signedData.Txs = make(types.Txs, len(batch.Transactions))
7272
for i, tx := range batch.Transactions {
73-
signedData.Data.Txs[i] = types.Tx(tx)
73+
signedData.Txs[i] = types.Tx(tx)
7474
}
7575

7676
signature, err := m.getDataSignature(&signedData.Data)
@@ -120,9 +120,9 @@ func TestSubmitBatchToDA_Failure(t *testing.T) {
120120
},
121121
}
122122

123-
signedData.Data.Txs = make(types.Txs, len(batch.Transactions))
123+
signedData.Txs = make(types.Txs, len(batch.Transactions))
124124
for i, tx := range batch.Transactions {
125-
signedData.Data.Txs[i] = types.Tx(tx)
125+
signedData.Txs[i] = types.Tx(tx)
126126
}
127127

128128
signature, err := m.getDataSignature(&signedData.Data)

types/serialization.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ func byteSlicesToTxs(bytes [][]byte) Txs {
350350

351351
// ToProto converts SignedData into protobuf representation and returns it.
352352
func (sd *SignedData) ToProto() (*pb.SignedData, error) {
353-
var dataProto *pb.Data
354-
if &sd.Data != nil {
355-
dataProto = sd.Data.ToProto()
356-
}
353+
dataProto := sd.Data.ToProto()
357354

358355
var signerProto *pb.Signer
359356
if sd.Signer.PubKey != nil {

0 commit comments

Comments
 (0)