Added `Proposal` along with `ProposalType`

feature/proposal
frozen 9 months ago
parent fa5efdc5dc
commit 1d633712df
No known key found for this signature in database
GPG Key ID: 5391C63E79B03EDE
  1. 19
      consensus/consensus.go
  2. 2
      consensus/consensus_service.go
  3. 8
      consensus/consensus_v2.go
  4. 2
      consensus/view_change.go
  5. 7
      internal/utils/singleton.go
  6. 13
      internal/utils/singleton_test.go
  7. 4
      node/node_newblock.go

@ -34,6 +34,17 @@ var errLeaderPriKeyNotFound = errors.New("leader private key not found locally")
// ProposalType is to indicate the type of signal for new block proposal
type ProposalType byte
// Proposal is to indicate the type of signal for new block proposal
type Proposal struct {
Type ProposalType
Message string
}
// NewProposal creates a new proposal
func NewProposal(t ProposalType) Proposal {
return Proposal{Type: t, Message: utils.FileNo()}
}
// Constant of the type of new block proposal
const (
SyncProposal ProposalType = iota
@ -90,7 +101,7 @@ type Consensus struct {
// ViewChange struct
vc *viewChange
// Signal channel for proposing a new block and start new consensus
readySignal chan ProposalType
readySignal chan Proposal
// Channel to send full commit signatures to finish new block proposal
commitSigChannel chan []byte
// The post-consensus job func passed from Node object
@ -151,11 +162,11 @@ func (consensus *Consensus) ChainReader() engine.ChainReader {
return consensus.Blockchain()
}
func (consensus *Consensus) ReadySignal(p ProposalType) {
func (consensus *Consensus) ReadySignal(p Proposal) {
consensus.readySignal <- p
}
func (consensus *Consensus) GetReadySignal() chan ProposalType {
func (consensus *Consensus) GetReadySignal() chan Proposal {
return consensus.readySignal
}
@ -304,7 +315,7 @@ func New(
// displayed on explorer as Height right now
consensus.setCurBlockViewID(0)
consensus.SlashChan = make(chan slash.Record)
consensus.readySignal = make(chan ProposalType)
consensus.readySignal = make(chan Proposal)
consensus.commitSigChannel = make(chan []byte)
// channel for receiving newly generated VDF
consensus.RndChannel = make(chan [vdfAndSeedSize]byte)

@ -459,7 +459,7 @@ func (consensus *Consensus) updateConsensusInformation() Mode {
consensus.GetLogger().Info().
Str("myKey", myPubKeys.SerializeToHexStr()).
Msg("[UpdateConsensusInformation] I am the New Leader")
consensus.ReadySignal(SyncProposal)
consensus.ReadySignal(NewProposal(SyncProposal))
}()
}
return Normal

@ -258,7 +258,7 @@ func (consensus *Consensus) finalCommit() {
// No pipelining
go func() {
consensus.getLogger().Info().Msg("[finalCommit] sending block proposal signal")
consensus.ReadySignal(SyncProposal)
consensus.ReadySignal(NewProposal(SyncProposal))
}()
} else {
// pipelining
@ -334,7 +334,7 @@ func (consensus *Consensus) StartChannel() {
consensus.start = true
consensus.getLogger().Info().Time("time", time.Now()).Msg("[ConsensusMainLoop] Send ReadySignal")
consensus.mutex.Unlock()
consensus.ReadySignal(SyncProposal)
consensus.ReadySignal(NewProposal(SyncProposal))
return
}
consensus.mutex.Unlock()
@ -586,7 +586,7 @@ func (consensus *Consensus) preCommitAndPropose(blk *types.Block) error {
// Send signal to Node to propose the new block for consensus
consensus.getLogger().Info().Msg("[preCommitAndPropose] sending block proposal signal")
consensus.mutex.Unlock()
consensus.ReadySignal(AsyncProposal)
consensus.ReadySignal(NewProposal(AsyncProposal))
}()
return nil
@ -814,7 +814,7 @@ func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg
blockPeriod := consensus.BlockPeriod
go func() {
<-time.After(blockPeriod)
consensus.ReadySignal(SyncProposal)
consensus.ReadySignal(NewProposal(SyncProposal))
}()
}
}

@ -429,7 +429,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
consensus.getLogger().Error().Err(err).Msg("[onViewChange] startNewView failed")
return
}
go consensus.ReadySignal(SyncProposal)
go consensus.ReadySignal(NewProposal(SyncProposal))
return
}

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path"
"runtime"
"strconv"
"sync"
"time"
@ -212,3 +213,9 @@ func GetPort() int {
}
return 0
}
// FileNo returns source code file and line
func FileNo() string {
_, file, line, _ := runtime.Caller(1)
return fmt.Sprintf("%s:%d", file, line)
}

@ -0,0 +1,13 @@
package utils
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestFileNo(t *testing.T) {
f1 := FileNo()
f2 := FileNo()
require.NotEqual(t, f1, f2)
}

@ -53,7 +53,7 @@ func (node *Node) WaitForConsensusReadyV2(cs *consensus.Consensus, stopChan chan
time.Sleep(SleepPeriod)
utils.Logger().Info().
Uint64("blockNum", cs.Blockchain().CurrentBlock().NumberU64()+1).
Bool("asyncProposal", proposalType == consensus.AsyncProposal).
Bool("asyncProposal", proposalType.Type == consensus.AsyncProposal).
Msg("PROPOSING NEW BLOCK ------------------------------------------------")
// Prepare last commit signatures
@ -61,7 +61,7 @@ func (node *Node) WaitForConsensusReadyV2(cs *consensus.Consensus, stopChan chan
go func() {
waitTime := 0 * time.Second
if proposalType == consensus.AsyncProposal {
if proposalType.Type == consensus.AsyncProposal {
waitTime = consensus.CommitSigReceiverTimeout
}
select {

Loading…
Cancel
Save