Also check timestamp when comparing STHs

otherwise we might fail to delete unverified_sths if they have a different timestamp
This commit is contained in:
Andrew Ayer 2025-05-21 14:33:58 -04:00
parent 90ead642b0
commit 694eb276a6
2 changed files with 5 additions and 1 deletions

View File

@ -31,3 +31,7 @@ type GossipedSignedTreeHead struct {
func (sth *SignedTreeHead) TimestampTime() time.Time { func (sth *SignedTreeHead) TimestampTime() time.Time {
return time.UnixMilli(int64(sth.Timestamp)) return time.UnixMilli(int64(sth.Timestamp))
} }
func (sth *SignedTreeHead) Same(other *SignedTreeHead) bool {
return sth.TreeSize == other.TreeSize && sth.Timestamp == other.Timestamp && sth.RootHash == other.RootHash
}

View File

@ -357,7 +357,7 @@ func newBatch(number uint64, begin uint64, sths []*StoredSTH, downloadJobSize ui
func appendSTH(sths []*StoredSTH, sth *StoredSTH) []*StoredSTH { func appendSTH(sths []*StoredSTH, sth *StoredSTH) []*StoredSTH {
i := len(sths) i := len(sths)
for i > 0 { for i > 0 {
if sths[i-1].TreeSize == sth.TreeSize && sths[i-1].RootHash == sth.RootHash { if sths[i-1].Same(&sth.SignedTreeHead) {
return sths return sths
} }
if sths[i-1].TreeSize < sth.TreeSize { if sths[i-1].TreeSize < sth.TreeSize {