Skip to content
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

Shutter service #560

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ddb320a
shutter-service: basic setup
blockchainluffy Nov 27, 2024
873d0a7
shutter-service: added trigger conditions
blockchainluffy Nov 27, 2024
a631319
shutter-service: implemented triggers
blockchainluffy Nov 28, 2024
743de42
shutter-service: added command to run
blockchainluffy Nov 29, 2024
6121f53
shutter-service: added msg middleware
blockchainluffy Nov 29, 2024
7b9970a
shutter-service: implemented middleware for decryption keys message
blockchainluffy Dec 3, 2024
fb6db69
shutter-service: added message handlers
blockchainluffy Dec 3, 2024
c507bf1
shutter-service: update events table when keys are released
blockchainluffy Dec 3, 2024
0c8529d
shutter-service: fixed executable to run commands
blockchainluffy Dec 3, 2024
bb706eb
shutter-service: added registry syncer
blockchainluffy Dec 3, 2024
00f386a
shutter-service: updated database connectivity version
blockchainluffy Dec 4, 2024
7454b26
shutter-service: updated get registration query
blockchainluffy Dec 6, 2024
a6d37a2
add filte test
faheelsattar Dec 9, 2024
34e46c8
fix sql schema and queries
faheelsattar Dec 9, 2024
5ce9983
add insert test
faheelsattar Dec 9, 2024
c83d171
update error message
faheelsattar Dec 9, 2024
83cd239
fix logs
faheelsattar Dec 9, 2024
7040b64
shutter-service: tested registry syncer
blockchainluffy Dec 10, 2024
15cb080
shutter-service: updated queries and schema
blockchainluffy Dec 10, 2024
fd5253a
Merge pull request #564 from shutter-network/test/registry-event
faheelsattar Dec 10, 2024
616305d
shutter-service: updated decryption trigger handling
blockchainluffy Dec 10, 2024
4c505e9
shutter-service: updated decryption signature encoding
blockchainluffy Dec 10, 2024
00e5747
shutter-service: updated decryption signature table
blockchainluffy Dec 11, 2024
9e02271
add key share test
faheelsattar Dec 11, 2024
4681096
dec keys release test
faheelsattar Dec 11, 2024
146975d
upd doc
faheelsattar Dec 11, 2024
bade3e5
clean test
faheelsattar Dec 11, 2024
554afe9
validate and handle dec keys test
faheelsattar Dec 11, 2024
8964786
add invalidate dec key msg test
faheelsattar Dec 11, 2024
6aab5f6
shutter-service: added identity to registered events table
blockchainluffy Dec 12, 2024
4cfd837
shutter-service: fixed flag updation
blockchainluffy Dec 12, 2024
f52e859
Merge pull request #565 from shutter-network/test/new-handlers
blockchainluffy Dec 12, 2024
89577e7
shutter-service: fix error check
faheelsattar Dec 12, 2024
61a9f0b
process block test
faheelsattar Dec 13, 2024
f4e6001
add test for can be triggered
faheelsattar Dec 13, 2024
af1831b
shutter-serice: add test when decryption cant be triggered
faheelsattar Dec 13, 2024
33bef97
shutter-service: fix update latest trigger time after err check
faheelsattar Dec 13, 2024
3a615cf
shutter-service: remove unnecessary map initialization
faheelsattar Dec 13, 2024
9b73241
shutter-service: update latest trigger time at last
faheelsattar Dec 13, 2024
1a37167
shutter-service: fix pre commit
blockchainluffy Dec 16, 2024
7c72e6c
upd latestTriggeredTime at start
faheelsattar Dec 16, 2024
50e59ef
shutter-service: fix lint ci
blockchainluffy Dec 16, 2024
219a7bc
shutter-service: remove math/rand pkg
faheelsattar Dec 16, 2024
5f512cd
shutter-service: pass event without reference
faheelsattar Dec 16, 2024
b5c0de2
shutter-service: remove math/rand pkg
faheelsattar Dec 16, 2024
ba37ab3
shutter-service: upd random byte generator function
faheelsattar Dec 16, 2024
7425f0c
Merge branch 'shutter-service' into test/newblock-dec-trigger
faheelsattar Dec 16, 2024
5bb3141
Merge pull request #566 from shutter-network/test/newblock-dec-trigger
blockchainluffy Dec 16, 2024
77148df
shutter-service: fix precommit ci
blockchainluffy Dec 16, 2024
57f80ee
shutter-service: updated comment
blockchainluffy Dec 16, 2024
85e4578
shutter-service: update protoc version
blockchainluffy Dec 16, 2024
f6dc1a2
shutter-service: added helpers to test
blockchainluffy Dec 16, 2024
c98b26a
shutter-service: added readme files
blockchainluffy Dec 16, 2024
dee7f84
shutter-service: refactor test
blockchainluffy Dec 17, 2024
816c5e7
shutter-service: refactor test
blockchainluffy Dec 17, 2024
4953891
shutter-service: updated contracts version
blockchainluffy Dec 20, 2024
12c2328
shutter-service: updated contracts repo go module
blockchainluffy Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rolling-shutter/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/gnosiskeyper"
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/optimism"
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/p2pnode"
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shutterservice"
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/snapshot"
"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/snapshotkeyper"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/rootcmd"
Expand All @@ -27,6 +28,7 @@ func Subcommands() []*cobra.Command {
gnosisaccessnode.Cmd(),
cryptocmd.Cmd(),
p2pnode.Cmd(),
shutterservice.Cmd(),
}
}

