Scan transaction to select test cases (#2225)

* Scan txs

* Find examples with access lists

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
This commit is contained in:
ledgerwatch 2021-06-23 23:34:17 +01:00 committed by GitHub
parent 876dde506f
commit adf4766191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2030,6 +2030,44 @@ func trimTxs(chaindata string) error {
return nil
}
func scanTxs(chaindata string) error {
db := kv2.MustOpen(chaindata).RwKV()
defer db.Close()
tx, err := db.BeginRo(context.Background())
if err != nil {
return err
}
defer tx.Rollback()
c, err := tx.Cursor(dbutils.EthTx)
if err != nil {
return err
}
defer c.Close()
trTypes := make(map[byte]int)
trTypesAl := make(map[byte]int)
for k, v, err := c.First(); k != nil; k, v, err = c.Next() {
if err != nil {
return err
}
var tr types.Transaction
if tr, err = types.DecodeTransaction(rlp.NewStream(bytes.NewReader(v), 0)); err != nil {
return err
}
if _, ok := trTypes[tr.Type()]; !ok {
fmt.Printf("Example for type %d:\n%x\n", tr.Type(), v)
}
trTypes[tr.Type()]++
if tr.GetAccessList().StorageKeys() > 0 {
if _, ok := trTypesAl[tr.Type()]; !ok {
fmt.Printf("Example for type %d with AL:\n%x\n", tr.Type(), v)
}
trTypesAl[tr.Type()]++
}
}
fmt.Printf("Transaction types: %v\n", trTypes)
return nil
}
func scanReceipts(chaindata string) error {
dbdb := kv2.MustOpen(chaindata).RwKV()
defer dbdb.Close()
@ -2266,6 +2304,9 @@ func main() {
case "trimTxs":
err = trimTxs(*chaindata)
case "scanTxs":
err = scanTxs(*chaindata)
case "scanReceipts":
err = scanReceipts(*chaindata)
}