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 { if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback() b.pendingReaderTx.Rollback()
} }
tx, err := b.m.DB.BeginRo(context.Background()) tx, err := b.m.DB.BeginRo(context.Background()) //nolint:gocritic
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -122,11 +122,13 @@ func CompareAccountRange(logger log.Logger, erigonURL, gethURL, tmpDataDir, geth
log.Error(err.Error()) log.Error(err.Error())
return return
} }
defer tgTx.Rollback()
gethTx, err := gethKV.BeginRo(context.Background()) gethTx, err := gethKV.BeginRo(context.Background())
if err != nil { if err != nil {
log.Error(err.Error()) log.Error(err.Error())
return return
} }
defer gethTx.Rollback()
tgCursor, err := tgTx.Cursor(kv.E2AccountsHistory) tgCursor, err := tgTx.Cursor(kv.E2AccountsHistory)
if err != nil { if err != nil {
log.Error(err.Error()) 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) InternalDB() kv.RwDB { return db.RwDB }
func (db *DB) BeginTemporalRo(ctx context.Context) (kv.TemporalTx, error) { 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 { if err != nil {
return nil, err return nil, err
} }

View File

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

View File

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