github.com/okex/exchain@v1.8.0/libs/tendermint/consensus/block_transport.go (about)

     1  package consensus
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/okex/exchain/libs/system/trace"
     6  	"github.com/okex/exchain/libs/tendermint/libs/log"
     7  	"sync"
     8  	"time"
     9  )
    10  
    11  type BlockTransport struct {
    12  	height int64
    13  	recvProposal time.Time
    14  	firstPart time.Time
    15  	droppedDue2NotExpected int
    16  	droppedDue2NotAdded int
    17  	droppedDue2Error int
    18  	droppedDue2WrongHeight int
    19  	totalParts int
    20  	Logger  log.Logger
    21  
    22  	bpStatMtx sync.RWMutex
    23  	bpSend          int
    24  	bpNOTransByData int
    25  	bpNOTransByACK  int
    26  }
    27  
    28  func (bt *BlockTransport) onProposal(height int64)  {
    29  	if bt.height == height || bt.height == 0 {
    30  		bt.recvProposal = time.Now()
    31  		bt.height = height
    32  	}
    33  }
    34  
    35  func (bt *BlockTransport) reset(height int64) {
    36  	bt.height = height
    37  	bt.droppedDue2NotExpected = 0
    38  	bt.droppedDue2NotAdded = 0
    39  	bt.droppedDue2Error = 0
    40  	bt.droppedDue2WrongHeight = 0
    41  	bt.totalParts = 0
    42  	bt.bpNOTransByData = 0
    43  	bt.bpNOTransByACK = 0
    44  	bt.bpSend = 0
    45  }
    46  
    47  func (bt *BlockTransport) on1stPart(height int64)  {
    48  	if bt.height == height || bt.height == 0 {
    49  		bt.firstPart = time.Now()
    50  		bt.height = height
    51  	}
    52  }
    53  
    54  func (bt *BlockTransport) onRecvBlock(height int64)  {
    55  	if bt.height == height {
    56  		//totalElapsed := time.Now().Sub(bt.recvProposal)
    57  		//trace.GetElapsedInfo().AddInfo(trace.RecvBlock, fmt.Sprintf("<%dms>", totalElapsed.Milliseconds()))
    58  		first2LastPartElapsed := time.Now().Sub(bt.firstPart)
    59  		trace.GetElapsedInfo().AddInfo(trace.First2LastPart, fmt.Sprintf("%dms", first2LastPartElapsed.Milliseconds()))
    60  	}
    61  }
    62  
    63  // blockpart send times
    64  func (bt *BlockTransport) onBPSend() {
    65  	bt.bpStatMtx.Lock()
    66  	bt.bpSend++
    67  	bt.bpStatMtx.Unlock()
    68  }
    69  
    70  // blockpart-ack receive times, specific blockpart won't send  to the peer from where the ack fired
    71  func (bt *BlockTransport) onBPACKHit() {
    72  	bt.bpStatMtx.Lock()
    73  	bt.bpNOTransByACK++
    74  	bt.bpStatMtx.Unlock()
    75  }
    76  
    77  // blockpart data receive times, specific blockpart won't send to the peer from where the data fired
    78  func (bt *BlockTransport) onBPDataHit() {
    79  	bt.bpStatMtx.Lock()
    80  	bt.bpNOTransByData++
    81  	bt.bpStatMtx.Unlock()
    82  }