Skip to content

Commit

Permalink
Add reset method to remove the local confidential store (#163)
Browse files Browse the repository at this point in the history
* Reset conf store

* Fix attach
  • Loading branch information
ferranbt authored Jan 18, 2024
1 parent ca7a24f commit 1cd057c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

const (
ipcAPIs = "admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 suavex:1.0 txpool:1.0 web3:1.0"
ipcAPIs = "admin:1.0 clique:1.0 debug:1.0 engine:1.0 eth:1.0 miner:1.0 net:1.0 rpc:1.0 suavex:1.0 suavey:1.0 txpool:1.0 web3:1.0"
httpAPIs = "eth:1.0 net:1.0 rpc:1.0 suavex:1.0 web3:1.0"
)

Expand Down
16 changes: 16 additions & 0 deletions cmd/geth/forgecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
Description: `Internal command used by MEVM precompiles in forge to access the MEVM API utilities.`,
Subcommands: []*cli.Command{
forgeStatusCmd,
resetConfStore,
},
Action: func(ctx *cli.Context) error {
args := ctx.Args()
Expand Down Expand Up @@ -129,3 +130,18 @@ var forgeStatusCmd = &cli.Command{
return nil
},
}

var resetConfStore = &cli.Command{
Name: "reset-conf-store",
Usage: "Internal command to reset the confidential store",
Action: func(ctx *cli.Context) error {
rpcClient, err := rpc.Dial(defaultRemoteSuaveHost)
if err != nil {
return err
}
if err := rpcClient.Call(nil, "suavey_resetConfStore"); err != nil {
return err
}
return nil
},
}
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ func prepareSuaveDev(ctx *cli.Context) error {
utils.HTTPVirtualHostsFlag.Name: "*",
utils.HTTPCORSDomainFlag.Name: "*",
utils.HTTPListenAddrFlag.Name: "0.0.0.0",
utils.HTTPApiFlag.Name: "suavex,debug,suavey,eth",
utils.WSEnabledFlag.Name: "true",
utils.WSAllowedOriginsFlag.Name: "*",
utils.WSListenAddrFlag.Name: "0.0.0.0",
Expand Down
6 changes: 6 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ func (s *Ethereum) APIs() []rpc.API {
Service: suave_builder_api.NewServer(sessionManager),
})

// if in devnet test mode, enable the suave dev jsonrpc endpoint
apis = append(apis, rpc.API{
Namespace: "suavey",
Service: &backends.SuaveInternalBackend{Cstore: s.APIBackend.SuaveEngine()},
})

// Append any APIs exposed explicitly by the consensus engine
apis = append(apis, s.engine.APIs(s.BlockChain())...)

Expand Down
21 changes: 21 additions & 0 deletions suave/backends/dev_suave_backend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package backends

import (
"context"

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

type confidentialStore interface {
Reset() error
}

// SuaveInternalBackend is a jsonrpc backend for internal suave testing
type SuaveInternalBackend struct {
Cstore confidentialStore
}

func (d *SuaveInternalBackend) ResetConfStore(ctx context.Context) error {
log.Info("Resetting Confidential Store")
return d.Cstore.Reset()
}
10 changes: 9 additions & 1 deletion suave/cstore/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func NewEngine(backend ConfidentialStorageBackend, transportTopic StoreTransport
}
}

func (e *CStoreEngine) Reset() error {
if local, ok := e.storage.(*LocalConfidentialStore); ok {
// only allow reset for local store
return local.Reset()
}
return nil
}

// NewTransactionalStore creates a new transactional store.
func (e *CStoreEngine) NewTransactionalStore(sourceTx *types.Transaction) *TransactionalStore {
return &TransactionalStore{
Expand Down Expand Up @@ -119,7 +127,7 @@ func (e *CStoreEngine) Start() error {
// Stop terminates the CStoreEngine.
func (e *CStoreEngine) Stop() error {
if e.cancel == nil {
return errors.New("Confidential engine: Stop() called before Start()")
return errors.New("confidential engine: Stop() called before Start()")
}

e.cancel()
Expand Down
11 changes: 11 additions & 0 deletions suave/cstore/local_store_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ func NewLocalConfidentialStore() *LocalConfidentialStore {
}
}

func (l *LocalConfidentialStore) Reset() error {
l.lock.Lock()
defer l.lock.Unlock()

l.records = make(map[suave.DataId]suave.DataRecord)
l.dataMap = make(map[string][]byte)
l.index = make(map[string][]suave.DataId)

return nil
}

func (l *LocalConfidentialStore) Stop() error {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion suave/cstore/redis_store_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *RedisStoreBackend) start() error {

func (r *RedisStoreBackend) Stop() error {
if r.cancel == nil || r.client == nil {
return errors.New("Redis store: Stop() called before Start()")
return errors.New("redis store: Stop() called before Start()")
}

if r.local != nil {
Expand Down
2 changes: 1 addition & 1 deletion suave/cstore/redis_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *RedisPubSubTransport) Start() error {

func (r *RedisPubSubTransport) Stop() error {
if r.cancel == nil || r.client == nil {
return errors.New("Redis pubsub: Stop() called before Start()")
return errors.New("redis pubsub: Stop() called before Start()")
}

r.cancel()
Expand Down

0 comments on commit 1cd057c

Please sign in to comment.