Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
db26652c
Commit
db26652c
authored
Jan 31, 2019
by
caopingcp
Committed by
vipwzw
Feb 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add commands in valnode
parent
def4afbb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
443 additions
and
12 deletions
+443
-12
consensus_state.go
plugin/consensus/tendermint/consensus_state.go
+5
-4
tendermint.go
plugin/consensus/tendermint/tendermint.go
+39
-5
valnode.go
plugin/dapp/valnode/commands/valnode.go
+192
-0
exec_local.go
plugin/dapp/valnode/executor/exec_local.go
+2
-1
plugin.go
plugin/dapp/valnode/plugin.go
+4
-2
tendermint.proto
plugin/dapp/valnode/proto/tendermint.proto
+5
-0
valnode.proto
plugin/dapp/valnode/proto/valnode.proto
+7
-0
rpc.go
plugin/dapp/valnode/rpc/rpc.go
+57
-0
rpc_test.go
plugin/dapp/valnode/rpc/rpc_test.go
+94
-0
types.go
plugin/dapp/valnode/rpc/types.go
+33
-0
tendermint.pb.go
plugin/dapp/valnode/types/tendermint.pb.go
+0
-0
valnode.go
plugin/dapp/valnode/types/valnode.go
+5
-0
valnode.pb.go
plugin/dapp/valnode/types/valnode.pb.go
+0
-0
No files found.
plugin/consensus/tendermint/consensus_state.go
View file @
db26652c
...
...
@@ -729,7 +729,8 @@ func (cs *ConsensusState) createProposalBlock() (block *ttypes.TendermintBlock)
// Mempool validated transactions
beg
:=
time
.
Now
()
pblock
:=
cs
.
client
.
BuildBlock
()
tendermintlog
.
Info
(
fmt
.
Sprintf
(
"createProposalBlock BuildBlock. Current: %v/%v/%v"
,
cs
.
Height
,
cs
.
Round
,
cs
.
Step
),
"txs-len"
,
len
(
pblock
.
Txs
),
"cost"
,
types
.
Since
(
beg
))
tendermintlog
.
Info
(
fmt
.
Sprintf
(
"createProposalBlock BuildBlock. Current: %v/%v/%v"
,
cs
.
Height
,
cs
.
Round
,
cs
.
Step
),
"txs-len"
,
len
(
pblock
.
Txs
),
"cost"
,
types
.
Since
(
beg
))
if
pblock
.
Height
!=
cs
.
Height
{
tendermintlog
.
Error
(
"pblock.Height is not equal to cs.Height"
)
...
...
@@ -1097,6 +1098,7 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
valNodes
,
err
:=
cs
.
client
.
QueryValidatorsByHeight
(
block
.
Header
.
Height
)
if
err
==
nil
&&
valNodes
!=
nil
{
if
len
(
valNodes
.
Nodes
)
>
0
{
tendermintlog
.
Info
(
"finalizeCommit validators of statecopy update"
,
"update-valnodes"
,
valNodes
)
prevValSet
:=
stateCopy
.
LastValidators
.
Copy
()
nextValSet
:=
prevValSet
.
Copy
()
err
:=
updateValidators
(
nextValSet
,
valNodes
.
Nodes
)
...
...
@@ -1107,10 +1109,9 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
stateCopy
.
LastHeightValidatorsChanged
=
block
.
Header
.
Height
+
1
nextValSet
.
IncrementAccum
(
1
)
stateCopy
.
Validators
=
nextValSet
tendermintlog
.
Info
(
"finalizeCommit validators of statecopy updated"
,
"update-valnodes"
,
valNodes
)
}
}
tendermintlog
.
Debug
(
"finalizeCommit
real
validators of statecopy"
,
"validators"
,
stateCopy
.
Validators
)
tendermintlog
.
Debug
(
"finalizeCommit validators of statecopy"
,
"validators"
,
stateCopy
.
Validators
)
// NewHeightStep!
cs
.
updateToState
(
stateCopy
)
...
...
@@ -1383,7 +1384,7 @@ func (cs *ConsensusState) signVote(voteType byte, hash []byte) (*ttypes.Vote, er
}
beg
:=
time
.
Now
()
err
:=
cs
.
privValidator
.
SignVote
(
cs
.
state
.
ChainID
,
vote
)
tendermintlog
.
Info
(
"signVote"
,
"height"
,
cs
.
Height
,
"cost"
,
types
.
Since
(
beg
))
tendermintlog
.
Debug
(
"signVote"
,
"height"
,
cs
.
Height
,
"cost"
,
types
.
Since
(
beg
))
return
vote
,
err
}
...
...
plugin/consensus/tendermint/tendermint.go
View file @
db26652c
...
...
@@ -266,7 +266,7 @@ OuterLoop:
}
state
=
statetmp
.
Copy
()
}
else
{
tendermintlog
.
Info
(
"StartConsensus"
,
"blockinfo"
,
blockInfo
)
tendermintlog
.
Debug
(
"StartConsensus"
,
"blockinfo"
,
blockInfo
)
csState
:=
blockInfo
.
GetState
()
if
csState
==
nil
{
tendermintlog
.
Error
(
"StartConsensus"
,
"msg"
,
"blockInfo.GetState is nil"
)
...
...
@@ -282,25 +282,24 @@ OuterLoop:
}
}
tendermintlog
.
Info
(
"load state finish"
,
"state"
,
state
,
"validators"
,
state
.
Validators
)
tendermintlog
.
Debug
(
"Load state finish"
,
"state"
,
state
)
valNodes
,
err
:=
client
.
QueryValidatorsByHeight
(
curHeight
)
if
err
==
nil
&&
valNodes
!=
nil
{
if
len
(
valNodes
.
Nodes
)
>
0
{
tendermintlog
.
Info
(
"StartConsensus validators update"
,
"update-valnodes"
,
valNodes
)
prevValSet
:=
state
.
LastValidators
.
Copy
()
nextValSet
:=
prevValSet
.
Copy
()
err
:=
updateValidators
(
nextValSet
,
valNodes
.
Nodes
)
if
err
!=
nil
{
tendermintlog
.
Error
(
"Error changing validator set"
,
"error"
,
err
)
//return s, fmt.Errorf("Error changing validator set: %v", err)
}
// change results from this height but only applies to the next height
state
.
LastHeightValidatorsChanged
=
curHeight
+
1
nextValSet
.
IncrementAccum
(
1
)
state
.
Validators
=
nextValSet
tendermintlog
.
Info
(
"StartConsensus validators updated"
,
"update-valnodes"
,
valNodes
)
}
}
tendermintlog
.
Info
(
"StartConsensus"
,
"
real
validators"
,
state
.
Validators
)
tendermintlog
.
Info
(
"StartConsensus"
,
"validators"
,
state
.
Validators
)
// Log whether this node is a validator or an observer
if
state
.
Validators
.
HasAddress
(
client
.
privValidator
.
GetAddress
())
{
tendermintlog
.
Info
(
"This node is a validator"
)
...
...
@@ -574,3 +573,38 @@ func (client *Client) LoadProposalBlock(height int64) *tmtypes.TendermintBlock {
}
return
proposalBlock
}
// Query_IsHealthy query whether consensus is sync
func
(
client
*
Client
)
Query_IsHealthy
(
req
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
if
client
==
nil
{
return
nil
,
fmt
.
Errorf
(
"%s"
,
"client not bind message queue."
)
}
isHealthy
:=
false
if
client
.
IsCaughtUp
()
&&
client
.
GetCurrentHeight
()
<=
client
.
csState
.
GetRoundState
()
.
Height
+
1
{
isHealthy
=
true
}
return
&
tmtypes
.
IsHealthy
{
IsHealthy
:
isHealthy
},
nil
}
// Query_NodeInfo query validator node info
func
(
client
*
Client
)
Query_NodeInfo
(
req
*
types
.
ReqNil
)
(
types
.
Message
,
error
)
{
if
client
==
nil
{
return
nil
,
fmt
.
Errorf
(
"%s"
,
"client not bind message queue."
)
}
nodes
:=
client
.
csState
.
GetRoundState
()
.
Validators
.
Validators
validators
:=
make
([]
*
tmtypes
.
Validator
,
0
)
for
_
,
node
:=
range
nodes
{
if
node
==
nil
{
validators
=
append
(
validators
,
&
tmtypes
.
Validator
{})
}
else
{
item
:=
&
tmtypes
.
Validator
{
Address
:
node
.
Address
,
PubKey
:
node
.
PubKey
,
VotingPower
:
node
.
VotingPower
,
Accum
:
node
.
Accum
,
}
validators
=
append
(
validators
,
item
)
}
}
return
&
tmtypes
.
ValidatorSet
{
Validators
:
validators
,
Proposer
:
&
tmtypes
.
Validator
{}},
nil
}
plugin/dapp/valnode/commands/valnode.go
0 → 100644
View file @
db26652c
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
commands
import
(
"encoding/hex"
"fmt"
"math/rand"
"os"
"time"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
"github.com/spf13/cobra"
)
// ValCmd valnode cmd register
func
ValCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"valnode"
,
Short
:
"Construct valnode transactions"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
IsSyncCmd
(),
GetBlockInfoCmd
(),
GetNodeInfoCmd
(),
AddNodeCmd
(),
)
return
cmd
}
// IsSyncCmd query tendermint is sync
func
IsSyncCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"is_sync"
,
Short
:
"Query tendermint consensus is sync"
,
Run
:
isSync
,
}
return
cmd
}
func
isSync
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
res
bool
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"valnode.IsSync"
,
nil
,
&
res
)
ctx
.
Run
()
}
// GetNodeInfoCmd get validator nodes
func
GetNodeInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"nodes"
,
Short
:
"Get tendermint validator nodes"
,
Run
:
getNodeInfo
,
}
return
cmd
}
func
getNodeInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
res
string
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"valnode.GetNodeInfo"
,
nil
,
&
res
)
ctx
.
SetResultCb
(
parseNodeInfo
)
ctx
.
Run
()
}
func
parseNodeInfo
(
arg
interface
{})
(
interface
{},
error
)
{
var
result
vt
.
ValidatorSet
res
:=
arg
.
(
*
string
)
data
,
err
:=
hex
.
DecodeString
(
*
res
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
types
.
Decode
(
data
,
&
result
)
if
err
!=
nil
{
return
nil
,
err
}
return
result
.
Validators
,
nil
}
// GetBlockInfoCmd get block info
func
GetBlockInfoCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"info"
,
Short
:
"Get tendermint consensus info"
,
Run
:
getBlockInfo
,
}
addGetBlockInfoFlags
(
cmd
)
return
cmd
}
func
addGetBlockInfoFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Int64P
(
"height"
,
"t"
,
0
,
"block height (larger than 0)"
)
cmd
.
MarkFlagRequired
(
"height"
)
}
func
getBlockInfo
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
height
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"height"
)
req
:=
&
vt
.
ReqBlockInfo
{
Height
:
height
,
}
params
:=
rpctypes
.
Query4Jrpc
{
Execer
:
vt
.
ValNodeX
,
FuncName
:
"GetBlockInfoByHeight"
,
Payload
:
types
.
MustPBToJSON
(
req
),
}
var
res
vt
.
TendermintBlockInfo
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
// AddNodeCmd add validator node
func
AddNodeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"add"
,
Short
:
"Add tendermint validator node"
,
Run
:
addNode
,
}
addNodeFlags
(
cmd
)
return
cmd
}
func
addNodeFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"pubkey"
,
"p"
,
""
,
"public key"
)
cmd
.
MarkFlagRequired
(
"pubkey"
)
cmd
.
Flags
()
.
Int64P
(
"power"
,
"w"
,
0
,
"voting power"
)
cmd
.
MarkFlagRequired
(
"power"
)
}
func
addNode
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
pubkey
,
_
:=
cmd
.
Flags
()
.
GetString
(
"pubkey"
)
power
,
_
:=
cmd
.
Flags
()
.
GetInt64
(
"power"
)
pubkeybyte
,
err
:=
hex
.
DecodeString
(
pubkey
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
privkey
,
err
:=
getprivkey
()
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
value
:=
&
vt
.
ValNodeAction_Node
{
Node
:
&
vt
.
ValNode
{
PubKey
:
pubkeybyte
,
Power
:
power
}}
action
:=
&
vt
.
ValNodeAction
{
Value
:
value
,
Ty
:
vt
.
ValNodeActionUpdate
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
vt
.
ValNodeX
),
Payload
:
types
.
Encode
(
action
),
Fee
:
0
}
err
=
tx
.
SetRealFee
(
types
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
random
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
tx
.
Nonce
=
random
.
Int63
()
tx
.
To
=
address
.
ExecAddress
(
vt
.
ValNodeX
)
tx
.
Sign
(
types
.
SECP256K1
,
privkey
)
txHex
:=
types
.
Encode
(
tx
)
data
:=
hex
.
EncodeToString
(
txHex
)
params
:=
rpctypes
.
RawParm
{
Data
:
data
,
}
ctx
:=
jsonclient
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.SendTransaction"
,
params
,
nil
)
ctx
.
RunWithoutMarshal
()
}
func
getprivkey
()
(
crypto
.
PrivKey
,
error
)
{
key
:=
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
cr
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
if
err
!=
nil
{
return
nil
,
err
}
bkey
,
err
:=
common
.
FromHex
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
priv
,
err
:=
cr
.
PrivKeyFromBytes
(
bkey
)
if
err
!=
nil
{
return
nil
,
err
}
return
priv
,
nil
}
plugin/dapp/valnode/executor/exec_local.go
View file @
db26652c
...
...
@@ -5,6 +5,7 @@
package
executor
import
(
"encoding/hex"
"errors"
"github.com/33cn/chain33/types"
...
...
@@ -20,7 +21,7 @@ func (val *ValNode) ExecLocal_Node(node *pty.ValNode, tx *types.Transaction, rec
if
node
.
GetPower
()
<
0
{
return
nil
,
errors
.
New
(
"validator power must not be negative"
)
}
clog
.
Info
(
"update validator"
,
"pubkey"
,
node
.
GetPubKey
(
),
"power"
,
node
.
GetPower
())
clog
.
Info
(
"update validator"
,
"pubkey"
,
hex
.
EncodeToString
(
node
.
GetPubKey
()
),
"power"
,
node
.
GetPower
())
key
:=
CalcValNodeUpdateHeightIndexKey
(
val
.
GetHeight
(),
index
)
set
.
KV
=
append
(
set
.
KV
,
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
node
)})
return
set
,
nil
...
...
plugin/dapp/valnode/plugin.go
View file @
db26652c
...
...
@@ -6,6 +6,8 @@ package valnode
import
(
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/valnode/rpc"
"github.com/33cn/plugin/plugin/dapp/valnode/commands"
"github.com/33cn/plugin/plugin/dapp/valnode/executor"
"github.com/33cn/plugin/plugin/dapp/valnode/types"
)
...
...
@@ -15,7 +17,7 @@ func init() {
Name
:
types
.
ValNodeX
,
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
nil
,
RPC
:
nil
,
Cmd
:
commands
.
ValCmd
,
RPC
:
rpc
.
Init
,
})
}
plugin/dapp/valnode/proto/tendermint.proto
View file @
db26652c
...
...
@@ -186,3 +186,7 @@ message Heartbeat {
int32
sequence
=
5
;
bytes
signature
=
6
;
}
message
IsHealthy
{
bool
isHealthy
=
1
;
}
\ No newline at end of file
plugin/dapp/valnode/proto/valnode.proto
View file @
db26652c
syntax
=
"proto3"
;
package
types
;
import
"common.proto"
;
import
"tendermint.proto"
;
message
ValNode
{
...
...
@@ -26,4 +27,9 @@ message ReqNodeInfo {
message
ReqBlockInfo
{
int64
height
=
1
;
}
service
valnode
{
rpc
IsSync
(
ReqNil
)
returns
(
IsHealthy
)
{}
rpc
GetNodeInfo
(
ReqNil
)
returns
(
ValidatorSet
)
{}
}
\ No newline at end of file
plugin/dapp/valnode/rpc/rpc.go
0 → 100644
View file @
db26652c
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc
import
(
"context"
"encoding/hex"
"github.com/33cn/chain33/types"
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
)
// IsSync query is sync
func
(
c
*
channelClient
)
IsSync
(
ctx
context
.
Context
,
req
*
types
.
ReqNil
)
(
*
vt
.
IsHealthy
,
error
)
{
data
,
err
:=
c
.
QueryConsensusFunc
(
"tendermint"
,
"IsHealthy"
,
&
types
.
ReqNil
{})
if
err
!=
nil
{
return
nil
,
err
}
if
resp
,
ok
:=
data
.
(
*
vt
.
IsHealthy
);
ok
{
return
resp
,
nil
}
return
nil
,
types
.
ErrDecode
}
// IsSync query is sync
func
(
c
*
Jrpc
)
IsSync
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
IsSync
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
data
.
IsHealthy
return
nil
}
// GetNodeInfo query block info
func
(
c
*
channelClient
)
GetNodeInfo
(
ctx
context
.
Context
,
req
*
types
.
ReqNil
)
(
*
vt
.
ValidatorSet
,
error
)
{
data
,
err
:=
c
.
QueryConsensusFunc
(
"tendermint"
,
"NodeInfo"
,
&
types
.
ReqNil
{})
if
err
!=
nil
{
return
nil
,
err
}
if
resp
,
ok
:=
data
.
(
*
vt
.
ValidatorSet
);
ok
{
return
resp
,
nil
}
return
nil
,
types
.
ErrDecode
}
// GetNodeInfo query block info
func
(
c
*
Jrpc
)
GetNodeInfo
(
req
*
types
.
ReqNil
,
result
*
interface
{})
error
{
data
,
err
:=
c
.
cli
.
GetNodeInfo
(
context
.
Background
(),
req
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
types
.
Encode
(
data
))
return
nil
}
plugin/dapp/valnode/rpc/rpc_test.go
0 → 100644
View file @
db26652c
/*
* Copyright Fuzamei Corp. 2018 All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package
rpc
//only load all plugin and system
import
(
"encoding/hex"
"testing"
"github.com/33cn/chain33/client/mocks"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
func
newGrpc
(
api
*
mocks
.
QueueProtocolAPI
)
*
channelClient
{
return
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
},
}
}
func
newJrpc
(
api
*
mocks
.
QueueProtocolAPI
)
*
Jrpc
{
return
&
Jrpc
{
cli
:
newGrpc
(
api
)}
}
func
TestChannelClient_IsSync
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"valnode"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
api
.
On
(
"QueryConsensusFunc"
,
"tendermint"
,
"IsHealthy"
,
req
)
.
Return
(
&
vt
.
IsHealthy
{
IsHealthy
:
true
},
nil
)
result
,
err
:=
client
.
IsSync
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
result
.
IsHealthy
)
}
func
TestJrpc_IsSync
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
J
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqNil
{}
var
result
interface
{}
api
.
On
(
"QueryConsensusFunc"
,
"tendermint"
,
"IsHealthy"
,
req
)
.
Return
(
&
vt
.
IsHealthy
{
IsHealthy
:
true
},
nil
)
err
:=
J
.
IsSync
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
result
)
}
func
TestChannelClient_GetNodeInfo
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"valnode"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
node
:=
&
vt
.
Validator
{
Address
:
[]
byte
(
"aaa"
),
PubKey
:
[]
byte
(
"bbb"
),
VotingPower
:
10
,
Accum
:
-
1
,
}
set
:=
&
vt
.
ValidatorSet
{
Validators
:
[]
*
vt
.
Validator
{
node
},
Proposer
:
node
,
}
api
.
On
(
"QueryConsensusFunc"
,
"tendermint"
,
"NodeInfo"
,
req
)
.
Return
(
set
,
nil
)
result
,
err
:=
client
.
GetNodeInfo
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
assert
.
EqualValues
(
t
,
set
,
result
)
}
func
TestJrpc_GetNodeInfo
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
J
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqNil
{}
var
result
interface
{}
node
:=
&
vt
.
Validator
{
Address
:
[]
byte
(
"aaa"
),
PubKey
:
[]
byte
(
"bbb"
),
VotingPower
:
10
,
Accum
:
-
1
,
}
set
:=
&
vt
.
ValidatorSet
{
Validators
:
[]
*
vt
.
Validator
{
node
},
Proposer
:
node
,
}
api
.
On
(
"QueryConsensusFunc"
,
"tendermint"
,
"NodeInfo"
,
req
)
.
Return
(
set
,
nil
)
err
:=
J
.
GetNodeInfo
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
assert
.
EqualValues
(
t
,
hex
.
EncodeToString
(
types
.
Encode
(
set
)),
result
)
}
plugin/dapp/valnode/rpc/types.go
0 → 100644
View file @
db26652c
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rpc
import
(
"github.com/33cn/chain33/rpc/types"
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
)
// Jrpc valnode jrpc interface
type
Jrpc
struct
{
cli
*
channelClient
}
// Grpc valnode Grpc interface
type
Grpc
struct
{
*
channelClient
}
type
channelClient
struct
{
types
.
ChannelClient
}
// Init valnode rpc register
func
Init
(
name
string
,
s
types
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
Jrpc
{
cli
:
cli
},
grpc
)
vt
.
RegisterValnodeServer
(
s
.
GRPC
(),
grpc
)
}
plugin/dapp/valnode/types/tendermint.pb.go
View file @
db26652c
This diff is collapsed.
Click to expand it.
plugin/dapp/valnode/types/valnode.go
View file @
db26652c
...
...
@@ -17,6 +17,11 @@ func init() {
types
.
RegisterDappFork
(
ValNodeX
,
"Enable"
,
0
)
}
// GetExecName get exec name
func
GetExecName
()
string
{
return
types
.
ExecName
(
ValNodeX
)
}
// ValNodeType stuct
type
ValNodeType
struct
{
types
.
ExecTypeBase
...
...
plugin/dapp/valnode/types/valnode.pb.go
View file @
db26652c
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment