Skip to content

Commit 836c1d7

Browse files
committed
GetCertStore codecov
1 parent 246fdf9 commit 836c1d7

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

f3.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,35 @@ func (m *F3) Broadcast(ctx context.Context, signatureBuilder *gpbft.SignatureBui
113113
}
114114

115115
func (m *F3) GetLatestCert(context.Context) (*certs.FinalityCertificate, error) {
116-
if state := m.state.Load(); state != nil {
117-
return state.cs.Latest(), nil
116+
cs, err := m.GetCertStore()
117+
if err != nil {
118+
return nil, err
118119
}
119-
return nil, ErrF3NotRunning
120+
return cs.Latest(), nil
120121
}
121122

122123
func (m *F3) GetCert(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) {
123-
if state := m.state.Load(); state != nil {
124-
return state.cs.Get(ctx, instance)
124+
cs, err := m.GetCertStore()
125+
if err != nil {
126+
return nil, err
125127
}
126-
return nil, ErrF3NotRunning
128+
return cs.Get(ctx, instance)
127129
}
128130

129-
func (m *F3) GetCertStore(ctx context.Context) (*certstore.Store, error) {
130-
if state := m.state.Load(); state != nil {
131+
func (m *F3) GetCertStore() (*certstore.Store, error) {
132+
if state := m.state.Load(); state != nil && state.cs != nil {
131133
return state.cs, nil
132134
}
133135
return nil, ErrF3NotRunning
134136
}
135137

136138
// GetPowerTableByInstance returns the power table (committee) used to validate the specified instance.
137139
func (m *F3) GetPowerTableByInstance(ctx context.Context, instance uint64) (gpbft.PowerEntries, error) {
138-
if state := m.state.Load(); state != nil {
139-
return state.cs.GetPowerTable(ctx, instance)
140+
cs, err := m.GetCertStore()
141+
if err != nil {
142+
return nil, err
140143
}
141-
return nil, ErrF3NotRunning
144+
return cs.GetPowerTable(ctx, instance)
142145
}
143146

144147
// computeBootstrapDelay returns the time at which the F3 instance specified by

0 commit comments

Comments
 (0)