Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Connectivity and Consensus #2014

Merged
merged 15 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/daemons/candidate_node_votings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type VotingTotal struct {
Data map[string]VotingRes `json:"data"`
AgreeQuantity int64 `json:"agreeQuantity"`
LocalAddress string `json:"localAddress"`
St int64 `json:"st"`
}

func ToUpdateMachineStatus(currentTcpAddress, tcpAddress string, ch chan map[string]VotingRes, logger *log.Entry) error {
Expand Down Expand Up @@ -78,6 +79,7 @@ func CandidateNodeVoting(ctx context.Context, d *daemon) error {
candidateNodes sqldb.CandidateNodes
err error
agreeQuantity int64
st int64
)
defer func() {
d.sleepTime = time.Minute
Expand Down Expand Up @@ -144,13 +146,14 @@ func CandidateNodeVoting(ctx context.Context, d *daemon) error {
}
}
close(ch)
st = time.Now().UnixMilli()
if len(nodeConnMap) > 0 {
var wg sync.WaitGroup
for _, node := range candidateNodes {
wg.Add(1)
go func(tcpAddress string) {
defer wg.Done()
votingTotal := VotingTotal{Data: nodeConnMap, AgreeQuantity: agreeQuantity, LocalAddress: currentTcpAddress}
votingTotal := VotingTotal{Data: nodeConnMap, AgreeQuantity: agreeQuantity, LocalAddress: currentTcpAddress, St: st}
err = ToBroadcastNodeConnInfo(votingTotal, tcpAddress, d.logger)
if err != nil {
d.logger.WithFields(log.Fields{"type": consts.NetworkError, "error": err, "tcpAddress": tcpAddress}).Error("broadcast node conn info error")
Expand Down
2 changes: 2 additions & 0 deletions packages/network/tcpserver/candidate_node_voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type VotingTotal struct {
Data map[string]VotingRes `json:"data"`
AgreeQuantity int64 `json:"agreeQuantity"`
LocalAddress string `json:"localAddress"`
St int64 `json:"st"`
}

func SyncMatchineStateRes(request *network.BroadcastNodeConnInfoRequest) (*network.BroadcastNodeConnInfoResponse, error) {
Expand All @@ -58,6 +59,7 @@ func SyncMatchineStateRes(request *network.BroadcastNodeConnInfoRequest) (*netwo
candidateNode := &sqldb.CandidateNode{
TcpAddress: votingTotal.LocalAddress,
ReplyCount: votingTotal.AgreeQuantity,
DateReply: votingTotal.St,
CandidateNodes: request.Data,
}
err = candidateNode.UpdateCandidateNodeInfo()
Expand Down
4 changes: 1 addition & 3 deletions packages/storage/sqldb/candidate_node.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sqldb

import (
"time"

"github.com/IBAX-io/go-ibax/packages/consts"
"github.com/shopspring/decimal"
)
Expand Down Expand Up @@ -61,7 +59,7 @@ func (c *CandidateNode) UpdateCandidateNodeInfo() error {
if err != nil {
return err
}
err = GetDB(nil).Model(&c).Where("tcp_address = ? and deleted = ? and earnest_total >= ?", c.TcpAddress, 0, pledgeAmount).Updates(CandidateNode{ReplyCount: c.ReplyCount, DateReply: time.Now().UnixMilli(), CandidateNodes: c.CandidateNodes}).Error
err = GetDB(nil).Model(&c).Where("tcp_address = ? and deleted = ? and earnest_total >= ?", c.TcpAddress, 0, pledgeAmount).Updates(CandidateNode{ReplyCount: c.ReplyCount, DateReply: c.DateReply, CandidateNodes: c.CandidateNodes}).Error
if err != nil {
return err
}
Expand Down