Expand Down
53 changes: 53 additions & 0 deletions rolling-shutter/cmd/shutterservice/shutterservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package shutterservice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other keyper implementations all have keyper in their command name. I think we should keep that convention.


import (
"context"

"github.com/jackc/pgx/v4/pgxpool"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shversion"
keyper "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/shutterservice"
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/shutterservice/database"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration/command"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/db"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
)

func Cmd() *cobra.Command {
builder := command.Build(
main,
command.Usage(
"Run a Shutter keyper for Shutter Service",
`This command runs a keyper node. It will connect to both a Shutter service and a
Shuttermint node which have to be started separately in advance.`,
),
command.WithGenerateConfigSubcommand(),
command.WithDumpConfigSubcommand(),
)
builder.AddInitDBCommand(initDB)
return builder.Command()
}

func main(config *keyper.Config) error {
log.Info().
Str("version", shversion.Version()).
Str("address", config.GetAddress().Hex()).
Str("shuttermint", config.Shuttermint.ShuttermintURL).
Msg("starting shutter service keyper")

kpr := keyper.New(config)
return service.RunWithSighandler(context.Background(), kpr)
}

func initDB(cfg *keyper.Config) error {
ctx := context.Background()
dbpool, err := pgxpool.Connect(ctx, cfg.DatabaseURL)
if err != nil {
return errors.Wrap(err, "failed to connect to database")
}
defer dbpool.Close()
return db.InitDB(ctx, dbpool, database.Definition.Name(), database.Definition)
}
1 change: 1 addition & 0 deletions rolling-shutter/docs/rolling-shutter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A collection of commands to run and interact with Rolling Shutter nodes
* [rolling-shutter op-bootstrap](rolling-shutter_op-bootstrap.md) - Bootstrap validator utility functions for a shuttermint chain
* [rolling-shutter op-keyper](rolling-shutter_op-keyper.md) - Run a Shutter optimism keyper node
* [rolling-shutter p2pnode](rolling-shutter_p2pnode.md) - Run a Shutter p2p bootstrap node
* [rolling-shutter shutterservice](rolling-shutter_shutterservice.md) - Run a Shutter keyper for Shutter Service
* [rolling-shutter snapshot](rolling-shutter_snapshot.md) - Run the Snapshot Hub communication module
* [rolling-shutter snapshotkeyper](rolling-shutter_snapshotkeyper.md) - Run a Shutter snapshotkeyper node

35 changes: 35 additions & 0 deletions rolling-shutter/docs/rolling-shutter_shutterservice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## rolling-shutter shutterservice

Run a Shutter keyper for Shutter Service

### Synopsis

