拜占庭将军问题OM算法详解(m=1,m=2)

拜占庭将军问题OM算法介绍

网上关于拜占庭将军问题的讨论有很多了,但是关于OM算法的讨论,并没有太深入,网上能看到比较多m=1的情况,对于m>1的情况,并没有过多的介绍。

本人在一开始,对m=2的情况进行推演的时候,遇到了较多的问题,花费了些时间弄清楚整个流程。

本篇文章,主要就是对m=1,2的情况进行介绍,结合文章《The Byzantine Generals Problem》中的OM算法描述,把整个过程梳理一下。

OM算法

OM算法,即oral messages algorithm,是为了解决在拜占庭将军问题中,达成一致的算法。

如果拜占庭将军问题当中,最多有m个叛徒,则将军总数n>=3m+1才能够通过OM算法来达成一致性,记为OM(m),需要进行m+1轮,才能达成最终的共识。

下面是OM算法的描述:1

Algorithm OM(0):
(1) The commander sends his value to every lieutenant.
(2) Each lieutenant uses the value he receives from the commander, or uses the value RETREAT if he receives no value.

Algorithm OM(m), m > 0:
(1) The commander sends his value to every lieutenant.
(2) For each i, let vi be the value Lieutenant i receives from the commander, or else be RETREAT if he receives no value. Lieutenant i acts as the commander in Algorithm OM(m - 1) to send the value vi to each of the n - 2 other lieutenants.
(3) For each i, and each j ≠ i, let vj be the value Lieutenant i received from Lieutenant j in step (2) (using Algorithm OM(m - 1)), or else RETREAT
if he received no such value. Lieutenant i uses the value majority (v1 … vn-1 ).

1)m=1,n=4的情况

背景:
general G(是叛徒),发送命令给1,2,3三位副官,记为Li(i∈{1,2,3})。

步骤1:m=1>0,OM(1),G发送指令到各个副将。

The commander sends his value to every lieutenant.

图1

步骤2:Li 接受从G获取的指令,记为Vi,并每个Vi都作为新的将军,向除了将军和自己以外的副官发送一次命令,即,以Vi为将军执行一次OM(0)。

For each i, let vi be the value Lieutenant i receives from the commander, or else be RETREAT if he receives no value. Lieutenant i acts as the commander in Algorithm OM(m - 1) to send the value vi to each of the n - 2 other lieutenants.

在这里插入图片描述

步骤3:对于Li , 结合自己从将军收到的命令,以及从其他将军获取的命令,通过majority(V1,V2,V3…Vn-1),形成Li 采纳的命令。

For each i, and each j ≠ i, let vj be the value Lieutenant i received from Lieutenant j in step (2) (using Algorithm OM(m - 1)), or else RETREAT
if he received no such value. Lieutenant i uses the value majority (v1 … vn-1 ).

为什么存在步骤3?是因为将军也可能是叛徒,需要询问其他副官,他们都从将军那里得到了什么命令,再进行决策。

以L1为例,从将军接收到的命令为V1,从L2接受到的命令为V2-1,从L3接收到的命令为V3-1,L1将采纳majority(V1,V2-1,V3-1)=A。
同理,可以知道L2采纳的是A,L3也采纳的是A。
在这里插入图片描述
最终副官们达成的一致,采用A命令。

2)m=2,n=7的情况

背景:
general G,发送命令给1,2,3,4,5,6 七位副官,记为Li(i∈{1,2,3,4,5,6})。其中将军G和L6是叛徒。

步骤1:m=2>0,OM(2),G发送指令到各个副将。

The commander sends his value to every lieutenant.

在这里插入图片描述

步骤2:Li 接受从G获取的指令,记为Vi,并每个Vi都作为新的将军,向出了将军和自己以外的副官发送一次命令,即,以Vi为将军执行一次OM(1)。

For each i, let vi be the value Lieutenant i receives from the commander, or else be RETREAT if he receives no value. Lieutenant i acts as the commander in Algorithm OM(m - 1) to send the value vi to each of the n - 2 other lieutenants.

在这里插入图片描述

步骤3:对于Li , 结合自己从将军收到的命令,以及从其他将军获取的命令,通过majority(V1,V2,V3…Vn-1),形成Li 接受的命令。

For each i, and each j ≠ i, let vj be the value Lieutenant i received from Lieutenant j in step (2) (using Algorithm OM(m - 1)), or else RETREAT
if he received no such value. Lieutenant i uses the value majority (v1 … vn-1 ).

步骤3是各个副官根据步骤2中的OM(1),进行裁决,也就是通过majority(V1,V2,V3…Vn-1)得到应该采取的命令。

同样以L1作为例子,L1采取的值为majority(V1,V2-1,V3-1,V4-1,V5-1,V6-1),所需的值均在步骤二的图示中标识出来。

以V2-1为例,V2-1处于L2的OM(1)阶段,V2-1的值应该取什么值,需要进行一轮OM(1),才能确定,所以此处将进入OM(1)。其实这里可以将问题转换,转化为了L2为将军发布了命令,确定L1值。(即回到了m=1的问题)

对L2进行一轮OM(1)算法,如下图,V2-1=majority(V2,V’3-1,V’4-1,V’5-1,V’6-1)=majority(R,R,R,R,A)=R。
在这里插入图片描述
同理,可以得到V3-1,V4-1,V5-1为别为A,R,A。

L6是叛徒,如下图,V6-1=majority(V6,V"2-1,V"3-1,V"4-1,V"5-1)=A
在这里插入图片描述
至此,已经求出确定L1采纳命令所需的值。
L1采取的值为majority(V1,V2-1,V3-1,V4-1,V5-1,V6-1)=majority(A,R,A,R,A,A)=A

其他的副官采取的命令也可以通过这样的方法得出来。

L2,L3,L4,L5采纳的命令均为A,而L6为X(可能为A也可能为R),最终超过半数的副官达成了A的共识。

其他

对于OM(2),b站李永乐也有相关的视频2,通过表格的方法讲得也很清楚。但是表格的缺点在于,m=3的时候就显得比较复杂。

本文描述的方法,指出了产生递归调用所在的环节。当m>2的情况,也是能够比较清晰的处理。

这篇《极客时间之分布式协议与算法实战 01 拜占庭将军问题,有叛徒的情况下,如何才能达成共识》3有OM算法的程序实现,对于我梳理整个流程,也有很大帮助。


  1. The Byzantine Generals Problem ↩︎

  2. 拜占庭将军问题是什么?区块链如何防范恶意节点? ↩︎

  3. 极客时间之分布式协议与算法实战 01 拜占庭将军问题,有叛徒的情况下,如何才能达成共识 ↩︎

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值