| 426 | } |
| 427 | |
| 428 | bool CheckPBFTMessage(const int32_t msgType ,const CPBFTMessage& msg) { |
| 429 | |
| 430 | |
| 431 | //check message type; |
| 432 | if(msg.msgType != msgType ) { |
| 433 | LogPrint(BCLog::PBFT, "msgType is illegal"); |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | CAccount account; |
| 438 | CBlockIndex* localFinBlock = pbftMan.GetLocalFinIndex(); |
| 439 | { |
| 440 | LOCK(cs_main); |
| 441 | |
| 442 | //check height |
| 443 | if(msg.height - chainActive.Height() > 500 || (localFinBlock && msg.height < (uint32_t)localFinBlock->height) ) { |
| 444 | LogPrint(BCLog::PBFT, "messages height is out of range\n"); |
| 445 | return false; |
| 446 | } |
| 447 | |
| 448 | //if block received,check whether in chainActive |
| 449 | CBlockIndex* pIndex = chainActive[msg.height]; |
| 450 | if(pIndex == nullptr || pIndex->GetBlockHash() != msg.blockHash) { |
| 451 | LogPrint(BCLog::PBFT, "msg_block=%s not in chainActive! miner=%s\n", |
| 452 | msg.GetBlockId(), msg.miner.ToString()); |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | //check signature |
| 457 | if(!pCdMan->pAccountCache->GetAccount(msg.miner, account)) { |
| 458 | LogPrint(BCLog::PBFT, "the miner=%s of msg is not found! msg_block=%s\n", |
| 459 | msg.miner.ToString(), msg.GetBlockId()); |
| 460 | return false; |
| 461 | } |
| 462 | } |
| 463 | uint256 messageHash = msg.GetHash(); |
| 464 | if (!VerifySignature(messageHash, msg.vSignature, account.owner_pubkey)) { |
| 465 | if (!VerifySignature(messageHash, msg.vSignature, account.miner_pubkey)) { |
| 466 | LogPrint(BCLog::INFO, "verify signature error! miner=%s, msg_block=%s\n", |
| 467 | msg.miner.ToString(), msg.GetBlockId()); |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | return true; |
| 473 | |
| 474 | } |
| 475 | |
| 476 | bool RelayBlockConfirmMessage(const CBlockConfirmMessage& msg){ |
| 477 |
no test coverage detected