Code Monkey home page Code Monkey logo

mantlemint's Introduction

terra-money/mantlemint

What is Mantlemint?

Mantlemint is a fast core optimized for serving massive user queries.

Native query performance on RPC is slow and is not suitable for massive query handling, due to the inefficiencies introduced by IAVL tree. Mantlemint is running on fauxMerkleTree mode, basically removing the IAVL inefficiencies while using the same core to compute the same module outputs.

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

Features

  • Superior LCD performance
    • With the exception of Tendermint RPC/Transactions.
  • Super reliable and effective LCD response cache to prevent unnecessary computation for query resolving
  • Fully archival; historical states are available with ?height query parameter.
  • Useful default indexes

Installation

This specific directory contains mantlemint implementation for @terra-money/[email protected] (compatible with [email protected]).

Go v1.17+ is recommended for this project (install instructions).

  1. As a statically-linked application

    $ make build-static # results in build/mantlemint
  2. As a dynamically-linked application

    $ make build # results in build/mantlemint
    $ make install # results in $GOPATH/bin/mantlemint

Usage

Preparation

  1. Access to at least 1 running RPC node with archival ability. Node synced with pruned snapshot DOES NOT work. Since mantlemint cannot join p2p network by itself, it depends on RPC to receive recently proposed blocks. Any archival Terra node with port 26657 enabled can be used for this.

  2. config/app.toml

    Mantlemint internally runs the same Terra Core, therefore you need to provide the same configuration files as if you would run an RPC. Bare minimum you would at least need app.toml.

  3. A genesis file (link)

WARNING: It is required to run mantlemint in a separate $HOME directory than RPC; while mantlemint maintains its own database, some of the data may be overwritten by either mantlemint or RPC and may cause trouble.

Run Mantlemint

Mantlemint depends on 2 configs:

  • $HOME/config/app.toml; you can reuse app.toml you're using with core
  • Environment variables; mantlemint specific runtime variables to configure various properties of mantlemint. Examples as follows

WARNING: Make sure you separate MANTLEMINT_HOME from other mantlemint instances, or core. Doing so may result in an undefined behaviour.

# Location of genesis file
GENESIS_PATH=config/genesis.json \

# Home directory for mantlemint.
# Mantlemint will use this to:
# - read $HOME/config/app.toml
# - create and maintain $HOME/mantlemint.db directory
# - create and maintain $HOME/data/* for wasm blobs; (unsafe to share with RPC!)
# - create and maintain $HOME/$(INDEXER_DB).db for mantle indexers
MANTLEMINT_HOME=mantlemint \

# Chain ID
CHAIN_ID=columbus-5 \

# RPC Endpoint; used to sync previous blocks when mantlemint is catching up
RPC_ENDPOINTS=http://rpc1:26657,http://rpc2:26657 \

# WS Endpoint; used to sync live block as soon as they are available through RPC websocket
WS_ENDPOINTS=ws://rpc1:26657/websocket,ws://rpc2:26657/websocket \

# Name of mantlemint.db, akin to application.db for core
MANTLEMINT_DB=mantlemint \

# Name of indexer db
INDEXER_DB=indexer \

# Flag to enable/disable mantlemint sync, mainly for debugging
DISABLE_SYNC=false \

# Flag to enable/disable export module. Used for accounts export and circulating supply endpoint
ENABLE_EXPORT_MODULE=true \

# Length of richlist. it have to be greater than or equal to 0, richlist function will be off if length is 0
RICHLIST_LENGTH=100 \

# Threshold(the minimum amount) of richlist
# NOTE: this is *not* low limit of the richlist to be shown
#       this is about internal parameter to manage memory usage.
RICHLIST_THRESHOLD=10000000000uluna \

# Run sync binary (compiled with `make install`)
mantlemint

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

Adjusting smart contract memory cache size

The wasm section in app.toml may play a critical role in how mantlemint performs under heavy load. We recommend adjusting contract-memory-cache-size if you are planning to run mantlemint publicly, as loading contract instances from disk is an expensive operation.

