/
request.go
42 lines (34 loc) · 882 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
package sbftx
import (
"github.com/ibalajiarun/go-consensus/pkg/command/commandpb"
pb "github.com/ibalajiarun/go-consensus/protocols/sbftx/sbftxpb"
)
func (s *sbftx) onRequest(cmd *commandpb.Command) *instance {
s.logger.Debugf("Replica %v received command: %v\n", s.id, cmd.Timestamp)
index := s.index.GetAndIncrement()
instID := pb.InstanceID{
ReplicaID: s.id,
Index: index,
}
inst := &instance{
s: s,
is: pb.InstanceState{
View: s.view,
InstanceID: instID,
Status: pb.InstanceState_Prepared,
Command: cmd,
},
cCert: newQuorum(s),
}
s.log[instID] = inst
s.logger.Debugf("onRequest inst %v", instID)
pm := &pb.NormalMessage{
View: s.view,
InstanceID: instID,
Type: pb.NormalMessage_Prepare,
Command: cmd,
}
mBytes := s.marshall(pm)
s.broadcast(mBytes, true /* sendToSelf */, nil)
return inst
}