github.com/klaytn/klaytn@v1.12.1/datasync/downloader/types.go (about)

     1  // Modifications Copyright 2018 The klaytn Authors
     2  // Copyright 2015 The go-ethereum Authors
     3  // This file is part of the go-ethereum library.
     4  //
     5  // The go-ethereum library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The go-ethereum library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from eth/downloader/types.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package downloader
    22  
    23  import (
    24  	"fmt"
    25  
    26  	"github.com/klaytn/klaytn/blockchain/types"
    27  	"github.com/klaytn/klaytn/reward"
    28  )
    29  
    30  // peerDropFn is a callback type for dropping a peer detected as malicious.
    31  type peerDropFn func(id string)
    32  
    33  // dataPack is a data message returned by a peer for some query.
    34  type dataPack interface {
    35  	PeerId() string
    36  	Items() int
    37  	Stats() string
    38  }
    39  
    40  // headerPack is a batch of block headers returned by a peer.
    41  type headerPack struct {
    42  	peerId  string
    43  	headers []*types.Header
    44  }
    45  
    46  func (p *headerPack) PeerId() string { return p.peerId }
    47  func (p *headerPack) Items() int     { return len(p.headers) }
    48  func (p *headerPack) Stats() string  { return fmt.Sprintf("%d", len(p.headers)) }
    49  
    50  // bodyPack is a batch of block bodies returned by a peer.
    51  type bodyPack struct {
    52  	peerId       string
    53  	transactions [][]*types.Transaction
    54  }
    55  
    56  func (p *bodyPack) PeerId() string { return p.peerId }
    57  func (p *bodyPack) Items() int {
    58  	return len(p.transactions)
    59  }
    60  func (p *bodyPack) Stats() string { return fmt.Sprintf("%d", len(p.transactions)) }
    61  
    62  // receiptPack is a batch of receipts returned by a peer.
    63  type receiptPack struct {
    64  	peerId   string
    65  	receipts [][]*types.Receipt
    66  }
    67  
    68  func (p *receiptPack) PeerId() string { return p.peerId }
    69  func (p *receiptPack) Items() int     { return len(p.receipts) }
    70  func (p *receiptPack) Stats() string  { return fmt.Sprintf("%d", len(p.receipts)) }
    71  
    72  // statePack is a batch of states returned by a peer.
    73  type statePack struct {
    74  	peerId string
    75  	states [][]byte
    76  }
    77  
    78  func (p *statePack) PeerId() string { return p.peerId }
    79  func (p *statePack) Items() int     { return len(p.states) }
    80  func (p *statePack) Stats() string  { return fmt.Sprintf("%d", len(p.states)) }
    81  
    82  type stakingInfoPack struct {
    83  	peerId       string
    84  	stakingInfos []*reward.StakingInfo
    85  }
    86  
    87  func (p *stakingInfoPack) PeerId() string { return p.peerId }
    88  func (p *stakingInfoPack) Items() int     { return len(p.stakingInfos) }
    89  func (p *stakingInfoPack) Stats() string  { return fmt.Sprintf("%d", len(p.stakingInfos)) }