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 ability to run rollapps with the roller run command #66

Merged
merged 2 commits into from
Jun 18, 2023
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: 0 additions & 2 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package initconfig

var FlagNames = struct {
Home string
DAEndpoint string
Decimals string
RollappBinary string
HubID string
}{
Home: "home",
DAEndpoint: "data-availability-endpoint",
Decimals: "decimals",
RollappBinary: "rollapp-binary",
HubID: "hub",
Expand Down
26 changes: 12 additions & 14 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"fmt"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
)

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(FlagNames.HubID, "", TestnetHubID, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage()))
cmd.Flags().StringP(FlagNames.DAEndpoint, "", "", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(FlagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")

Expand Down Expand Up @@ -41,22 +41,20 @@ func getRollappBinaryPath(cmd *cobra.Command) string {
return rollappBinaryPath
}

func GetInitConfig(cmd *cobra.Command, args []string) InitConfig {
func GetInitConfig(initCmd *cobra.Command, args []string) InitConfig {
rollappId := args[0]
denom := args[1]
home := cmd.Flag(FlagNames.Home).Value.String()
createLightNode := !cmd.Flags().Changed(FlagNames.DAEndpoint)
rollappBinaryPath := getRollappBinaryPath(cmd)
decimals := getDecimals(cmd)
hubID := cmd.Flag(FlagNames.HubID).Value.String()
home := initCmd.Flag(utils.FlagNames.Home).Value.String()
rollappBinaryPath := getRollappBinaryPath(initCmd)
decimals := getDecimals(initCmd)
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
return InitConfig{
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
CreateDALightNode: createLightNode,
Denom: denom,
Decimals: decimals,
HubData: Hubs[hubID],
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
Denom: denom,
Decimals: decimals,
HubData: Hubs[hubID],
}
}

Expand Down
20 changes: 9 additions & 11 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
)

type InitConfig struct {
Home string
RollappID string
RollappBinary string
CreateDALightNode bool
Denom string
Decimals uint64
HubData HubData
Home string
RollappID string
RollappBinary string
Denom string
Decimals uint64
HubData HubData
}

func InitCmd() *cobra.Command {
Expand All @@ -37,10 +36,9 @@ func InitCmd() *cobra.Command {
}
}

addresses := initializeKeys(initConfig)
if initConfig.CreateDALightNode {
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
}
addresses, err := generateKeys(initConfig)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
initializeRollappConfig(initConfig)
utils.PrettifyErrorIfExists(initializeRollappGenesis(initConfig))
utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{
Expand Down
22 changes: 0 additions & 22 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,6 @@ func getDefaultKeysConfig(initConfig InitConfig) []utils.KeyConfig {
ID: consts.KeyNames.RollappRelayer,
CoinType: consts.CoinTypes.EVM,
Prefix: consts.AddressPrefixes.Rollapp,
}, {

Dir: path.Join(consts.ConfigDirName.DALightNode, KeysDirName),
ID: consts.KeyNames.DALightNode,
CoinType: consts.CoinTypes.Cosmos,
Prefix: consts.AddressPrefixes.DA,
},
}
}

func initializeKeys(initConfig InitConfig) map[string]string {
if initConfig.CreateDALightNode {
addresses, err := generateKeys(initConfig)
if err != nil {
panic(err)
}
return addresses
} else {
addresses, err := generateKeys(initConfig, consts.KeyNames.DALightNode)
if err != nil {
panic(err)
}
return addresses
}
}
4 changes: 2 additions & 2 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var KeyNames = struct {
HubSequencer: "hub_sequencer",
RollappSequencer: "rollapp_sequencer",
RollappRelayer: "relayer-rollapp-key",
DALightNode: "my-celes-key",
DALightNode: "my_celes_key",
HubRelayer: "relayer-hub-key",
}

Expand All @@ -43,7 +43,7 @@ var ConfigDirName = struct {
}{
Rollapp: "rollapp",
Relayer: "relayer",
DALightNode: "light-node",
DALightNode: "da-light-node",
}

var CoinTypes = struct {
Expand Down
8 changes: 2 additions & 6 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package register
import (
"bytes"
"errors"
"github.com/dymensionxyz/roller/cmd/consts"
"path/filepath"

"fmt"
Expand All @@ -14,6 +13,7 @@ import (

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/spf13/cobra"
)

Expand All @@ -34,14 +34,10 @@ func RegisterCmd() *cobra.Command {
printRegisterOutput(rollappConfig)
},
}
addFlags(registerCmd)
utils.AddGlobalFlags(registerCmd)
return registerCmd
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(initconfig.FlagNames.Home, "", utils.GetRollerRootDir(), "The directory of the roller config files")
}

func registerRollapp(rollappConfig initconfig.InitConfig) error {
cmd := getRegisterRollappCmd(rollappConfig)
var stdout bytes.Buffer
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/dymensionxyz/roller/cmd/config"
"github.com/dymensionxyz/roller/cmd/register"
"github.com/dymensionxyz/roller/cmd/run"
"github.com/dymensionxyz/roller/cmd/version"
"github.com/spf13/cobra"
)
Expand All @@ -28,4 +29,5 @@ func init() {
rootCmd.AddCommand(config.ConfigCmd())
rootCmd.AddCommand(version.VersionCmd())
rootCmd.AddCommand(register.RegisterCmd())
rootCmd.AddCommand(run.RunCmd())
}
62 changes: 62 additions & 0 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package run

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"os/exec"
"path/filepath"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
)

