Commit c701dbcd authored by kingwang's avatar kingwang Committed by mdj33

add para node test

parent 1d956b38
......@@ -11,14 +11,15 @@ import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/queue"
_ "github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util/testnode"
_ "github.com/33cn/plugin/plugin/dapp/init"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
_ "github.com/33cn/plugin/plugin/store/init"
"github.com/stretchr/testify/assert"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin/dapp/init"
_ "github.com/33cn/plugin/plugin/store/init"
)
func TestTicket(t *testing.T) {
......
package testnode
var paraconfig = `
Title="user.p.guodun."
# TestNet=true
[log]
# 日志级别,支持debug(dbug)/info/warn/error(eror)/crit
loglevel = "debug"
logConsoleLevel = "info"
# 日志文件名,可带目录,所有生成的日志文件都放到此目录下
logFile = "logs/chain33.para.log"
# 单个日志文件的最大值(单位:兆)
maxFileSize = 300
# 最多保存的历史日志文件个数
maxBackups = 100
# 最多保存的历史日志消息(单位:天)
maxAge = 28
# 日志文件名是否使用本地事件(否则使用UTC时间)
localTime = true
# 历史日志文件是否压缩(压缩格式为gz)
compress = true
# 是否打印调用源文件和行号
callerFile = false
# 是否打印调用方法
callerFunction = false
[blockchain]
defCacheSize=128
maxFetchBlockNum=128
timeoutSeconds=5
batchBlockNum=128
driver="leveldb"
dbPath="paradatadir"
dbCache=64
isStrongConsistency=true
singleMode=true
batchsync=false
isRecordBlockSequence=false
isParaChain = true
enableTxQuickIndex=false
[p2p]
seeds=[]
enable=false
isSeed=false
serverStart=true
innerSeedEnable=true
useGithub=true
innerBounds=300
msgCacheSize=10240
driver="leveldb"
dbPath="paradatadir/addrbook"
dbCache=4
grpcLogFile="grpc33.log"
[rpc]
# 避免与主链配置冲突
jrpcBindAddr="localhost:8901"
grpcBindAddr="localhost:8902"
whitelist=["127.0.0.1"]
jrpcFuncWhitelist=["*"]
grpcFuncWhitelist=["*"]
[mempool]
name="timeline"
poolCacheSize=10240
minTxFee=100000
maxTxNumPerAccount=10000
[consensus]
name="para"
genesisBlockTime=1514533394
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[mver.consensus]
fundKeyAddr = "1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
coinReward = 18
coinDevFund = 12
ticketPrice = 10000
powLimitBits = "0x1f00ffff"
retargetAdjustmentFactor = 4
futureBlockTime = 16
ticketFrozenTime = 5 #5s only for test
ticketWithdrawTime = 10 #10s only for test
ticketMinerWaitTime = 2 #2s only for test
maxTxNumber = 1600 #160
targetTimespan = 2304
targetTimePerBlock = 16
[consensus.sub.para]
#主链节点的grpc服务器ip,当前可以支持多ip负载均衡,如“101.37.227.226:8802,39.97.20.242:8802,47.107.15.126:8802,jiedian2.33.cn”
ParaRemoteGrpcClient=""
#主链指定高度的区块开始同步
startHeight=0
#打包时间间隔,单位秒
writeBlockSeconds=2
#主链每隔几个没有相关交易的区块,平行链上打包空区块
emptyBlockInterval=50
#验证账户,验证节点需要配置自己的账户,并且钱包导入对应种子,非验证节点留空
authAccount=""
#等待平行链共识消息在主链上链并成功的块数,超出会重发共识消息,最小是2
waitBlocks4CommitMsg=2
#云端主链节点切换后,平行链适配新主链节点block,回溯查找和自己记录的相同blockhash的深度
searchHashMatchedBlockDepth=10000
#创世地址额度
genesisAmount=100000000
[store]
name="mavl"
driver="leveldb"
dbPath="paradatadir/mavltree"
dbCache=128
enableMavlPrefix=false
enableMVCC=false
enableMavlPrune=false
pruneHeight=10000
[wallet]
minFee=100000
driver="leveldb"
dbPath="parawallet"
dbCache=16
signType="secp256k1"
minerdisable=true
[exec]
isFree=true
minExecFee=100000
enableStat=false
[exec.sub.relay]
genesis="14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[exec.sub.manage]
superManager=[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
[exec.sub.token]
saveTokenTxList=true
tokenApprs = [
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S",
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK",
"1LY8GFia5EiyoTodMLfkB5PHNNpXRqxhyB",
"1GCzJDS6HbgTQ2emade7mEJGGWFfA15pS9",
"1JYB8sxi4He5pZWHCd3Zi2nypQ4JMB6AxN",
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv",
]
[pprof]
listenAddr = "localhost:6062"
`
package testnode
import (
"testing"
"github.com/33cn/chain33/util"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
)
func TestParaNode(t *testing.T) {
para := NewParaNode(nil, nil)
//通过rpc 发生信息
txs := util.GenNoneTxs(para.Para.GetGenesisKey(), 10)
for i := 0; i < len(txs); i++ {
para.Para.SendTxRPC(txs[i])
}
para.Para.WaitHeight(1)
txs = util.GenNoneTxs(para.Para.GetGenesisKey(), 10)
for i := 0; i < len(txs); i++ {
para.Para.SendTxRPC(txs[i])
}
para.Para.WaitHeight(2)
}
package testnode
import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
)
/*
1. solo 模式,后台启动一个 主节点
2. 启动一个平行链节点:注意,这个要测试的话,会依赖平行链插件
*/
//ParaNode 平行链节点由两个节点组成
type ParaNode struct {
Main *testnode.Chain33Mock
Para *testnode.Chain33Mock
}
//NewParaNode 创建一个平行链节点
func NewParaNode(main *testnode.Chain33Mock, para *testnode.Chain33Mock) *ParaNode {
if main == nil {
main = testnode.New("", nil)
main.Listen()
}
if para == nil {
cfg, sub := types.InitCfgString(paraconfig)
testnode.ModifyParaClient(sub, main.GetCfg().RPC.GrpcBindAddr)
para = testnode.NewWithConfig(cfg, sub, nil)
para.Listen()
}
return &ParaNode{Main: main, Para: para}
}
//Close 关闭系统
func (node *ParaNode) Close() {
node.Para.Close()
node.Main.Close()
}
......@@ -105,9 +105,11 @@ func (exec *Executor) SetQueueClient(qcli queue.Client) {
if err != nil {
panic(err)
}
exec.grpccli, err = grpcclient.NewMainChainClient("")
if err != nil {
panic(err)
if types.IsPara() {
exec.grpccli, err = grpcclient.NewMainChainClient("")
if err != nil {
panic(err)
}
}
//recv 消息的处理
go func() {
......
......@@ -178,14 +178,16 @@ func NewGRpcServer(c queue.Client, api client.QueueProtocolAPI) *Grpcserver {
func NewJSONRPCServer(c queue.Client, api client.QueueProtocolAPI) *JSONRPCServer {
j := &JSONRPCServer{jrpc: &Chain33{}}
j.jrpc.cli.Init(c, api)
grpcCli, err := grpcclient.NewMainChainClient("")
if err != nil {
panic(err)
if types.IsPara() {
grpcCli, err := grpcclient.NewMainChainClient("")
if err != nil {
panic(err)
}
j.jrpc.mainGrpcCli = grpcCli
}
j.jrpc.mainGrpcCli = grpcCli
server := rpc.NewServer()
j.s = server
err = server.RegisterName("Chain33", j.jrpc)
err := server.RegisterName("Chain33", j.jrpc)
if err != nil {
return nil
}
......
......@@ -224,7 +224,6 @@ func S(key string, value interface{}) {
} else {
tlog.Error("modify " + key + " is only for test")
}
return
}
setChainConfig(key, value)
}
......
......@@ -12,7 +12,6 @@ import (
"math/rand"
"os"
"strings"
"sync"
"time"
"github.com/33cn/chain33/account"
......@@ -49,7 +48,6 @@ func init() {
//保证只有一个chain33 会运行
var lognode = log15.New("module", "lognode")
var chain33globalLock sync.Mutex
//Chain33Mock :
type Chain33Mock struct {
......@@ -82,7 +80,6 @@ func NewWithConfig(cfg *types.Config, sub *types.ConfigSubModule, mockapi client
}
func newWithConfig(cfg *types.Config, sub *types.ConfigSubModule, mockapi client.QueueProtocolAPI) *Chain33Mock {
chain33globalLock.Lock()
return newWithConfigNoLock(cfg, sub, mockapi)
}
......@@ -172,13 +169,17 @@ func (mock *Chain33Mock) Listen() {
l := len(mock.cfg.RPC.GrpcBindAddr)
mock.cfg.RPC.GrpcBindAddr = mock.cfg.RPC.GrpcBindAddr[0:l-2] + ":" + fmt.Sprint(portgrpc)
}
if mock.sub.Consensus["para"] != nil {
data, err := types.ModifySubConfig(mock.sub.Consensus["para"], "ParaRemoteGrpcClient", mock.cfg.RPC.GrpcBindAddr)
}
//ModifyParaClient modify para config
func ModifyParaClient(sub *types.ConfigSubModule, gaddr string) {
if sub.Consensus["para"] != nil {
data, err := types.ModifySubConfig(sub.Consensus["para"], "ParaRemoteGrpcClient", gaddr)
if err != nil {
panic(err)
}
mock.sub.Consensus["para"] = data
types.S("config.consensus.sub.para.ParaRemoteGrpcClient", mock.cfg.RPC.GrpcBindAddr)
sub.Consensus["para"] = data
types.S("config.consensus.sub.para.ParaRemoteGrpcClient", gaddr)
}
}
......@@ -292,7 +293,6 @@ func (mock *Chain33Mock) GetCfg() *types.Config {
//Close :
func (mock *Chain33Mock) Close() {
mock.closeNoLock()
chain33globalLock.Unlock()
}
func (mock *Chain33Mock) closeNoLock() {
......@@ -373,6 +373,22 @@ func (mock *Chain33Mock) SendTx(tx *types.Transaction) []byte {
return reply.GetMsg()
}
//SendTxRPC :
func (mock *Chain33Mock) SendTxRPC(tx *types.Transaction) []byte {
var txhash string
hextx := common.ToHex(types.Encode(tx))
err := mock.GetJSONC().Call("Chain33.SendTransaction", &rpctypes.RawParm{Data: hextx}, &txhash)
if err != nil {
panic(err)
}
hash, err := common.FromHex(txhash)
if err != nil {
panic(err)
}
mock.lastsend = hash
return hash
}
//Wait :
func (mock *Chain33Mock) Wait() error {
if mock.lastsend == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment