Add specifying consensusID when starting test consensus
This commit is contained in:
parent
d47925db4b
commit
ed675a6b75
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/Secured-Finance/dione/models"
|
||||
"github.com/Secured-Finance/dione/pb"
|
||||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -42,8 +41,8 @@ func NewPBFTConsensusManager(psb *pb.PubSubRouter, maxFaultNodes int) *PBFTConse
|
||||
return pcm
|
||||
}
|
||||
|
||||
func (pcm *PBFTConsensusManager) NewTestConsensus(data string) {
|
||||
consensusID := uuid.New().String()
|
||||
func (pcm *PBFTConsensusManager) NewTestConsensus(data string, consensusID string) {
|
||||
//consensusID := uuid.New().String()
|
||||
cData := &ConsensusData{}
|
||||
cData.test = true
|
||||
pcm.Consensuses[consensusID] = cData
|
||||
@ -66,6 +65,7 @@ func (pcm *PBFTConsensusManager) handlePreparedMessage(message *models.Message)
|
||||
logrus.Warn("Unknown consensus ID: " + consensusID)
|
||||
return
|
||||
}
|
||||
logrus.Debug("received prepared msg")
|
||||
data := pcm.Consensuses[consensusID]
|
||||
|
||||
// validate payload data
|
||||
|
2
go.mod
2
go.mod
@ -16,7 +16,7 @@ require (
|
||||
github.com/golang/protobuf v1.4.2 // indirect
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
|
||||
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4 // indirect
|
||||
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4
|
||||
github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect
|
||||
github.com/libp2p/go-libp2p v0.10.2
|
||||
github.com/libp2p/go-libp2p-core v0.6.1
|
||||
|
1
go.sum
1
go.sum
@ -494,6 +494,7 @@ github.com/libp2p/go-libp2p-quic-transport v0.5.0/go.mod h1:IEcuC5MLxvZ5KuHKjRu+
|
||||
github.com/libp2p/go-libp2p-record v0.1.2/go.mod h1:pal0eNcT5nqZaTV7UGhqeGqxFgGdsU/9W//C8dqjQDk=
|
||||
github.com/libp2p/go-libp2p-record v0.1.3 h1:R27hoScIhQf/A8XJZ8lYpnqh9LatJ5YbHs28kCIfql0=
|
||||
github.com/libp2p/go-libp2p-record v0.1.3/go.mod h1:yNUff/adKIfPnYQXgp6FQmNu3gLJ6EMg7+/vv2+9pY4=
|
||||
github.com/libp2p/go-libp2p-routing-helpers v0.2.3 h1:xY61alxJ6PurSi+MXbywZpelvuU4U4p/gPTxjqCqTzY=
|
||||
github.com/libp2p/go-libp2p-routing-helpers v0.2.3/go.mod h1:795bh+9YeoFl99rMASoiVgHdi5bjack0N1+AFAdbvBw=
|
||||
github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8=
|
||||
github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g=
|
||||
|
@ -4,18 +4,19 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Secured-Finance/dione/config"
|
||||
"github.com/Secured-Finance/dione/consensus"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestConsensus(t *testing.T) {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
//log.SetAllLoggers(log.LevelDebug)
|
||||
|
||||
cfg := &config.Config{
|
||||
ListenPort: "1234",
|
||||
ListenAddr: "127.0.0.1",
|
||||
ListenAddr: "0.0.0.0",
|
||||
Bootstrap: true,
|
||||
Rendezvous: "dione",
|
||||
PubSub: config.PubSubConfig{
|
||||
@ -23,6 +24,8 @@ func TestConsensus(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
//cfg.BootstrapNodeMultiaddr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
|
||||
|
||||
// setup first node
|
||||
privKey, err := generatePrivateKey()
|
||||
if err != nil {
|
||||
@ -45,8 +48,8 @@ func TestConsensus(t *testing.T) {
|
||||
ctx, ctxCancel = context.WithCancel(context.Background())
|
||||
cfg.ListenPort = "1235"
|
||||
cfg.Bootstrap = false
|
||||
//cfg.BootstrapNodeMultiaddr = node1.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", node1.Host.ID().String())
|
||||
cfg.BootstrapNodeMultiaddr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
|
||||
cfg.BootstrapNodeMultiaddr = node1.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", node1.Host.ID().String())
|
||||
|
||||
node2 := &Node{
|
||||
OracleTopic: "dione",
|
||||
Config: cfg,
|
||||
@ -70,16 +73,10 @@ func TestConsensus(t *testing.T) {
|
||||
}
|
||||
node3.setupNode(ctx, privKey)
|
||||
|
||||
node2.ConsensusManager.NewTestConsensus("test")
|
||||
node1.ConsensusManager.NewTestConsensus("test1")
|
||||
node3.ConsensusManager.NewTestConsensus("test")
|
||||
var last consensus.ConsensusState = -1
|
||||
for {
|
||||
for _, v := range node1.ConsensusManager.Consensuses {
|
||||
if v.State != last {
|
||||
last = v.State
|
||||
t.Log("new state: " + fmt.Sprint(v.State))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
go node2.ConsensusManager.NewTestConsensus("test", "123")
|
||||
go node1.ConsensusManager.NewTestConsensus("test1", "123")
|
||||
go node3.ConsensusManager.NewTestConsensus("test", "123")
|
||||
select{}
|
||||
}
|
Loading…
Reference in New Issue
Block a user