const daLightClientEndpointFlag = "da-light-client-endpoint"

func RunCmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "run",
Short: "Runs the rollapp sequencer.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getStartRollapCmd(rollappConfig, cmd.Flag(daLightClientEndpointFlag).Value.String())
startRollappErr := startRollappCmd.Run()
utils.PrettifyErrorIfExists(startRollappErr)
},
}
addFlags(runCmd)
utils.AddGlobalFlags(runCmd)
return runCmd
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(daLightClientEndpointFlag, "", "http://localhost:26659", "The DA light client endpoint.")
}

func getStartRollapCmd(rollappConfig initconfig.InitConfig, daLightClientEndpoint string) *exec.Cmd {
daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`, daLightClientEndpoint)
rollappConfigDir := filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp)
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "2000000udym"}`,
rollappConfig.HubData.RPC_URL, rollappConfig.RollappID, consts.KeyNames.HubSequencer, rollappConfigDir)

return exec.Command(
rollappConfig.RollappBinary, "start",
"--dymint.aggregator",
"--json-rpc.enable",
"--json-rpc.api", "eth,txpool,personal,net,debug,web3,miner",
"--dymint.da_layer", "celestia",
"--dymint.da_config", daConfig,
"--dymint.settlement_layer", "dymension",
"--dymint.settlement_config", settlementConfig,
"--dymint.block_batch_size", "1200",
"--dymint.namespace_id", "000000000000ffff",
"--dymint.block_time", "0.2s",
"--home", rollappConfigDir,
"--log_level", "debug",
"--log-file", filepath.Join(rollappConfigDir, "rollapp.log"),
"--max-log-size", "2000",
"--module-log-level-override", "",
)
}
12 changes: 8 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ TGZ_URL="https://github.com/dymensionxyz/roller/releases/download/v0.0.0/roller_
# Create internal dir
INTERNAL_DIR="/usr/local/bin/roller_bins"
ROLLER_BIN_PATH="/usr/local/bin/roller"
ROLLAPP_EVM_PATH="/usr/local/bin/rollapp_evm" # The path where rollapp_evm will be installed

# Check if Roller binary already exists
if [ -f "$ROLLER_BIN_PATH" ] || [ -d "$INTERNAL_DIR" ]; then
# Check if Roller and rollapp_evm binaries already exist or the internal directory exists
if [ -f "$ROLLER_BIN_PATH" ] || [ -f "$ROLLAPP_EVM_PATH" ] || [ -d "$INTERNAL_DIR" ]; then
sudo rm -f "$ROLLER_BIN_PATH"
sudo rm -f "$ROLLAPP_EVM_PATH"
sudo rm -rf "$INTERNAL_DIR"
fi

Expand All @@ -25,14 +27,16 @@ sudo mkdir -p "/tmp/roller_tmp"
echo "$EMOJI Downloading roller..."
sudo curl -L "$TGZ_URL" --progress-bar | sudo tar -xz -C "/tmp/roller_tmp"

