Merge pull request #1253 from chaosma/r3

Revert workaround PRs for restarting network
pull/1254/head
chaosma 5 years ago committed by GitHub
commit bd121ff1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      consensus/config.go
  2. 30
      consensus/consensus_service.go
  3. 103
      consensus/consensus_v2.go
  4. 7
      node/node.go
  5. 11
      node/node_newblock.go

@ -15,14 +15,6 @@ const (
maxLogSize uint32 = 1000
// threshold between received consensus message blockNum and my blockNum
consensusBlockNumBuffer uint64 = 2
// ReProposeBlockNumShard0: leader propose this block from it's database and validators accept them
ReProposeBlockNumShard0 uint64 = 270108
// ReProposeBlockNumShard1: leader propose this block from it's database and validators accept them
ReProposeBlockNumShard1 uint64 = 275559
// ReProposeBlockNumShard2: leader propose this block from it's database and validators accept them
ReProposeBlockNumShard2 uint64 = 275057
// ReProposeBlockNumShard3: leader propose this block from it's database and validators accept them
ReProposeBlockNumShard3 uint64 = 276805
)
// TimeoutType is the type of timeout in view change protocol

@ -667,36 +667,6 @@ func (consensus *Consensus) updateConsensusInformation() {
}
}
// NeedsBlockRecovery returns true if the current block needs recovery
func (consensus *Consensus) NeedsBlockRecovery(blockNum uint64) bool {
switch {
case blockNum == ReProposeBlockNumShard0 && consensus.ShardID == 0:
return true
case blockNum == ReProposeBlockNumShard1 && consensus.ShardID == 1:
return true
case blockNum == ReProposeBlockNumShard2 && consensus.ShardID == 2:
return true
case blockNum == ReProposeBlockNumShard3 && consensus.ShardID == 3:
return true
}
return false
}
// RecoveryBlockNumber returns the recovery block number of a shard
func (consensus *Consensus) RecoveryBlockNumber(shardID uint32) uint64 {
switch {
case consensus.ShardID == 0:
return ReProposeBlockNumShard0
case consensus.ShardID == 1:
return ReProposeBlockNumShard1
case consensus.ShardID == 2:
return ReProposeBlockNumShard2
case consensus.ShardID == 3:
return ReProposeBlockNumShard3
}
return 0
}
// IsLeader check if the node is a leader or not by comparing the public key of
// the node with the leader public key
func (consensus *Consensus) IsLeader() bool {

@ -177,20 +177,6 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
return
}
// TODO: remove it after shard0 fix
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) {
consensus.getLogger().Debug().
Uint64("MsgViewID", recvMsg.ViewID).
Uint64("MsgBlockNum", recvMsg.BlockNum).
Msg("[OnAnnounce] Announce message Added")
consensus.PbftLog.AddMessage(recvMsg)
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.blockHash = recvMsg.BlockHash
consensus.prepare()
return
}
// verify validity of block header object
blockHeader := recvMsg.Payload
var headerObj types.Header
@ -439,56 +425,6 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
Uint64("MsgViewID", recvMsg.ViewID).
Msg("[OnPrepared] Received prepared message")
// TODO: remove it after fix
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) {
block := recvMsg.Block
var blockObj types.Block
err = rlp.DecodeBytes(block, &blockObj)
if err != nil {
consensus.getLogger().Warn().
Err(err).
Uint64("MsgBlockNum", recvMsg.BlockNum).
Msg("[OnPrepared] Unparseable block header data")
return
}
consensus.PbftLog.AddBlock(&blockObj)
recvMsg.Block = []byte{} // save memory space
consensus.PbftLog.AddMessage(recvMsg)
consensus.getLogger().Debug().
Uint64("MsgViewID", recvMsg.ViewID).
Uint64("MsgBlockNum", recvMsg.BlockNum).
Bytes("blockHash", recvMsg.BlockHash[:]).
Msg("[OnPrepared] Prepared message and block added")
// add block field
blockPayload := make([]byte, len(block))
copy(blockPayload[:], block[:])
consensus.block = blockPayload
// Construct and send the commit message
blockNumBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(blockNumBytes, consensus.blockNum)
commitPayload := append(blockNumBytes, consensus.blockHash[:]...)
msgToSend := consensus.constructCommitMessage(commitPayload)
if err := consensus.host.SendMessageToGroups([]p2p.GroupID{p2p.NewGroupIDByShardID(p2p.ShardID(consensus.ShardID))}, host.ConstructP2pMessage(byte(17), msgToSend)); err != nil {
consensus.getLogger().Warn().
Msg("[OnPrepared] Cannot send commit message!!")
} else {
consensus.getLogger().Info().
Bytes("BlockHash", consensus.blockHash[:]).
Uint64("BlockNum", consensus.blockNum).
Msg("[OnPrepared] Sent Commit Message!!")
}
consensus.getLogger().Debug().
Str("From", string(consensus.phase)).
Str("To", string(Commit)).
Msg("[OnPrepared] Switching phase")
consensus.switchPhase(Commit, true)
return
}
if recvMsg.BlockNum < consensus.blockNum {
consensus.getLogger().Debug().Uint64("MsgBlockNum", recvMsg.BlockNum).Msg("Old Block Received, ignoring!!")
return
@ -885,28 +821,6 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
return
}
// TODO: remove it after fix
if consensus.NeedsBlockRecovery(recvMsg.BlockNum) {
consensus.PbftLog.AddMessage(recvMsg)
consensus.getLogger().Debug().
Uint64("MsgViewID", recvMsg.ViewID).
Uint64("MsgBlockNum", recvMsg.BlockNum).
Msg("[OnCommitted] Committed message added")
consensus.tryCatchup()
if consensus.consensusTimeout[timeoutBootstrap].IsActive() {
consensus.consensusTimeout[timeoutBootstrap].Stop()
consensus.getLogger().Debug().
Msg("[OnCommitted] Start consensus timer; stop bootstrap timer only once")
} else {
consensus.getLogger().Debug().
Msg("[OnCommitted] Start consensus timer")
}
consensus.consensusTimeout[timeoutConsensus].Start()
return
}
if recvMsg.BlockNum < consensus.blockNum {
consensus.getLogger().Info().
Uint64("MsgBlockNum", recvMsg.BlockNum).
@ -1036,23 +950,6 @@ func (consensus *Consensus) tryCatchup() {
break
}
if consensus.NeedsBlockRecovery(block.NumberU64()) && block.NumberU64() == consensus.ChainReader.CurrentHeader().Number.Uint64() {
consensus.getLogger().Info().Msg("[TryCatchup] Skip Commit ReProposeBlock")
consensus.blockNum = block.NumberU64() + 1
consensus.viewID = msgs[0].ViewID + 1
consensus.ResetState()
return
}
if consensus.NeedsBlockRecovery(block.NumberU64()) && block.NumberU64() != consensus.ChainReader.CurrentHeader().Number.Uint64() {
consensus.getLogger().Info().Msg("[TryCatchup] Commit ReProposeBlock")
consensus.blockNum = block.NumberU64() + 1
consensus.viewID = msgs[0].ViewID + 1
consensus.OnConsensusDone(block)
consensus.ResetState()
return
}
if consensus.BlockVerifier == nil {
// do nothing
} else if err := consensus.BlockVerifier(block); err != nil {

@ -335,12 +335,7 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
node.Consensus.VerifiedNewBlock = make(chan *types.Block)
// the sequence number is the next block number to be added in consensus protocol, which is always one more than current chain header block
// TODO: remove it after fix
if node.Consensus.NeedsBlockRecovery(chain.CurrentBlock().NumberU64()) {
node.Consensus.SetBlockNum(node.Consensus.RecoveryBlockNumber(node.Consensus.ShardID))
} else {
node.Consensus.SetBlockNum(chain.CurrentBlock().NumberU64() + 1)
}
node.Consensus.SetBlockNum(chain.CurrentBlock().NumberU64() + 1)
// Add Faucet contract to all shards, so that on testnet, we can demo wallet in explorer
// TODO (leo): we need to have support of cross-shard tx later so that the token can be transferred from beacon chain shard to other tx shards.

@ -27,9 +27,6 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
// Setup stoppedChan
defer close(stoppedChan)
// TODO: remove it later
firstTime := true
utils.GetLogInstance().Debug("Waiting for Consensus ready")
time.Sleep(30 * time.Second) // Wait for other nodes to be ready (test-only)
@ -61,14 +58,6 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
continue
}
//TODO: remove it after shard0 fix
if node.Consensus.NeedsBlockRecovery(node.Blockchain().CurrentBlock().NumberU64()) && firstTime {
firstTime = false
newBlock := node.Blockchain().CurrentBlock()
node.BlockChannel <- newBlock
break
}
coinbase := node.Consensus.SelfAddress
// Normal tx block consensus
selectedTxs := types.Transactions{} // Empty transaction list

Loading…
Cancel
Save