This command runs a keyper node. It will connect to both a Shutter service and a
Shuttermint node which have to be started separately in advance.

```
rolling-shutter shutterservice [flags]
```

### Options

```
--config string config file
-h, --help help for shutterservice
```

### Options inherited from parent commands

```
--logformat string set log format, possible values: min, short, long, max (default "long")
--loglevel string set log level, possible values: warn, info, debug (default "info")
--no-color do not write colored logs
```

### SEE ALSO

* [rolling-shutter](rolling-shutter.md) - A collection of commands to run and interact with Rolling Shutter nodes
* [rolling-shutter shutterservice dump-config](rolling-shutter_shutterservice_dump-config.md) - Dump a 'shutterservice' configuration file, based on given config and env vars
* [rolling-shutter shutterservice generate-config](rolling-shutter_shutterservice_generate-config.md) - Generate a 'shutterservice' configuration file
* [rolling-shutter shutterservice initdb](rolling-shutter_shutterservice_initdb.md) - Initialize the database of the 'shutterservice'

29 changes: 29 additions & 0 deletions rolling-shutter/docs/rolling-shutter_shutterservice_dump-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## rolling-shutter shutterservice dump-config

Dump a 'shutterservice' configuration file, based on given config and env vars

```
rolling-shutter shutterservice dump-config [flags]
```

### Options

```
--config string config file
-f, --force overwrite existing file
-h, --help help for dump-config
--output string output file
```

### Options inherited from parent commands

```
--logformat string set log format, possible values: min, short, long, max (default "long")
--loglevel string set log level, possible values: warn, info, debug (default "info")
--no-color do not write colored logs
```

### SEE ALSO

* [rolling-shutter shutterservice](rolling-shutter_shutterservice.md) - Run a Shutter keyper for Shutter Service

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## rolling-shutter shutterservice generate-config

Generate a 'shutterservice' configuration file

```
rolling-shutter shutterservice generate-config [flags]
```

### Options

```
-f, --force overwrite existing file
-h, --help help for generate-config
--output string output file
```

### Options inherited from parent commands

```
--config string config file
--logformat string set log format, possible values: min, short, long, max (default "long")
--loglevel string set log level, possible values: warn, info, debug (default "info")
--no-color do not write colored logs
```

### SEE ALSO

* [rolling-shutter shutterservice](rolling-shutter_shutterservice.md) - Run a Shutter keyper for Shutter Service

27 changes: 27 additions & 0 deletions rolling-shutter/docs/rolling-shutter_shutterservice_initdb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## rolling-shutter shutterservice initdb

Initialize the database of the 'shutterservice'

```
rolling-shutter shutterservice initdb [flags]
```

### Options

```
-h, --help help for initdb
```

### Options inherited from parent commands

```
--config string config file
--logformat string set log format, possible values: min, short, long, max (default "long")
--loglevel string set log level, possible values: warn, info, debug (default "info")
--no-color do not write colored logs
```

### SEE ALSO

* [rolling-shutter shutterservice](rolling-shutter_shutterservice.md) - Run a Shutter keyper for Shutter Service

1 change: 1 addition & 0 deletions rolling-shutter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/rs/zerolog v1.28.0
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a
github.com/shutter-network/gnosh-contracts v0.4.0
github.com/shutter-network/shop-contracts v0.0.0-20240407151512-08ef5d8355b6
github.com/shutter-network/shutter/shlib v0.1.19
Expand Down
2 changes: 2 additions & 0 deletions rolling-shutter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a h1:hWw2nJLGPZU7Rvd6YmEEDfvlTUbwZKZl5UP2ThVVNSU=
github.com/shutter-network/contracts/v2 v2.0.0-beta.2.0.20250108084129-3b743179373a/go.mod h1:V8KhVM75wyWVSzZJ6GeC9dWCjRrinIQVb7mYNP+knbg=
github.com/shutter-network/gnosh-contracts v0.4.0 h1:2GJcHK9w4lJZMsccklmxDhNnrkRLJDRwsL1acBnAeak=
github.com/shutter-network/gnosh-contracts v0.4.0/go.mod h1:QB0d64ybbVFKMrLjrc1tldri87KNjTmKQjhk9jaso2E=
github.com/shutter-network/shop-contracts v0.0.0-20240407151512-08ef5d8355b6 h1:m6Ti1/IH+GBTtGqyAX3xbh+ruUKvC+m+/uzYDUa+JDQ=
Expand Down
153 changes: 153 additions & 0 deletions rolling-shutter/keyperimpl/shutterservice/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package shutterservice

