github.com/annchain/OG@v0.0.9/consensus/annsensus/archive/message_handler.go (about) 1 // Copyright © 2019 Annchain Authors <EMAIL ADDRESS> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package archive 15 16 // 17 //func (a *AnnSensus) HandleConsensusDkgGenesisPublicKey(request *p2p_message.MessageConsensusDkgGenesisPublicKey, peerId string) { 18 // if a.disable { 19 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 20 // return 21 // } 22 // log := a.dkg.Log() 23 // if request == nil { 24 // log.Warn("got nil MessageConsensusDkgGenesisPublicKey") 25 // return 26 // } 27 // if atomic.LoadUint32(&a.genesisBftIsRunning) == 0 { 28 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("i am not participant in genesis bft") 29 // return 30 // } 31 // log.WithField("dkg data", request).WithField("from peer ", peerId).Debug("got genesis pub key") 32 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 33 // s := ogcrypto.NewSigner(pk.Type) 34 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 35 // if !ok { 36 // log.Warn("verify signature failed") 37 // return 38 // } 39 // a.genesisPkChan <- request 40 //} 41 // 42 ////HandleConsensusDkgDeal 43 //func (a *AnnSensus) HandleConsensusDkgDeal(request *p2p_message.MessageConsensusDkgDeal, peerId string) { 44 // if a.disable { 45 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 46 // return 47 // } 48 // log := a.dkg.Log() 49 // if request == nil { 50 // log.Warn("got nil MessageConsensusDkgDeal") 51 // return 52 // } 53 // log.WithField("dkg data", request).WithField("from peer ", peerId).Debug("got dkg") 54 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 55 // s := ogcrypto.NewSigner(pk.Type) 56 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 57 // if !ok { 58 // log.Warn("verify signature failed") 59 // return 60 // } 61 // a.dkg.HandleDkgDeal(request) 62 // 63 //} 64 // 65 ////HandleConsensusDkgDealResponse 66 //func (a *AnnSensus) HandleConsensusDkgDealResponse(request *p2p_message.MessageConsensusDkgDealResponse, peerId string) { 67 // if a.disable { 68 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 69 // return 70 // } 71 // log := a.dkg.Log() 72 // if request == nil { 73 // log.Warn("got nil MessageConsensusDkgDealResponse") 74 // return 75 // } 76 // log.WithField("dkg response data", request).WithField("from peer ", peerId).Debug("got dkg response") 77 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 78 // s := ogcrypto.NewSigner(pk.Type) 79 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 80 // if !ok { 81 // log.Warn("verify signature failed") 82 // return 83 // } 84 // log.Debug("response ok") 85 // 86 // a.dkg.HandleDkgDealRespone(request) 87 //} 88 // 89 ////HandleConsensusDkgSigSets 90 //func (a *AnnSensus) HandleConsensusDkgSigSets(request *p2p_message.MessageConsensusDkgSigSets, peerId string) { 91 // if a.disable { 92 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 93 // return 94 // } 95 // log := a.dkg.Log() 96 // if request == nil { 97 // log.Warn("got nil MessageConsensusDkgSigSets") 98 // return 99 // } 100 // log.WithField("data", request).WithField("from peer ", peerId).Debug("got dkg bls sigsets") 101 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 102 // s := ogcrypto.NewSigner(pk.Type) 103 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 104 // if !ok { 105 // log.WithField("pkbls ", hex.EncodeToString(request.PkBls)).WithField("pk ", hex.EncodeToString(request.PublicKey)).WithField( 106 // "sig ", hex.EncodeToString(request.Signature)).Warn("verify signature failed") 107 // return 108 // } 109 // log.Debug("response ok") 110 // 111 // a.dkg.HandleSigSet(request) 112 //} 113 // 114 ////HandleConsensusProposal 115 //func (a *AnnSensus) HandleConsensusProposal(request *bft.MessageProposal, peerId string) { 116 // if a.disable { 117 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 118 // return 119 // } 120 // log := a.dkg.Log() 121 // if request == nil || request.Value == nil { 122 // log.Warn("got nil MessageConsensusDkgSigSets") 123 // return 124 // } 125 // if !a.bft.Started() { 126 // log.Debug("bft not started yet") 127 // return 128 // } 129 // switch msg := request.Value.(type) { 130 // case *bft.SequencerProposal: 131 // default: 132 // log.WithField("request ", msg).Warn("unsupported proposal type") 133 // return 134 // } 135 // seq := request.Value.(*bft.SequencerProposal).Sequencer 136 // log.WithField("data", request).WithField("from peer ", peerId).Debug("got bft proposal data") 137 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, seq.PublicKey) 138 // s := ogcrypto.NewSigner(pk.Type) 139 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 140 // if !ok { 141 // log.WithField("pub ", seq.PublicKey[0:5]).WithField("sig ", hex.EncodeToString(request.Signature)).WithField("request ", request).Warn("verify MessageProposal signature failed") 142 // return 143 // } 144 // seq.Proposing = true 145 // 146 // if !a.bft.VerifyProposal(request, pk) { 147 // log.WithField("seq ", request).Warn("verify raw seq fail") 148 // return 149 // } 150 // //cache them and sent to buffer to verify 151 // a.bft.CacheProposal(seq.GetHash(), request) 152 // a.HandleNewTxi(&seq, peerId) 153 // log.Debug("response ok") 154 // //m := BftMessage{ 155 // // Type: p2p_message.MessageTypeProposal, 156 // // Payload: request, 157 // //} 158 // //a.pbft.BFTPartner.GetIncomingMessageChannel() <- m 159 // 160 //} 161 // 162 ////HandleConsensusPreVote 163 //func (a *AnnSensus) HandleConsensusPreVote(request *bft.MessagePreVote, peerId string) { 164 // if a.disable { 165 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 166 // return 167 // } 168 // log := a.dkg.Log() 169 // if request == nil { 170 // log.Warn("got nil MessageConsensusDkgSigSets") 171 // return 172 // } 173 // if !a.bft.Started() { 174 // log.Debug("bft not started yet") 175 // return 176 // } 177 // log.WithField("data", request).WithField("from peer ", peerId).Debug("got bft PreVote data") 178 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 179 // s := ogcrypto.NewSigner(pk.Type) 180 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 181 // if !ok { 182 // log.WithField("request ", request).Warn("verify signature failed") 183 // return 184 // } 185 // if !a.bft.VerifyIsPartNer(pk, int(request.SourceId)) { 186 // log.WithField("pks ", a.bft.BFTPartner.PeersInfo).WithField("sourc id ", request.SourceId).WithField("pk ", pk).WithField("request ", request).Warn("verify partner failed") 187 // return 188 // } 189 // 190 // m := bft.BftMessage{ 191 // Type: p2p_message.MessageTypePreVote, 192 // Payload: request, 193 // } 194 // a.bft.BFTPartner.GetIncomingMessageChannel() <- m 195 // 196 //} 197 // 198 ////HandleConsensusPreCommit 199 //func (a *AnnSensus) HandleConsensusPreCommit(request *bft.MessagePreCommit, peerId string) { 200 // if a.disable { 201 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 202 // return 203 // } 204 // log := a.dkg.Log() 205 // if request == nil { 206 // log.Warn("got nil MessageConsensusDkgSigSets") 207 // return 208 // } 209 // 210 // if !a.bft.Started() { 211 // log.Debug("bft not started yet") 212 // return 213 // } 214 // log.WithField("data", request).WithField("from peer ", peerId).Debug("got bft PreCommit data") 215 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, request.PublicKey) 216 // s := ogcrypto.NewSigner(pk.Type) 217 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, request.Signature), request.SignatureTargets()) 218 // if !ok { 219 // log.WithField("request ", request).Warn("verify signature failed") 220 // return 221 // } 222 // 223 // if !a.bft.VerifyIsPartNer(pk, int(request.SourceId)) { 224 // log.WithField("request ", request).Warn("verify signature failed") 225 // return 226 // } 227 // a.bft.HandlePreCommit(request) 228 // 229 //} 230 // 231 //func (a *AnnSensus) HandleTermChangeRequest(request *p2p_message.MessageTermChangeRequest, peerId string) { 232 // if a.disable { 233 // log.WithField("from ", peerId).WithField("reqest ", request).Warn("annsensus disabled") 234 // return 235 // } 236 // log := log.WithField("me", a.dkg.GetId()) 237 // if request == nil { 238 // log.Warn("got nil MessageConsensusDkgSigSets") 239 // return 240 // } 241 // if !a.term.Started() { 242 // log.Debug("term change not started yet") 243 // return 244 // } 245 // s := ogcrypto.NewSigner(a.cryptoType) 246 // 247 // //send genesis term change 248 // tc := a.term.GetGenesisTermChange() 249 // tc.GetBase().PublicKey = a.MyAccount.PublicKey.KeyBytes 250 // tc.GetBase().Signature = s.Sign(a.MyAccount.PrivateKey, tc.SignatureTargets()).KeyBytes 251 // tc.GetBase().Hash = tc.CalcTxHash() 252 // msg := &p2p_message.MessageTermChangeResponse{ 253 // TermChange: tc, 254 // } 255 // a.Hub.SendToPeer(peerId, message.MessageTypeTermChangeResponse, msg) 256 // 257 // log.WithField("data", msg).WithField("to peer ", peerId).Debug("send term change") 258 //} 259 // 260 //func (a *AnnSensus) HandleTermChangeResponse(response *p2p_message.MessageTermChangeResponse, peerId string) { 261 // if a.disable { 262 // log.WithField("from ", peerId).WithField("response ", response).Warn("annsensus disabled") 263 // return 264 // } 265 // if response == nil || response.TermChange == nil { 266 // log.Warn("got nil MessageConsensusDkgSigSets") 267 // return 268 // } 269 // if a.term.Started() { 270 // log.Debug("term change already stated") 271 // return 272 // } 273 // tc := response.TermChange 274 // log.WithField("data", response).WithField("from peer ", peerId).Debug("got term chan") 275 // s := ogcrypto.NewSigner(a.cryptoType) 276 // 277 // pk := ogcrypto.PublicKeyFromBytes(a.cryptoType, tc.PublicKey) 278 // 279 // ok := s.Verify(pk, ogcrypto.SignatureFromBytes(a.cryptoType, tc.Signature), tc.SignatureTargets()) 280 // if !ok { 281 // log.WithField("request ", response).Warn("verify signature failed") 282 // return 283 // } 284 // if !a.VerifyRequestedTermChange(tc) { 285 // log.WithField("request ", response).Warn("verify term change failed") 286 // return 287 // } 288 // a.termChangeChan <- tc 289 //}