Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tuky191 committed Sep 12, 2023
2 parents b0470df + 111d8e0 commit c75da60
Show file tree
Hide file tree
Showing 42 changed files with 269 additions and 321 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## Unreleased
This release contains a dependency upgrade for [classic-terra/core](https://github.com/classic-terra/core)@v2.1.2 with AppHash fix caused by legacy wasm codec

## [v2.1.1](https://github.com/classic-terra/mantlemint/tree/v2.1.1) (2023-06-11)
This release contains a dependency upgrade for [classic-terra/core](https://github.com/classic-terra/core)@v2.1.1

## [v2.0.2](https://github.com/classic-terra/mantlemint/tree/v2.1.1) (2023-05-12)
This release contains a dependency upgrade for [classic-terra/core](https://github.com/classic-terra/core)@v2.0.2

## [v1.1.0]
This release contains a dependency upgrade for [classic-terra/core](https://github.com/classic-terra/core)@v1.1.0

## [v1.0.5]
This release contains a dependency upgrade for [classic-terra/core](https://github.com/classic-terra/core)@v1.0.5

## [v0.1.2](https://github.com/terra-money/mantlemint/tree/v0.1.2) (2022-04-14)

This release contains a depencency upgrade for [core](https://github.com/terra-money/core)@0.5.17...@0.5.18. Apart from the dependency bump all functionalities should be exactly the same as v0.1.1.
Expand Down
72 changes: 24 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
ARG GO_VERSION="1.20"
ARG ALPINE_VERSION="3.16"
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18-alpine3.17 AS go-builder
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE="golang:${GO_VERSION}-alpine${ALPINE_VERSION}"
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base

###############################################################################
# Builder
###############################################################################
FROM base as builder-stage-1

ARG BUILDPLATFORM

# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
linux-headers \
ca-certificates \
linux-headers \
build-base \
cmake \
git

WORKDIR /go/src/mimalloc

# use mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 --branch v2.0.9 \
git clone --depth 1 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install

WORKDIR /go/src/mantlemint
COPY . .
WORKDIR /code
COPY . /code/

# Cosmwasm - Download correct libwasmvm version
# See https://github.com/CosmWasm/wasmvm/releases
# Cosmwasm - Download correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"; \
Expand All @@ -52,44 +43,29 @@ RUN set -eux &&\
wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a; \
CHECKSUM=`sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1`; \
grep ${CHECKSUM} /tmp/checksums.txt; \
rm /tmp/checksums.txt
rm /tmp/checksums.txt

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN set -eux &&\
LEDGER_ENABLED=false \
go build -work \
-tags muslc,linux \
RUN LEDGER_ENABLED=false \
go build \
-mod=readonly \
-ldflags="-extldflags '-L/go/src/mimalloc/build -lmimalloc -static'" \
-o /go/bin/mantlemint \
./sync.go
-tags "muslc,linux" \
-ldflags " \
-w -s -linkmode=external -extldflags \
'-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static' \
" \
-trimpath \
-o build/mantlemint ./sync.go

###############################################################################
FROM alpine:${ALPINE_VERSION} as terra-core
FROM alpine:3.17

WORKDIR /root

COPY --from=builder-stage-1 /go/bin/mantlemint /usr/local/bin/mantlemint

ENV CHAIN_ID="localterra" \
MANTLEMINT_HOME="/app" \
## db paths relative to MANTLEMINT_HOME
INDEXER_DB="/data/indexer" \
MANTLEMINT_DB="/data/mantlemint" \
GENESIS_PATH="/app/config/genesis.json" \
DISABLE_SYNC="false" \
RUST_BACKTRACE="full" \
ENABLE_EXPORT_MODULE="false" \
RICHLIST_LENGTH="100" \
RICHLIST_THRESHOLD="0uluna" \
ACCOUNT_ADDRESS_PREFIX="terra" \
BOND_DENOM="uluna" \
LCD_ENDPOINTS="http://localhost:1317" \
RPC_ENDPOINTS="http://localhost:26657" \
WS_ENDPOINTS="ws://localhost:26657/websocket"
COPY --from=go-builder /code/build/mantlemint /usr/local/bin/mantlemint

# lcd & grpc ports
# rest server
EXPOSE 1317
# grpc
EXPOSE 9090

CMD ["/usr/local/bin/mantlemint"]
71 changes: 17 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#!/usr/bin/make -f

BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
SHA256_CMD = sha256sum
GO_VERSION ?= "1.20"

ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

build: go.sum
ifeq ($(OS),Windows_NT)
Expand All @@ -20,54 +9,28 @@ else
go build -mod=readonly $(BUILD_FLAGS) -o build/mantlemint ./sync.go
endif

lint:
golangci-lint run --out-format=tab

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0

lint-strict:
find . -path './_build' -prune -o -type f -name '*.go' -exec gofumpt -w -l {} +

build-static:
mkdir -p $(BUILDDIR)
$(DOCKER) buildx build --tag terramoney/mantlemint ./
$(DOCKER) create --name temp terramoney/mantlemint:latest
$(DOCKER) cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
$(DOCKER) rm temp
docker buildx build --tag terramoney/mantlemint ./
docker create --name temp terramoney/mantlemint:latest
docker cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
docker rm temp

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify

build-release-amd64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/amd64 \
--build-arg GOOS=linux \
--build-arg GOARCH=amd64 \
-t mantlemint:local-amd64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-amd64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder

build-release-arm64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/arm64 \
--build-arg GOOS=linux \
--build-arg GOARCH=arm64 \
-t mantlemint:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-arm64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_aarch64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder
clean:
rm -rf $(BUILDDIR)/
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# terra-money/mantlemint
# classic-terra/mantlemint


## What is Mantlemint?
Expand All @@ -9,8 +9,8 @@ Native query performance on RPC is slow and is not suitable for massive query ha

If you are looking to serve any kind of public node accepting varying degrees of end-user queries, it is recommended that you run a mantlemint instance alongside of your RPC. While mantlemint is indeed faster at resolving queries, due to the absence of IAVL tree and native tendermint, it cannot join p2p network by itself. Rather, you would have to relay finalized blocks to mantlemint, using RPC's websocket.

## Currently supported terra-money/core versions
- columbus-5 | terra-money/core@0.5.x | tendermint v0.34.x
## Currently supported classic-terra/core versions
- columbus-5 | classic-terra/core@2.1.x | tendermint v0.34.x


## Features
Expand All @@ -24,7 +24,7 @@ If you are looking to serve any kind of public node accepting varying degrees of

## Installation

This specific directory contains mantlemint implementation for [@terra-money/core@0.5.x](https://github.com/terra-money/core) (compatible with [[email protected]](https://github.com/tendermint/tendermint)).
This specific directory contains mantlemint implementation for [@classic-terra/core@2.1.x](https://github.com/terra-money/core) (compatible with [[email protected]](https://github.com/tendermint/tendermint)).

Go v1.17+ is recommended for this project.

Expand All @@ -47,7 +47,7 @@ $ make install # results in $GOPATH/bin/mantlemint

Since mantlemint cannot join p2p network by itself, it depends on RPC to receive recently proposed blocks.

Any [Terra node](https://github.com/terra-money/core) with port 26657 enabled can be used for this.
Any [Terra node](https://github.com/classic-terra/core) with port 26657 enabled can be used for this.

#### 2. `config/app.toml`, a genesis file

Expand Down Expand Up @@ -94,12 +94,12 @@ INDEXER_DB=indexer \
# Flag to enable/disable mantlemint sync, mainly for debugging
DISABLE_SYNC=false \

# Run sync binary
sync
# Run mantlemint binary
mantlemint

# Optional: crisis module's invariant check is known to take hours.
# You can skip it by providing --x-crisis-skip-assert-invariants flag
sync --x-crisis-skip-assert-invariants
mantlemint --x-crisis-skip-assert-invariants
```

### Adjusting smart contract memory cache size
Expand Down Expand Up @@ -138,14 +138,14 @@ Please note that mantlemint still is able to serve queries while `/health` retur
- `/index/tx/by_height/{height}`: List all transactions and their responses in a block. Equivalent to `tendermint/block?height=xxx`, with tx responses base64-decoded for better usability.
- `/index/tx/by_hash/{txHash}`: Get transaction and its response by hash. Equivalent to `lcd/txs/{hash}`, but without hitting RPC.

## Notable Differences from [core](https://github.com/terra-money/core)
## Notable Differences from [core](https://github.com/classic-terra/core)

- Uses a forked [tendermint/tm-db](https://github.com/terra-money/tm-db/commit/c71e8b6e9f20d7f5be32527db4a92ae19ac0d2b2): Disables unncessary mutexes in `prefixdb` methods
- Replaces ABCIClient with [NewConcurrentQueryClient](https://github.com/terra-money/mantlemint/blob/main/mantlemint/client.go#L110): Removal of mutexes allow better concurrency, even during block injection
- Uses single batch-protected db: All state changes are flushed at once, making it safe to read from db during block injection
- Automatic failover: In case of block injection failure, mantlemint reverts back to the previous known state and retry
- Strictly no `tendermint`; some parameters in app.toml would not affect `mantlemint`
- Following endpoints are not implemented
- Following endpoints are not implemented
- `GET /blocks/`
- `GET /blocks/latest`
- `GET /txs/{hash}`
Expand All @@ -156,7 +156,7 @@ Please note that mantlemint still is able to serve queries while `/health` retur

## FAQ

### Q1. Can I use public RPC (http://public-node.terra.dev:26657) as RPC and WS endpoints?
### Q1. Can I use public RPC and WS endpoints?

While you can, we do NOT recommend doing so. We only expose public node as a seed node for p2p, and its http/ws connection may not be stable. It is safer to have your own RPC

Expand Down
4 changes: 2 additions & 2 deletions block_feed/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func NewAggregateBlockFeed(
rpcEndpoints []string,
wsEndpoints []string,
) *AggregateSubscription {
var rpc, rpcErr = NewRpcSubscription(rpcEndpoints)
rpc, rpcErr := NewRpcSubscription(rpcEndpoints)
if rpcErr != nil {
panic(rpcErr)
}

// ws starts with 1st occurrence of ws endpoints
var ws, wsErr = NewWSSubscription(wsEndpoints)
ws, wsErr := NewWSSubscription(wsEndpoints)
if wsErr != nil {
panic(wsErr)
}
Expand Down
10 changes: 5 additions & 5 deletions block_feed/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package block_feed

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
)
Expand All @@ -11,18 +11,18 @@ var _ BlockFeed = (*RPCSubscription)(nil)

type RPCSubscription struct {
rpcEndpoints []string
cSub chan *BlockResult
cSub chan *BlockResult
}

func NewRpcSubscription(rpcEndpoints []string) (*RPCSubscription, error) {
return &RPCSubscription{
rpcEndpoints: rpcEndpoints,
cSub: make(chan *BlockResult),
cSub: make(chan *BlockResult),
}, nil
}

func (rpc *RPCSubscription) SyncFromUntil(from int64, to int64, rpcIndex int) {
var cSub = rpc.cSub
cSub := rpc.cSub

log.Printf("[block_feed/rpc] subscription started, from=%d, to=%d\n", from, to)

Expand All @@ -35,7 +35,7 @@ func (rpc *RPCSubscription) SyncFromUntil(from int64, to int64, rpcIndex int) {
log.Fatalf("block request failed, %v", err)
}

resBytes, err := ioutil.ReadAll(res.Body)
resBytes, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalf("block request failed, %v", err)
}
Expand Down
Loading

0 comments on commit c75da60

Please sign in to comment.