@@ -15,27 +15,32 @@ import (
15
15
type thresholdNotMetError struct {
16
16
BlobKey string
17
17
ConfirmationThreshold uint8
18
- QuorumNumbers []uint32
19
- SignedPercentages []uint8
18
+ // these are the quorum numbers defined in the blob header
19
+ BlobQuorumNumbers []uint32
20
+ // map from quorumID to percent signed from the quorum
21
+ SignedPercentagesMap map [uint32 ]uint8
20
22
}
21
23
22
24
// Error implements the error interface and returns a formatted error message
23
25
func (e * thresholdNotMetError ) Error () string {
24
26
stringBuilder := strings.Builder {}
27
+ stringBuilder .WriteString (fmt .Sprintf (
28
+ "Blob Key: %s, Confirmation Threshold: %d%% [" , e .BlobKey , e .ConfirmationThreshold ))
25
29
26
- stringBuilder .WriteString ("\n Blob Key: " )
27
- stringBuilder .WriteString (e .BlobKey )
28
- stringBuilder .WriteString (fmt .Sprintf ("\n Confirmation Threshold: %d%%" , e .ConfirmationThreshold ))
30
+ for index , quorumID := range e .BlobQuorumNumbers {
31
+ signedPercentage := e .SignedPercentagesMap [quorumID ]
29
32
30
- for index , quorum := range e .QuorumNumbers {
31
- signedPercentage := e .SignedPercentages [index ]
32
-
33
- stringBuilder .WriteString (fmt .Sprintf ("\n Quorum %d: %d%% signed" , quorum , signedPercentage ))
33
+ stringBuilder .WriteString (fmt .Sprintf ("quorum_%d: %d%%" , quorumID , signedPercentage ))
34
34
35
35
if signedPercentage < e .ConfirmationThreshold {
36
36
stringBuilder .WriteString (" (DOES NOT MEET THRESHOLD)" )
37
37
}
38
+
39
+ if index < len (e .BlobQuorumNumbers )- 1 {
40
+ stringBuilder .WriteString (", " )
41
+ }
38
42
}
43
+ stringBuilder .WriteString ("]" )
39
44
40
45
return stringBuilder .String ()
41
46
}
@@ -47,16 +52,23 @@ func checkThresholds(
47
52
blobStatusReply * dispgrpc.BlobStatusReply ,
48
53
blobKey string ,
49
54
) error {
50
- quorumNumbers := blobStatusReply .GetBlobInclusionInfo ().GetBlobCertificate ().GetBlobHeader ().GetQuorumNumbers ()
51
- if len (quorumNumbers ) == 0 {
52
- return fmt .Errorf ("expected >0 quorum numbers: %v" , protoToString (blobStatusReply ))
55
+ blobQuorumNumbers := blobStatusReply .GetBlobInclusionInfo ().GetBlobCertificate ().GetBlobHeader ().GetQuorumNumbers ()
56
+ if len (blobQuorumNumbers ) == 0 {
57
+ return fmt .Errorf ("expected >0 quorum numbers in blob header: %v" , protoToString (blobStatusReply ))
58
+ }
59
+
60
+ attestation := blobStatusReply .GetSignedBatch ().GetAttestation ()
61
+ batchQuorumNumbers := attestation .GetQuorumNumbers ()
62
+ batchSignedPercentages := attestation .GetQuorumSignedPercentages ()
63
+
64
+ if len (batchQuorumNumbers ) != len (batchSignedPercentages ) {
65
+ return fmt .Errorf ("batch quorum number count and signed percentage count don't match" )
53
66
}
54
67
55
- quorumSignedPercentages := blobStatusReply .GetSignedBatch ().GetAttestation ().GetQuorumSignedPercentages ()
56
- if len (quorumSignedPercentages ) != len (quorumNumbers ) {
57
- return fmt .Errorf ("expected number of signed percentages to match number of quorums. " +
58
- "signed percentages count: %d; quorum count: %d" ,
59
- len (quorumSignedPercentages ), len (quorumNumbers ))
68
+ // map from quorum ID to the percentage stake signed from that quorum
69
+ signedPercentagesMap := make (map [uint32 ]uint8 , len (batchQuorumNumbers ))
70
+ for index , quorumID := range batchQuorumNumbers {
71
+ signedPercentagesMap [quorumID ] = batchSignedPercentages [index ]
60
72
}
61
73
62
74
batchHeader := blobStatusReply .GetSignedBatch ().GetHeader ()
@@ -69,14 +81,15 @@ func checkThresholds(
69
81
return fmt .Errorf ("get confirmation threshold: %w" , err )
70
82
}
71
83
72
- // Check if all thresholds are met
73
- for _ , signedPercentage := range quorumSignedPercentages {
84
+ // Check if all thresholds are met for the quorums defined in the blob header
85
+ for _ , quorum := range blobQuorumNumbers {
86
+ signedPercentage := signedPercentagesMap [quorum ]
74
87
if signedPercentage < confirmationThreshold {
75
88
return & thresholdNotMetError {
76
89
BlobKey : blobKey ,
77
90
ConfirmationThreshold : confirmationThreshold ,
78
- QuorumNumbers : quorumNumbers ,
79
- SignedPercentages : quorumSignedPercentages ,
91
+ BlobQuorumNumbers : blobQuorumNumbers ,
92
+ SignedPercentagesMap : signedPercentagesMap ,
80
93
}
81
94
}
82
95
}
0 commit comments