github pbft代码问题

最近在做毕设,参考github相关代码时发现一些问题,这里给自己做个笔记提醒。(github总是犯神经,报错超时无语)
链接为 https://github.com/kenzarh/SG-PBFT

代码中间进行视图切换的消息类型操作时,有一句逻辑为给全部节点发送new-view类型消息的代码,直接修改main.py的timer_limit_before_view_change测试view-change操作时会触发receive方法中一些解密的操作问题,实际上问题出在给全部节点发送new-view类型消息这里。

源代码为:

点击查看代码
if (min_s>=self.stable_checkpoint["sequence_number"]):
                            # The primary node enters the new view
                            self.view_number=new_asked_view

                            # Decrement the credibility of the previous primary node
                            #credibility[self.primary_node_id] -= 1

                            # Change primary node (locally first then broadcast view change)
                            self.primary_node_id=self.node_id

                            # self.broadcast_message(the_nodes_ids_list,new_view_message) # broadcast_message 在接受消息时进行解密,而这里直接就发送了,没有进行加密操作,应当设置方法来集成操作
                            self.broadcast_new_view_message(the_nodes_ids_list,new_view_message)

所以我们需要给发送new-view消息创建独立的方法进行集成。

修改添加代码如下:

点击查看代码
def broadcast_new_view_message(self,nodes_ids_list,new_view_message):
        signing_key = SigningKey.generate()

        # Sign the message with the signing key
        signed_new_view = signing_key.sign(str(new_view_message).encode())

        # Obtain the verify key for a given signing key
        verify_key = signing_key.verify_key

        # Serialize the verify key to send it to a third party
        public_key = verify_key.encode()

        new_view_message = signed_new_view +(b'split')+  public_key

        self.broadcast_message(nodes_ids_list,new_view_message)
posted @ 2024-12-19 21:28  jockerliu  阅读(7)  评论(0编辑  收藏  举报