/
request.go
44 lines (34 loc) · 945 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 sbft
import (
"context"
"github.com/ibalajiarun/go-consensus/pkg/command/commandpb"
pb "github.com/ibalajiarun/go-consensus/protocols/sbft/sbftpb"
"github.com/opentracing/opentracing-go"
)
func (s *sbft) onRequest(ctx context.Context, cmd *commandpb.Command) *instance {
s.logger.Debugf("Replica %v received command ID %v\n", s.id, cmd.Timestamp)
span, ctx := opentracing.StartSpanFromContext(ctx, "onRequest")
defer span.Finish()
index := s.index.GetAndIncrement()
inst := &instance{
s: s,
is: pb.InstanceState{
View: s.view,
Index: index,
Status: pb.InstanceState_Prepared,
Command: cmd,
},
cCert: newQuorum(s),
}
s.log[index] = inst
s.logger.Debugf("onRequest inst %v", index)
pm := &pb.NormalMessage{
View: s.view,
Index: index,
Type: pb.NormalMessage_Prepare,
Command: cmd,
}
mBytes := s.marshall(pm)
s.broadcast(mBytes, true /* sendToSelf */, nil)
return inst
}