@@ -57,10 +57,10 @@ type HistoryArchiveState struct {
5757 HotArchiveBuckets BucketList `json:"hotArchiveBuckets"`
5858}
5959
60- func ( h * HistoryArchiveState ) LevelSummary ( ) (string , int , error ) {
60+ func summarizeBucketList ( buckets BucketList ) (string , int , error ) {
6161 summ := ""
6262 nz := 0
63- for _ , b := range h . CurrentBuckets {
63+ for _ , b := range buckets {
6464 state := '_'
6565 for _ , bs := range []string {
6666 b .Curr , b .Snap , b .Next .Output ,
@@ -87,26 +87,66 @@ func (h *HistoryArchiveState) LevelSummary() (string, int, error) {
8787 return summ , nz , nil
8888}
8989
90- func (h * HistoryArchiveState ) Buckets () ([]Hash , error ) {
91- r := []Hash {}
92- for _ , b := range h .CurrentBuckets {
93- for _ , bs := range []string {
94- b .Curr , b .Snap , b .Next .Output ,
95- } {
90+ func (h * HistoryArchiveState ) LevelSummary () (string , int , error ) {
91+ currentSummary , currentNz , err := summarizeBucketList (h .CurrentBuckets )
92+ if err != nil {
93+ return "" , 0 , err
94+ }
95+
96+ // For V2+, include hot archive buckets
97+ if h .Version >= HistoryArchiveStateVersionForProtocol23 {
98+ hotSummary , hotNz , err := summarizeBucketList (h .HotArchiveBuckets )
99+ if err != nil {
100+ return "" , 0 , err
101+ }
102+ return currentSummary + "|" + hotSummary , currentNz + hotNz , nil
103+ }
104+
105+ return currentSummary , currentNz , nil
106+ }
107+
108+ func extractBucketHashes (buckets BucketList ) ([]Hash , error ) {
109+ var result []Hash
110+ for _ , b := range buckets {
111+ for _ , bs := range []string {b .Curr , b .Snap , b .Next .Output } {
96112 // Ignore empty values
97113 if bs == "" {
98114 continue
99115 }
100116
101117 h , err := DecodeHash (bs )
102118 if err != nil {
103- return r , err
119+ return result , err
104120 }
105121 if ! h .IsZero () {
106- r = append (r , h )
122+ result = append (result , h )
107123 }
108124 }
109125 }
126+ return result , nil
127+ }
128+
129+ // Returns all Buckets reference by the HistoryArchiveState. This includes
130+ // both the live Buckets and hot archive Buckets (for HAS version 2+).
131+ func (h * HistoryArchiveState ) Buckets () ([]Hash , error ) {
132+ r := []Hash {}
133+
134+ // Extract current buckets
135+ currentBuckets , err := extractBucketHashes (h .CurrentBuckets )
136+ if err != nil {
137+ return r , err
138+ }
139+ r = append (r , currentBuckets ... )
140+
141+ // Include hot archive buckets for version 2+ (protocol 23+)
142+ if h .Version >= HistoryArchiveStateVersionForProtocol23 {
143+ hotArchiveBuckets , err := extractBucketHashes (h .HotArchiveBuckets )
144+ if err != nil {
145+ return r , err
146+ }
147+ r = append (r , hotArchiveBuckets ... )
148+ }
149+
110150 return r , nil
111151}
112152
0 commit comments