github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/consense/dpoa/comm/tmsg.go (about)

     1  package comm
     2  
     3  import (
     4  	"encoding/json"
     5  	"math/big"
     6  	"github.com/sixexorg/magnetic-ring/common"
     7  	//"github.com/ontio/ontology-crypto/keypair"
     8  	p2pmsg "github.com/sixexorg/magnetic-ring/p2pserver/common"
     9  	"github.com/sixexorg/magnetic-ring/crypto"
    10  )
    11  
    12  type P2pMsgPayload struct {
    13  	FromPeer string
    14  	Payload  *p2pmsg.ConsensusPayload
    15  }
    16  
    17  
    18  type  EarthSigsFetchRspMsg struct {
    19  	BlkNum   uint64
    20  	PubKey   string
    21  	Sigs     []byte
    22  	BlkHash  common.Hash
    23  }
    24  
    25  func (e *EarthSigsFetchRspMsg) Type() MsgType {
    26  	return EarthFetchRspSigs
    27  }
    28  
    29  func (e *EarthSigsFetchRspMsg) Verify(pub crypto.PublicKey) error {
    30  	return nil
    31  }
    32  
    33  func (e *EarthSigsFetchRspMsg) GetBlockNum() uint64 {
    34  	return e.BlkNum
    35  }
    36  
    37  func (e *EarthSigsFetchRspMsg) Serialize() ([]byte, error) {
    38  	return json.Marshal(e)
    39  }
    40  
    41  type VrfData struct {
    42  	BlockNum uint64 `json:"block_num"`
    43  	PrevVrf  []byte `json:"prev_vrf"`
    44  }
    45  
    46  type  TimeoutFetchRspMsg struct {
    47  	BlkNum   uint64
    48  	PubKey   string
    49  	Sigs     []byte
    50  	SigsArr  [][]byte
    51  }
    52  
    53  func (e *TimeoutFetchRspMsg) Type() MsgType {
    54  	return TimeoutFetchRspMessage
    55  }
    56  
    57  func (e *TimeoutFetchRspMsg) Verify(pub crypto.PublicKey) error {
    58  	return nil
    59  }
    60  
    61  func (e *TimeoutFetchRspMsg) GetBlockNum() uint64 {
    62  	return e.BlkNum
    63  }
    64  
    65  func (e *TimeoutFetchRspMsg) Serialize() ([]byte, error) {
    66  	return json.Marshal(e)
    67  }
    68  
    69  type  TimeoutFetchMsg struct {
    70  	BlkNum   uint64
    71  	PubKey   string
    72  	Sigs     []byte
    73  }
    74  
    75  func (e *TimeoutFetchMsg) Type() MsgType {
    76  	return TimeoutFetchMessage
    77  }
    78  
    79  func (e *TimeoutFetchMsg) Verify(pub crypto.PublicKey) error {
    80  	return nil
    81  }
    82  
    83  func (e *TimeoutFetchMsg) GetBlockNum() uint64 {
    84  	return e.BlkNum
    85  }
    86  
    87  func (e *TimeoutFetchMsg) Serialize() ([]byte, error) {
    88  	return json.Marshal(e)
    89  }
    90  
    91  
    92  type ViewData struct {
    93  	BlkNum 		   uint64
    94  	View 		   uint32
    95  }
    96  
    97  type ViewtimeoutMsg struct {
    98  	RawData      *ViewData
    99  	Signature    []byte
   100  	PubKey       string
   101  }
   102  
   103  func (v *ViewtimeoutMsg) Type() MsgType {
   104  	return ViewTimeout
   105  }
   106  
   107  func (v *ViewtimeoutMsg) Verify(pub crypto.PublicKey) error {
   108  	return nil
   109  }
   110  
   111  func (v *ViewtimeoutMsg) GetBlockNum() uint64 {
   112  	return v.RawData.BlkNum
   113  }
   114  
   115  func (v *ViewtimeoutMsg) Serialize() ([]byte, error) {
   116  	return json.Marshal(v)
   117  }
   118  
   119  type EvilMsg struct {
   120  	BlkNum   uint64
   121  	EvilSigs [][]byte
   122  }
   123  
   124  func (e *EvilMsg) Type() MsgType {
   125  	return EvilEvent
   126  }
   127  
   128  func (e *EvilMsg) Verify(pub crypto.PublicKey) error {
   129  	return nil
   130  }
   131  
   132  func (e *EvilMsg) GetBlockNum() uint64 {
   133  	return e.BlkNum
   134  }
   135  
   136  func (e *EvilMsg) Serialize() ([]byte, error) {
   137  	return json.Marshal(e)
   138  }
   139  
   140  type  EventFetchMsg struct {
   141  	BlkNum   uint64
   142  }
   143  
   144  func (e *EventFetchMsg) Type() MsgType {
   145  	return EventFetchMessage
   146  }
   147  
   148  func (e *EventFetchMsg) Verify(pub crypto.PublicKey) error {
   149  	return nil
   150  }
   151  
   152  func (e *EventFetchMsg) GetBlockNum() uint64 {
   153  	return e.BlkNum
   154  }
   155  
   156  func (e *EventFetchMsg) Serialize() ([]byte, error) {
   157  	return json.Marshal(e)
   158  }
   159  
   160  type TimeoutDesc struct {
   161  	BlkNum uint32
   162  	View   uint32
   163  	PubKey string
   164  	Sig    []byte
   165  }
   166  
   167  
   168  type  EventFetchRspMsg struct {
   169  	BlkNum    uint64
   170  	TimeoutEv []interface{}
   171  	EvilEv    []interface{}
   172  }
   173  
   174  func (e *EventFetchRspMsg) Type() MsgType {
   175  	return EventFetchRspMessage
   176  }
   177  
   178  func (e *EventFetchRspMsg) Verify(pub crypto.PublicKey) error {
   179  	return nil
   180  }
   181  
   182  func (e *EventFetchRspMsg) GetBlockNum() uint64 {
   183  	return e.BlkNum
   184  }
   185  
   186  func (e *EventFetchRspMsg) Serialize() ([]byte, error) {
   187  	return json.Marshal(e)
   188  }
   189  
   190  type  EvilFetchMsg struct {
   191  	BlkNum   uint64
   192  }
   193  
   194  func (e *EvilFetchMsg) Type() MsgType {
   195  	return EvilFetchMessage
   196  }
   197  
   198  func (e *EvilFetchMsg) Verify(pub crypto.PublicKey) error {
   199  	return nil
   200  }
   201  
   202  func (e *EvilFetchMsg) GetBlockNum() uint64 {
   203  	return e.BlkNum
   204  }
   205  
   206  func (e *EvilFetchMsg) Serialize() ([]byte, error) {
   207  	return json.Marshal(e)
   208  }
   209  
   210  type  EvilFetchRspMsg struct {
   211  	BlkNum   uint64
   212  	Sigs     [][]byte
   213  }
   214  
   215  func (e *EvilFetchRspMsg) Type() MsgType {
   216  	return EvilFetchRspMessage
   217  }
   218  
   219  func (e *EvilFetchRspMsg) Verify(pub crypto.PublicKey) error {
   220  	return nil
   221  }
   222  
   223  func (e *EvilFetchRspMsg) GetBlockNum() uint64 {
   224  	return e.BlkNum
   225  }
   226  
   227  func (e *EvilFetchRspMsg) Serialize() ([]byte, error) {
   228  	return json.Marshal(e)
   229  }
   230  
   231  
   232  type ConsedoneMsg struct {
   233  	BlockNumber    uint64
   234  	View           uint32
   235  	BlockData      []byte
   236  	PublicKey      string
   237  	SigData        []byte
   238  }
   239  
   240  func (p *ConsedoneMsg)Type() MsgType{
   241  	return ConsenseDone
   242  }
   243  func (p *ConsedoneMsg)Verify(pub crypto.PublicKey) error{
   244  	return nil
   245  }
   246  func (p *ConsedoneMsg)GetBlockNum() uint64{
   247  	return p.BlockNumber
   248  }
   249  
   250  func (p *ConsedoneMsg)Serialize() ([]byte, error){
   251  	return json.Marshal(p)
   252  }
   253  
   254  type P1a struct {
   255  	Ballot       Ballot
   256  	ID           uint32
   257  	BlockNumber  uint64
   258  	View         uint32
   259  	TxHashs      []common.Hash
   260  	TotalGas     *big.Int
   261  }
   262  
   263  type PrepareMsg struct {
   264  	Msg    P1a `json:"msg"`
   265  	Sig   []byte
   266  }
   267  
   268  func (p *PrepareMsg)Type() MsgType{
   269  	return ConsensePrepare
   270  }
   271  func (p *PrepareMsg)Verify(pub crypto.PublicKey) error{
   272  	return nil
   273  }
   274  func (p *PrepareMsg)GetBlockNum() uint64{
   275  	return p.Msg.BlockNumber
   276  }
   277  
   278  func (p *PrepareMsg)Serialize() ([]byte, error){
   279  	return json.Marshal(p)
   280  }
   281  
   282  type P1b struct {
   283  	Ballot Ballot
   284  	ID     uint32               // node id
   285  	Ab	  Ballot
   286  	Av    []byte
   287  	BlockNumber  uint64
   288  	View         uint32
   289  }
   290  
   291  type PromiseMsg struct {
   292  	Msg P1b `json:"msg"`
   293  	Sig []byte
   294  }
   295  
   296  func (p *PromiseMsg)Type() MsgType{
   297  	return ConsensePromise
   298  }
   299  func (p *PromiseMsg)Verify(pub crypto.PublicKey) error{
   300  	return nil
   301  }
   302  func (p *PromiseMsg)GetBlockNum() uint64{
   303  	return p.Msg.BlockNumber
   304  }
   305  
   306  func (p *PromiseMsg)Serialize() ([]byte, error){
   307  	return json.Marshal(p)
   308  }
   309  
   310  type P2a struct {
   311  	ID      uint32
   312  	Ballot  Ballot
   313  	Slot    int
   314  	Av      []byte
   315  
   316  	BlockNumber  uint64
   317  	View         uint32
   318  }
   319  
   320  type ProposerMsg struct {
   321  	Msg P2a `json:"msg"`
   322  	Sig []byte
   323  }
   324  
   325  func (p *ProposerMsg)Type() MsgType{
   326  	return ConsenseProposer
   327  }
   328  func (p *ProposerMsg)Verify(pub crypto.PublicKey) error{
   329  	return nil
   330  }
   331  func (p *ProposerMsg)GetBlockNum() uint64{
   332  	return p.Msg.BlockNumber
   333  }
   334  
   335  func (p *ProposerMsg)Serialize() ([]byte, error){
   336  	return json.Marshal(p)
   337  }
   338  
   339  type P2b struct {
   340  	Ballot Ballot
   341  	ID     uint32 // from node id
   342  	BlockNumber  uint64
   343  	View         uint32
   344  	Signature []byte
   345  }
   346  
   347  type AcceptMsg struct {
   348  	Msg P2b `json:"msg"`
   349  	Sig []byte
   350  }
   351  
   352  func (p *AcceptMsg)Type() MsgType{
   353  	return ConsenseAccept
   354  }
   355  func (p *AcceptMsg)Verify(pub crypto.PublicKey) error{
   356  	return nil
   357  }
   358  func (p *AcceptMsg)GetBlockNum() uint64{
   359  	return p.Msg.BlockNumber
   360  }
   361  
   362  func (p *AcceptMsg)Serialize() ([]byte, error){
   363  	return json.Marshal(p)
   364  }
   365  
   366  
   367  type BlockFetchMsg struct {
   368  	BlockNum uint64 `json:"block_num"`
   369  }
   370  
   371  func (msg *BlockFetchMsg) Type() MsgType {
   372  	return BlockFetchMessage
   373  }
   374  
   375  func (msg *BlockFetchMsg) Verify(pub crypto.PublicKey) error {
   376  	return nil
   377  }
   378  
   379  func (msg *BlockFetchMsg) GetBlockNum() uint64 {
   380  	return 0
   381  }
   382  
   383  func (msg *BlockFetchMsg) Serialize() ([]byte, error) {
   384  	return json.Marshal(msg)
   385  }