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

R4R: Sync with develop #305

Merged
merged 14 commits into from
Sep 27, 2018
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
1 change: 1 addition & 0 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace))
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper, app.iparamsKeeper.GovSetter())
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper)
app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.iparamsKeeper.GovSetter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace))

// register message routes
Expand Down
36 changes: 36 additions & 0 deletions docs/get-started/irislcd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# What is Irislcd

An irislcd node is a REST server which can connect to any full nodes and provide a set of rest APIs. By these APIs, users can send transactions and query blockchain data. Irislcd can verify the proof of query result. So it can provide the same security as a full node with the minimal requirements on bandwidth, computing and storage resource. Besides, it also provides swagger-ui which presents detailed description about what APIs it provides and how to use the them.

## Irislcd options

To start a irislcd, we need to specify the following parameters:

| Parameter | Type | Default | Required | Description |
| --------------- | --------- | ----------------------- | -------- | ---------------------------------------------------- |
| chain-id | string | null | true | Chain ID of Tendermint node |
| home | string | "$HOME/.irislcd" | false | Directory for config and data, such as key and checkpoint |
| node | string | "tcp://localhost:26657" | false | Full node to connect to |
| laddr | string | "tcp://localhost:1317" | false | Address for server to listen on |
| trust-node | bool | false | false | Trust connected full nodes (Don't verify proofs for responses) |
| max-open | int | 1000 | false | The number of maximum open connections |
| cors | string | "" | false |Set the domains that can make CORS requests |

## Start Irislcd

Sample command to start irislcd:
```
irislcd start --chain-id=<chain-id>
```
Please visit the following url with in your internet explorer to open Swagger-UI:
```
http://localhost:1317/swagger-ui/
```
Execute the following command to print the irislcd version.
```
irislcd version
```

When the connected full node is trusted, then the proof is not necessary, so you can run irislcd with trust-node option:
```
irislcd start --chain-id=<chain-id> --trust-node
36 changes: 36 additions & 0 deletions docs/zh/get-started/irislcd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 介绍

irislcd是一个能连接到任何全节点并且提供rest API接口的服务。通过这些API接口,用户可以发起交易或者查询区块链上的数据。irislcd可以验证全节点返回数据的完整性和有效性,因此irislcd可以以最小的带宽资源,最小的计算需求和最小的存储消耗来获取可全节点一样的数据安全。另外,irislcd还提供swagger-ui页面,这个页面列出来所以得API接口并且附有详细的说明文档。

## Irislcd options

irislcd有如下这些参数可以配置

| 参数名 | 类型 | 默认值 | 是否必须 | 功能介绍 |
| --------------- | --------- | ----------------------- | -------- | ---------------------------------------------------- |
| chain-id | 字符串 | null | true | 所连接的tendermint区块链网络的ID |
| home | 字符串 | "$HOME/.irislcd" | false | irislcd的home目录,用来存储秘钥和历史验证信息 |
| node | 字符串 | "tcp://localhost:26657" | false | 所要连接的全节点的url |
| laddr | 字符串 | "tcp://localhost:1317" | false | 侦听的网络端口 |
| trust-node | 布尔型 | false | false | 是否信任全节点 |
| max-open | 整型 | 1000 | false | 最大支持的连接数 |
| cors | 字符串 | "" | false | 是否支持跨域请求 |

## Start Irislcd

启动irislcd:
```
irislcd start --chain-id=<chain-id>
```
在浏览器中访问以下的url就可以打开Swagger-UI:
```
http://localhost:1317/swagger-ui/
```
打印版本号.
```
irislcd version
```
如果所连接的全节点是可信的,可以加上`trust-node`:
```
irislcd start --chain-id=<chain-id> --trust-node
```
7 changes: 6 additions & 1 deletion modules/gov/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
CodeInvalidGenesis sdk.CodeType = 10
CodeInvalidProposalStatus sdk.CodeType = 11
CodeInvalidParam sdk.CodeType = 12
CodeInvalidParamOp sdk.CodeType = 13
)

//----------------------------------------
Expand Down Expand Up @@ -68,5 +69,9 @@ func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error {
}

func ErrInvalidParam(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidParam, fmt.Sprintf("Param '%s' is not valid"))
return sdk.NewError(codespace, CodeInvalidParam, fmt.Sprintf("Param is not valid"))
}

func ErrInvalidParamOp(codespace sdk.CodespaceType, opStr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidParamOp, fmt.Sprintf("Op '%s' is not valid", opStr))
}
5 changes: 5 additions & 0 deletions modules/gov/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
}

}

if msg.Param.Op != Update && msg.Param.Op != Insert {
return ErrInvalidParamOp(DefaultCodespace, msg.Param.Op)
}

return nil
}

Expand Down
19 changes: 13 additions & 6 deletions modules/upgrade/keep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package upgrade

import (
"fmt"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/irisnet/irishub/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"strings"
"testing"
"github.com/irisnet/irishub/modules/upgrade/params"
)

func TestUpdateKeeper(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, _ := createTestInput(t)
router := baseapp.NewRouter()
router.AddRoute("main", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
router.AddRoute("acc", []*sdk.KVStoreKey{sdk.NewKVStoreKey("acc")}, nil)
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestSwitchKeeper(t *testing.T) {
}

func TestSetKVStoreKeylist(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, paramKeeper := createTestInput(t)

router := baseapp.NewRouter()
router.AddRoute("main-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
Expand All @@ -133,6 +134,10 @@ func TestSetKVStoreKeylist(t *testing.T) {
router.AddRoute("stake-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("stake")}, nil)
router.AddRoute("upgrade-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("upgrade")}, nil)


upgradeparams.ProposalAcceptHeightParameter.SetReadWriter(paramKeeper.Setter())
upgradeparams.CurrentUpgradeProposalIdParameter.SetReadWriter(paramKeeper.Setter())

InitGenesis(ctx, keeper, router)
keeper.SetKVStoreKeylist(ctx)
}
Expand All @@ -153,7 +158,7 @@ func getModuleList(router baseapp.Router) ModuleLifeTimeList {
}

func TestKeeper_InitGenesis_commidID(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, paramKeeper := createTestInput(t)
router := baseapp.NewRouter()
router.AddRoute("main", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
router.AddRoute("acc", []*sdk.KVStoreKey{sdk.NewKVStoreKey("acc")}, nil)
Expand All @@ -169,6 +174,8 @@ func TestKeeper_InitGenesis_commidID(t *testing.T) {
InitGenesis_commitID(ctx, keeper)
fmt.Println(keeper.GetKVStoreKeylist(ctx))

keeper.SetCurrentProposalAcceptHeight(ctx, 1234234000)
fmt.Println(keeper.GetCurrentProposalAcceptHeight(ctx))
upgradeparams.ProposalAcceptHeightParameter.SetReadWriter(paramKeeper.Setter())

upgradeparams.SetProposalAcceptHeight(ctx, 1234234000)
fmt.Println(upgradeparams.GetProposalAcceptHeight(ctx))
}
5 changes: 1 addition & 4 deletions modules/upgrade/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/irisnet/irishub/modules/iparams"
"math"
)

Expand All @@ -18,15 +17,13 @@ type Keeper struct {
cdc *wire.Codec
// The ValidatorSet to get information about validators
sk stake.Keeper
params iparams.GovSetter
}

func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, sk stake.Keeper, ps iparams.GovSetter) Keeper {
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, sk stake.Keeper) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
sk: sk,
params: ps,
}
return keeper
}
Expand Down
16 changes: 10 additions & 6 deletions modules/upgrade/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"encoding/hex"
"github.com/irisnet/irishub/modules/iparams"
"github.com/cosmos/cosmos-sdk/x/params"
)

var (
Expand Down Expand Up @@ -54,18 +54,20 @@ func createTestCodec() *wire.Codec {
return cdc
}

func createTestInput(t *testing.T) (sdk.Context, Keeper) {
func createTestInput(t *testing.T) (sdk.Context, Keeper, params.Keeper) {
keyAcc := sdk.NewKVStoreKey("acc")
keyStake := sdk.NewKVStoreKey("stake")
keyUpdate := sdk.NewKVStoreKey("update")
keyParams := sdk.NewKVStoreKey("params")
keyIparams := sdk.NewKVStoreKey("iparams")

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyStake, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyUpdate, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams,sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyIparams, sdk.StoreTypeIAVL, db)

err := ms.LoadLatestVersion()
require.Nil(t, err)
Expand All @@ -74,7 +76,9 @@ func createTestInput(t *testing.T) (sdk.Context, Keeper) {
accountMapper := auth.NewAccountMapper(cdc, keyAcc, auth.ProtoBaseAccount)
ck := bank.NewKeeper(accountMapper)
sk := stake.NewKeeper(cdc, keyStake, ck, stake.DefaultCodespace)
pk := iparams.NewKeeper(cdc,keyParams)
keeper := NewKeeper(cdc, keyUpdate, sk,pk.GovSetter())
return ctx, keeper

keeper := NewKeeper(cdc, keyUpdate, sk)
paramKeeper := params.NewKeeper(wire.NewCodec(), keyParams)

return ctx, keeper, paramKeeper
}