Skip to content

Commit a8f8282

Browse files
Merge pull request #560 from shutter-network/shutter-service
Shutter service
2 parents c4980f3 + 1e67b7a commit a8f8282

33 files changed

+3517
-148
lines changed

rolling-shutter/cmd/command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/gnosiskeyper"
1111
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/optimism"
1212
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/p2pnode"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shutterservicekeyper"
1314
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/snapshot"
1415
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/snapshotkeyper"
1516
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/rootcmd"
@@ -27,6 +28,7 @@ func Subcommands() []*cobra.Command {
2728
gnosisaccessnode.Cmd(),
2829
cryptocmd.Cmd(),
2930
p2pnode.Cmd(),
31+
shutterservicekeyper.Cmd(),
3032
}
3133
}
3234

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package shutterservicekeyper
2+
3+
import (
4+
"context"
5+
6+
"github.com/jackc/pgx/v4/pgxpool"
7+
"github.com/pkg/errors"
8+
"github.com/rs/zerolog/log"
9+
"github.com/spf13/cobra"
10+
11+
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shversion"
12+
keyper "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/shutterservice"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/shutterservice/database"
14+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration/command"
15+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/db"
16+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
17+
)
18+
19+
func Cmd() *cobra.Command {
20+
builder := command.Build(
21+
main,
22+
command.Usage(
23+
"Run a Shutter keyper for Shutter Service",
24+
`This command runs a keyper node. It will connect to both a Shutter service and a
25+
Shuttermint node which have to be started separately in advance.`,
26+
),
27+
command.WithGenerateConfigSubcommand(),
28+
command.WithDumpConfigSubcommand(),
29+
)
30+
builder.AddInitDBCommand(initDB)
31+
return builder.Command()
32+
}
33+
34+
func main(config *keyper.Config) error {
35+
log.Info().
36+
Str("version", shversion.Version()).
37+
Str("address", config.GetAddress().Hex()).
38+
Str("shuttermint", config.Shuttermint.ShuttermintURL).
39+
Msg("starting shutter service keyper")
40+
41+
kpr := keyper.New(config)
42+
return service.RunWithSighandler(context.Background(), kpr)
43+
}
44+
45+
func initDB(cfg *keyper.Config) error {
46+
ctx := context.Background()
47+
dbpool, err := pgxpool.Connect(ctx, cfg.DatabaseURL)
48+
if err != nil {
49+
return errors.Wrap(err, "failed to connect to database")
50+
}
51+
defer dbpool.Close()
52+
return db.InitDB(ctx, dbpool, database.Definition.Name(), database.Definition)
53+
}

