Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit cc4e302

Browse files
feat(tx_list_validator): remove unused code in tx_list_validator package (#609)
1 parent 8159155 commit cc4e302

File tree

3 files changed

+19
-58
lines changed

3 files changed

+19
-58
lines changed

driver/chain_syncer/calldata/syncer.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/taikoxyz/taiko-client/internal/metrics"
2525
eventIterator "github.com/taikoxyz/taiko-client/pkg/chain_iterator/event_iterator"
2626
"github.com/taikoxyz/taiko-client/pkg/rpc"
27-
txListValidator "github.com/taikoxyz/taiko-client/pkg/txlistvalidator"
27+
txListValidator "github.com/taikoxyz/taiko-client/pkg/txlist_validator"
2828
)
2929

3030
var (
@@ -248,20 +248,6 @@ func (s *Syncer) onBlockProposed(
248248
return fmt.Errorf("failed to decode tx list: %w", err)
249249
}
250250

251-
// Check whether the transactions list is valid.
252-
hint, invalidTxIndex, err := s.txListValidator.ValidateTxList(event.BlockId, txListBytes, event.Meta.BlobUsed)
253-
if err != nil {
254-
return fmt.Errorf("failed to validate transactions list: %w", err)
255-
}
256-
257-
log.Info(
258-
"Validate transactions list",
259-
"blockID", event.BlockId,
260-
"hint", hint,
261-
"invalidTxIndex", invalidTxIndex,
262-
"bytes", len(txListBytes),
263-
)
264-
265251
l1Origin := &rawdb.L1Origin{
266252
BlockID: event.BlockId,
267253
L2BlockHash: common.Hash{}, // Will be set by taiko-geth.
@@ -275,7 +261,7 @@ func (s *Syncer) onBlockProposed(
275261
}
276262

277263
// If the transactions list is invalid, we simply insert an empty L2 block.
278-
if hint != txListValidator.HintOK {
264+
if !s.txListValidator.ValidateTxList(event.BlockId, txListBytes, event.Meta.BlobUsed) {
279265
log.Info("Invalid transactions list, insert an empty L2 block instead", "blockID", event.BlockId)
280266
txListBytes = []byte{}
281267
}

pkg/txlistvalidator/tx_list_validator.go pkg/txlist_validator/tx_list_validator.go

+8-26
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ import (
88
"github.com/ethereum/go-ethereum/rlp"
99
)
1010

11-
// InvalidTxListReason represents a reason why a transactions list is invalid.
12-
type InvalidTxListReason uint8
13-
14-
// All invalid transactions list reasons.
15-
const (
16-
HintNone InvalidTxListReason = iota
17-
HintOK
18-
)
19-
11+
// TxListValidator is responsible for validating the transactions list in a TaikoL1.proposeBlock transaction.
2012
type TxListValidator struct {
2113
blockMaxGasLimit uint64
2214
maxTransactionsPerBlock uint64
@@ -45,40 +37,30 @@ func (v *TxListValidator) ValidateTxList(
4537
blockID *big.Int,
4638
txListBytes []byte,
4739
blobUsed bool,
48-
) (hint InvalidTxListReason, txIdx int, err error) {
40+
) (isValid bool) {
41+
// If the transaction list is empty, it's valid.
4942
if len(txListBytes) == 0 {
50-
return HintOK, 0, nil
43+
return true
5144
}
5245

53-
hint, txIdx = v.isTxListValid(blockID, txListBytes, blobUsed)
54-
55-
return hint, txIdx, nil
56-
}
57-
58-
// isTxListValid checks whether the transaction list is valid.
59-
func (v *TxListValidator) isTxListValid(
60-
blockID *big.Int,
61-
txListBytes []byte,
62-
blobUsed bool,
63-
) (hint InvalidTxListReason, txIdx int) {
6446
if !blobUsed && (len(txListBytes) > int(v.maxBytesPerTxList)) {
6547
log.Info("Transactions list binary too large", "length", len(txListBytes), "blockID", blockID)
66-
return HintNone, 0
48+
return false
6749
}
6850

6951
var txs types.Transactions
7052
if err := rlp.DecodeBytes(txListBytes, &txs); err != nil {
7153
log.Info("Failed to decode transactions list bytes", "blockID", blockID, "error", err)
72-
return HintNone, 0
54+
return false
7355
}
7456

7557
log.Debug("Transactions list decoded", "blockID", blockID, "length", len(txs))
7658

7759
if txs.Len() > int(v.maxTransactionsPerBlock) {
7860
log.Info("Too many transactions", "blockID", blockID, "count", txs.Len())
79-
return HintNone, 0
61+
return false
8062
}
8163

8264
log.Info("Transaction list is valid", "blockID", blockID)
83-
return HintOK, 0
65+
return true
8466
}

pkg/txlistvalidator/tx_list_validator_test.go pkg/txlist_validator/tx_list_validator_test.go

+9-16
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,44 @@ func TestIsTxListValid(t *testing.T) {
4242
name string
4343
blockID *big.Int
4444
txListBytes []byte
45-
wantReason InvalidTxListReason
46-
wantTxIdx int
45+
isValid bool
4746
}{
4847
{
4948
"txListBytes binary too large",
5049
chainID,
5150
randBytes(maxTxlistBytes + 1),
52-
HintNone,
53-
0,
51+
false,
5452
},
5553
{
5654
"txListBytes not decodable to rlp",
5755
chainID,
58-
randBytes(0),
59-
HintNone,
60-
0,
56+
randBytes(0x1),
57+
false,
6158
},
6259
{
6360
"txListBytes too many transactions",
6461
chainID,
6562
rlpEncodedTransactionBytes(int(maxBlockNumTxs)+1, true),
66-
HintNone,
67-
0,
63+
false,
6864
},
6965
{
7066
"success empty tx list",
7167
chainID,
7268
rlpEncodedTransactionBytes(0, true),
73-
HintOK,
74-
0,
69+
true,
7570
},
7671
{
7772
"success non-empty tx list",
7873
chainID,
7974
rlpEncodedTransactionBytes(1, true),
80-
HintOK,
81-
0,
75+
true,
8276
},
8377
}
8478

8579
for _, tt := range tests {
8680
t.Run(tt.name, func(t *testing.T) {
87-
reason, txIdx := v.isTxListValid(tt.blockID, tt.txListBytes, false)
88-
require.Equal(t, tt.wantReason, reason)
89-
require.Equal(t, tt.wantTxIdx, txIdx)
81+
isValid := v.ValidateTxList(tt.blockID, tt.txListBytes, false)
82+
require.Equal(t, tt.isValid, isValid)
9083
})
9184
}
9285
}

0 commit comments

Comments
 (0)