MCPcopy Create free account
hub / github.com/DNAProject/DNA / verifyBlock

Method verifyBlock

txnpool/proc/txnpool_server.go:679–744  ·  view source on GitHub ↗

verifyBlock verifies the block from consensus. There are three cases to handle. 1, for those unverified txs, assign them to the available worker; 2, for those verified txs whose height >= block's height, nothing to do; 3, for those verified txs whose height < block's height, re-verify their stateful

(req *tc.VerifyBlockReq, sender *actor.PID)

Source from the content-addressed store, hash-verified

677// 3, for those verified txs whose height < block's height, re-verify their
678// stateful data.
679func (s *TXPoolServer) verifyBlock(req *tc.VerifyBlockReq, sender *actor.PID) {
680 if req == nil || len(req.Txs) == 0 {
681 return
682 }
683
684 s.setHeight(req.Height)
685 s.pendingBlock.mu.Lock()
686 defer s.pendingBlock.mu.Unlock()
687
688 s.pendingBlock.sender = sender
689 s.pendingBlock.height = req.Height
690 s.pendingBlock.processedTxs = make(map[common.Uint256]*tc.VerifyTxResult, len(req.Txs))
691 s.pendingBlock.unProcessedTxs = make(map[common.Uint256]*tx.Transaction, 0)
692
693 txs := make(map[common.Uint256]bool, len(req.Txs))
694
695 // Check whether a tx's gas price is lower than the required, if yes,
696 // just return error
697 for _, t := range req.Txs {
698 if t.GasPrice < s.gasPrice {
699 entry := &tc.VerifyTxResult{
700 Height: s.pendingBlock.height,
701 Tx: t,
702 ErrCode: errors.ErrGasPrice,
703 }
704 s.pendingBlock.processedTxs[t.Hash()] = entry
705 s.sendBlkResult2Consensus()
706 return
707 }
708 // Check whether double spent
709 if _, ok := txs[t.Hash()]; ok {
710 entry := &tc.VerifyTxResult{
711 Height: s.pendingBlock.height,
712 Tx: t,
713 ErrCode: errors.ErrDoubleSpend,
714 }
715 s.pendingBlock.processedTxs[t.Hash()] = entry
716 s.sendBlkResult2Consensus()
717 return
718 }
719 txs[t.Hash()] = true
720 }
721
722 checkBlkResult := s.txPool.GetUnverifiedTxs(req.Txs, req.Height)
723
724 for _, t := range checkBlkResult.UnverifiedTxs {
725 s.assignTxToWorker(t, tc.NilSender, nil)
726 s.pendingBlock.unProcessedTxs[t.Hash()] = t
727 }
728
729 for _, t := range checkBlkResult.OldTxs {
730 s.reVerifyStateful(t, tc.NilSender)
731 s.pendingBlock.unProcessedTxs[t.Hash()] = t
732 }
733
734 for _, t := range checkBlkResult.VerifiedTxs {
735 s.pendingBlock.processedTxs[t.Tx.Hash()] = t
736 }

Callers 1

ReceiveMethod · 0.80

Calls 6

setHeightMethod · 0.95
assignTxToWorkerMethod · 0.95
reVerifyStatefulMethod · 0.95
GetUnverifiedTxsMethod · 0.80
HashMethod · 0.65

Tested by

no test coverage detected