Skip to content

Commit

Permalink
chore: public release (#10)
Browse files Browse the repository at this point in the history
* chore: Dockerfile, repo restructure

* chore: remove root package, invariant check for config

* chore: remove sidesync

* chore: remove unused, default wasm instance cache to 1G
  • Loading branch information
kjessec authored Dec 7, 2021
1 parent 4acb3da commit 3a199c4
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 311 deletions.
35 changes: 35 additions & 0 deletions bin/v0.34.x/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.17-alpine3.14 AS go-builder

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; apk add --no-cache ca-certificates build-base;

RUN apk add git
# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers

WORKDIR /code
COPY . /code/

# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v0.16.2/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep 0e62296b9f24cf3a05f8513f99cee536c7087079855ea6ffb4f89b35eccdaa66

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false go build -work -tags muslc,linux -mod=readonly -o build/mantlemint ./sync.go

FROM alpine:3.12

WORKDIR /root

COPY --from=go-builder /code/build/mantlemint /usr/local/bin/mantlemint

# rest server
EXPOSE 1317
# grpc
EXPOSE 9090

CMD ["/usr/local/bin/mantlemint"]
37 changes: 17 additions & 20 deletions bin/v0.34.x/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
terra "github.com/terra-money/core/app"
"os"
"strconv"
"strings"
)

Expand All @@ -13,40 +12,39 @@ type Config struct {
Home string
ChainID string
RPCEndpoints []string
WSEndpoints []string
WSEndpoints []string
MantlemintDB string
IndexerDB string
IndexerSideSyncPort int64
DisableSync bool
}

