feat(lns): expose locked prefix size
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
b0f04de1e0
commit
a021273064
4 changed files with 21 additions and 0 deletions
6
lns.go
6
lns.go
|
|
@ -301,6 +301,12 @@ func (s *Service) LockedSize() int {
|
|||
return s.LockedCatalog().Size()
|
||||
}
|
||||
|
||||
// LockedPrefixSize reports the byte offset where locked-name entries begin in
|
||||
// the reference table.
|
||||
func (s *Service) LockedPrefixSize() int {
|
||||
return s.LockedCatalog().PrefixSize()
|
||||
}
|
||||
|
||||
// LockedEntries exposes the locked-name catalog entries used by the service.
|
||||
func (s *Service) LockedEntries() []covenant.LockedEntry {
|
||||
return s.LockedCatalog().Entries()
|
||||
|
|
|
|||
|
|
@ -493,6 +493,10 @@ func TestServiceLockedCatalog(t *testing.T) {
|
|||
t.Fatalf("LockedSize() = %d, want %d", got, catalog.Size())
|
||||
}
|
||||
|
||||
if got := svc.LockedPrefixSize(); got != catalog.PrefixSize() {
|
||||
t.Fatalf("LockedPrefixSize() = %d, want %d", got, catalog.PrefixSize())
|
||||
}
|
||||
|
||||
if !catalog.HasByName("NEC") {
|
||||
t.Fatal("LockedCatalog should expose the locked catalog helpers")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ type LockedEntry struct {
|
|||
Value LockedName
|
||||
}
|
||||
|
||||
const lockedCatalogPrefixSize = 4
|
||||
|
||||
var (
|
||||
lockedCatalogOnce sync.Once
|
||||
lockedCatalog *LockedCatalog
|
||||
|
|
@ -87,6 +89,11 @@ func (c *LockedCatalog) Size() int {
|
|||
return len(c.byHash)
|
||||
}
|
||||
|
||||
// PrefixSize reports the byte offset where the locked-name table entries begin.
|
||||
func (c *LockedCatalog) PrefixSize() int {
|
||||
return lockedCatalogPrefixSize
|
||||
}
|
||||
|
||||
// Has reports whether the catalog contains the hash.
|
||||
func (c *LockedCatalog) Has(hash primitives.Hash) bool {
|
||||
if c == nil {
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ func TestLockedCatalogHelpers(t *testing.T) {
|
|||
t.Fatal("catalog should report a non-zero size")
|
||||
}
|
||||
|
||||
if catalog.PrefixSize() != lockedCatalogPrefixSize {
|
||||
t.Fatalf("catalog.PrefixSize() = %d, want %d", catalog.PrefixSize(), lockedCatalogPrefixSize)
|
||||
}
|
||||
|
||||
if !catalog.HasByName("NEC") {
|
||||
t.Fatal("catalog should find names case-insensitively")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue