gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
892 stars 371 forks source link

Transactions with realms that have static assets #1124

Closed schollz closed 1 year ago

schollz commented 1 year ago

Hi all - I'm working through issues on the haiku realm (#860). One of the roadblocks is adding a dictionary of words into the realm, which generally may be a problem associated with any realm that wants a lot of static assets.

I previously tried using the avl.Tree to add the wordlist dynamically but this had a cost in allocations that was substantially high during the make transaction.

As @moul suggested, I retried using some code generation, to generate a static dictionary dominated by a switch-case for returning word syllables (wordlist.gno).

The code-generated file works and pasts tests quickly:

gno test --verbose examples/gno.land/r/demo/art/haiku
=== RUN   TestAmulet
--- PASS: TestAmulet (0.05s)
ok      ./examples/gno.land/r/demo/art/haiku    0.77s

...but now I'm unable to create a realm with it - presumably because of the size of the actual codebase. The wordlist.gno file is 844,755 bytes. When making a transaction with this realm I get a RPC error about the request body being too large:

gnokey maketx addpkg --pkgpath "gno.land/r/demo/art/haikus" \
  --pkgdir "examples/gno.land/r/demo/art/haiku" \
  --deposit 100000ugnot --gas-fee 2000000ugnot \
  --gas-wanted 10000000 --broadcast --chainid dev \
  --remote localhost:26657 zzkey1
Enter password.
--= Error =--
Data: RPC error -32600 - Invalid Request: http: request body too large
Msg Traces:
    0  /home/zns/Documents/gno/tm2/pkg/bft/rpc/lib/client/http_client.go:355 - response error
    1  /home/zns/Documents/gno/tm2/pkg/bft/rpc/client/httpclient.go:171 - broadcast_tx_commit
    2  /home/zns/Documents/gno/tm2/pkg/crypto/keys/client/broadcast.go:111 - broadcasting bytes
    3  /home/zns/Documents/gno/tm2/pkg/crypto/keys/client/addpkg.go:208 - broadcast tx
--= /Error =--

Is there a way to increase the allotted request body size? Or is there another way to produce a realm with a lot of static assets (e.g. multiple http requests?)

moul commented 1 year ago

@thehowl encountered similar challenges with gnochess.

We deliberated on adjusting the max gas per transaction, which, in my opinion, tackles a separate issue. However, your scenario could serve as a more intricate benchmark to assess this behavior.

Nonetheless, even if we elevate the existing limits, your realm might still exceed them. Perhaps it would be pragmatic for you to concentrate on a framework that utilizes a compact contract combined with a provision script. This script can then execute multiple transactions to populate a structure, whether it's AVL or another type.

schollz commented 1 year ago

Thanks @moul - this is solved with doing multiple transactions: https://github.com/schollz/gno/tree/realm/haiku/examples/gno.land/r/demo/art/haiku