// NewConfig converts envvars into consumable config chunks
func NewConfig() Config {
return Config{
// GenesisPath sets the location of genesis
GenesisPath: os.Getenv("GENESIS_PATH"),
GenesisPath: getValidEnv("GENESIS_PATH"),

// Home sets where the default terra home is.
Home: os.Getenv("HOME"),
Home: getValidEnv("HOME"),

// ChainID sets expected chain id for this mantlemint instance
ChainID: os.Getenv("CHAIN_ID"),
ChainID: getValidEnv("CHAIN_ID"),

// RPCEndpoints is where to pull txs from when fast-syncing
RPCEndpoints: func() []string {
endpoints := os.Getenv("RPC_ENDPOINTS")
endpoints := getValidEnv("RPC_ENDPOINTS")
return strings.Split(endpoints, ",")
}(),

// WSEndpoints is where to pull txs from when normal syncing
WSEndpoints: func() []string {
endpoints := os.Getenv("WS_ENDPOINTS")
endpoints := getValidEnv("WS_ENDPOINTS")
return strings.Split(endpoints, ",")
}(),

// MantlemintDB is the db name for mantlemint. Defaults to terra.DefaultHome
MantlemintDB: func() string {
mantlemintDB := os.Getenv("MANTLEMINT_DB")
mantlemintDB := getValidEnv("MANTLEMINT_DB")
if mantlemintDB == "" {
return terra.DefaultNodeHome
} else {
Expand All @@ -55,20 +53,11 @@ func NewConfig() Config {
}(),

// IndexerDB is the db name for indexed data
IndexerDB: os.Getenv("INDEXER_DB"),

// IndexerSideSyncPort is
IndexerSideSyncPort: func() int64 {
port, portErr := strconv.Atoi(os.Getenv("INDEXER_SIDESYNC_PORT"))
if portErr != nil {
panic(portErr)
}
return int64(port)
}(),
IndexerDB: getValidEnv("INDEXER_DB"),

// DisableSync sets a flag where if true mantlemint won't accept any blocks (usually for debugging)
DisableSync: func() bool {
disableSync := os.Getenv("DISABLE_SYNC")
disableSync := getValidEnv("DISABLE_SYNC")
return disableSync == "true"
}(),
}
Expand All @@ -77,3 +66,11 @@ func NewConfig() Config {
func (cfg Config) Print() {
fmt.Println(cfg)
}

func getValidEnv(tag string) string {
if e := os.Getenv(tag); e == "" {
panic(fmt.Errorf("environment variable %s not set; expected string, got %s \"\"", tag, e))
} else {
return e
}
}
2 changes: 1 addition & 1 deletion bin/v0.34.x/db/heleveldb/leveldb_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

tmdb "github.com/tendermint/tm-db"
"github.com/terra-money/mantlemint-provider-v0.34.x/db/hld"
"github.com/terra-money/mantlemint/lib"
"github.com/terra-money/mantlemint-provider-v0.34.x/lib"
)

var _ hld.HeightLimitEnabledBatch = (*LevelBatch)(nil)
Expand Down
2 changes: 1 addition & 1 deletion bin/v0.34.x/db/heleveldb/leveldb_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

tmdb "github.com/tendermint/tm-db"
"github.com/terra-money/mantlemint-provider-v0.34.x/db/hld"
"github.com/terra-money/mantlemint/lib"
"github.com/terra-money/mantlemint-provider-v0.34.x/lib"
)

type Driver struct {
Expand Down
2 changes: 1 addition & 1 deletion bin/v0.34.x/db/hld/height_limited_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"sync"

"github.com/terra-money/mantlemint/lib"
"github.com/terra-money/mantlemint-provider-v0.34.x/lib"

tmdb "github.com/tendermint/tm-db"
)
Expand Down
3 changes: 0 additions & 3 deletions bin/v0.34.x/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ require (
github.com/tendermint/tendermint v0.34.13
github.com/tendermint/tm-db v0.6.4
github.com/terra-money/core v0.5.11
github.com/terra-money/mantlemint v0.0.0

)

Expand Down Expand Up @@ -113,8 +112,6 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/terra-money/mantlemint => ../../

replace github.com/cosmos/ledger-cosmos-go => github.com/terra-money/ledger-terra-go v0.11.2

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
1 change: 0 additions & 1 deletion bin/v0.34.x/indexer/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ func TestIndexBlock(t *testing.T) {
assert.NotNil(t, block)

fmt.Println(string(block))

}
2 changes: 1 addition & 1 deletion bin/v0.34.x/indexer/block/lazy_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func LazySync(height int64, rpcEndpoint string, indexerDB tmdb.DB) (json.RawMessage, error) {
fmt.Printf("[indexer/block/sidesync] syncing block %d..\n", height)
fmt.Printf("[indexer/block/lazysync] syncing block %d..\n", height)

resp, err := http.Get(fmt.Sprintf("%v/block?height=%d", rpcEndpoint, height))
if err != nil {
Expand Down
97 changes: 0 additions & 97 deletions bin/v0.34.x/indexer/block/sidesync.go

This file was deleted.

2 changes: 1 addition & 1 deletion bin/v0.34.x/indexer/block/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package block

import (
tm "github.com/tendermint/tendermint/types"
"github.com/terra-money/mantlemint/lib"
"github.com/terra-money/mantlemint-provider-v0.34.x/lib"
)

var prefix = []byte("block/height:")
Expand Down
20 changes: 0 additions & 20 deletions bin/v0.34.x/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (
tmdb "github.com/tendermint/tm-db"
"github.com/terra-money/mantlemint-provider-v0.34.x/db/snappy"
"github.com/terra-money/mantlemint-provider-v0.34.x/mantlemint"
"net/http"
"time"
)

type Indexer struct {
db tmdb.DB
indexerTags []string
indexers []IndexFunc
sidesyncRouter *mux.Router
}

func NewIndexer(dbName, path string) (*Indexer, error) {
Expand Down Expand Up @@ -60,25 +58,7 @@ func (idx *Indexer) Run(block *tm.Block, blockId *tm.BlockID, evc *mantlemint.Ev
return nil
}

func (idx *Indexer) WithSideSyncRouter(registerer func(sidesyncRouter *mux.Router)) *Indexer {
idx.sidesyncRouter = mux.NewRouter()
registerer(idx.sidesyncRouter)

return idx
}

func (idx *Indexer) RegisterRESTRoute(router *mux.Router, postRouter *mux.Router, registerer RESTRouteRegisterer) {
registerer(router, postRouter, idx.db)
}

func (idx *Indexer) StartSideSync(port int64) {
if idx.sidesyncRouter == nil {
panic(fmt.Errorf("sidesync router not set, perhaps you didn't call WithSyideSyncRouter first?\n"))
}

router := idx.sidesyncRouter
err := http.ListenAndServe(fmt.Sprintf(":%d", port), router)
if err != nil {
panic(err)
}
}
Loading

0 comments on commit 3a199c4

Please sign in to comment.