Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix mem store bug && rename to proxy #19

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LDFLAGS := -ldflags "$(LDFLAGSSTRING)"

.PHONY: eigenda-proxy
eigenda-proxy:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/daserver
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/eigenda-proxy ./cmd/server

.PHONY: docker-build
docker-build:
Expand Down
14 changes: 7 additions & 7 deletions cmd/daserver/entrypoint.go → cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import (
"context"
"fmt"

"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/metrics"
"github.com/Layr-Labs/op-plasma-eigenda/store"
"github.com/Layr-Labs/op-plasma-eigenda/verify"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"

proxy "github.com/Layr-Labs/op-plasma-eigenda"
proxy "github.com/Layr-Labs/eigenda-proxy"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/opio"
)

func LoadStore(cfg CLIConfig, ctx context.Context, log log.Logger) (proxy.Store, error) {
if cfg.MemStoreCfg.Enabled {
log.Info("Using memstore backend")
return store.NewMemStore(ctx, &cfg.MemStoreCfg)
return store.NewMemStore(ctx, &cfg.MemStoreCfg, log)
}

log.Info("Using eigenda backend")
Expand Down Expand Up @@ -56,7 +56,7 @@ func StartProxySvr(cliCtx *cli.Context) error {
log := oplog.NewLogger(oplog.AppOut(cliCtx), oplog.ReadCLIConfig(cliCtx)).New("role", "eigenda_proxy")
oplog.SetGlobalLogHandler(log.Handler())

log.Info("Initializing EigenDA Plasma DA server...")
log.Info("Initializing EigenDA proxy server...")

da, err := LoadStore(cfg, ctx, log)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/daserver/flags.go → cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/urfave/cli/v2"

"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/store"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda-proxy/store"
opservice "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion eigenda/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package eigenda
import (
"testing"

"github.com/Layr-Labs/eigenda-proxy/common"
eigen_da_common "github.com/Layr-Labs/eigenda/api/grpc/common"
"github.com/Layr-Labs/op-plasma-eigenda/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Layr-Labs/op-plasma-eigenda
module github.com/Layr-Labs/eigenda-proxy

go 1.21

Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"strconv"
"time"

"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/metrics"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
Expand Down
4 changes: 2 additions & 2 deletions store/eigenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/verify"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/ethereum/go-ethereum/rlp"
)

Expand Down
24 changes: 16 additions & 8 deletions store/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/log"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/urfave/cli/v2"
Expand All @@ -31,37 +33,41 @@ type MemStore struct {
sync.RWMutex

cfg *MemStoreConfig
l log.Logger
keyStarts map[string]time.Time
store map[string][]byte
}

// NewMemStore ... constructor
func NewMemStore(ctx context.Context, cfg *MemStoreConfig) (*MemStore, error) {
func NewMemStore(ctx context.Context, cfg *MemStoreConfig, l log.Logger) (*MemStore, error) {
store := &MemStore{
cfg: cfg,
l: l,
keyStarts: make(map[string]time.Time),
store: make(map[string][]byte),
}

if cfg.BlobExpiration != 0 {
l.Info("memstore expiration enabled", "time", cfg.BlobExpiration)
go store.EventLoop(ctx)
}

return store, nil
}

func (e *MemStore) EventLoop(ctx context.Context) {

timer := time.NewTicker(DefaultPruneInterval)

select {
case <-ctx.Done():
return
for {
select {
case <-ctx.Done():
return

case <-timer.C:
e.pruneExpired()
case <-timer.C:
e.l.Debug("pruning expired blobs")
e.pruneExpired()
}
}

}

func (e *MemStore) pruneExpired() {
Expand All @@ -72,6 +78,8 @@ func (e *MemStore) pruneExpired() {
if time.Since(dur) >= e.cfg.BlobExpiration {
delete(e.keyStarts, commit)
delete(e.store, commit)

e.l.Info("blob pruned", "commit", commit)
}
}

Expand Down
5 changes: 4 additions & 1 deletion store/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/assert"
)

Expand All @@ -22,6 +23,7 @@ func TestGetSet(t *testing.T) {
Enabled: true,
BlobExpiration: time.Hour * 1000,
},
log.New(),
)

assert.NoError(t, err)
Expand All @@ -46,6 +48,7 @@ func TestExpiration(t *testing.T) {
Enabled: true,
BlobExpiration: time.Millisecond * 10,
},
log.New(),
)

assert.NoError(t, err)
Expand All @@ -54,7 +57,7 @@ func TestExpiration(t *testing.T) {
key, err := ms.Put(ctx, preimage)
assert.NoError(t, err)

// sleep 1ms and verify that older entries are removed
// sleep 1 second and verify that older blob entries are removed
time.Sleep(time.Second * 1)

_, err = ms.Get(ctx, key)
Expand Down
12 changes: 6 additions & 6 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"testing"
"time"

plasma "github.com/Layr-Labs/eigenda-proxy"
proxy "github.com/Layr-Labs/eigenda-proxy"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/store"
"github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/Layr-Labs/eigenda/encoding/kzg"
plasma "github.com/Layr-Labs/op-plasma-eigenda"
proxy "github.com/Layr-Labs/op-plasma-eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/Layr-Labs/op-plasma-eigenda/metrics"
"github.com/Layr-Labs/op-plasma-eigenda/store"
"github.com/Layr-Labs/op-plasma-eigenda/verify"
op_plasma "github.com/ethereum-optimism/optimism/op-plasma"

oplog "github.com/ethereum-optimism/optimism/op-service/log"
Expand Down
2 changes: 1 addition & 1 deletion verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/Layr-Labs/eigenda/encoding"

"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/Layr-Labs/eigenda/encoding/kzg/prover"
"github.com/Layr-Labs/eigenda/encoding/rs"
"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
)

type Verifier struct {
Expand Down
2 changes: 1 addition & 1 deletion verify/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"runtime"
"testing"

"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/Layr-Labs/eigenda/api/grpc/common"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/Layr-Labs/op-plasma-eigenda/eigenda"
"github.com/stretchr/testify/assert"
)

Expand Down
Loading