Skip to content

Commit 86e2fb3

Browse files
committed
add TestReadSkippedTransactionV1AsV2
1 parent ae0dca4 commit 86e2fb3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

core/rawdb/accessors_skipped_txs.go

+16
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ func writeSkippedTransaction(db ethdb.KeyValueWriter, tx *types.Transaction, tra
104104
}
105105
}
106106

107+
// writeSkippedTransactionV1 is the old version of writeSkippedTransaction, we keep it for testing compatibility purpose.
108+
func writeSkippedTransactionV1(db ethdb.KeyValueWriter, tx *types.Transaction, reason string, blockNumber uint64, blockHash *common.Hash) {
109+
// workaround: RLP decoding fails if this is nil
110+
if blockHash == nil {
111+
blockHash = &common.Hash{}
112+
}
113+
stx := SkippedTransaction{Tx: tx, Reason: reason, BlockNumber: blockNumber, BlockHash: blockHash}
114+
bytes, err := rlp.EncodeToBytes(stx)
115+
if err != nil {
116+
log.Crit("Failed to RLP encode skipped transaction", "hash", tx.Hash().String(), "err", err)
117+
}
118+
if err := db.Put(SkippedTransactionKey(tx.Hash()), bytes); err != nil {
119+
log.Crit("Failed to store skipped transaction", "hash", tx.Hash().String(), "err", err)
120+
}
121+
}
122+
107123
// readSkippedTransactionRLP retrieves a skipped transaction in its raw RLP database encoding.
108124
func readSkippedTransactionRLP(db ethdb.Reader, txHash common.Hash) rlp.RawValue {
109125
data, err := db.Get(SkippedTransactionKey(txHash))

core/rawdb/accessors_skipped_txs_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ func TestReadWriteSkippedTransactionNoIndex(t *testing.T) {
5151
}
5252
}
5353

54+
func TestReadSkippedTransactionV1AsV2(t *testing.T) {
55+
tx := newTestTransaction(123)
56+
db := NewMemoryDatabase()
57+
writeSkippedTransactionV1(db, tx, "random reason", 1, &common.Hash{1})
58+
got := ReadSkippedTransaction(db, tx.Hash())
59+
if got == nil || got.Tx.Hash() != tx.Hash() || got.Reason != "random reason" || got.BlockNumber != 1 || got.BlockHash == nil || *got.BlockHash != (common.Hash{1}) {
60+
t.Fatal("Skipped transaction mismatch", "got", got)
61+
}
62+
}
63+
5464
func TestReadWriteSkippedTransaction(t *testing.T) {
5565
tx := newTestTransaction(123)
5666
db := NewMemoryDatabase()

0 commit comments

Comments
 (0)