rolling-shutter/docs/rolling-shutter.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ A collection of commands to run and interact with Rolling Shutter nodes
2121
* [rolling-shutter op-bootstrap](rolling-shutter_op-bootstrap.md) - Bootstrap validator utility functions for a shuttermint chain
2222
* [rolling-shutter op-keyper](rolling-shutter_op-keyper.md) - Run a Shutter optimism keyper node
2323
* [rolling-shutter p2pnode](rolling-shutter_p2pnode.md) - Run a Shutter p2p bootstrap node
24+
* [rolling-shutter shutterservicekeyper](rolling-shutter_shutterservicekeyper.md) - Run a Shutter keyper for Shutter Service
2425
* [rolling-shutter snapshot](rolling-shutter_snapshot.md) - Run the Snapshot Hub communication module
2526
* [rolling-shutter snapshotkeyper](rolling-shutter_snapshotkeyper.md) - Run a Shutter snapshotkeyper node
2627

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## rolling-shutter shutterservicekeyper
2+
3+
Run a Shutter keyper for Shutter Service
4+
5+
### Synopsis
6+
7+
This command runs a keyper node. It will connect to both a Shutter service and a
8+
Shuttermint node which have to be started separately in advance.
9+
10+
```
11+
rolling-shutter shutterservicekeyper [flags]
12+
```
13+
14+
### Options
15+
16+
```
17+
--config string config file
18+
-h, --help help for shutterservicekeyper
19+
```
20+
21+
### Options inherited from parent commands
22+
23+
```
24+
--logformat string set log format, possible values: min, short, long, max (default "long")
25+
--loglevel string set log level, possible values: warn, info, debug (default "info")
26+
--no-color do not write colored logs
27+
```
28+
29+
### SEE ALSO
30+
31+
* [rolling-shutter](rolling-shutter.md) - A collection of commands to run and interact with Rolling Shutter nodes
32+
* [rolling-shutter shutterservicekeyper dump-config](rolling-shutter_shutterservicekeyper_dump-config.md) - Dump a 'shutterservicekeyper' configuration file, based on given config and env vars
33+
* [rolling-shutter shutterservicekeyper generate-config](rolling-shutter_shutterservicekeyper_generate-config.md) - Generate a 'shutterservicekeyper' configuration file
34+
* [rolling-shutter shutterservicekeyper initdb](rolling-shutter_shutterservicekeyper_initdb.md) - Initialize the database of the 'shutterservicekeyper'
35+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## rolling-shutter shutterservicekeyper dump-config
2+
3+
Dump a 'shutterservicekeyper' configuration file, based on given config and env vars
4+
5+
```
6+
rolling-shutter shutterservicekeyper dump-config [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--config string config file
13+
-f, --force overwrite existing file
14+
-h, --help help for dump-config
15+
--output string output file
16+
```
17+
18+
### Options inherited from parent commands
19+
20+
```
21+
--logformat string set log format, possible values: min, short, long, max (default "long")
22+
--loglevel string set log level, possible values: warn, info, debug (default "info")
23+
--no-color do not write colored logs
24+
```
25+
26+
### SEE ALSO
27+
28+
* [rolling-shutter shutterservicekeyper](rolling-shutter_shutterservicekeyper.md) - Run a Shutter keyper for Shutter Service
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## rolling-shutter shutterservicekeyper generate-config
2+
3+
Generate a 'shutterservicekeyper' configuration file
4+
5+
```
6+
rolling-shutter shutterservicekeyper generate-config [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-f, --force overwrite existing file
13+
-h, --help help for generate-config
14+
--output string output file
15+
```
16+
17+
### Options inherited from parent commands
18+
19+
```
20+
--config string config file
21+
--logformat string set log format, possible values: min, short, long, max (default "long")
22+
--loglevel string set log level, possible values: warn, info, debug (default "info")
23+
--no-color do not write colored logs
24+
```
25+
26+
### SEE ALSO
27+
28+
* [rolling-shutter shutterservicekeyper](rolling-shutter_shutterservicekeyper.md) - Run a Shutter keyper for Shutter Service
29+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## rolling-shutter shutterservicekeyper initdb
2+
3+
Initialize the database of the 'shutterservicekeyper'
4+
5+
```
6+
rolling-shutter shutterservicekeyper initdb [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for initdb
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--config string config file
19+
--logformat string set log format, possible values: min, short, long, max (default "long")
20+
--loglevel string set log level, possible values: warn, info, debug (default "info")
21+
--no-color do not write colored logs
22+
```
23+
24+
### SEE ALSO
25+
26+
* [rolling-shutter shutterservicekeyper](rolling-shutter_shutterservicekeyper.md) - Run a Shutter keyper for Shutter Service
27+

rolling-shutter/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/pkg/errors v0.9.1
3232
github.com/prometheus/client_golang v1.19.1
3333
github.com/rs/zerolog v1.28.0
34+
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a
3435
github.com/shutter-network/gnosh-contracts v0.4.0
3536
github.com/shutter-network/shop-contracts v0.0.0-20240407151512-08ef5d8355b6
3637
github.com/shutter-network/shutter/shlib v0.1.19