# Assuming that the tar file contains the lib folder and the roller binary inside the roller_bins directory.
# Assuming that the tar file contains the lib folder and the roller and rollapp_evm binaries inside the roller_bins directory.
# Move binaries to their correct locations
echo "$EMOJI Installing roller..."
sudo mv "/tmp/roller_tmp/roller_bins/lib"/* "$INTERNAL_DIR"
sudo mv "/tmp/roller_tmp/roller_bins/roller" "$ROLLER_BIN_PATH"
sudo mv "/tmp/roller_tmp/roller_bins/rollapp_evm" "$ROLLAPP_EVM_PATH" # move the rollapp_evm binary

# Make roller executable
# Make roller and rollapp_evm executables
sudo chmod +x "$ROLLER_BIN_PATH"
sudo chmod +x "$ROLLAPP_EVM_PATH"

# Cleanup temporary directory
sudo rm -rf "/tmp/roller_tmp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[Core]
IP = "0.0.0.0"
RPCPort = "0"
GRPCPort = "0"

[State]
KeyringAccName = ""
KeyringBackend = "test"

[P2P]
ListenAddresses = ["/ip4/0.0.0.0/udp/2121/quic-v1", "/ip6/::/udp/2121/quic-v1", "/ip4/0.0.0.0/tcp/2121", "/ip6/::/tcp/2121"]
AnnounceAddresses = []
NoAnnounceAddresses = ["/ip4/0.0.0.0/udp/2121/quic-v1", "/ip4/127.0.0.1/udp/2121/quic-v1", "/ip6/::/udp/2121/quic-v1", "/ip4/0.0.0.0/tcp/2121", "/ip4/127.0.0.1/tcp/2121", "/ip6/::/tcp/2121"]
MutualPeers = []
PeerExchange = false
RoutingTableRefreshPeriod = "1m0s"
[P2P.ConnManager]
Low = 50
High = 100
GracePeriod = "1m0s"

[RPC]
Address = "0.0.0.0"
Port = "26658"

[Gateway]
Address = "0.0.0.0"
Port = "26659"
Enabled = false

[Share]
UseShareExchange = true
[Share.ShrExEDSParams]
ServerReadTimeout = "5s"
ServerWriteTimeout = "1m0s"
HandleRequestTimeout = "1m0s"
ConcurrencyLimit = 10
BufferSize = 32768
[Share.ShrExNDParams]
ServerReadTimeout = "5s"
ServerWriteTimeout = "1m0s"
HandleRequestTimeout = "1m0s"
ConcurrencyLimit = 10
[Share.PeerManagerParams]
PoolValidationTimeout = "2m0s"
PeerCooldown = "3s"
GcInterval = "30s"
EnableBlackListing = false
[Share.LightAvailability]
SampleAmount = 16
[Share.Discovery]
PeersLimit = 5
AdvertiseInterval = "22h0m0s"

[Header]
TrustedHash = ""
TrustedPeers = []
[Header.Store]
StoreCacheSize = 4096
IndexCacheSize = 16384
WriteBatchSize = 2048
[Header.Syncer]
TrustingPeriod = "168h0m0s"
[Header.Server]
WriteDeadline = "8s"
ReadDeadline = "1m0s"
RangeRequestTimeout = "10s"
[Header.Client]
MaxHeadersPerRangeRequest = 64
RangeRequestTimeout = "8s"

[DASer]
SamplingRange = 100
ConcurrencyLimit = 16
BackgroundStoreInterval = "10m0s"
SampleFrom = 1
SampleTimeout = "4m0s"
6 changes: 1 addition & 5 deletions test/config/init/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func TestInitCmd(t *testing.T) {
DAEndpoint := "http://localhost:26659"
decimals := "6"
testCases := []struct {
name string
Expand All @@ -30,7 +29,6 @@ func TestInitCmd(t *testing.T) {
name: "Roller config init with custom flags",
goldenDirPath: "./goldens/init_with_flags",
optionalFlags: []string{
"--" + initconfig.FlagNames.DAEndpoint, DAEndpoint,
"--" + initconfig.FlagNames.Decimals, decimals,
},
},
Expand Down Expand Up @@ -59,9 +57,7 @@ func TestInitCmd(t *testing.T) {
assert.NoError(os.Remove(filepath.Join(tempDir, initconfig.RollerConfigFileName)))
assert.NoError(testutils.VerifyRollappKeys(tempDir))
assert.NoError(testutils.VerifyRelayerKeys(tempDir, rollappID, initConfig.HubData.ID))
if !testutils.Contains(tc.optionalFlags, "--"+initconfig.FlagNames.DAEndpoint) {
assert.NoError(testutils.VerifyLightNodeKeys(tempDir))
}
assert.NoError(testutils.VerifyLightNodeKeys(tempDir))
assert.NoError(testutils.ClearKeys(tempDir))
are_dirs_equal, err := testutils.CompareDirs(tempDir, tc.goldenDirPath)
assert.NoError(err)
Expand Down