github.com/klaytn/klaytn@v1.12.1/node/sc/protocol.go (about)

     1  // Modifications Copyright 2019 The klaytn Authors
     2  // Copyright 2014 The go-ethereum Authors
     3  // This file is part of go-ethereum.
     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/protocol.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package sc
    22  
    23  import (
    24  	"math/big"
    25  
    26  	"github.com/klaytn/klaytn/common"
    27  )
    28  
    29  const ProtocolMaxMsgSize = 12 * 1024 * 1024 // Maximum cap on the size of a protocol message
    30  
    31  const (
    32  	// Protocol messages belonging to servicechain/1
    33  	StatusMsg = 0x00
    34  
    35  	// Below message can be deprecated.
    36  	ServiceChainTxsMsg                     = 0x01
    37  	ServiceChainReceiptResponseMsg         = 0x02
    38  	ServiceChainReceiptRequestMsg          = 0x03
    39  	ServiceChainParentChainInfoResponseMsg = 0x04
    40  	ServiceChainParentChainInfoRequestMsg  = 0x05
    41  
    42  	ServiceChainCall     = 0x06
    43  	ServiceChainResponse = 0x07
    44  	ServiceChainNotify   = 0x08
    45  
    46  	ServiceChainInvalidTxResponseMsg = 0x09
    47  )
    48  
    49  var (
    50  	SCProtocolName    = "servicechain"
    51  	SCProtocolVersion = []uint{2}
    52  	SCProtocolLength  = []uint64{10}
    53  )
    54  
    55  // Protocol defines the protocol of the consensus
    56  type SCProtocol struct {
    57  	// Official short name of the protocol used during capability negotiation.
    58  	Name string
    59  	// Supported versions of the Klaytn protocol (first is primary).
    60  	Versions []uint
    61  	// Number of implemented message corresponding to different protocol versions.
    62  	Lengths []uint64
    63  }
    64  
    65  type errCode int
    66  
    67  const (
    68  	ErrMsgTooLarge = iota
    69  	ErrDecode
    70  	ErrInvalidMsgCode
    71  	ErrProtocolVersionMismatch
    72  	ErrNetworkIdMismatch
    73  	ErrNoStatusMsg
    74  	ErrUnexpectedTxType
    75  )
    76  
    77  func (e errCode) String() string {
    78  	return errorToString[int(e)]
    79  }
    80  
    81  // XXX change once legacy code is out
    82  var errorToString = map[int]string{
    83  	ErrMsgTooLarge:             "Message too long",
    84  	ErrDecode:                  "Invalid message",
    85  	ErrInvalidMsgCode:          "Invalid message code",
    86  	ErrProtocolVersionMismatch: "Protocol version mismatch",
    87  	ErrNetworkIdMismatch:       "NetworkId mismatch",
    88  	ErrNoStatusMsg:             "No status message",
    89  	ErrUnexpectedTxType:        "Unexpected tx type",
    90  }
    91  
    92  // statusData is the network packet for the status message.
    93  type statusData struct {
    94  	ProtocolVersion uint32
    95  	NetworkId       uint64
    96  	TD              *big.Int
    97  	CurrentBlock    common.Hash
    98  	ChainID         *big.Int // A child chain must know parent chain's ChainID to sign a transaction.
    99  }