Add readonly transaction rollback check rule (#8682)

This commit is contained in:
pwd123 2023-11-09 13:40:11 +09:00 committed by GitHub
parent 466031ab8f
commit a0682088ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 2 deletions

View File

@ -177,7 +177,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
tx, err := b.m.DB.BeginRo(context.Background())
tx, err := b.m.DB.BeginRo(context.Background()) //nolint:gocritic
if err != nil {
panic(err)
}

View File

@ -122,11 +122,13 @@ func CompareAccountRange(logger log.Logger, erigonURL, gethURL, tmpDataDir, geth
log.Error(err.Error())
return
}
defer tgTx.Rollback()
gethTx, err := gethKV.BeginRo(context.Background())
if err != nil {
log.Error(err.Error())
return
}
defer gethTx.Rollback()
tgCursor, err := tgTx.Cursor(kv.E2AccountsHistory)
if err != nil {
log.Error(err.Error())

View File

@ -105,7 +105,7 @@ func (db *DB) Agg() *state.AggregatorV3 { return db.agg }
func (db *DB) InternalDB() kv.RwDB { return db.RwDB }
func (db *DB) BeginTemporalRo(ctx context.Context) (kv.TemporalTx, error) {
kvTx, err := db.RwDB.BeginRo(ctx)
kvTx, err := db.RwDB.BeginRo(ctx) //nolint:gocritic
if err != nil {
return nil, err
}

View File

@ -34,6 +34,8 @@ func txDeferRollback(m dsl.Matcher) {
`$tx, $err = $db.BeginRw($ctx); $chk; $rollback`,
`$tx, $err := $db.Begin($ctx); $chk; $rollback`,
`$tx, $err = $db.Begin($ctx); $chk; $rollback`,
`$tx, $err := $db.BeginRo($ctx); $chk; $rollback`,
`$tx, $err = $db.BeginRo($ctx); $chk; $rollback`,
).
Where(!m["rollback"].Text.Matches(`defer .*\.Rollback()`)).
//At(m["rollback"]).

View File

@ -33,6 +33,8 @@ func txDeferRollback(m dsl.Matcher) {
`$tx, $err = $db.BeginRw($ctx); $chk; $rollback`,
`$tx, $err := $db.Begin($ctx); $chk; $rollback`,
`$tx, $err = $db.Begin($ctx); $chk; $rollback`,
`$tx, $err := $db.BeginRo($ctx); $chk; $rollback`,
`$tx, $err = $db.BeginRo($ctx); $chk; $rollback`,
).
Where(!m["rollback"].Text.Matches(`defer .*\.Rollback()`)).
//At(m["rollback"]).

View File

@ -14,6 +14,7 @@ func (api *ErigonImpl) CacheCheck() (*kvcache.CacheValidationResult, error) {
if err != nil {
return nil, err
}
defer tx.Rollback()
result, err := cache.ValidateCurrentRoot(ctx, tx)
if err != nil {