import (
"io"

"github.com/ethereum/go-ethereum/common"

"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/kprconfig"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration"
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/metricsserver"
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing an assignment check to verify the structs actually satisfy the interface. See for example:

var (
_ configuration.Config = &Config{}
_ configuration.Config = &GnosisConfig{}
_ configuration.Config = &GnosisContractsConfig{}
)

func NewConfig() *Config {
c := &Config{}
c.Init()
return c
}

func (c *Config) Init() {
c.P2P = p2p.NewConfig()
c.Shuttermint = kprconfig.NewShuttermintConfig()
c.Metrics = metricsserver.NewConfig()
c.Chain = NewChainConfig()
}

type Config struct {
InstanceID uint64 `shconfig:",required"`
DatabaseURL string `shconfig:",required" comment:"If it's empty, we use the standard PG_ environment variables"`

HTTPEnabled bool
HTTPListenAddress string

Chain *ChainConfig
P2P *p2p.Config
Shuttermint *kprconfig.ShuttermintConfig
Metrics *metricsserver.MetricsConfig

MaxNumKeysPerMessage uint64
}

func (c *Config) Validate() error {
// TODO: needs to be implemented
return nil
}

func (c *Config) Name() string {
return "shutterservice"
}

func (c *Config) SetDefaultValues() error {
c.HTTPEnabled = false
c.HTTPListenAddress = ":3000"
c.MaxNumKeysPerMessage = 500 // TODO: need to confirm on this
return nil
}

func (c *Config) SetExampleValues() error {
err := c.SetDefaultValues()
if err != nil {
return err
}
c.InstanceID = 42
c.DatabaseURL = "postgres://pguser:pgpassword@localhost:5432/shutter"

return nil
}

func (c Config) TOMLWriteHeader(_ io.Writer) (int, error) {
return 0, nil
}

func (c *Config) GetAddress() common.Address {
return c.Chain.Node.PrivateKey.EthereumAddress()
}

type ChainConfig struct {
Node *configuration.EthnodeConfig `shconfig:",required"`
Contracts *ContractsConfig `shconfig:",required"`
SyncStartBlockNumber uint64 `shconfig:",required"`
}

func NewChainConfig() *ChainConfig {
c := &ChainConfig{
Node: configuration.NewEthnodeConfig(),
Contracts: NewContractsConfig(),
SyncStartBlockNumber: 0,
}
c.Init()
return c
}

func (c *ChainConfig) Init() {
c.Node.Init()
c.Contracts.Init()
}

func (c *ChainConfig) Name() string {
return "chain"
}

func (c *ChainConfig) Validate() error {
return nil
}

func (c *ChainConfig) SetDefaultValues() error {
c.SyncStartBlockNumber = 0
return c.Contracts.SetDefaultValues()
}

func (c *ChainConfig) SetExampleValues() error {
return nil
}

func (c *ChainConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
return 0, nil
}

type ContractsConfig struct {
KeyperSetManager common.Address `shconfig:",required"`
ShutterRegistry common.Address `shconfig:",required"`
KeyBroadcastContract common.Address `shconfig:",required"`
}

func NewContractsConfig() *ContractsConfig {
return &ContractsConfig{
KeyperSetManager: common.Address{},
ShutterRegistry: common.Address{},
KeyBroadcastContract: common.Address{},
}
}

func (c *ContractsConfig) Init() {}

func (c *ContractsConfig) Name() string {
return "contracts"
}

func (c *ContractsConfig) Validate() error {
return nil
}

func (c *ContractsConfig) SetDefaultValues() error {
return nil
}

func (c *ContractsConfig) SetExampleValues() error {
return nil
}

func (c *ContractsConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
return 0, nil
}
Loading