github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/p2pserver/common/message.go (about)

     1  package common
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	comm "github.com/sixexorg/magnetic-ring/common"
     8  	"github.com/sixexorg/magnetic-ring/common/sink"
     9  	ct "github.com/sixexorg/magnetic-ring/core/mainchain/types"
    10  	orgtypes "github.com/sixexorg/magnetic-ring/core/orgchain/types"
    11  	"github.com/sixexorg/magnetic-ring/p2pserver/discover"
    12  	"github.com/sixexorg/magnetic-ring/store/mainchain/extstates"
    13  )
    14  
    15  // "version" 握手用
    16  type VersionPayload struct {
    17  	Version      uint32
    18  	Services     uint64
    19  	TimeStamp    uint64
    20  	SyncPort     uint16
    21  	HttpInfoPort uint16
    22  	ConsPort     uint16
    23  	Cap          [32]byte
    24  	Nonce        uint64
    25  	StartHeight  uint64
    26  	Relay        uint8
    27  	IsConsensus  bool
    28  }
    29  type Version struct {
    30  	P VersionPayload
    31  	N discover.Node
    32  }
    33  
    34  //Serialize message payload
    35  func (this *Version) Serialization(sink *sink.ZeroCopySink) error {
    36  	return nil
    37  }
    38  func (this *Version) CmdType() string {
    39  	return VERSION_TYPE
    40  }
    41  
    42  //Deserialize message payload
    43  func (this *Version) Deserialization(source *sink.ZeroCopySource) error {
    44  	return nil
    45  }
    46  
    47  // "verack"
    48  type VerACK struct {
    49  	IsConsensus bool
    50  }
    51  
    52  //Serialize message payload
    53  func (this *VerACK) Serialization(sink *sink.ZeroCopySink) error {
    54  	return nil
    55  }
    56  
    57  func (this *VerACK) CmdType() string {
    58  	return VERACK_TYPE
    59  }
    60  
    61  //Deserialize message payload
    62  func (this *VerACK) Deserialization(source *sink.ZeroCopySource) error {
    63  	return nil
    64  }
    65  
    66  // "getaddr"
    67  type AddrReq struct{}
    68  
    69  //Serialize message payload
    70  func (this AddrReq) Serialization(sink *sink.ZeroCopySink) error {
    71  	return nil
    72  }
    73  
    74  func (this *AddrReq) CmdType() string {
    75  	return GetADDR_TYPE
    76  }
    77  
    78  //Deserialize message payload
    79  func (this *AddrReq) Deserialization(source *sink.ZeroCopySource) error {
    80  	return nil
    81  }
    82  
    83  // "addr"
    84  type Addr struct {
    85  	NodeAddrs []PeerAddr
    86  }
    87  
    88  //Serialize message payload
    89  func (this Addr) Serialization(sink *sink.ZeroCopySink) error {
    90  	return nil
    91  }
    92  
    93  func (this *Addr) CmdType() string {
    94  	return ADDR_TYPE
    95  }
    96  
    97  func (this *Addr) Deserialization(source *sink.ZeroCopySource) error {
    98  
    99  	return nil
   100  }
   101  
   102  // "ping"
   103  
   104  type OrgPIPOInfo struct {
   105  	OrgID  comm.Address
   106  	Height uint64
   107  }
   108  
   109  type Ping struct {
   110  	Height   uint64
   111  	InfoType string
   112  	OrgInfo  []OrgPIPOInfo
   113  }
   114  
   115  //Serialize message payload
   116  func (this Ping) Serialization(sink *sink.ZeroCopySink) error {
   117  	return nil
   118  }
   119  
   120  func (this *Ping) CmdType() string {
   121  	return PING_TYPE
   122  }
   123  
   124  //Deserialize message payload
   125  func (this *Ping) Deserialization(source *sink.ZeroCopySource) error {
   126  	return nil
   127  }
   128  
   129  // "pong"
   130  type Pong struct {
   131  	Height   uint64
   132  	InfoType string
   133  	OrgInfo  []OrgPIPOInfo
   134  }
   135  
   136  //Serialize message payload
   137  func (this Pong) Serialization(sink *sink.ZeroCopySink) error {
   138  	return nil
   139  }
   140  
   141  func (this Pong) CmdType() string {
   142  	return PONG_TYPE
   143  }
   144  
   145  //Deserialize message payload
   146  func (this *Pong) Deserialization(source *sink.ZeroCopySource) error {
   147  	return nil
   148  }
   149  
   150  // "getheaders"
   151  type HeadersReq struct {
   152  	Len       uint8     //no use
   153  	HashStart comm.Hash //no use
   154  	HashEnd   comm.Hash //no use
   155  	Height    uint64    //
   156  	OrgID     comm.Address
   157  	SyncType  string
   158  }
   159  
   160  //Serialize message payload
   161  func (this *HeadersReq) Serialization(sink *sink.ZeroCopySink) error {
   162  	return nil
   163  }
   164  
   165  func (this *HeadersReq) CmdType() string {
   166  	return GET_HEADERS_TYPE
   167  }
   168  
   169  //Deserialize message payload
   170  func (this *HeadersReq) Deserialization(source *sink.ZeroCopySource) error {
   171  	return nil
   172  }
   173  
   174  // "headers"
   175  type BlkHeader struct {
   176  	BlkHdr    []*ct.Header
   177  	BlkOrgHdr []*orgtypes.Header
   178  	OrgID     comm.Address
   179  	SyncType  string
   180  }
   181  
   182  //
   183  type BlkP2PHeader struct {
   184  	BlkHdr    []*ct.Header
   185  	BlkOrgHdr []*orgtypes.Header
   186  	OrgID     comm.Address
   187  	SyncType  string
   188  }
   189  
   190  func BlkP2PHeaderToBlkHeader(bh *BlkP2PHeader) (*BlkHeader, error) {
   191  	headers := bh.BlkHdr
   192  	hds := make([]*ct.Header, len(headers))
   193  	headerorgs := bh.BlkOrgHdr
   194  	hdorgs := make([]*orgtypes.Header, len(headerorgs))
   195  
   196  	if bh.SyncType == SYNC_DATA_MAIN {
   197  		for index, head := range headers {
   198  			hds[index] = head
   199  		}
   200  	} else if bh.SyncType == SYNC_DATA_ORG {
   201  		for index, head := range headerorgs {
   202  			hdorgs[index] = head
   203  		}
   204  	}
   205  	return &BlkHeader{
   206  		BlkHdr:    hds,
   207  		BlkOrgHdr: hdorgs,
   208  		OrgID:     bh.OrgID,
   209  		SyncType:  bh.SyncType,
   210  	}, nil
   211  }
   212  
   213  //Serialize message payload
   214  func (this BlkHeader) Serialization(sink *sink.ZeroCopySink) error {
   215  	return nil
   216  }
   217  
   218  func (this *BlkHeader) CmdType() string {
   219  	return HEADERS_TYPE
   220  }
   221  
   222  //Deserialize message payload
   223  func (this *BlkHeader) Deserialization(source *sink.ZeroCopySource) error {
   224  	return nil
   225  }
   226  
   227  func (this BlkP2PHeader) Serialization(sink *sink.ZeroCopySink) error {
   228  	return nil
   229  }
   230  
   231  func (this *BlkP2PHeader) CmdType() string {
   232  	return HEADERS_TYPE
   233  }
   234  
   235  //Deserialize message payload
   236  func (this *BlkP2PHeader) Deserialization(source *sink.ZeroCopySource) error {
   237  	return nil
   238  }
   239  
   240  // "inv"
   241  var LastInvHash comm.Hash
   242  
   243  type InvPayload struct {
   244  	InvType comm.InventoryType
   245  	Blk     []comm.Hash
   246  	Heis    []uint64
   247  }
   248  
   249  type Inv struct {
   250  	P InvPayload
   251  }
   252  
   253  func (this Inv) invType() comm.InventoryType {
   254  	return this.P.InvType
   255  }
   256  
   257  func (this *Inv) CmdType() string {
   258  	return INV_TYPE
   259  }
   260  
   261  //Serialize message payload
   262  func (this Inv) Serialization(sink *sink.ZeroCopySink) error {
   263  
   264  	return nil
   265  }
   266  
   267  //Deserialize message payload
   268  func (this *Inv) Deserialization(source *sink.ZeroCopySource) error {
   269  	return nil
   270  }
   271  
   272  // getdata
   273  type DataReq struct {
   274  	DataType comm.InventoryType
   275  	Hash     comm.Hash
   276  	OrgID    comm.Address
   277  	SyncType string
   278  }
   279  
   280  //Serialize message payload
   281  func (this DataReq) Serialization(sink *sink.ZeroCopySink) error {
   282  	return nil
   283  }
   284  
   285  func (this *DataReq) CmdType() string {
   286  	return GET_DATA_TYPE
   287  }
   288  
   289  //Deserialize message payload
   290  func (this *DataReq) Deserialization(source *sink.ZeroCopySource) error {
   291  	return nil
   292  }
   293  
   294  // block
   295  type P2PTransaction struct {
   296  	Raw []byte // raw transaction data
   297  }
   298  
   299  type P2PBlock struct {
   300  	Header       *ct.Header //*P2PHeader
   301  	Transactions []*P2PTransaction
   302  	Sigs         *ct.SigData
   303  }
   304  
   305  type P2POrgBlock struct {
   306  	Header       *orgtypes.Header //*P2POrgHeader
   307  	Transactions []*P2PTransaction
   308  }
   309  
   310  type Block struct {
   311  	Blk      *ct.Block
   312  	BlkOrg   *orgtypes.Block
   313  	OrgID    comm.Address
   314  	SyncType string
   315  }
   316  
   317  func TransToP2Ptrans(trans []*ct.Transaction) []*P2PTransaction {
   318  	txs := make([]*P2PTransaction, len(trans))
   319  	for index, tran := range trans {
   320  		txs[index] = new(P2PTransaction)
   321  		txs[index].Raw = tran.Raw
   322  	}
   323  	return txs
   324  }
   325  
   326  func OrgTransToP2Ptrans(trans []*orgtypes.Transaction) []*P2PTransaction {
   327  	txs := make([]*P2PTransaction, len(trans))
   328  	for index, tran := range trans {
   329  		txs[index] = new(P2PTransaction)
   330  		txs[index].Raw = tran.Raw
   331  	}
   332  	return txs
   333  }
   334  
   335  func P2PtransToTrans(trans []*P2PTransaction) []*ct.Transaction {
   336  	txs := make([]*ct.Transaction, len(trans))
   337  	for index, tran := range trans {
   338  
   339  		// txs[index],_ = ct.TransactionFromRawBytes(tran.Raw)
   340  		source := sink.NewZeroCopySource(tran.Raw)
   341  		tx := &ct.Transaction{}
   342  		tx.Deserialization(source)
   343  		txs[index] = tx
   344  	}
   345  	return txs
   346  }
   347  
   348  func P2PtransToOrgTrans(trans []*P2PTransaction) []*orgtypes.Transaction {
   349  	txs := make([]*orgtypes.Transaction, len(trans))
   350  	for index, tran := range trans {
   351  		source := sink.NewZeroCopySource(tran.Raw)
   352  		tx := &orgtypes.Transaction{}
   353  		tx.Deserialization(source)
   354  		txs[index] = tx
   355  	}
   356  	return txs
   357  }
   358  
   359  type TrsBlock struct {
   360  	Blk      *P2PBlock
   361  	BlkOrg   *P2POrgBlock
   362  	OrgID    comm.Address
   363  	SyncType string
   364  }
   365  
   366  func BlockToTrsBlock(tb *Block) *TrsBlock {
   367  	blk := new(P2PBlock)
   368  	blkorg := new(P2POrgBlock)
   369  
   370  	if tb.SyncType == SYNC_DATA_MAIN {
   371  		block := tb.Blk
   372  		blk.Header = block.Header
   373  		blk.Transactions = TransToP2Ptrans(block.Transactions)
   374  		blk.Sigs = tb.Blk.Sigs
   375  		// init org
   376  		blkorg.Header = &orgtypes.Header{} //&P2POrgHeader{}
   377  
   378  	} else if tb.SyncType == SYNC_DATA_ORG || tb.SyncType == SYNC_DATA_A_TO_STELLAR || tb.SyncType == SYNC_DATA_STELLAR_TO_STELLAR {
   379  		block := tb.BlkOrg
   380  		blkorg.Header = block.Header
   381  		blkorg.Transactions = OrgTransToP2Ptrans(block.Transactions)
   382  		// init main
   383  		blk.Header = &ct.Header{} //&P2PHeader{}
   384  		blk.Sigs = &ct.SigData{}
   385  		fmt.Println("🌐 blockToTrsBlock type ", tb.SyncType)
   386  	}
   387  	return &TrsBlock{
   388  		Blk:      blk,
   389  		BlkOrg:   blkorg,
   390  		OrgID:    tb.OrgID,
   391  		SyncType: tb.SyncType,
   392  	}
   393  }
   394  
   395  func TrsBlockToBlock(tb *TrsBlock) (*Block, error) {
   396  	blk := new(ct.Block)
   397  	blkorg := new(orgtypes.Block)
   398  	var err error
   399  	if tb.SyncType == SYNC_DATA_MAIN {
   400  		block := tb.Blk
   401  		blk.Header = block.Header
   402  		blk.Sigs = tb.Blk.Sigs
   403  		if err != nil {
   404  			return nil, err
   405  		}
   406  		blk.Transactions = P2PtransToTrans(block.Transactions)
   407  	} else if tb.SyncType == SYNC_DATA_ORG || tb.SyncType == SYNC_DATA_A_TO_STELLAR || tb.SyncType == SYNC_DATA_STELLAR_TO_STELLAR {
   408  		block := tb.BlkOrg
   409  		blkorg.Header = block.Header
   410  		blkorg.Transactions = P2PtransToOrgTrans(block.Transactions)
   411  	}
   412  	return &Block{
   413  		Blk:      blk,
   414  		BlkOrg:   blkorg,
   415  		OrgID:    tb.OrgID,
   416  		SyncType: tb.SyncType,
   417  	}, nil
   418  }
   419  
   420  func (this *TrsBlock) Serialization(sink *sink.ZeroCopySink) error {
   421  	return nil
   422  }
   423  
   424  func (this *TrsBlock) CmdType() string {
   425  	return BLOCK_TYPE
   426  }
   427  
   428  //Deserialize message payload
   429  func (this *TrsBlock) Deserialization(source *sink.ZeroCopySource) error {
   430  	return nil
   431  }
   432  
   433  //Serialize message payload
   434  func (this *Block) Serialization(sink *sink.ZeroCopySink) error {
   435  	return nil
   436  }
   437  
   438  func (this *Block) CmdType() string {
   439  	return BLOCK_TYPE
   440  }
   441  
   442  //Deserialize message payload
   443  func (this *Block) Deserialization(source *sink.ZeroCopySource) error {
   444  	return nil
   445  }
   446  
   447  //consensus
   448  
   449  // notfoud
   450  type NotFound struct {
   451  	Hash comm.Hash
   452  }
   453  
   454  //Serialize message payload
   455  func (this NotFound) Serialization(sink *sink.ZeroCopySink) error {
   456  	return nil
   457  }
   458  
   459  func (this NotFound) CmdType() string {
   460  	return NOT_FOUND_TYPE
   461  }
   462  
   463  //Deserialize message payload
   464  func (this *NotFound) Deserialization(source *sink.ZeroCopySource) error {
   465  	return nil
   466  }
   467  
   468  // tx
   469  // Transaction message
   470  type Trn struct {
   471  	Txn      *ct.Transaction
   472  	OrgTxn   *orgtypes.Transaction
   473  	OrgID    comm.Address
   474  	SyncType string
   475  }
   476  
   477  type P2PTrn struct {
   478  	Txn      *P2PTransaction
   479  	OrgTxn   *P2PTransaction
   480  	OrgID    comm.Address
   481  	SyncType string
   482  }
   483  
   484  func TrnToP2PTrn(trn *Trn) *P2PTrn {
   485  	res := new(P2PTransaction)
   486  	orgres := new(P2PTransaction)
   487  
   488  	if trn.SyncType == SYNC_DATA_MAIN {
   489  		res.Raw = trn.Txn.Raw
   490  	} else if trn.SyncType == SYNC_DATA_ORG {
   491  		orgres.Raw = trn.OrgTxn.Raw
   492  	}
   493  
   494  	res.Raw = trn.Txn.Raw
   495  	return &P2PTrn{
   496  		Txn:      res,
   497  		OrgTxn:   orgres,
   498  		OrgID:    trn.OrgID,
   499  		SyncType: trn.SyncType,
   500  	}
   501  }
   502  
   503  func P2PTrnToTrn(trn *P2PTrn) (*Trn, error) {
   504  	var err error
   505  	res := new(ct.Transaction)
   506  	orgres := new(orgtypes.Transaction)
   507  
   508  	if trn.SyncType == SYNC_DATA_MAIN {
   509  		source := sink.NewZeroCopySource(trn.Txn.Raw)
   510  		err = res.Deserialization(source)
   511  		// res,err = ct.TransactionFromRawBytes(trn.Txn.Raw)
   512  	} else if trn.SyncType == SYNC_DATA_ORG {
   513  		source := sink.NewZeroCopySource(trn.OrgTxn.Raw)
   514  		err = orgres.Deserialization(source)
   515  	}
   516  
   517  	return &Trn{
   518  		Txn:      res,
   519  		OrgTxn:   orgres,
   520  		OrgID:    trn.OrgID,
   521  		SyncType: trn.SyncType,
   522  	}, err
   523  }
   524  
   525  //Serialize message payload
   526  func (this Trn) Serialization(sink *sink.ZeroCopySink) error {
   527  	return nil
   528  }
   529  
   530  func (this *Trn) CmdType() string {
   531  	return TX_TYPE
   532  }
   533  
   534  //Deserialize message payload
   535  func (this *Trn) Deserialization(source *sink.ZeroCopySource) error {
   536  	return nil
   537  }
   538  
   539  //Serialize message payload
   540  func (this P2PTrn) Serialization(sink *sink.ZeroCopySink) error {
   541  	return nil
   542  }
   543  
   544  func (this *P2PTrn) CmdType() string {
   545  	return TX_TYPE
   546  }
   547  
   548  //Deserialize message payload
   549  func (this *P2PTrn) Deserialization(source *sink.ZeroCopySource) error {
   550  	return nil
   551  }
   552  
   553  // disconnect
   554  type Disconnected struct{}
   555  
   556  //Serialize message payload
   557  func (this Disconnected) Serialization(sink *sink.ZeroCopySink) error {
   558  	return nil
   559  }
   560  
   561  func (this Disconnected) CmdType() string {
   562  	return DISCONNECT_TYPE
   563  }
   564  
   565  //Deserialize message payload
   566  func (this *Disconnected) Deserialization(source *sink.ZeroCopySource) error {
   567  	return nil
   568  }
   569  
   570  ///////
   571  type PingSpc struct {
   572  	BNodeASrc bool // true:Source from node A false:Source from stellar
   573  }
   574  
   575  //Serialize message payload
   576  func (this PingSpc) Serialization(sink *sink.ZeroCopySink) error {
   577  	return nil
   578  }
   579  
   580  func (this *PingSpc) CmdType() string {
   581  	return PINGSPC_TYPE
   582  }
   583  
   584  //Deserialize message payload
   585  func (this *PingSpc) Deserialization(source *sink.ZeroCopySource) error {
   586  	return nil
   587  }
   588  
   589  // "pong"
   590  type PongSpc struct {
   591  	BNodeASrc bool // true:Source from node A false:Source from stellar
   592  	// true:Is the node requested by the other party // fale:Otherwise, the opposite
   593  	BOtherSideReq bool
   594  }
   595  
   596  //Serialize message payload
   597  func (this PongSpc) Serialization(sink *sink.ZeroCopySink) error {
   598  	return nil
   599  }
   600  
   601  func (this PongSpc) CmdType() string {
   602  	return PONGSPC_TYPE
   603  }
   604  
   605  //Deserialize message payload
   606  func (this *PongSpc) Deserialization(source *sink.ZeroCopySource) error {
   607  	return nil
   608  }
   609  
   610  type EarthNotifyMsg struct {
   611  	Height uint64
   612  	Hash   comm.Hash
   613  }
   614  
   615  //Serialize message payload
   616  func (this EarthNotifyMsg) Serialization(sink *sink.ZeroCopySink) error {
   617  	return nil
   618  }
   619  
   620  func (this EarthNotifyMsg) CmdType() string {
   621  	return EARTHNOTIFYHASH
   622  }
   623  
   624  //Deserialize message payload
   625  func (this *EarthNotifyMsg) Deserialization(source *sink.ZeroCopySource) error {
   626  	return nil
   627  }
   628  
   629  //////
   630  
   631  // message
   632  //MsgPayload in link channel
   633  type MsgPayload struct {
   634  	Id          uint64  //peer ID
   635  	Addr        string  //link address
   636  	PayloadSize uint32  //payload size
   637  	Payload     Message //msg payload
   638  }
   639  
   640  type Message interface {
   641  	Serialization(sink *sink.ZeroCopySink) error
   642  	Deserialization(source *sink.ZeroCopySource) error
   643  	CmdType() string
   644  }
   645  
   646  func MakeEmptyMessage(cmdType string) (Message, error) {
   647  	switch cmdType {
   648  	case PING_TYPE:
   649  		return &Ping{}, nil
   650  	case VERSION_TYPE:
   651  		return &Version{}, nil
   652  	case VERACK_TYPE:
   653  		return &VerACK{}, nil
   654  	case ADDR_TYPE:
   655  		return &Addr{}, nil
   656  	case GetADDR_TYPE:
   657  		return &AddrReq{}, nil
   658  	case PONG_TYPE:
   659  		return &Pong{}, nil
   660  	case GET_HEADERS_TYPE:
   661  		return &HeadersReq{}, nil
   662  	case HEADERS_TYPE:
   663  		// return &BlkHeader{}, nil
   664  		return &BlkP2PHeader{}, nil
   665  	case INV_TYPE:
   666  		return &Inv{}, nil
   667  	case GET_DATA_TYPE:
   668  		return &DataReq{}, nil
   669  	case BLOCK_TYPE:
   670  		// return &Block{}, nil
   671  		return &TrsBlock{}, nil
   672  	case TX_TYPE:
   673  		// return &Trn{}, nil
   674  		return &P2PTrn{}, nil
   675  	case CONSENSUS_TYPE:
   676  		// return &Consensus{}, nil
   677  		return &P2PConsPld{}, nil
   678  	case NOT_FOUND_TYPE:
   679  		return &NotFound{}, nil
   680  	case DISCONNECT_TYPE:
   681  		return &Disconnected{}, nil
   682  	case GET_BLOCKS_TYPE:
   683  		return &BlocksReq{}, nil
   684  	case PINGSPC_TYPE:
   685  		return &PingSpc{}, nil
   686  	case PONGSPC_TYPE:
   687  		return &PongSpc{}, nil
   688  	case EARTHNOTIFYHASH:
   689  		return &EarthNotifyMsg{}, nil
   690  	case NODE_LEAGUE_HEIGHT:
   691  		return &NodeLHMsg{}, nil
   692  	case EXTDATA_RSP_TYPE:
   693  		return &ExtDataResponse{}, nil
   694  	case EXTDATA_REQ_TYPE:
   695  		return &ExtDataRequest{}, nil
   696  	default:
   697  		return nil, errors.New("unsupported cmd type:" + cmdType)
   698  	}
   699  
   700  }
   701  
   702  // getblocks
   703  type BlocksReq struct {
   704  	HeaderHashCount uint8
   705  	HashStart       comm.Hash
   706  	HashStop        comm.Hash
   707  }
   708  
   709  //Serialize message payload
   710  func (this *BlocksReq) Serialization(sink *sink.ZeroCopySink) error {
   711  	return nil
   712  }
   713  
   714  func (this *BlocksReq) CmdType() string {
   715  	return GET_BLOCKS_TYPE
   716  }
   717  
   718  //Deserialize message payload
   719  func (this *BlocksReq) Deserialization(source *sink.ZeroCopySource) error {
   720  	return nil
   721  }
   722  
   723  //=========================================================
   724  type RdrBlock struct {
   725  	Blk      *P2PBlock
   726  	BlkOrg   *P2POrgBlock
   727  	OrgID    comm.Address
   728  	SyncType string
   729  }
   730  
   731  func BlockToRdrBlock(tb *Block) *RdrBlock {
   732  	blk := new(P2PBlock)
   733  	blkorg := new(P2POrgBlock)
   734  
   735  	if tb.SyncType == SYNC_DATA_MAIN {
   736  		block := tb.Blk
   737  		blk.Header = block.Header
   738  		blk.Transactions = TransToP2Ptrans(block.Transactions)
   739  		blk.Sigs = tb.Blk.Sigs
   740  		// init org
   741  		blkorg.Header = &orgtypes.Header{} //&P2POrgHeader{}
   742  	} else if tb.SyncType == SYNC_DATA_ORG {
   743  		block := tb.BlkOrg
   744  		blkorg.Header = block.Header
   745  		blkorg.Transactions = OrgTransToP2Ptrans(block.Transactions)
   746  		// init main
   747  		blk.Header = &ct.Header{} //&P2PHeader{}
   748  		blk.Sigs = &ct.SigData{}
   749  	}
   750  	return &RdrBlock{
   751  		Blk:      blk,
   752  		BlkOrg:   blkorg,
   753  		OrgID:    tb.OrgID,
   754  		SyncType: tb.SyncType,
   755  	}
   756  }
   757  
   758  func RdrBlockToBlock(tb *RdrBlock) (*Block, error) {
   759  	blk := new(ct.Block)
   760  	blkorg := new(orgtypes.Block)
   761  	if tb.SyncType == SYNC_DATA_MAIN {
   762  		block := tb.Blk
   763  		blk.Header = block.Header
   764  		blk.Sigs = tb.Blk.Sigs
   765  		blk.Transactions = P2PtransToTrans(block.Transactions)
   766  	} else if tb.SyncType == SYNC_DATA_ORG {
   767  		block := tb.BlkOrg
   768  		blkorg.Header = block.Header
   769  		blkorg.Transactions = P2PtransToOrgTrans(block.Transactions)
   770  	}
   771  	return &Block{
   772  		Blk:      blk,
   773  		BlkOrg:   blkorg,
   774  		OrgID:    tb.OrgID,
   775  		SyncType: tb.SyncType,
   776  	}, nil
   777  }
   778  
   779  func (this *RdrBlock) Serialization(sink *sink.ZeroCopySink) error {
   780  	return nil
   781  }
   782  
   783  func (this *RdrBlock) CmdType() string {
   784  	return GET_DATA_TYPE
   785  }
   786  
   787  //Deserialize message payload
   788  func (this *RdrBlock) Deserialization(source *sink.ZeroCopySource) error {
   789  	return nil
   790  }
   791  
   792  type NodeLHMsg struct {
   793  	NodeId   string
   794  	LeagueId comm.Address
   795  	Height   uint64
   796  }
   797  
   798  //Serialize message payload
   799  func (this NodeLHMsg) Serialization(sink *sink.ZeroCopySink) error {
   800  	return nil
   801  }
   802  
   803  func (this NodeLHMsg) CmdType() string {
   804  	return NODE_LEAGUE_HEIGHT
   805  }
   806  
   807  //Deserialize message payload
   808  func (this *NodeLHMsg) Deserialization(source *sink.ZeroCopySource) error {
   809  	return nil
   810  }
   811  
   812  func (nlh *NodeLHMsg) Unique() string {
   813  	return fmt.Sprintf("%s_%s_%d", nlh.LeagueId, nlh.NodeId, nlh.Height)
   814  }
   815  
   816  type ExtDataRequest struct {
   817  	LeagueId comm.Address //if IsReq=true, must have
   818  	Height   uint64       //if IsReq=true, must have
   819  }
   820  
   821  func (this *ExtDataRequest) Serialization(sink *sink.ZeroCopySink) error {
   822  	return nil
   823  }
   824  
   825  func (this *ExtDataRequest) CmdType() string {
   826  	return EXTDATA_REQ_TYPE
   827  }
   828  
   829  //Deserialize message payload
   830  func (this *ExtDataRequest) Deserialization(source *sink.ZeroCopySource) error {
   831  	return nil
   832  }
   833  
   834  type ExtDataResponse struct {
   835  	*extstates.ExtData
   836  }
   837  
   838  func (this *ExtDataResponse) Serialization(sink *sink.ZeroCopySink) error {
   839  	return nil
   840  }
   841  
   842  func (this *ExtDataResponse) CmdType() string {
   843  	return EXTDATA_RSP_TYPE
   844  }
   845  
   846  //Deserialize message payload
   847  func (this *ExtDataResponse) Deserialization(source *sink.ZeroCopySource) error {
   848  	return nil
   849  }