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

feat: add KeyringKeyname #4

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ USER ${USER_NAME}

# Expose ports:
EXPOSE 1317 9090 26657 1095 8080 26658
ENTRYPOINT ["sh", "-c", "/bin/celestia-server --enable-rpc --rpc-addr $RPC_ADDR --rpc-port $RPC_PORT --celestia.auth-token $AUTH_TOKEN --celestia.gas-price $GAS_PRICE --celestia.gas-multiplier $GAS_MULTIPLIER --celestia.namespace-id $NAMESPACEID --celestia.rpc $CELESTIA_NODE_ENDPOINT"]
ENTRYPOINT ["sh", "-c", "/bin/celestia-server --enable-rpc --rpc-addr $RPC_ADDR --rpc-port $RPC_PORT --celestia.auth-token $AUTH_TOKEN --celestia.gas-price $GAS_PRICE --celestia.gas-multiplier $GAS_MULTIPLIER --celestia.namespace-id $NAMESPACEID --celestia.rpc $CELESTIA_NODE_ENDPOINT --celestia.keyring-keyname $KEYNAME"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
## Example usage

```
./celestia-server --enable-rpc --rpc-addr $RPC_ADDR --rpc-port $RPC_PORT --celestia.auth-token $AUTH_TOKEN --celestia.gas-price $GAS_PRICE --celestia.gas-multiplier $GAS_MULTIPLIER --celestia.namespace-id $NAMESPACEID --celestia.rpc $CELESTIA_NODE_ENDPOINT
./celestia-server --enable-rpc --rpc-addr $RPC_ADDR \
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just to improve UX of the readme and avoid people sidescrolling, so they can see things at once

--rpc-port $RPC_PORT --celestia.auth-token $AUTH_TOKEN \
--celestia.gas-price $GAS_PRICE \
--celestia.gas-multiplier $GAS_MULTIPLIER \
--celestia.namespace-id $NAMESPACEID \
--celestia.rpc $CELESTIA_NODE_ENDPOINT \
--celestia.keyring-keyname $KEYNAME
```

## Flags
Expand All @@ -27,6 +33,7 @@ Usage of daserver:
--celestia.enable Enable Celestia DA
--celestia.gas-multiplier float Gas multiplier for Celestia transactions (default 1.01)
--celestia.gas-price float Gas for retrying Celestia transactions (default 0.01)
--celestia.keyring-keyname string Celestia DA node keyring keyname for blobs submissions
--celestia.namespace-id string Celestia Namespace to post data to
--celestia.noop-writer Noop writer (disable posting to celestia)
--celestia.read-auth-token string Auth token for Celestia Node
Expand Down
18 changes: 18 additions & 0 deletions das/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DAConfig struct {
NamespaceId string `koanf:"namespace-id" `
AuthToken string `koanf:"auth-token" reload:"hot"`
ReadAuthToken string `koanf:"read-auth-token" reload:"hot"`
KeyringKeyname string `koanf:"keyring-keyname" reload:"hot"`
Copy link
Member Author

Choose a reason for hiding this comment

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

I added these in this spot of the struct so that DA-related auth stuff is near each other. Totally cool to move elsewhere if it makes more sense

NoopWriter bool `koanf:"noop-writer" reload:"hot"`
ValidatorConfig *ValidatorConfig `koanf:"validator-config"`
ReorgOnReadFailure bool `koanf:"dangerous-reorg-on-read-failure"`
Expand Down Expand Up @@ -108,6 +109,7 @@ func CelestiaDAConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".namespace-id", "", "Celestia Namespace to post data to")
f.String(prefix+".auth-token", "", "Auth token for Celestia Node")
f.String(prefix+".read-auth-token", "", "Auth token for Celestia Node")
f.String(prefix+".keyring-keyname", "", "Keyring keyname for Celestia Node for blobs submission")
f.Bool(prefix+".noop-writer", false, "Noop writer (disable posting to celestia)")
f.String(prefix+".validator-config"+".tendermint-rpc", "", "Tendermint RPC endpoint, only used for validation")
f.String(prefix+".validator-config"+".eth-rpc", "", "L1 Websocket connection, only used for validation")
Expand Down Expand Up @@ -147,6 +149,17 @@ func NewCelestiaDA(cfg *DAConfig, ethClient *ethclient.Client) (*CelestiaDA, err
return nil, err
}

if cfg.KeyringKeyname == "" {
return nil, errors.New("keyring keyname cannot be blank")
}
if !isValidKeyringKeyname(cfg.KeyringKeyname) {
return nil, fmt.Errorf("invalid keyring keyname format: %s", cfg.KeyringKeyname)
}
err = daClient.SetKeyringKeyname(cfg.KeyringKeyname)
if err != nil {
return nil, fmt.Errorf("failed to set keyring keyname: %w", err)
}

if cfg.ValidatorConfig != nil {
trpc, err := http.New(cfg.ValidatorConfig.TendermintRPC, "/websocket")
if err != nil {
Expand Down Expand Up @@ -704,3 +717,8 @@ func (c *CelestiaDA) returnErrorHelper(err error) (*ReadResult, error) {

return nil, err
}

// Validate that the KeyringKeyname is a alphanumeric string of length > 0
func isValidKeyringKeyname(name string) bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if we need this tbh!

return len(name) > 0 && regexp.MustCompile(`^[a-zA-Z0-9_-]+$`).MatchString(name)
}