-
Notifications
You must be signed in to change notification settings - Fork 4
/
request.go
44 lines (37 loc) · 970 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
package pbft
import (
"github.com/ibalajiarun/go-consensus/pkg/command/commandpb"
pb "github.com/ibalajiarun/go-consensus/protocols/pbft/pbftpb"
)
func (p *PBFT) onRequest(cmd *commandpb.Command) *instance {
p.logger.Debugf("Replica %v received %v\n", p.id, cmd.Timestamp)
if uint64(p.view)%uint64(len(p.nodes)) != uint64(p.id) {
p.logger.Errorf("Not the leader of view %d: %d", p.view, p.id)
return nil
}
p.index++
cmdHash := cmd.Hash()
inst := &instance{
p: p,
is: pb.InstanceState{
View: p.view,
Index: p.index,
Status: pb.InstanceState_PrePrepared,
Command: cmd,
CommandHash: cmdHash[:],
},
pCert: newQuorum(p),
cCert: newQuorum(p),
}
p.log[p.index] = inst
ppm := &pb.AgreementMessage{
View: p.view,
Index: p.index,
Type: pb.AgreementMessage_PrePrepare,
Command: cmd,
CommandHash: cmdHash[:],
}
inst.pCert.log(p.id, ppm)
p.broadcast(ppm, false)
return inst
}