Skip to content

Commit

Permalink
Da store as a single package (#71)
Browse files Browse the repository at this point in the history
* Move things to custom package

* Move core types to cstore

* Finish

* Pass lint
  • Loading branch information
ferranbt authored Oct 20, 2023
1 parent dd3875e commit b157a4a
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 170 deletions.
12 changes: 6 additions & 6 deletions core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/suave/artifacts"
"github.com/ethereum/go-ethereum/suave/backends"
suave "github.com/ethereum/go-ethereum/suave/core"
"github.com/ethereum/go-ethereum/suave/cstore"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -61,11 +61,11 @@ func (m *mockSuaveBackend) BuildEthBlockFromBundles(ctx context.Context, args *s
return nil, nil
}

func (m *mockSuaveBackend) Subscribe() (<-chan suave.DAMessage, context.CancelFunc) {
func (m *mockSuaveBackend) Subscribe() (<-chan cstore.DAMessage, context.CancelFunc) {
return nil, func() {}
}

func (m *mockSuaveBackend) Publish(suave.DAMessage) {}
func (m *mockSuaveBackend) Publish(cstore.DAMessage) {}

var dummyBlockContext = BlockContext{
CanTransfer: func(StateDB, common.Address, *big.Int) bool { return true },
Expand All @@ -77,7 +77,7 @@ func TestSuavePrecompileStub(t *testing.T) {
// This test ensures that the Suave precompile stubs work as expected
// for encoding/decoding.
mockSuaveBackend := &mockSuaveBackend{}
stubEngine := suave.NewConfidentialStoreEngine(mockSuaveBackend, mockSuaveBackend, suave.MockSigner{}, suave.MockChainSigner{})
stubEngine := cstore.NewConfidentialStoreEngine(mockSuaveBackend, mockSuaveBackend, cstore.MockSigner{}, cstore.MockChainSigner{})

reqTx := types.NewTx(&types.ConfidentialComputeRequest{
ConfidentialComputeRecord: types.ConfidentialComputeRecord{
Expand Down Expand Up @@ -142,8 +142,8 @@ func TestSuavePrecompileStub(t *testing.T) {
}

func newTestBackend(t *testing.T) *suaveRuntime {
confStore := backends.NewLocalConfidentialStore()
confEngine := suave.NewConfidentialStoreEngine(confStore, &suave.MockTransport{}, suave.MockSigner{}, suave.MockChainSigner{})
confStore := cstore.NewLocalConfidentialStore()
confEngine := cstore.NewConfidentialStoreEngine(confStore, &cstore.MockTransport{}, cstore.MockSigner{}, cstore.MockChainSigner{})

require.NoError(t, confEngine.Start())
t.Cleanup(func() { confEngine.Stop() })
Expand Down
5 changes: 3 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
suave "github.com/ethereum/go-ethereum/suave/core"
"github.com/ethereum/go-ethereum/suave/cstore"
)

// EthAPIBackend implements ethapi.Backend for full nodes
Expand All @@ -49,12 +50,12 @@ type EthAPIBackend struct {
allowUnprotectedTxs bool
eth *Ethereum
gpo *gasprice.Oracle
suaveEngine *suave.ConfidentialStoreEngine
suaveEngine *cstore.ConfidentialStoreEngine
suaveEthBackend suave.ConfidentialEthBackend
}

// For testing purposes
func (b *EthAPIBackend) SuaveEngine() *suave.ConfidentialStoreEngine {
func (b *EthAPIBackend) SuaveEngine() *cstore.ConfidentialStoreEngine {
return b.suaveEngine
}

Expand Down
20 changes: 12 additions & 8 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
"github.com/ethereum/go-ethereum/suave/backends"
suave_backends "github.com/ethereum/go-ethereum/suave/backends"
suave "github.com/ethereum/go-ethereum/suave/core"
"github.com/ethereum/go-ethereum/suave/cstore"
)

// Config contains the configuration options of the ETH protocol.
Expand Down Expand Up @@ -230,18 +231,21 @@ 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))

var confidentialStoreBackend suave.ConfidentialStoreBackend
var confidentialStoreBackend cstore.ConfidentialStorageBackend
if config.Suave.RedisStoreUri != "" {
confidentialStoreBackend = suave_backends.NewRedisStoreBackend(config.Suave.RedisStoreUri)
confidentialStoreBackend, err = cstore.NewRedisStoreBackend(config.Suave.RedisStoreUri)
if err != nil {
return nil, err
}
} else {
confidentialStoreBackend = suave_backends.NewLocalConfidentialStore()
confidentialStoreBackend = cstore.NewLocalConfidentialStore()
}

var confidentialStoreTransport suave.StoreTransportTopic
var confidentialStoreTransport cstore.StoreTransportTopic
if config.Suave.RedisStorePubsubUri != "" {
confidentialStoreTransport = suave_backends.NewRedisPubSubTransport(config.Suave.RedisStorePubsubUri)
confidentialStoreTransport = cstore.NewRedisPubSubTransport(config.Suave.RedisStorePubsubUri)
} else {
confidentialStoreTransport = suave.MockTransport{}
confidentialStoreTransport = cstore.MockTransport{}
}

var suaveEthBackend suave.ConfidentialEthBackend
Expand All @@ -251,9 +255,9 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
suaveEthBackend = &suave_backends.EthMock{}
}

suaveDaSigner := &suave_backends.AccountManagerDASigner{Manager: eth.AccountManager()}
suaveDaSigner := &cstore.AccountManagerDASigner{Manager: eth.AccountManager()}

confidentialStoreEngine := suave.NewConfidentialStoreEngine(confidentialStoreBackend, confidentialStoreTransport, suaveDaSigner, types.LatestSigner(chainConfig))
confidentialStoreEngine := cstore.NewConfidentialStoreEngine(confidentialStoreBackend, confidentialStoreTransport, suaveDaSigner, types.LatestSigner(chainConfig))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil, confidentialStoreEngine, suaveEthBackend}
if eth.APIBackend.allowUnprotectedTxs {
Expand Down
14 changes: 0 additions & 14 deletions suave/backends/redis_store_backend_test.go

This file was deleted.

31 changes: 0 additions & 31 deletions suave/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/node"
"github.com/google/uuid"
)

type Bytes = hexutil.Bytes
Expand Down Expand Up @@ -48,16 +47,6 @@ var (
ErrUnsignedFinalize = errors.New("finalize called with unsigned transaction, refusing to propagate")
)

type DASigner interface {
Sign(account common.Address, data []byte) ([]byte, error)
Sender(data []byte, signature []byte) (common.Address, error)
LocalAddresses() []common.Address
}

type ChainSigner interface {
Sender(tx *types.Transaction) (common.Address, error)
}

type ConfidentialStoreBackend interface {
node.Lifecycle

Expand All @@ -72,23 +61,3 @@ type ConfidentialEthBackend interface {
BuildEthBlock(ctx context.Context, args *BuildBlockArgs, txs types.Transactions) (*engine.ExecutionPayloadEnvelope, error)
BuildEthBlockFromBundles(ctx context.Context, args *BuildBlockArgs, bundles []types.SBundle) (*engine.ExecutionPayloadEnvelope, error)
}

type StoreTransportTopic interface {
node.Lifecycle
Subscribe() (<-chan DAMessage, context.CancelFunc)
Publish(DAMessage)
}

type DAMessage struct {
SourceTx *types.Transaction `json:"sourceTx"`
StoreWrites []StoreWrite `json:"storeWrites"`
StoreUUID uuid.UUID `json:"storeUUID"`
Signature Bytes `json:"signature"`
}

type StoreWrite struct {
Bid Bid `json:"bid"`
Caller common.Address `json:"caller"`
Key string `json:"key"`
Value Bytes `json:"value"`
}
18 changes: 0 additions & 18 deletions suave/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,11 @@ package suave

import (
"encoding/json"
"fmt"

"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
)

var bidUuidSpace = uuid.UUID{0x42}
var emptyId [16]byte

func calculateBidId(bid types.Bid) (types.BidId, error) {
copy(bid.Id[:], emptyId[:])

body, err := json.Marshal(bid)
if err != nil {
return types.BidId{}, fmt.Errorf("could not marshal bid to calculate its id: %w", err)
}

uuidv5 := uuid.NewSHA1(bidUuidSpace, body)
copy(bid.Id[:], uuidv5[:])

return bid.Id, nil
}

func RandomBidId() types.BidId {
return types.BidId(uuid.New())
}
Expand Down
2 changes: 1 addition & 1 deletion suave/backends/am_signer.go → suave/cstore/am_signer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backends
package cstore

import (
"github.com/ethereum/go-ethereum/accounts"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backends
package cstore

import (
"testing"
Expand All @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

func testBackendStore(t *testing.T, store suave.ConfidentialStoreBackend) {
func testBackendStore(t *testing.T, store ConfidentialStorageBackend) {
bid := suave.Bid{
Id: suave.RandomBidId(),
DecryptionCondition: 10,
Expand Down
Loading

0 comments on commit b157a4a

Please sign in to comment.