为了实现Bizantine共识,必须适用这3条规则:在每一轮中,每个进程必须向其他n-1个进程发送一个比特(值为0或1);在新一轮开始前,每个进程必须从其他进程那里收到一个比特;在每一轮中,每个进程都向所有其他进程发送了他的比特。
我需要对991个总进程中的661个非叛徒进程实现以下基于Rabin的Monte Carlo Byzantine Consensus随机协议。
Variables:
b(i) = value to send to all other processes, initially = input value
p = global random number which can be either 1 and 0, picked after every run
maj(i) = majority value
tally(i) = number of times majority appears in b(i)
Implementation:
loop = TRUE
while (loop)
1. send b(i) to the other n−1 processes
2. receive the values sent by the other n−1 processes
3. set maj(i) = majority value in b(i)
4. set tally(i) = number of times the majority value appears
5. if tally(i) ≥ 2t + 1
then b(i) = maj(i)
else if (p=1) then b(i) = 1
else b(i) ← 0
我的问题是: 我如何实现数据结构,为每个进程存储他们发送和接收的比特, 更不用说如何实现发送机制本身?我想为每个进程实现一个数组A.i[j],其中j的范围是所有进程的id。我听说可以让进程从这样的表中读取其他n-1个进程的值,而不是实现发送机制,如何实现呢?
我解决这个问题的方法是创建一个具有类型和投票属性的类Process和一个 getVote()
方法。
v0
起初,它将趋于 v
(按照协议)setVote()
:设置投票。getVote()
如果类型可靠,则返回位,否则返回随机数,介于两者之间。0
和 1
.为了模拟一个分布式的Algo,你可以在不同的线程中运行协议,每个线程都包含一个进程类,并与一个共享的公共数组进行通信,你可以在每一轮更新。
一个例子 此处
你也可以从这些对象的数组开始模拟一切,而不需要单独的线程。
我相信这应该足以处理这个模型。
类似这样的东西。
export class Process {
constructor(public pid: number, public vote: number, public type: ProcessType ) { }
set(bit: number) {
this.vote = this.send(bit);
}
send(b) {
if (this.type === ProcessType.unreliable) {
return Math.round(Math.random());
}
return b;
}
get() {
return { pid: this.pid, vote: this.vote, type: this.type};
}
getVote() {
return this.send(this.vote);
}
}
祝你好运!