Skip to content

Commit

Permalink
shutter: listen for decryption keys (#13306)
Browse files Browse the repository at this point in the history
closes #13191
  • Loading branch information
taratorio authored Jan 13, 2025
1 parent e2563f8 commit cc9388b
Show file tree
Hide file tree
Showing 17 changed files with 1,733 additions and 41 deletions.
28 changes: 18 additions & 10 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,13 +1092,17 @@ var (
Usage: "Enable 'chaos monkey' to generate spontaneous network/consensus/etc failures. Use ONLY for testing",
Value: false,
}
ShutterEnabled = cli.BoolFlag{
ShutterEnabledFlag = cli.BoolFlag{
Name: "shutter",
Usage: "Enable the Shutter encrypted transactions mempool (defaults to false)",
}
ShutterKeyperBootnodes = cli.StringSliceFlag{
Name: "shutter.keyper.bootnodes",
Usage: "Use to override the default keyper bootnodes (defaults to using the bootnodes from the embedded config)",
ShutterP2pBootstrapNodesFlag = cli.StringSliceFlag{
Name: "shutter.p2p.bootstrap.nodes",
Usage: "Use to override the default p2p bootstrap nodes (defaults to using the values in the embedded config)",
}
ShutterP2pListenPortFlag = cli.UintFlag{
Name: "shutter.p2p.listen.port",
Usage: "Use to override the default p2p listen port (defaults to 23102)",
}
)

Expand Down Expand Up @@ -1582,18 +1586,22 @@ func setTxPool(ctx *cli.Context, dbDir string, fullCfg *ethconfig.Config) {
fullCfg.TxPool = cfg
}

func setShutter(ctx *cli.Context, chainName string, cfg *ethconfig.Config) {
if enabled := ctx.Bool(ShutterEnabled.Name); !enabled {
func setShutter(ctx *cli.Context, chainName string, nodeConfig *nodecfg.Config, ethConfig *ethconfig.Config) {
if enabled := ctx.Bool(ShutterEnabledFlag.Name); !enabled {
return
}

config := shutter.ConfigByChainName(chainName)
config.PrivateKey = nodeConfig.P2P.PrivateKey
// check for cli overrides
if ctx.IsSet(ShutterKeyperBootnodes.Name) {
config.KeyperBootnodes = ctx.StringSlice(ShutterKeyperBootnodes.Name)
if ctx.IsSet(ShutterP2pBootstrapNodesFlag.Name) {
config.BootstrapNodes = ctx.StringSlice(ShutterP2pBootstrapNodesFlag.Name)
}
if ctx.IsSet(ShutterP2pListenPortFlag.Name) {
config.ListenPort = ctx.Uint64(ShutterP2pListenPortFlag.Name)
}

cfg.Shutter = config
ethConfig.Shutter = config
}

func setEthash(ctx *cli.Context, datadir string, cfg *ethconfig.Config) {
Expand Down Expand Up @@ -1898,7 +1906,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
setGPO(ctx, &cfg.GPO)

setTxPool(ctx, nodeConfig.Dirs.TxPool, cfg)
setShutter(ctx, chain, cfg)
setShutter(ctx, chain, nodeConfig, cfg)

setEthash(ctx, nodeConfig.Dirs.DataDir, cfg)
setClique(ctx, &cfg.Clique, nodeConfig.Dirs.DataDir)
Expand Down
16 changes: 14 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,11 +1589,23 @@ func (s *Ethereum) Start() error {
// 1) Hive tests requires us to do so and starting it from eth_sendRawTransaction is not viable as we have not enough data
// to initialize it properly.
// 2) we cannot propose for block 1 regardless.
s.bgComponentsEg.Go(func() error { return s.txPool.Run(s.sentryCtx) })
s.bgComponentsEg.Go(func() error {
err := s.txPool.Run(s.sentryCtx)
if err != nil {
s.logger.Error("txPool.Run error", "err", err)
}
return err
})
}

if s.shutterPool != nil {
s.bgComponentsEg.Go(func() error { return s.shutterPool.Run(s.sentryCtx) })
s.bgComponentsEg.Go(func() error {
err := s.shutterPool.Run(s.sentryCtx)
if err != nil {
s.logger.Error("shutterPool.Run error", "err", err)
}
return err
})
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ var DefaultFlags = []cli.Flag{

&utils.ChaosMonkeyFlag,

&utils.ShutterEnabled,
&utils.ShutterKeyperBootnodes,
&utils.ShutterEnabledFlag,
&utils.ShutterP2pBootstrapNodesFlag,
&utils.ShutterP2pListenPortFlag,
}
1 change: 1 addition & 0 deletions txnprovider/shutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
37 changes: 37 additions & 0 deletions txnprovider/shutter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GOBINREL = build/bin
GOBIN = $(CURDIR)/$(GOBINREL)

OS = $(shell uname -s)
ARCH = $(shell uname -m)

ifeq ($(OS),Darwin)
PROTOC_OS := osx
ifeq ($(ARCH),arm64)
ARCH = aarch_64
endif
endif
ifeq ($(OS),Linux)
PROTOC_OS = linux
endif

PROTOC_INCLUDE = build/include/google
PROTO_DIR = $(CURDIR)/proto

$(GOBINREL):
mkdir -p "$(GOBIN)"

$(GOBINREL)/protoc: $(GOBINREL)
$(eval PROTOC_TMP := $(shell mktemp -d))
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v27.1/protoc-27.1-$(PROTOC_OS)-$(ARCH).zip -o "$(PROTOC_TMP)/protoc.zip"
cd "$(PROTOC_TMP)" && unzip protoc.zip
cp "$(PROTOC_TMP)/bin/protoc" "$(GOBIN)"
mkdir -p "$(PROTOC_INCLUDE)"
cp -R "$(PROTOC_TMP)/include/google/" "$(PROTOC_INCLUDE)"
rm -rf "$(PROTOC_TMP)"

$(GOBINREL)/protoc-gen-go: $(GOBINREL)
go build -o "$(GOBIN)/protoc-gen-go" google.golang.org/protobuf/cmd/protoc-gen-go

.PHONY: proto
proto: $(GOBINREL)/protoc $(GOBINREL)/protoc-gen-go
PATH="$(GOBIN):$(PATH)" protoc -I=$(PROTO_DIR) --go_out=$(PROTO_DIR) $(PROTO_DIR)/shutter.proto
75 changes: 59 additions & 16 deletions txnprovider/shutter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,48 @@
package shutter

import (
"crypto/ecdsa"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"

"github.com/erigontech/erigon-lib/chain/networkname"
"github.com/erigontech/erigon/params"
)

type Config struct {
Enabled bool `json:"-"`
InstanceId uint64 `json:"instanceId"`
SequencerContractAddress string `json:"sequencerContractAddress"`
ValidatorRegistryContractAddress string `json:"validatorRegistryContractAddress"`
KeyBroadcastContractAddress string `json:"keyBroadcastContractAddress"`
KeyperSetManagerContractAddress string `json:"keyperSetManagerContractAddress"`
KeyperBootnodes []string `json:"keyperBootnodes"`
P2pConfig
Enabled bool
InstanceId uint64
SequencerContractAddress string
ValidatorRegistryContractAddress string
KeyBroadcastContractAddress string
KeyperSetManagerContractAddress string
MaxNumKeysPerMessage uint64
}

type P2pConfig struct {
PrivateKey *ecdsa.PrivateKey
ListenPort uint64
BootstrapNodes []string
}

func (c P2pConfig) BootstrapNodesAddrInfo() ([]peer.AddrInfo, error) {
addrInfos := make([]peer.AddrInfo, len(c.BootstrapNodes))
for i, node := range c.BootstrapNodes {
ma, err := multiaddr.NewMultiaddr(node)
if err != nil {
return nil, err
}

ai, err := peer.AddrInfoFromP2pAddr(ma)
if err != nil {
return nil, err
}

addrInfos[i] = *ai
}

return addrInfos, nil
}

func ConfigByChainName(chainName string) Config {
Expand All @@ -45,27 +75,40 @@ func ConfigByChainName(chainName string) Config {
var (
chiadoConfig = Config{
Enabled: true,
InstanceId: params.ChiadoChainConfig.ChainID.Uint64(),
InstanceId: 102_000,
SequencerContractAddress: "0x2aD8E2feB0ED5b2EC8e700edB725f120576994ed",
ValidatorRegistryContractAddress: "0xa9289A3Dd14FEBe10611119bE81E5d35eAaC3084",
KeyBroadcastContractAddress: "0x9D31865BEffcE842FBd36CDA587aDDA8bef804B7",
KeyperSetManagerContractAddress: "0xC4DE9FAf4ec882b33dA0162CBE628B0D8205D0c0",
KeyperBootnodes: []string{
"/ip4/167.99.177.227/tcp/23005/p2p/12D3KooWSdm5guPBdn8DSaBphVBzUUgPLg9sZLnazEUrcbtLy254",
"/ip4/159.89.15.119/tcp/23005/p2p/12D3KooWPP6bp2PJQR8rUvG1SD4qNH4WFrKve6DMgWThyKxwNbbH",
MaxNumKeysPerMessage: defaultMaxNumKeysPerMessage,
P2pConfig: P2pConfig{
ListenPort: defaultP2PListenPort,
BootstrapNodes: []string{
"/ip4/167.99.177.227/tcp/23005/p2p/12D3KooWSdm5guPBdn8DSaBphVBzUUgPLg9sZLnazEUrcbtLy254",
"/ip4/159.89.15.119/tcp/23005/p2p/12D3KooWPP6bp2PJQR8rUvG1SD4qNH4WFrKve6DMgWThyKxwNbbH",
},
},
}

gnosisConfig = Config{
Enabled: true,
InstanceId: params.GnosisChainConfig.ChainID.Uint64(),
InstanceId: 1_000,
SequencerContractAddress: "0xc5C4b277277A1A8401E0F039dfC49151bA64DC2E",
ValidatorRegistryContractAddress: "0xefCC23E71f6bA9B22C4D28F7588141d44496A6D6",
KeyBroadcastContractAddress: "0x626dB87f9a9aC47070016A50e802dd5974341301",
KeyperSetManagerContractAddress: "0x7C2337f9bFce19d8970661DA50dE8DD7d3D34abb",
KeyperBootnodes: []string{
"/ip4/167.99.177.227/tcp/23003/p2p/12D3KooWD35AESYCttDEi3J5WnQdTFuM5JNtmuXEb1x4eQ28gb1s",
"/ip4/159.89.15.119/tcp/23003/p2p/12D3KooWRzAhgPA16DiBQhiuYoasYzJaQSAbtc5i5FvgTi9ZDQtS",
MaxNumKeysPerMessage: defaultMaxNumKeysPerMessage,
P2pConfig: P2pConfig{
ListenPort: defaultP2PListenPort,
BootstrapNodes: []string{
"/ip4/167.99.177.227/tcp/23003/p2p/12D3KooWD35AESYCttDEi3J5WnQdTFuM5JNtmuXEb1x4eQ28gb1s",
"/ip4/159.89.15.119/tcp/23003/p2p/12D3KooWRzAhgPA16DiBQhiuYoasYzJaQSAbtc5i5FvgTi9ZDQtS",
},
},
}
)

const (
defaultP2PListenPort = 23_102
defaultMaxNumKeysPerMessage = 500
)
Loading

0 comments on commit cc9388b

Please sign in to comment.