-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Add additional serving bundle checks * feat: Subscribe to node events * feat: Subscribe to node events * fix: Panic on unhealthy node without an initialized wallclock * Fix: Reduce checkpointz status edge caching time * feat: Serve block_sidecars route * Merge master * fix: typo * fix: Remove debug logs * chore: linting * feat: Handle no DENEB fork definition * fix: Fix assignment in error handling condition * fix: duplicate metrics
- Loading branch information
Showing
9 changed files
with
349 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package store | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/deneb" | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/ethpandaops/checkpointz/pkg/cache" | ||
"github.com/ethpandaops/checkpointz/pkg/eth" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type BlobSidecar struct { | ||
store *cache.TTLMap | ||
log logrus.FieldLogger | ||
} | ||
|
||
func NewBlobSidecar(log logrus.FieldLogger, config Config, namespace string) *BlobSidecar { | ||
d := &BlobSidecar{ | ||
log: log.WithField("component", "beacon/store/blob_sidecar"), | ||
store: cache.NewTTLMap(config.MaxItems, "blob_sidecar", namespace), | ||
} | ||
|
||
d.store.OnItemDeleted(func(key string, value interface{}, expiredAt time.Time) { | ||
d.log.WithField("key", key).WithField("expired_at", expiredAt.String()).Debug("Blob sidecar was deleted from the cache") | ||
}) | ||
|
||
d.store.EnableMetrics(namespace) | ||
|
||
return d | ||
} | ||
|
||
func (d *BlobSidecar) Add(slot phase0.Slot, sidecars []*deneb.BlobSidecar, expiresAt time.Time) error { | ||
d.store.Add(eth.SlotAsString(slot), sidecars, expiresAt, false) | ||
|
||
d.log.WithFields( | ||
logrus.Fields{ | ||
"slot": eth.SlotAsString(slot), | ||
"expires_at": expiresAt.String(), | ||
}, | ||
).Debug("Added blob sidecar") | ||
|
||
return nil | ||
} | ||
|
||
func (d *BlobSidecar) GetBySlot(slot phase0.Slot) ([]*deneb.BlobSidecar, error) { | ||
data, _, err := d.store.Get(eth.SlotAsString(slot)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return d.parseSidecar(data) | ||
} | ||
|
||
func (d *BlobSidecar) parseSidecar(data interface{}) ([]*deneb.BlobSidecar, error) { | ||
sidecar, ok := data.([]*deneb.BlobSidecar) | ||
if !ok { | ||
return nil, errors.New("invalid blob sidecar type") | ||
} | ||
|
||
return sidecar, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package store | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/attestantio/go-eth2-client/spec/deneb" | ||
"github.com/attestantio/go-eth2-client/spec/phase0" | ||
"github.com/sirupsen/logrus/hooks/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBlobSidecarAddAndGet(t *testing.T) { | ||
logger, _ := test.NewNullLogger() | ||
config := Config{MaxItems: 10} | ||
namespace := "test_a" | ||
blobSidecarStore := NewBlobSidecar(logger, config, namespace) | ||
|
||
slot := phase0.Slot(100) | ||
expiresAt := time.Now().Add(10 * time.Minute) | ||
sidecars := []*deneb.BlobSidecar{ | ||
{ | ||
Blob: deneb.Blob{}, | ||
}, | ||
} | ||
|
||
err := blobSidecarStore.Add(slot, sidecars, expiresAt) | ||
assert.NoError(t, err) | ||
|
||
retrievedSidecars, err := blobSidecarStore.GetBySlot(slot) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, retrievedSidecars) | ||
assert.Equal(t, sidecars, retrievedSidecars) | ||
} | ||
|
||
func TestBlobSidecarGetBySlotNotFound(t *testing.T) { | ||
logger, _ := test.NewNullLogger() | ||
config := Config{MaxItems: 10} | ||
namespace := "test_b" | ||
blobSidecarStore := NewBlobSidecar(logger, config, namespace) | ||
|
||
slot := phase0.Slot(200) | ||
|
||
retrievedSidecars, err := blobSidecarStore.GetBySlot(slot) | ||
assert.Error(t, err) | ||
assert.Nil(t, retrievedSidecars) | ||
} |
Oops, something went wrong.