Fix some minor mistakes in various places
This commit is contained in:
parent
29c38e80b7
commit
2952983c94
@ -5,6 +5,8 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/Secured-Finance/dione/cache"
|
||||||
|
|
||||||
"github.com/asaskevich/EventBus"
|
"github.com/asaskevich/EventBus"
|
||||||
|
|
||||||
"github.com/Secured-Finance/dione/blockchain"
|
"github.com/Secured-Finance/dione/blockchain"
|
||||||
@ -92,6 +94,7 @@ func (pcm *PBFTConsensusManager) propose(blk *types3.Block) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pcm.psb.BroadcastToServiceTopic(prePrepareMsg)
|
pcm.psb.BroadcastToServiceTopic(prePrepareMsg)
|
||||||
|
pcm.blockPool.AddBlock(blk)
|
||||||
pcm.state.status = StateStatusPrePrepared
|
pcm.state.status = StateStatusPrePrepared
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -152,18 +155,11 @@ func (pcm *PBFTConsensusManager) handlePrepare(message *pubsub.GenericMessage) {
|
|||||||
Type: types.ConsensusMessageTypePrepare,
|
Type: types.ConsensusMessageTypePrepare,
|
||||||
From: message.From,
|
From: message.From,
|
||||||
Blockhash: prepare.Blockhash,
|
Blockhash: prepare.Blockhash,
|
||||||
Signature: prepare.Signature, // TODO check the signature
|
Signature: prepare.Signature,
|
||||||
}
|
}
|
||||||
|
|
||||||
pk, _ := message.From.ExtractPublicKey()
|
if _, err := pcm.blockPool.GetBlock(cmsg.Blockhash); errors.Is(err, cache.ErrNotFound) {
|
||||||
ok, err := pk.Verify(cmsg.Blockhash, cmsg.Signature)
|
logrus.Debugf("received unknown block")
|
||||||
if err != nil {
|
|
||||||
logrus.Warnf("Failed to verify PREPARE message signature: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
logrus.Errorf("Signature of PREPARE message of peer %s isn't valid!", cmsg.From)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +167,7 @@ func (pcm *PBFTConsensusManager) handlePrepare(message *pubsub.GenericMessage) {
|
|||||||
logrus.Debugf("received existing prepare msg, dropping...")
|
logrus.Debugf("received existing prepare msg, dropping...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pcm.validator.Valid(cmsg, nil) {
|
if !pcm.validator.Valid(cmsg, nil) {
|
||||||
logrus.Warn("received invalid prepare msg, dropping...")
|
logrus.Warn("received invalid prepare msg, dropping...")
|
||||||
return
|
return
|
||||||
@ -204,15 +201,8 @@ func (pcm *PBFTConsensusManager) handleCommit(message *pubsub.GenericMessage) {
|
|||||||
Signature: commit.Signature, // TODO check the signature
|
Signature: commit.Signature, // TODO check the signature
|
||||||
}
|
}
|
||||||
|
|
||||||
pk, _ := message.From.ExtractPublicKey()
|
if _, err := pcm.blockPool.GetBlock(cmsg.Blockhash); errors.Is(err, cache.ErrNotFound) {
|
||||||
ok, err := pk.Verify(cmsg.Blockhash, cmsg.Signature)
|
logrus.Debugf("received unknown block")
|
||||||
if err != nil {
|
|
||||||
logrus.Warnf("Failed to verify COMMIT message signature: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
logrus.Errorf("Signature of COMMIT message of peer %s isn't valid!", cmsg.From)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +137,7 @@ func NewConsensusValidator(miner *Miner, bc *blockchain.BlockChain) *ConsensusVa
|
|||||||
for _, v := range msg.Block.Data {
|
for _, v := range msg.Block.Data {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(v *types3.Transaction, c chan error) {
|
go func(v *types3.Transaction, c chan error) {
|
||||||
|
defer wg.Done()
|
||||||
if err := utils.VerifyTx(msg.Block.Header, v); err != nil {
|
if err := utils.VerifyTx(msg.Block.Header, v); err != nil {
|
||||||
c <- fmt.Errorf("failed to verify tx: %w", err)
|
c <- fmt.Errorf("failed to verify tx: %w", err)
|
||||||
return
|
return
|
||||||
@ -157,7 +158,6 @@ func NewConsensusValidator(miner *Miner, bc *blockchain.BlockChain) *ConsensusVa
|
|||||||
} else {
|
} else {
|
||||||
logrus.Debugf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", task.OriginChain, task.RequestType)
|
logrus.Debugf("Origin chain [%v]/request type[%v] doesn't have any payload validation!", task.OriginChain, task.RequestType)
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
}(v, result)
|
}(v, result)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -108,7 +108,7 @@ func (m *Miner) MineBlock(randomness []byte, lastBlockHeader *types2.BlockHeader
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
txs := m.mempool.GetAllTransactions()
|
txs := m.mempool.GetTransactionsForNewBlock()
|
||||||
if txs == nil {
|
if txs == nil {
|
||||||
return nil, fmt.Errorf("there is no txes for processing") // skip new consensus round because there is no transaction for processing
|
return nil, fmt.Errorf("there is no txes for processing") // skip new consensus round because there is no transaction for processing
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user