-
Notifications
You must be signed in to change notification settings - Fork 52
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
Engine store api #53
Merged
Merged
Engine store api #53
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package backends | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
suave "github.com/ethereum/go-ethereum/suave/core" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func testBackendStore(t *testing.T, store suave.ConfidentialStoreBackend) { | ||
bid := suave.Bid{ | ||
Id: suave.RandomBidId(), | ||
DecryptionCondition: 10, | ||
AllowedPeekers: []common.Address{common.HexToAddress("0x424344")}, | ||
Version: "default:v0:ethBundles", | ||
} | ||
|
||
err := store.InitializeBid(bid) | ||
require.NoError(t, err) | ||
|
||
bidRes, err := store.FetchBidById(bid.Id) | ||
require.NoError(t, err) | ||
require.Equal(t, bid, bidRes) | ||
|
||
_, err = store.Store(bid, bid.AllowedPeekers[0], "xx", []byte{0x43, 0x14}) | ||
require.NoError(t, err) | ||
|
||
retrievedData, err := store.Retrieve(bid, bid.AllowedPeekers[0], "xx") | ||
require.NoError(t, err) | ||
require.Equal(t, []byte{0x43, 0x14}, retrievedData) | ||
|
||
bids := store.FetchBidsByProtocolAndBlock(10, "default:v0:ethBundles") | ||
require.Len(t, bids, 1) | ||
require.Equal(t, bid, bids[0]) | ||
} |
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 |
---|---|---|
|
@@ -112,10 +112,15 @@ func (r *RedisStoreBackend) InitializeBid(bid suave.Bid) error { | |
return err | ||
} | ||
|
||
err = r.indexBid(bid) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *RedisStoreBackend) FetchEngineBidById(bidId suave.BidId) (suave.Bid, error) { | ||
func (r *RedisStoreBackend) FetchBidById(bidId suave.BidId) (suave.Bid, error) { | ||
key := formatRedisBidKey(bidId) | ||
|
||
data, err := r.client.Get(r.ctx, key).Bytes() | ||
|
@@ -158,44 +163,39 @@ var ( | |
mempoolConfidentialStoreBid = suave.Bid{Id: mempoolConfStoreId, AllowedPeekers: []common.Address{mempoolConfStoreAddr}} | ||
) | ||
|
||
func (r *RedisStoreBackend) SubmitBid(bid types.Bid) error { | ||
func (r *RedisStoreBackend) indexBid(bid suave.Bid) error { | ||
defer log.Info("bid submitted", "bid", bid, "store", r.Store) | ||
|
||
var bidsByBlockAndProtocol []types.Bid | ||
var bidsByBlockAndProtocol []suave.BidId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indexing was changed to include only the bid id and no add extra space storing the bids again. |
||
bidsByBlockAndProtocolBytes, err := r.Retrieve(mempoolConfidentialStoreBid, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", bid.Version, bid.DecryptionCondition)) | ||
if err == nil { | ||
bidsByBlockAndProtocol = suave.MustDecode[[]types.Bid](bidsByBlockAndProtocolBytes) | ||
bidsByBlockAndProtocol = suave.MustDecode[[]suave.BidId](bidsByBlockAndProtocolBytes) | ||
} | ||
// store bid by block number and by protocol + block number | ||
bidsByBlockAndProtocol = append(bidsByBlockAndProtocol, bid) | ||
bidsByBlockAndProtocol = append(bidsByBlockAndProtocol, bid.Id) | ||
|
||
r.Store(mempoolConfidentialStoreBid, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", bid.Version, bid.DecryptionCondition), suave.MustEncode(bidsByBlockAndProtocol)) | ||
|
||
return nil | ||
} | ||
|
||
func (r *RedisStoreBackend) FetchBidById(bidId suave.BidId) (types.Bid, error) { | ||
engineBid, err := r.FetchEngineBidById(bidId) | ||
if err != nil { | ||
log.Error("bid missing!", "id", bidId, "err", err) | ||
return types.Bid{}, errors.New("not found") | ||
} | ||
|
||
return types.Bid{ | ||
Id: engineBid.Id, | ||
Salt: engineBid.Salt, | ||
DecryptionCondition: engineBid.DecryptionCondition, | ||
AllowedPeekers: engineBid.AllowedPeekers, | ||
AllowedStores: engineBid.AllowedStores, | ||
Version: engineBid.Version, | ||
}, nil | ||
} | ||
|
||
func (r *RedisStoreBackend) FetchBidsByProtocolAndBlock(blockNumber uint64, namespace string) []types.Bid { | ||
func (r *RedisStoreBackend) FetchBidsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.Bid { | ||
bidsByProtocolBytes, err := r.Retrieve(mempoolConfidentialStoreBid, mempoolConfStoreAddr, fmt.Sprintf("protocol-%s-bn-%d", namespace, blockNumber)) | ||
if err != nil { | ||
return nil | ||
} | ||
defer log.Info("bids fetched", "bids", string(bidsByProtocolBytes)) | ||
return suave.MustDecode[[]types.Bid](bidsByProtocolBytes) | ||
|
||
res := []suave.Bid{} | ||
|
||
bidIDs := suave.MustDecode[[]suave.BidId](bidsByProtocolBytes) | ||
for _, id := range bidIDs { | ||
bid, err := r.FetchBidById(id) | ||
if err != nil { | ||
continue | ||
} | ||
res = append(res, bid) | ||
} | ||
|
||
// defer log.Info("bids fetched", "bids", string(bidsByProtocolBytes)) | ||
return res | ||
} |
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,14 @@ | ||
package backends | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRedis_StoreSuite(t *testing.T) { | ||
store := NewRedisStoreBackend("") | ||
require.NoError(t, store.Start()) | ||
|
||
testBackendStore(t, store) | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A generic testing suite for any type of backend store.