From b2a46ad873f446df820dc4c4022e73162c731405 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:35:45 -0700 Subject: [PATCH 1/4] chores: catch the out of gas exception in preprocess --- gnovm/pkg/gnolang/preprocess.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index d21e9bf0efd..8e3f5d7cc37 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -8,6 +8,7 @@ import ( "sync/atomic" "github.com/gnolang/gno/tm2/pkg/errors" + tmstore "github.com/gnolang/gno/tm2/pkg/store" ) const ( @@ -117,6 +118,10 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { _ = Transcribe(bn, func(ns []Node, ftype TransField, index int, n Node, stage TransStage) (Node, TransCtrl) { defer func() { if r := recover(); r != nil { + // Catch the out-of-gas exception and throw it + if _, ok := r.(tmstore.OutOfGasException); ok { + panic(r) + } // before re-throwing the error, append location information to message. loc := last.GetLocation() if nline := n.GetLine(); nline > 0 { @@ -393,6 +398,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { defer func() { if r := recover(); r != nil { + // Catch the out-of-gas exception and throw it + if _, ok := r.(tmstore.OutOfGasException); ok { + panic(r) + } // before re-throwing the error, append location information to message. loc := last.GetLocation() if nline := n.GetLine(); nline > 0 { @@ -3169,6 +3178,10 @@ func checkIntegerKind(xt Type) { func predefineNow(store Store, last BlockNode, d Decl) (Decl, bool) { defer func() { if r := recover(); r != nil { + // Catch the out-of-gas exception and throw it + if _, ok := r.(tmstore.OutOfGasException); ok { + panic(r) + } // before re-throwing the error, append location information to message. loc := last.GetLocation() if nline := d.GetLine(); nline > 0 { From c73b83ab12a91492e70dca1f35ed4941c0bf3d2e Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:59:27 -0700 Subject: [PATCH 2/4] chore: lint --- gnovm/pkg/gnolang/preprocess.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 8e3f5d7cc37..eaf9fe9b510 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -120,7 +120,7 @@ func initStaticBlocks(store Store, ctx BlockNode, bn BlockNode) { if r := recover(); r != nil { // Catch the out-of-gas exception and throw it if _, ok := r.(tmstore.OutOfGasException); ok { - panic(r) + panic(r) } // before re-throwing the error, append location information to message. loc := last.GetLocation() @@ -3180,7 +3180,7 @@ func predefineNow(store Store, last BlockNode, d Decl) (Decl, bool) { if r := recover(); r != nil { // Catch the out-of-gas exception and throw it if _, ok := r.(tmstore.OutOfGasException); ok { - panic(r) + panic(r) } // before re-throwing the error, append location information to message. loc := last.GetLocation() From a86b93fcce47f4d2f7e58916f294e2d596cbbfec Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Sat, 3 Aug 2024 01:20:07 -0700 Subject: [PATCH 3/4] add a txtar file that catchs out-of-gas errors during preprocess --- .../gnoland/testdata/addpkg_outofgas.txtar | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar diff --git a/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar b/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar new file mode 100644 index 00000000000..d344c53faf6 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar @@ -0,0 +1,57 @@ +# ensure users get proper out of gas errors when they add packages + +# start a new node +gnoland start + +# add foo package +gnokey maketx addpkg -pkgdir $WORK/foo -pkgpath gno.land/r/foo -gas-fee 1000000ugnot -gas-wanted 211483 -broadcast -chainid=tendermint_test test1 + + +# add bar package +# out of gas at store.GetPackage() with gas 60000 + +! gnokey maketx addpkg -pkgdir $WORK/bar -pkgpath gno.land/r/bar -gas-fee 1000000ugnot -gas-wanted 60000 -broadcast -chainid=tendermint_test test1 + +# Out of gas error + +stderr '--= Error =--' +stderr 'Data: out of gas error' +stderr 'Msg Traces:' +stderr ' 0 /Users/b/dev/gnoplay/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 60000, gasUsed: 60343 location: ReadFlat' +stderr '--= /Error =--' + + + +# out of gas at store.store.GetTypeSafe() with gas 63000 + +! gnokey maketx addpkg -pkgdir $WORK/bar -pkgpath gno.land/r/bar -gas-fee 1000000ugnot -gas-wanted 63000 -broadcast -chainid=tendermint_test test1 + +stderr '--= Error =--' +stderr 'Data: out of gas error' +stderr 'Msg Traces:' +stderr ' 0 /Users/b/dev/gnoplay/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 63000, gasUsed: 63363 location: ReadFlat' +stderr '--= /Error =--' + + +-- foo/foo.gno -- +package foo + +type Counter int + +func Inc(i Counter) Counter{ + i = i+1 + return i +} + +-- bar/bar.gno -- +package bar + +import "gno.land/r/foo" + +type NewCounter foo.Counter + +func Add2(i NewCounter) NewCounter{ + i=i+2 + + return i +} From 8c2254182e667a699383545357b7850eb2d3ffc7 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Sat, 3 Aug 2024 01:53:59 -0700 Subject: [PATCH 4/4] updated txtar --- gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar b/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar index d344c53faf6..bddb3769c59 100644 --- a/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar +++ b/gno.land/cmd/gnoland/testdata/addpkg_outofgas.txtar @@ -17,7 +17,7 @@ gnokey maketx addpkg -pkgdir $WORK/foo -pkgpath gno.land/r/foo -gas-fee 1000000u stderr '--= Error =--' stderr 'Data: out of gas error' stderr 'Msg Traces:' -stderr ' 0 /Users/b/dev/gnoplay/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 60000, gasUsed: 60343 location: ReadFlat' +stderr ' 0 /home/runner/work/gno/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 60000, gasUsed: 60343 location: ReadFlat' stderr '--= /Error =--' @@ -29,7 +29,7 @@ stderr '--= /Error =--' stderr '--= Error =--' stderr 'Data: out of gas error' stderr 'Msg Traces:' -stderr ' 0 /Users/b/dev/gnoplay/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 63000, gasUsed: 63363 location: ReadFlat' +stderr ' 0 /home/runner/work/gno/gno/tm2/pkg/crypto/keys/client/maketx.go:215 - deliver transaction failed: log:out of gas, gasWanted: 63000, gasUsed: 63363 location: ReadFlat' stderr '--= /Error =--'