[wasm]
# The WASM VM memory cache size in MiB not bytes.
# Adjust this if you need to hold more smart contract instances in memory (less overhead for loading contracts to memory)
contract-memory-cache-size = "16384" # 16GB

Health check

mantlemint implements /health endpoint. It is useful if you want to suppress traffics being routed to mantlemint nodes still syncing or unavailable due to whatever reason.

The endpoint will respond:

  • 200 OK if mantlemint sync status is up-to date (i.e. syncing using websocket from RPC)
  • 400 NOK if mantlemint is still syncing past blocks, and is not ready to serve the latest state yet.

Please note that mantlemint is still able to serve queries while /health returns NOK.

Default Indexes

  • /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.
  • /index/richlist/{height}: Get a richlist at the given height. Height supports latest.

Notable Differences from core

  • Uses a forked tendermint/tm-db: Disables unncessary mutexes in prefixdb methods
  • Replaces ABCIClient with NewConcurrentQueryClient: 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
    • GET /blocks/
    • GET /blocks/latest
    • GET /txs/{hash}
    • GET /txs
    • GET /validatorset
    • All POST variants

FAQ

Q1. Can I use public RPC (http://public-node.terra.dev:26657) as 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

Q2. Can I convert existing core's database to mantlemint?

No. Mantlemint's db structure is NOT compatible with core's.

Q3. Mantlemint doesn't support tendermint queries like /blocks, /txs, but I still need them. What should I do?

You can route those traffic to an existing RPC that you use for RPC_ENDPOINTS and WS_ENDPOINTS with a load balancer.

Q4. Is it possible to disable archive? It takes up too much space!

Not yet, although it is on the roadmap.

Q5. Mantlemint seems to hang up on the first block.

Processing genesis block is known to take 2+ hours -- be patient!

Also, try disabling crisis module's invariant check on genesis block creation, by providing flag --x-crisis-skip-assert-invariants.

Q6. What are the system requirements to run mantlemint safely?

  • 4 or more CPU cores
  • At least 16GB memory, 32~64GB for genesis block creation.
    • You can scale down to smaller system after mantlemint successfully creates the genesis block
  • At least 2TB disk space, although we recommend bigger.

Q7. Are snapshots provided?

Not yet, but we have plans to do so.

Q8. What directories should I backup when creating snapshot?

${MANTLEMINT_HOME}/data
${MANTLEMINT_HOME}/indexer.db
${MANTLEMINT_HOME}/mantlemint.db

Community

License

This software is licensed under the Apache 2.0 license. Read more about it here.

© 2022 Terraform Labs, PTE LTD

mantlemint's People

Contributors

dependabot[bot] avatar gaohan137 avatar gregnuj avatar hanjukim avatar javiersuweijie avatar kjessec avatar tuky191 avatar vritra4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mantlemint's Issues

Block sync interruption and failures

Hi MantleMint expert!

As we sync from genesis, the process is very long and was interrupted a few times in between with the following error messages. Any ideas on what could be the problem? If we restart the binary, it picked up where it was left off. Thank you guys very much!

2022/04/13 10:31:27 [mantlemint/inject] nextState.LastBlockHeight=4775634, nextState.LastResultsHash=6fd73137f89b1b33a7b6146e68ca5f4fcd0a6f63bc22f66042db7c9fc47b503f
[indexer/block] indexing done for height 4775634
[indexer] finished 2 indexers, 7ms
[rollback-batch] rollback batch for height 4775634's record length 2484
!!! clearing write height...
[cache-middleware] purging cache at height 4775634
[rpc/latest] cache length 0, eviction count 0, serveCount 0, cacheServeCount 0
[rpc/archival] cache length 0, eviction count 0, serveCount 0, cacheServeCount 0
I[2022-04-13|10:31:27.888] executed block                               height=4775635 num_valid_txs=134 num_invalid_txs=0
D[2022-04-13|10:31:27.890] updates to validators                        updates=AF01CB3A74E3A78BD62364615D2006A17A5C51F4:1870220
2022/04/13 10:31:27 block parse failed, <nil>

Low Priority - Add --x-crisis-skip-assert-invariants

Problem

When running the first time, its validate the genesis and check for assert every invariants. This can take a huge time and CPU / Memory resources. This also affects the hardware requirements for running the mantlemint server or VM.

Proposed Solution

To reduce the start time on running the first time, we can skip assert invariants ( since the mantlemint is not like a fully lcd validator ) by adding --x-crisis-skip-assert-invariants as a parameter.

Low Priority - High Memory Consumption, mantlemint get OOM killed (32GB)

Hi team, thank you for this keeping this project up to date.

Problem

Using the following genesis and addrbook.
When running on a 4CPU and 32GB RAM AWS, the process is killed by OOM by using more than 32GB RAM.
SO Ubuntu 20.4 with unlimite ulimit.

RPC_ENDPOINTS=http://public-node.terra.dev:26657
INDEXER_DB=indexer
MANTLEMINT_HOME=.mantlemint

We are only running the mantlemint ( not the core terrad,which has his db on .terra folder)

{/home/ubuntu/.terra/config/genesis.json .mantlemint columbus-5 [http://public-node.terra.dev:26657] [ws://public-node.terra.dev:26657/websocket] apollomint indexer false}
I[2022-03-16|11:07:28.854] Starting localClient service                 module=abci-client connection=query impl=localClient
I[2022-03-16|11:07:28.854] Starting localClient service                 module=abci-client connection=snapshot impl=localClient
I[2022-03-16|11:07:28.854] Starting localClient service                 module=abci-client connection=mempool impl=localClient
I[2022-03-16|11:07:28.855] Starting localClient service                 module=abci-client connection=consensus impl=localClient
2022/03/16 11:07:31 [v0.34.x/sync] genesis shasum=806430011926512733a1b684c2f04601d6d6d5df
2022/03/16 11:07:48 genesisTime=2021-09-30 10:00:41 +0000 UTC, chainId=columbus-5
I[2022-03-16|11:13:15.530] created new capability                       module=ibc name=ports/transfer
I[2022-03-16|11:13:15.531] port binded                                  module=x/ibc/port port=transfer
I[2022-03-16|11:13:15.531] claimed capability                           module=transfer name=ports/transfer capability=1
[rollback-batch] rollback batch for height 4724001's record length 12
!!! clearing write height...
2022/03/16 11:13:20 Subscribing to tendermint rpc...
2022/03/16 11:13:21 Subscription and the first handshake done. Receiving blocks...
2022/03/16 11:13:35 [block_feed/aggregate] received the first block(6867954), but local blockchain is at (4724000)
2022/03/16 11:13:35 [block_feed/rpc] subscription started, from=4724001, to=6867954
2022/03/16 11:13:35 [block_feed/rpc] receiving block 4724001...
2022/03/16 11:13:36 [block_feed/rpc] receiving block 4724002...
2022/03/16 11:13:36 [block_feed/rpc] receiving block 4724003...
I[2022-03-16|11:13:38.125] burned tokens from module account            module=x/bank amount=1000000ukrw,1000000uluna,995454usdr from=burn
I[2022-03-16|11:13:38.349] executed block                               height=4724001 num_valid_txs=0 num_invalid_txs=0
Killed
  • What would be the hardware requirements?
  • Is is correct to use the col5 origin genesis?
  • What other options are that we can tune up the mantlemint regarding Memory usage?
  • What would be the suggested environment configuration to test?

Thanks!

Proposal: Adjust branching/release strategy post-terra 2

TLDR;

Make terra v2 main, classic a maintenance branch.
Create deterministic tagged releases.
Reduce number of branches to maintain and track.

Current

perceived logic: permanent branch by chain-id, no releases for now, track head on branch.

  • branch/main -> terra classic
  • branch/columbus-5 -> terra classic mainnet (same as main)
  • branch/pisco-1 -> terra v2 testnet
  • branch/phoenix-1 -> terra v2 mainnet (two line dependency diff from pisco-1)

Proposal

logic: github tag+releases done from main and maintenance branches only. Active development comes back to main else it is a maintenance release.

  • branch: main --> terra v2
    • permanent main development branch, terra v2
    • release major version: 1.x.x
      • use semver versioning
      • examples: 1.0.0-rc.0, 1.0.0
  • branch: classic -> terra-classic maintenance branch
    • permanent terra-classic maintenance branch
    • release major version: 0.x.x
      • use semver versioning
      • examples: 0.1.5, 0.1.5-1, 0.1.5-rc.0, 0.1.5-2
  • branch: feat/largetask --> temporary feature branch needing longer than one signle PR, to be merged to main
    • no releases
    • example: previousupgrade/terra2 branch

Example migration

  • merge branch columbus-5 into main
  • create branch classic from main
  • merge branch pisco-1 into phoenix-1
  • merge branch phoenix-1 into main

Remaining permanent branches: main, classic

Potentially outdated README

Hi there,

Is it possible to update the current README to make it up to date? After running the mantlemint as follows, I'm getting the error panic: environment variable MANTLEMINT_DB not set; expected string, got ""

GENESIS_PATH="/home/xxx/mantlemint_home/genesis.json" \
MANTLEMINT_HOME="/home/xxx/mantlemint_home" \
CHAIN_ID=columbus-5 \
RPC_ENDPOINTS=https://url \
WS_ENDPOINTS=wss://url \
INDEXER_DB=indexer \
DISABLE_SYNC=false ./build/mantlemint

The documentation didn't mean MANTLEMINT_DB.

Mantlemint continoulsy crashes

Hi Team,

I add the logs:

{.mantlemint/config/genesis.json .mantlemint columbus-5 [https://terra-rpc.easy2stake.com https://terra.stakesystems.io:2053 https://terra-node.mcontrol.ml] [wss://terra-rpc.easy2stake.com/websocket wss://terra.stakesystems.io:2053/websocket wss://terra-node.mcontrol.ml/websocket] apollomint indexer false}
I[2022-03-31|15:38:36.808] Starting localClient service                 module=abci-client connection=query impl=localClient
I[2022-03-31|15:38:36.808] Starting localClient service                 module=abci-client connection=snapshot impl=localClient
I[2022-03-31|15:38:36.808] Starting localClient service                 module=abci-client connection=mempool impl=localClient
I[2022-03-31|15:38:36.808] Starting localClient service                 module=abci-client connection=consensus impl=localClient
2022/03/31 15:38:38 [v0.34.x/sync] genesis shasum=806430011926512733a1b684c2f04601d6d6d5df
[rollback-batch] rollback batch for height 4724001's record length 0
2022/03/31 15:38:49 genesisTime=2021-09-30 10:00:41 +0000 UTC, chainId=columbus-5
!!! clearing write height...
2022/03/31 15:38:55 Subscribing to tendermint rpc...
2022/03/31 15:38:55 Subscription and the first handshake done. Receiving blocks...
2022/03/31 15:39:06 [block_feed/aggregate] received the first block(7066242), but local blockchain is at (5425885)
2022/03/31 15:39:06 [block_feed/rpc] subscription started, from=5425886, to=7066242
2022/03/31 15:39:06 [block_feed/rpc] receiving block 5425886...
2022/03/31 15:39:07 [block_feed/rpc] receiving block 5425887...
2022/03/31 15:39:07 [block_feed/aggregate] switching to ws...
goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x19
main.main()
	/code/sync.go:216 +0x158a
panic: wrong Block.Header.Height. Expected 5425886, got 7066243

goroutine 1 [running]:
main.main()
	/code/sync.go:217 +0x15a8

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.