/
request.go
45 lines (36 loc) · 872 Bytes
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package minbft
import (
"github.com/ibalajiarun/go-consensus/pkg/command/commandpb"
pb "github.com/ibalajiarun/go-consensus/protocols/minbft/minbftpb"
)
func (p *minbft) onRequest(cmd *commandpb.Command) *instance {
//TODO
if p.curView != p.stableView {
panic("Fix this")
}
p.logger.Debugf("Replica %v received %v\n", p.id, cmd)
if uint64(p.stableView)%uint64(len(p.nodes)) != uint64(p.id) {
panic("not the leader")
}
p.slot++
cmdHash := cmd.Hash()
inst := &instance{
p: p,
view: p.curView,
slot: p.slot,
command: cmd,
quorum: newQuorum(p),
}
p.log[inst.slot] = inst
pr := &pb.NormalMessage{
View: inst.view,
Order: inst.slot,
Type: pb.NormalMessage_Prepare,
Command: cmd,
CommandHash: cmdHash[:],
}
inst.quorum.log(p.id, pr)
inst.prepared = true
p.broadcastNormal(pr)
return inst
}