Skip to content

Commit 7f92ba9

Browse files
committed
fix: modify removeParity function
1 parent 924d382 commit 7f92ba9

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

core/txpool/blobpool/blobpool.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -167,33 +167,37 @@ func (ptx *PooledBlobTx) Convert() (*types.Transaction, error) {
167167

168168
return ptx.Transaction.WithBlobTxSidecar(sidecar), nil
169169
}
170-
171170
func (ptx *PooledBlobTx) RemoveParity() error {
172171
sc := ptx.Sidecar
173-
custodySize := sc.Custody.OneCount()
174-
if custodySize == 0 {
175-
return errors.New("blobless transaction")
172+
if sc == nil {
173+
return errors.New("nil sidecar")
176174
}
177-
blobCount := len(sc.Cells) / custodySize
178175

179-
var cellsWithoutParity []kzg4844.Cell
180-
pos := 0
181-
for range blobCount {
182-
for bit := 0; bit < kzg4844.CellsPerBlob; bit++ {
183-
if sc.Custody.IsSet(uint(bit)) {
184-
cell := sc.Cells[pos]
185-
pos++
186-
if bit < kzg4844.DataPerBlob {
187-
cellsWithoutParity = append(cellsWithoutParity, cell)
188-
}
189-
}
176+
for bit := range kzg4844.DataPerBlob {
177+
if !sc.Custody.IsSet(uint(bit)) {
178+
return errors.New("cannot remove parity for non-full payload transaction")
190179
}
191180
}
192-
sc.Cells = cellsWithoutParity
193-
for bit := 64; bit < kzg4844.CellsPerBlob; bit++ {
194-
sc.Custody.Clear(uint(bit))
181+
182+
blobCount := len(sc.Cells) / kzg4844.CellsPerBlob
183+
if blobCount == 0 || len(sc.Cells)%kzg4844.CellsPerBlob != 0 {
184+
return errors.New("inconsistent cell count")
195185
}
196186

187+
var cellsWithoutParity []kzg4844.Cell
188+
for blob := range blobCount {
189+
offset := blob * kzg4844.CellsPerBlob
190+
cellsWithoutParity = append(
191+
cellsWithoutParity,
192+
sc.Cells[offset:offset+kzg4844.DataPerBlob]...,
193+
)
194+
195+
for bit := 64; bit < kzg4844.CellsPerBlob; bit++ {
196+
sc.Custody.Clear(uint(bit))
197+
}
198+
}
199+
200+
sc.Cells = cellsWithoutParity
197201
return nil
198202
}
199203

core/txpool/validation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
145145
}
146146

147147
func ValidateBlobSidecar(tx *types.Transaction, sidecar *types.BlobTxCellSidecar, head *types.Header, opts *ValidationOptions) error {
148+
if sidecar.Custody.OneCount() == 0 {
149+
return errors.New("blobless blob transaction")
150+
}
148151
// Ensure the blob fee cap satisfies the minimum blob gas price
149152
if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 {
150153
return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrTxGasPriceTooLow, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice)

0 commit comments

Comments
 (0)