Add specifying consensusID when starting test consensus

This commit is contained in:
ChronosX88 2020-10-22 02:05:12 +04:00
parent d47925db4b
commit ed675a6b75
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
4 changed files with 19 additions and 21 deletions

View File

@ -5,7 +5,6 @@ import (
"github.com/Secured-Finance/dione/models" "github.com/Secured-Finance/dione/models"
"github.com/Secured-Finance/dione/pb" "github.com/Secured-Finance/dione/pb"
"github.com/google/uuid"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -42,8 +41,8 @@ func NewPBFTConsensusManager(psb *pb.PubSubRouter, maxFaultNodes int) *PBFTConse
return pcm return pcm
} }
func (pcm *PBFTConsensusManager) NewTestConsensus(data string) { func (pcm *PBFTConsensusManager) NewTestConsensus(data string, consensusID string) {
consensusID := uuid.New().String() //consensusID := uuid.New().String()
cData := &ConsensusData{} cData := &ConsensusData{}
cData.test = true cData.test = true
pcm.Consensuses[consensusID] = cData pcm.Consensuses[consensusID] = cData
@ -66,6 +65,7 @@ func (pcm *PBFTConsensusManager) handlePreparedMessage(message *models.Message)
logrus.Warn("Unknown consensus ID: " + consensusID) logrus.Warn("Unknown consensus ID: " + consensusID)
return return
} }
logrus.Debug("received prepared msg")
data := pcm.Consensuses[consensusID] data := pcm.Consensuses[consensusID]
// validate payload data // validate payload data

2
go.mod
View File

@ -16,7 +16,7 @@ require (
github.com/golang/protobuf v1.4.2 // indirect github.com/golang/protobuf v1.4.2 // indirect
github.com/google/uuid v1.1.1 github.com/google/uuid v1.1.1
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect 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/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect
github.com/libp2p/go-libp2p v0.10.2 github.com/libp2p/go-libp2p v0.10.2
github.com/libp2p/go-libp2p-core v0.6.1 github.com/libp2p/go-libp2p-core v0.6.1

1
go.sum
View File

@ -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.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 h1:R27hoScIhQf/A8XJZ8lYpnqh9LatJ5YbHs28kCIfql0=
github.com/libp2p/go-libp2p-record v0.1.3/go.mod h1:yNUff/adKIfPnYQXgp6FQmNu3gLJ6EMg7+/vv2+9pY4= 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-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.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8=
github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g= github.com/libp2p/go-libp2p-secio v0.2.0/go.mod h1:2JdZepB8J5V9mBp79BmwsaPQhRPNN2NrnB2lKQcdy6g=

View File

@ -4,18 +4,19 @@ import (
"context" "context"
"fmt" "fmt"
"testing" "testing"
"time"
"github.com/Secured-Finance/dione/config" "github.com/Secured-Finance/dione/config"
"github.com/Secured-Finance/dione/consensus"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func TestConsensus(t *testing.T) { func TestConsensus(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
//log.SetAllLoggers(log.LevelDebug)
cfg := &config.Config{ cfg := &config.Config{
ListenPort: "1234", ListenPort: "1234",
ListenAddr: "127.0.0.1", ListenAddr: "0.0.0.0",
Bootstrap: true, Bootstrap: true,
Rendezvous: "dione", Rendezvous: "dione",
PubSub: config.PubSubConfig{ PubSub: config.PubSubConfig{
@ -23,6 +24,8 @@ func TestConsensus(t *testing.T) {
}, },
} }
//cfg.BootstrapNodeMultiaddr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
// setup first node // setup first node
privKey, err := generatePrivateKey() privKey, err := generatePrivateKey()
if err != nil { if err != nil {
@ -45,8 +48,8 @@ func TestConsensus(t *testing.T) {
ctx, ctxCancel = context.WithCancel(context.Background()) ctx, ctxCancel = context.WithCancel(context.Background())
cfg.ListenPort = "1235" cfg.ListenPort = "1235"
cfg.Bootstrap = false cfg.Bootstrap = false
//cfg.BootstrapNodeMultiaddr = node1.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", node1.Host.ID().String()) cfg.BootstrapNodeMultiaddr = node1.Host.Addrs()[0].String() + fmt.Sprintf("/p2p/%s", node1.Host.ID().String())
cfg.BootstrapNodeMultiaddr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
node2 := &Node{ node2 := &Node{
OracleTopic: "dione", OracleTopic: "dione",
Config: cfg, Config: cfg,
@ -70,16 +73,10 @@ func TestConsensus(t *testing.T) {
} }
node3.setupNode(ctx, privKey) node3.setupNode(ctx, privKey)
node2.ConsensusManager.NewTestConsensus("test")
node1.ConsensusManager.NewTestConsensus("test1") time.Sleep(10 * time.Second)
node3.ConsensusManager.NewTestConsensus("test") go node2.ConsensusManager.NewTestConsensus("test", "123")
var last consensus.ConsensusState = -1 go node1.ConsensusManager.NewTestConsensus("test1", "123")
for { go node3.ConsensusManager.NewTestConsensus("test", "123")
for _, v := range node1.ConsensusManager.Consensuses { select{}
if v.State != last {
last = v.State
t.Log("new state: " + fmt.Sprint(v.State))
}
}
}
} }