Skip to content

Commit

Permalink
Simplify da backend stores around Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Sep 29, 2023
1 parent 753278b commit b98a2d8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 324 deletions.
10 changes: 1 addition & 9 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner = miner.New(eth, &config.Miner, eth.blockchain.Config(), eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

// TODO: opts, redis store backend
var confidentialStoreBackend suave.ConfidentialStoreBackend
if config.Suave.RedisStoreUri == "dev" {
confidentialStoreBackend = suave_backends.NewMiniredisBackend()
} else if config.Suave.RedisStoreUri != "" {
confidentialStoreBackend = suave_backends.NewRedisStoreBackend(config.Suave.RedisStoreUri)
} else {
confidentialStoreBackend = suave_backends.NewLocalConfidentialStore()
}
confidentialStoreBackend := suave_backends.NewRedisStoreBackend(config.Suave.RedisStoreUri)

var confidentialStoreTransport suave.StoreTransportTopic
if config.Suave.RedisStorePubsubUri != "" {
Expand Down
80 changes: 0 additions & 80 deletions suave/backends/cdas.go

This file was deleted.

160 changes: 0 additions & 160 deletions suave/backends/miniredis_backends.go

This file was deleted.

75 changes: 0 additions & 75 deletions suave/backends/redis_backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestMiniredisTransport(t *testing.T) {
mb := NewMiniredisBackend()
require.NoError(t, mb.Start())
t.Cleanup(func() { mb.Stop() })

msgSub, cancel := mb.Subscribe()
t.Cleanup(cancel)

daMsg := suave.DAMessage{
Bid: suave.Bid{
Id: suave.BidId{0x42},
DecryptionCondition: uint64(13),
AllowedPeekers: []common.Address{{0x41, 0x39}},
Version: string("vv"),
},
Value: []byte{},
Signature: []byte{},
}

mb.Publish(daMsg)

select {
case msg := <-msgSub:
require.Equal(t, daMsg, msg)
case <-time.After(100 * time.Millisecond):
t.Error("did not receive expected message")
}

select {
case <-msgSub:
t.Error("received an expected message")
case <-time.After(5 * time.Millisecond):
}

daMsg.Bid.Id[0] = 0x43
mb.Publish(daMsg)

select {
case msg := <-msgSub:
require.Equal(t, daMsg, msg)
case <-time.After(100 * time.Millisecond):
t.Error("did not receive expected message")
}
}

func TestMiniredisStore(t *testing.T) {
mb := NewMiniredisBackend()
require.NoError(t, mb.Start())
t.Cleanup(func() { mb.Stop() })

bid := suave.Bid{
Id: suave.BidId{0x42},
DecryptionCondition: uint64(13),
AllowedPeekers: []common.Address{{0x41, 0x39}},
Version: string("vv"),
}

err := mb.InitializeBid(bid)
require.NoError(t, err)

fetchedBid, err := mb.FetchEngineBidById(bid.Id)
require.NoError(t, err)
require.Equal(t, bid, fetchedBid)

_, err = mb.Store(bid, bid.AllowedPeekers[0], "xx", []byte{0x43, 0x14})
require.NoError(t, err)

retrievedData, err := mb.Retrieve(bid, bid.AllowedPeekers[0], "xx")
require.NoError(t, err)
require.Equal(t, []byte{0x43, 0x14}, retrievedData)

_, err = mb.Retrieve(bid, bid.AllowedPeekers[0], "xxy")
require.Error(t, err)
}

func TestRedisTransport(t *testing.T) {
mr := miniredis.RunT(t)

Expand Down
4 changes: 4 additions & 0 deletions suave/backends/redis_store_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type RedisStoreBackend struct {
local *miniredis.Miniredis
}

func NewLocalConfidentialStore() *RedisStoreBackend {
return NewRedisStoreBackend("")
}

func NewRedisStoreBackend(redisUri string) *RedisStoreBackend {
return &RedisStoreBackend{
cancel: nil,
Expand Down

0 comments on commit b98a2d8

Please sign in to comment.