Skip to content

Commit

Permalink
chore: Add cpu-cycle-overrun1.txtar . See the PR.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
  • Loading branch information
jefft0 committed Mar 5, 2024
1 parent 27c5a65 commit 83d99a2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions gno.land/cmd/gnoland/testdata/cpu-cycle-overrun1.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
loadpkg gno.land/p/demo/avl

# start a new node
gnoland start

gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/cpu_cycle_overrun1 -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# Call AddData 3 times
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1
stdout OK!
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1
stdout OK!
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# Call AddData one more time. The call to Render hangs. If you comment this out, then the call to Render returns quickly.
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1
stdout OK!

# Call Render
gnokey query vm/qrender --data "gno.land/r/cpu_cycle_overrun1\n"

-- cpu_cycle_overrun1.gno --
package cpu_cycle_overrun1

import (
"strconv"
"time"

"gno.land/p/demo/avl"
)

var gData = avl.Tree{} // id -> string

type MyData struct {
data avl.Tree
}

// Add a lot of data to gData (as much as we can do with the given maximum gas allowed).
func AddData() {
for i := 1; i <= 1000; i++ {
gData.Set(strconv.Itoa(gData.Size()), "hello")
}
}

func Render(path string) string {
// Put the data in allData.
subdata := &MyData{data: gData}
allData := avl.Tree{}
gData.Iterate("", "", func(key string, postI interface{}) bool {
allData.Set(strconv.Itoa(allData.Size()), subdata)
return false
})

// Iterate allData and make the render string.
now := time.Now()
str := ""
allData.Iterate("", "", func(key string, dataI interface{}) bool {
str += now.Format("2006-01-02 3:04pm MST")
return false
})
return "len " + strconv.Itoa(len(str))
}

0 comments on commit 83d99a2

Please sign in to comment.