btchain

package module
v0.0.0-...-48972bb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2019 License: MIT Imports: 27 Imported by: 0

README

btchain

A block chain for BT of JVV

BTChain Baseed on tendermint 0.27.0-9c236ffd

安装cmake[使用cleveldb必选]

wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
./boostrap
make && make install

编译snappy[使用cleveldb必选]

wget https://github.com/google/snappy/archive/1.1.7.tar.gz
tar zxf 1.1.7.tar.gz
cd snappy-1.1.7
编辑CMakeLists.txt将BUILD_SHARED_LIBS开关打开(默认生成静态库,编译cleavel要静态库)
mkdir build && cd build && cmake ../
make install

编译cleaveldb[使用cleveldb必选]

wget https://github.com/google/leveldb/archive/v1.20.tar.gz && \
  tar -zxvf v1.20.tar.gz && \
  cd leveldb-1.20/ && \
  make && \
  sudo cp -r out-static/lib* out-shared/lib* /usr/local/lib/ && \
  cd include/ && \
  sudo cp -r leveldb /usr/local/include/ && \
  sudo ldconfig && \
  rm -f v1.20.tar.gz

编译链程序

  • 先按照tendermint标准编译流程进行编译,确保单独编译tendermint可以成功
  • 修改tendermint/proxy/client.go,func:DefaultClientCreator,加入以下分支
	case "bt":
		return NewLocalClientCreator(btchain.NewBTApplication())

导入包

"github.com/axengine/btchain"
  • 确保gcc可用,因为要开启cgo
  • 进入tendermint目录执行CGO_LDFLAGS="-lsnappy" make build_c,生成的二进制文件在build目录
  • ldd tendermint,查看依赖的动态库是否都能找到

使用

  • 配置文件config.toml与可执行程序在同一目录
[genesis]
account = "0x061a060880BB4E5AD559350203d60a4349d3Ecd6"
amount = "10000000000"


[db]
type = "sqlite3"
path = "./data/"

[log]
env = "debug" # production
path = "./log/" #需先创建
  • 要使用cleveldb,需要修改.tendermint/config/config.toml 的backend
  • 日志目录,与可执行程序同级的log目录,需先创建

编译API

  • 进入github.com/axengine/btchain/api 执行go build即可
  • 配置文件,在可执行程序所在目录的config目录下
bind = ":10000"
rpc = "127.0.0.1:26657"
writable = true #false时只有查询API
isAdmin = true #true时有validator更新API

[log]
path = "./log/"

Documentation

Index

Constants

View Source
const (
	LDatabaseCache   = 128
	LDatabaseHandles = 1024
)
View Source
const (
	QUERY_TX      = "/tx"
	QUERY_ACCOUNT = "/account"
	QUERY_NONCE   = "/nonce"
)

Variables

View Source
var (
	ZERO_ADDRESS = ethcmn.Address{}
	ZERO_HASH    = ethcmn.Hash{}
)
View Source
var (
	EmptyTrieRoot = ethcmn.HexToHash("0000000000000000000000000000000000000000000000000000000000000000")
)

Functions

func MakeResultData

func MakeResultData(i interface{}) define.Result

func OpenDatabase

func OpenDatabase(datadir string, name string, cache int, handles int) (ethdb.Database, error)

Types

type BTApplication

type BTApplication struct {
	abcitypes.BaseApplication
	// contains filtered or unexported fields
}

func NewBTApplication

func NewBTApplication() *BTApplication

func (*BTApplication) BeginBlock

BeginBlock 区块开始,记录区块高度和hash

func (*BTApplication) CheckTx

func (app *BTApplication) CheckTx(tx []byte) abcitypes.ResponseCheckTx

CheckTx 初步检查,如果check失败,将不会被打包

func (*BTApplication) CheckValidatorUpdate

func (app *BTApplication) CheckValidatorUpdate(tx *define.Transaction) error

func (*BTApplication) Commit

func (app *BTApplication) Commit() abcitypes.ResponseCommit

func (*BTApplication) DBSwitch

func (app *BTApplication) DBSwitch()

func (*BTApplication) DeliverTx

func (app *BTApplication) DeliverTx(tx []byte) abcitypes.ResponseDeliverTx

func (*BTApplication) DeliverValidatorUpdate

func (app *BTApplication) DeliverValidatorUpdate(tx *define.Transaction) error

func (*BTApplication) Info

func (app *BTApplication) Info(req abcitypes.RequestInfo) (resInfo abcitypes.ResponseInfo)

Info TM Core启动时会查询chain信息 需要返回lastBlock相关信息,否则会从第一个块replay

func (*BTApplication) InitChain

func (*BTApplication) LoadLastBlock

func (app *BTApplication) LoadLastBlock() (lastBlock LastBlockInfo)

func (*BTApplication) Query

func (app *BTApplication) Query(reqQuery abcitypes.RequestQuery) (resQuery abcitypes.ResponseQuery)

func (*BTApplication) QueryAccount

func (app *BTApplication) QueryAccount(addr []byte) define.Result

func (*BTApplication) QueryTx

func (app *BTApplication) QueryTx(tx []byte) define.Result

func (*BTApplication) SaveDBData

func (app *BTApplication) SaveDBData() error

func (*BTApplication) SaveLastBlock

func (app *BTApplication) SaveLastBlock(appHash []byte, header *define.AppHeader)

type LastBlockInfo

type LastBlockInfo struct {
	Height    uint64
	StateRoot []byte
	AppHash   []byte
	PrevHash  []byte
}

type ValidatorMgr

type ValidatorMgr struct {
	// contains filtered or unexported fields
}

validators 说明 InitChain时参数中的validatorset是创世配置文件中配置的内容,本方法只调一次,程序重启不再调用 BeginBlock中的validator是空的,无法使用 validator持久化到leveldb了,包含从创世以来所有的validator信息,power=0时不移除 更新注意:如果power double set0,TMCore会出现一致性错误,必须重新创世

如果power不为0,如果网络不通也有可能出现问题,因此需要谨慎更新validator

func NewValidatorMgr

func NewValidatorMgr(chainDb ethdb.Database) *ValidatorMgr

func (*ValidatorMgr) Dump

func (p *ValidatorMgr) Dump()

Dump 将Validator信息持久化

func (*ValidatorMgr) Get

func (p *ValidatorMgr) Get(pubkey string) *define.Validator

func (*ValidatorMgr) Load

func (p *ValidatorMgr) Load()

Load 从磁盘加载validators信息

func (*ValidatorMgr) Save

func (p *ValidatorMgr) Save(vl *define.Validator)

func (*ValidatorMgr) String

func (p *ValidatorMgr) String() string

Directories

Path Synopsis
api
bean
定义对外开放的HTTP API
定义对外开放的HTTP API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL