Commit 8fd20a22 authored by 张振华's avatar 张振华

update

parent d6a85a25
...@@ -185,11 +185,11 @@ func (cs *ConsensusState) SetPrivValidator(priv ttypes.PrivValidator, index int) ...@@ -185,11 +185,11 @@ func (cs *ConsensusState) SetPrivValidator(priv ttypes.PrivValidator, index int)
} }
// SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing. // SetTimeoutTicker sets the local timer. It may be useful to overwrite for testing.
func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker) { //func (cs *ConsensusState) SetTimeoutTicker(timeoutTicker TimeoutTicker) {
cs.mtx.Lock() // cs.mtx.Lock()
defer cs.mtx.Unlock() // defer cs.mtx.Unlock()
cs.timeoutTicker = timeoutTicker // cs.timeoutTicker = timeoutTicker
} //}
// Start It start first time starts the timeout receive routines. // Start It start first time starts the timeout receive routines.
func (cs *ConsensusState) Start() { func (cs *ConsensusState) Start() {
...@@ -219,6 +219,7 @@ func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, stateType ...@@ -219,6 +219,7 @@ func (cs *ConsensusState) scheduleDPosTimeout(duration time.Duration, stateType
} }
// send a msg into the receiveRoutine regarding our own proposal, block part, or vote // send a msg into the receiveRoutine regarding our own proposal, block part, or vote
/*
func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) { func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
select { select {
case cs.internalMsgQueue <- mi: case cs.internalMsgQueue <- mi:
...@@ -231,7 +232,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) { ...@@ -231,7 +232,7 @@ func (cs *ConsensusState) sendInternalMessage(mi MsgInfo) {
go func() { cs.internalMsgQueue <- mi }() go func() { cs.internalMsgQueue <- mi }()
} }
} }
*/
// Updates ConsensusState and increments height to match that of state. // Updates ConsensusState and increments height to match that of state.
// The round becomes 0 and cs.Step becomes ttypes.RoundStepNewHeight. // The round becomes 0 and cs.Step becomes ttypes.RoundStepNewHeight.
func (cs *ConsensusState) updateToValMgr(valMgr ValidatorMgr) { func (cs *ConsensusState) updateToValMgr(valMgr ValidatorMgr) {
......
...@@ -76,6 +76,7 @@ type Client struct { ...@@ -76,6 +76,7 @@ type Client struct {
stopC chan struct{} stopC chan struct{}
isDelegator bool isDelegator bool
blockTime int64 blockTime int64
testFlag bool
} }
type subConfig struct { type subConfig struct {
...@@ -230,6 +231,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module { ...@@ -230,6 +231,7 @@ func New(cfg *types.Consensus, sub []byte) queue.Module {
crypto: cr, crypto: cr,
stopC: make(chan struct{}, 1), stopC: make(chan struct{}, 1),
isDelegator: false, isDelegator: false,
testFlag: false,
} }
c.SetChild(client) c.SetChild(client)
...@@ -366,7 +368,7 @@ OuterLoop: ...@@ -366,7 +368,7 @@ OuterLoop:
csState.SetPrivValidator(client.privValidator, client.ValidatorIndex()) csState.SetPrivValidator(client.privValidator, client.ValidatorIndex())
// Create & add listener // Create & add listener
protocol, listeningAddress := "tcp", "0.0.0.0:"+dposPort protocol, listeningAddress := "tcp", "0.0.0.0:" + dposPort
node := NewNode(validatorNodes, protocol, listeningAddress, client.privKey, valMgr.ChainID, dposVersion, csState) node := NewNode(validatorNodes, protocol, listeningAddress, client.privKey, valMgr.ChainID, dposVersion, csState)
client.node = node client.node = node
...@@ -376,7 +378,7 @@ OuterLoop: ...@@ -376,7 +378,7 @@ OuterLoop:
client.InitBlock() client.InitBlock()
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
client.csState.Init() client.csState.Init()
node.Start() node.Start(client.testFlag)
} }
//go client.MonitorCandidators() //go client.MonitorCandidators()
...@@ -763,3 +765,13 @@ func printCandidators(cands []*dty.Candidator) string { ...@@ -763,3 +765,13 @@ func printCandidators(cands []*dty.Candidator) string {
func (client *Client) GetConsensusState() *ConsensusState { func (client *Client) GetConsensusState() *ConsensusState {
return client.csState return client.csState
} }
// SetTestFlag set the test flag
func (client *Client) SetTestFlag() {
client.testFlag = true
}
// GetNode return the pointer to Node
func (client *Client) GetNode() *Node{
return client.node
}
\ No newline at end of file
...@@ -69,7 +69,7 @@ func init() { ...@@ -69,7 +69,7 @@ func init() {
pubkey, _ = hex.DecodeString(strPubkey) pubkey, _ = hex.DecodeString(strPubkey)
} }
func TestDposPerf(t *testing.T) { func TestDposPerf(t *testing.T) {
DposPerf() //DposPerf()
fmt.Println("=======start clear test data!=======") fmt.Println("=======start clear test data!=======")
clearTestData() clearTestData()
} }
...@@ -83,9 +83,10 @@ func DposPerf() { ...@@ -83,9 +83,10 @@ func DposPerf() {
defer q.Close() defer q.Close()
defer cs.Close() defer cs.Close()
defer p2p.Close() defer p2p.Close()
err := createConn() var err error
conn, c, err = createConn("127.0.0.1:8802")
for err != nil { for err != nil {
err = createConn() conn, c, err = createConn("127.0.0.1:8802")
} }
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
for i := 0; i < loopCount; i++ { for i := 0; i < loopCount; i++ {
...@@ -149,15 +150,7 @@ func DposPerf() { ...@@ -149,15 +150,7 @@ func DposPerf() {
dposClient.csState.SendCBTx(info) dposClient.csState.SendCBTx(info)
sendCBTx(dposClient.csState, info) sendCBTx(dposClient.csState, info)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
/*
info2 := dposClient.csState.GetCBInfoByCircle(task.Cycle)
if info2 != nil && info2.StopHeight == info.StopHeight {
fmt.Println("GetCBInfoByCircle ok")
} else {
fmt.Println("GetCBInfoByCircle failed")
}
time.Sleep(1 * time.Second)
*/
for { for {
now = time.Now().Unix() now = time.Now().Unix()
task = DecideTaskByTime(now) task = DecideTaskByTime(now)
...@@ -282,18 +275,18 @@ func initEnvDpos() (queue.Queue, *blockchain.BlockChain, queue.Module, queue.Mod ...@@ -282,18 +275,18 @@ func initEnvDpos() (queue.Queue, *blockchain.BlockChain, queue.Module, queue.Mod
return q, chain, s, mem, exec, cs, network return q, chain, s, mem, exec, cs, network
} }
func createConn() error { func createConn(url string) (*grpc.ClientConn, types.Chain33Client, error) {
var err error var err error
url := "127.0.0.1:8802" //url := "127.0.0.1:8802"
fmt.Println("grpc url:", url) fmt.Println("grpc url:", url)
conn, err = grpc.Dial(url, grpc.WithInsecure()) conn1, err := grpc.Dial(url, grpc.WithInsecure())
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
return err return conn1, nil, err
} }
c = types.NewChain33Client(conn) c1 := types.NewChain33Client(conn)
//r = rand.New(rand.NewSource(types.Now().UnixNano())) //r = rand.New(rand.NewSource(types.Now().UnixNano()))
return nil return conn1, c1, nil
} }
func generateKey(i, valI int) string { func generateKey(i, valI int) string {
......
{"genesis_time":"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgFj","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}
\ No newline at end of file
...@@ -169,7 +169,7 @@ func NewNode(seeds []string, protocol string, lAddr string, privKey crypto.PrivK ...@@ -169,7 +169,7 @@ func NewNode(seeds []string, protocol string, lAddr string, privKey crypto.PrivK
} }
// Start node // Start node
func (node *Node) Start() { func (node *Node) Start(testFlag bool) {
if atomic.CompareAndSwapUint32(&node.started, 0, 1) { if atomic.CompareAndSwapUint32(&node.started, 0, 1) {
// Create listener // Create listener
var listener net.Listener var listener net.Listener
...@@ -197,7 +197,7 @@ func (node *Node) Start() { ...@@ -197,7 +197,7 @@ func (node *Node) Start() {
addr := node.seeds[i] addr := node.seeds[i]
ip, _ := splitHostPort(addr) ip, _ := splitHostPort(addr)
_, ok := node.localIPs[ip] _, ok := node.localIPs[ip]
if ok { if ok && !testFlag{
dposlog.Info("find our ip ", "ourip", ip) dposlog.Info("find our ip ", "ourip", ip)
node.IP = ip node.IP = ip
return return
......
This diff is collapsed.
{"address":"2B226E6603E52C94715BA4E92080EEF236292E33","pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"last_height":1679,"last_round":0,"last_step":3,"last_signature":{"type":"secp256k1","data":"37892A916D6E487ADF90F9E88FE37024597677B6C6FED47444AD582F74144B3D6E4B364EAF16AF03A4E42827B6D3C86415D734A5A6CCA92E114B23EB9265AF09"},"last_signbytes":"7B22636861696E5F6964223A22636861696E33332D5A326367466A222C22766F7465223A7B22626C6F636B5F6964223A7B2268617368223A224F6A657975396B2B4149426A6E4859456739584765356A7A462B673D222C227061727473223A7B2268617368223A6E756C6C2C22746F74616C223A307D7D2C22686569676874223A313637392C22726F756E64223A302C2274696D657374616D70223A22323031382D30382D33315430373A35313A34332E3935395A222C2274797065223A327D7D","priv_key":{"type":"secp256k1","data":"5A6A14DA6F5A42835E529D75D87CC8904544F59EEE5387A37D87EEAD194D7EB2"}}
\ No newline at end of file
package dpos package dpos
import ( import (
"fmt"
"testing" "testing"
"time" "time"
...@@ -15,6 +16,7 @@ func TestTicker(t *testing.T) { ...@@ -15,6 +16,7 @@ func TestTicker(t *testing.T) {
Duration: time.Second * time.Duration(2), Duration: time.Second * time.Duration(2),
State: InitStateType, State: InitStateType,
} }
fmt.Println("timeoutInfo:", ti.String())
now := time.Now().Unix() now := time.Now().Unix()
ticker.ScheduleTimeout(ti) ticker.ScheduleTimeout(ti)
...@@ -23,5 +25,5 @@ func TestTicker(t *testing.T) { ...@@ -23,5 +25,5 @@ func TestTicker(t *testing.T) {
ticker.Stop() ticker.Stop()
assert.True(t, end-now >= 2) assert.True(t, end-now >= 2)
fmt.Println("TestTicker ok")
} }
...@@ -11,9 +11,9 @@ import ( ...@@ -11,9 +11,9 @@ import (
) )
const ( const (
errGenesisFile = `{"genesis_time:"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgFj","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}` errGenesisFile = `{"genesis_time:"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgFX","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
genesisFile = `{"genesis_time":"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgFj","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}` genesisFile = `{"genesis_time":"2018-08-16T15:38:56.951569432+08:00","chain_id":"chain33-Z2cgFX","validators":[{"pub_key":{"type":"secp256k1","data":"03EF0E1D3112CF571743A3318125EDE2E52A4EB904BCBAA4B1F75020C2846A7EB4"},"name":""},{"pub_key":{"type":"secp256k1","data":"027848E7FA630B759DB406940B5506B666A344B1060794BBF314EB459D40881BB3"},"name":""},{"pub_key":{"type":"secp256k1","data":"03F4AB6659E61E8512C9A24AC385CC1AC4D52B87D10ADBDF060086EA82BE62CDDE"},"name":""}],"app_hash":null}`
) )
func init() { func init() {
...@@ -40,7 +40,7 @@ func TestGenesisDocFromJSON(t *testing.T) { ...@@ -40,7 +40,7 @@ func TestGenesisDocFromJSON(t *testing.T) {
genDoc, err := GenesisDocFromJSON([]byte(genesisFile)) genDoc, err := GenesisDocFromJSON([]byte(genesisFile))
require.NotNil(t, genDoc) require.NotNil(t, genDoc)
require.Nil(t, err) require.Nil(t, err)
assert.True(t, genDoc.ChainID == "chain33-Z2cgFj") assert.True(t, genDoc.ChainID == "chain33-Z2cgFX")
assert.True(t, genDoc.AppHash == nil) assert.True(t, genDoc.AppHash == nil)
assert.True(t, len(genDoc.Validators) == 3) assert.True(t, len(genDoc.Validators) == 3)
...@@ -53,7 +53,7 @@ func TestSaveAs(t *testing.T) { ...@@ -53,7 +53,7 @@ func TestSaveAs(t *testing.T) {
genDoc, err := GenesisDocFromJSON([]byte(genesisFile)) genDoc, err := GenesisDocFromJSON([]byte(genesisFile))
require.NotNil(t, genDoc) require.NotNil(t, genDoc)
require.Nil(t, err) require.Nil(t, err)
assert.True(t, genDoc.ChainID == "chain33-Z2cgFj") assert.True(t, genDoc.ChainID == "chain33-Z2cgFX")
assert.True(t, genDoc.AppHash == nil) assert.True(t, genDoc.AppHash == nil)
assert.True(t, len(genDoc.Validators) == 3) assert.True(t, len(genDoc.Validators) == 3)
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/33cn/chain33/common/address"
"io/ioutil" "io/ioutil"
"os" "os"
"sync" "sync"
...@@ -136,7 +137,8 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp { ...@@ -136,7 +137,8 @@ func GenPrivValidatorImp(filePath string) *PrivValidatorImp {
panic(Fmt("GenPrivValidatorImp: GenKey failed:%v", err)) panic(Fmt("GenPrivValidatorImp: GenKey failed:%v", err))
} }
return &PrivValidatorImp{ return &PrivValidatorImp{
Address: GenAddressByPubKey(privKey.PubKey()), //Address: GenAddressByPubKey(privKey.PubKey()),
Address: address.PubKeyToAddress(privKey.PubKey().Bytes()).Hash160[:],
PubKey: privKey.PubKey(), PubKey: privKey.PubKey(),
PrivKey: privKey, PrivKey: privKey,
Signer: NewDefaultSigner(privKey), Signer: NewDefaultSigner(privKey),
......
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