rolling-shutter/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.
864864
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
865865
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
866866
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
867+
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a h1:hWw2nJLGPZU7Rvd6YmEEDfvlTUbwZKZl5UP2ThVVNSU=
868+
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a/go.mod h1:V8KhVM75wyWVSzZJ6GeC9dWCjRrinIQVb7mYNP+knbg=
867869
github.com/shutter-network/gnosh-contracts v0.4.0 h1:2GJcHK9w4lJZMsccklmxDhNnrkRLJDRwsL1acBnAeak=
868870
github.com/shutter-network/gnosh-contracts v0.4.0/go.mod h1:QB0d64ybbVFKMrLjrc1tldri87KNjTmKQjhk9jaso2E=
869871
github.com/shutter-network/shop-contracts v0.0.0-20240407151512-08ef5d8355b6 h1:m6Ti1/IH+GBTtGqyAX3xbh+ruUKvC+m+/uzYDUa+JDQ=
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package shutterservice
2+
3+
import (
4+
"io"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/kprconfig"
9+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration"
10+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/metricsserver"
11+
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
12+
)
13+
14+
var (
15+
_ configuration.Config = &Config{}
16+
_ configuration.Config = &ChainConfig{}
17+
_ configuration.Config = &ContractsConfig{}
18+
)
19+
20+
func NewConfig() *Config {
21+
c := &Config{}
22+
c.Init()
23+
return c
24+
}
25+
26+
func (c *Config) Init() {
27+
c.P2P = p2p.NewConfig()
28+
c.Shuttermint = kprconfig.NewShuttermintConfig()
29+
c.Metrics = metricsserver.NewConfig()
30+
c.Chain = NewChainConfig()
31+
}
32+
33+
type Config struct {
34+
InstanceID uint64 `shconfig:",required"`
35+
DatabaseURL string `shconfig:",required" comment:"If it's empty, we use the standard PG_ environment variables"`
36+
37+
HTTPEnabled bool
38+
HTTPListenAddress string
39+
40+
Chain *ChainConfig
41+
P2P *p2p.Config
42+
Shuttermint *kprconfig.ShuttermintConfig
43+
Metrics *metricsserver.MetricsConfig
44+
45+
MaxNumKeysPerMessage uint64
46+
}
47+
48+
func (c *Config) Validate() error {
49+
// TODO: needs to be implemented
50+
return nil
51+
}
52+
53+
func (c *Config) Name() string {
54+
return "shutterservicekeyper"
55+
}
56+
57+
func (c *Config) SetDefaultValues() error {
58+
c.HTTPEnabled = false
59+
c.HTTPListenAddress = ":3000"
60+
c.MaxNumKeysPerMessage = 500 // TODO: need to confirm on this
61+
return nil
62+
}
63+
64+
func (c *Config) SetExampleValues() error {
65+
err := c.SetDefaultValues()
66+
if err != nil {
67+
return err
68+
}
69+
c.InstanceID = 42
70+
c.DatabaseURL = "postgres://pguser:pgpassword@localhost:5432/shutter"
71+
72+
return nil
73+
}
74+
75+
func (c Config) TOMLWriteHeader(_ io.Writer) (int, error) {
76+
return 0, nil
77+
}
78+
79+
func (c *Config) GetAddress() common.Address {
80+
return c.Chain.Node.PrivateKey.EthereumAddress()
81+
}
82+
83+
type ChainConfig struct {
84+
Node *configuration.EthnodeConfig `shconfig:",required"`
85+
Contracts *ContractsConfig `shconfig:",required"`
86+
SyncStartBlockNumber uint64 `shconfig:",required"`
87+
}
88+
89+
func NewChainConfig() *ChainConfig {
90+
c := &ChainConfig{
91+
Node: configuration.NewEthnodeConfig(),
92+
Contracts: NewContractsConfig(),
93+
SyncStartBlockNumber: 0,
94+
}
95+
c.Init()
96+
return c
97+
}
98+
99+
func (c *ChainConfig) Init() {
100+
c.Node.Init()
101+
c.Contracts.Init()
102+
}
103+
104+
func (c *ChainConfig) Name() string {
105+
return "chain"
106+
}
107+
108+
func (c *ChainConfig) Validate() error {
109+
return nil
110+
}
111+
112+
func (c *ChainConfig) SetDefaultValues() error {
113+
c.SyncStartBlockNumber = 0
114+
return c.Contracts.SetDefaultValues()
115+
}
116+
117+
func (c *ChainConfig) SetExampleValues() error {
118+
return nil
119+
}
120+
121+
func (c *ChainConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
122+
return 0, nil
123+
}
124+
125+
type ContractsConfig struct {
126+
KeyperSetManager common.Address `shconfig:",required"`
127+
ShutterRegistry common.Address `shconfig:",required"`
128+
KeyBroadcastContract common.Address `shconfig:",required"`
129+
}
130+
131+
func NewContractsConfig() *ContractsConfig {
132+
return &ContractsConfig{
133+
KeyperSetManager: common.Address{},
134+
ShutterRegistry: common.Address{},
135+
KeyBroadcastContract: common.Address{},
136+
}
137+
}
138+
139+
func (c *ContractsConfig) Init() {}
140+
141+
func (c *ContractsConfig) Name() string {
142+
return "contracts"
143+
}
144+
145+
func (c *ContractsConfig) Validate() error {
146+
return nil
147+
}
148+
149+
func (c *ContractsConfig) SetDefaultValues() error {
150+
return nil
151+
}
152+
153+
func (c *ContractsConfig) SetExampleValues() error {
154+
return nil
155+
}
156+
157+
func (c *ContractsConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
158+
return 0, nil
159+
}

0 commit comments

Comments
 (0)