Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make gnovm wasm-friendly #1012

Merged
merged 21 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/gnovm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [ "1.19.x", "1.20.x" ]
goarch: [ "amd64" ]
goos: [ "linux" ]
program: [ "gno" ]
go-version: # two latest versions
- "1.19.x"
- "1.20.x"
goenv: # TODO: replace with pairs, so it's easier to read in the GH interface.
- "GOARCH=amd64 GOOS=linux"
- "GOARCH=wasm GOOS=js"
program:
- "gno"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -36,7 +40,7 @@ jobs:
- uses: actions/checkout@v3
- name: go install
working-directory: gnovm
run: GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go install ./cmd/${{ matrix.program }}
run: ${{ matrix.goenv }} go install ./cmd/${{ matrix.program }}

test:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/fortytw2/leaktest v1.3.0
github.com/gdamore/tcell/v2 v2.1.0
github.com/gnolang/cors v1.8.1
github.com/gnolang/goleveldb v0.0.9
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216
github.com/golang/protobuf v1.5.3
github.com/google/gofuzz v1.2.0
Expand All @@ -27,7 +28,6 @@ require (
github.com/peterbourgon/ff/v3 v3.4.0
github.com/pmezard/go-difflib v1.0.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.0
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c
go.etcd.io/bbolt v1.3.7
go.uber.org/multierr v1.9.0
Expand All @@ -52,7 +52,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion misc/deployments/staging.gno.land/overlay/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ moniker = "45-79-178-97"
fast_sync = true

# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# * goleveldb (github.com/gnolang/goleveldb, fork of github.com/syndtr/goleveldb) - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
Expand Down
2 changes: 1 addition & 1 deletion misc/deployments/test2.gno.land/overlay/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ moniker = "45-79-178-97"
fast_sync = true

# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# * goleveldb (github.com/gnolang/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
Expand Down
2 changes: 1 addition & 1 deletion misc/deployments/test3.gno.land/overlay/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ moniker = "45-79-178-97"
fast_sync = true

# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# * goleveldb (github.com/gnolang/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
Expand Down
19 changes: 7 additions & 12 deletions tm2/pkg/autofile/autofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package autofile

import (
"os"
"os/signal"
"sync"
"syscall"
"time"

"github.com/gnolang/gno/tm2/pkg/random"
Expand Down Expand Up @@ -63,19 +61,16 @@ func OpenAutoFile(path string) (*AutoFile, error) {
closeTicker: time.NewTicker(autoFileClosePeriod),
closeTickerStopc: make(chan struct{}),
}

if err := af.openFile(); err != nil {
af.Close()
return nil, err
}

// Close file on SIGHUP.
af.hupc = make(chan os.Signal, 1)
signal.Notify(af.hupc, syscall.SIGHUP)
go func() {
for range af.hupc {
af.closeFile()
}
}()
// see autofile_*.go implementations, following different build constraints.
if err := af.setupCloseHandler(); err != nil {
return nil, err
}

go af.closeFileRoutine()

Expand Down Expand Up @@ -158,10 +153,10 @@ func (af *AutoFile) openFile() error {
}
// fileInfo, err := file.Stat()
// if err != nil {
// return err
// return err
// }
// if fileInfo.Mode() != autoFilePerms {
// return errors.NewErrPermissionsChanged(file.Name(), fileInfo.Mode(), autoFilePerms)
// return errors.NewErrPermissionsChanged(file.Name(), fileInfo.Mode(), autoFilePerms)
// }
af.file = file
return nil
Expand Down
22 changes: 22 additions & 0 deletions tm2/pkg/autofile/autofile_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !js && !wasm
// +build !js,!wasm

package autofile

import (
"os"
"os/signal"
"syscall"
)

func (af *AutoFile) setupCloseHandler() error {
// Close file on SIGHUP.
af.hupc = make(chan os.Signal, 1)
signal.Notify(af.hupc, syscall.SIGHUP)
go func() {
for range af.hupc {
af.closeFile()
}
}()
return nil
}
8 changes: 8 additions & 0 deletions tm2/pkg/autofile/autofile_wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build js && wasm
// +build js,wasm

moul marked this conversation as resolved.
Show resolved Hide resolved
package autofile

func (af *AutoFile) setupCloseHandler() error {
return nil
}
6 changes: 4 additions & 2 deletions tm2/pkg/bft/abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/bft/abci/example/errors"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
"github.com/gnolang/gno/tm2/pkg/crypto"
dbm "github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/log"
)

Expand All @@ -19,6 +19,8 @@ const (
ValidatorKeyPrefix string = "/val/"
)

const dbBackend = db.GoLevelDBBackend

// -----------------------------------------

var _ abci.Application = (*PersistentKVStoreApplication)(nil)
Expand All @@ -34,7 +36,7 @@ type PersistentKVStoreApplication struct {

func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication {
name := "kvstore"
db, err := dbm.NewGoLevelDB(name, dbDir)
db, err := db.NewDB(name, dbBackend, dbDir)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type BaseConfig struct {
FastSyncMode bool `toml:"fast_sync"`

// Database backend: goleveldb | cleveldb | boltdb
// * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
// * goleveldb (github.com/gnolang/goleveldb - most popular implementation)
// - pure go
// - stable
// * cleveldb (uses levigo wrapper)
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ moniker = "{{ .BaseConfig.Moniker }}"
fast_sync = {{ .BaseConfig.FastSyncMode }}

# Database backend: goleveldb | cleveldb | boltdb
# * goleveldb (github.com/syndtr/goleveldb - most popular implementation)
# * goleveldb (github.com/gnolang/goleveldb - most popular implementation)
# - pure go
# - stable
# * cleveldb (uses levigo wrapper)
Expand Down
Loading