Skip to content

Commit

Permalink
fix: handle >1 sequencer when there are no state updates (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Aug 19, 2024
1 parent 4b9cc9b commit abc90b4
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 47 deletions.
2 changes: 1 addition & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
const (
binsDir = "/usr/local/bin"
DefaultTokenSupply = "1000000000000000000000000000"
DefaultFee = 100000000000000000 // 0.1
DefaultFee = 200000000000000000 // 0.2
)

var internalBinsDir = fmt.Sprintf("%s/roller_bins", binsDir)
Expand Down
2 changes: 1 addition & 1 deletion cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Cmd() *cobra.Command {

envs := []string{"devnet", "playground"}
env, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the node type you want to run").
WithDefaultText("select the environment you want to initialize for").
WithOptions(envs).
Show()
hd := consts.Hubs[env]
Expand Down
83 changes: 45 additions & 38 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,32 +184,37 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
return err
}

height, blockIdHash, err := GetLatestDABlock()
latestHeight, latestBlockIdHash, err := GetLatestDABlock()
if err != nil {
return err
}
heightInt, err := strconv.Atoi(latestHeight)
if err != nil {
return err
}

celestiaConfigFilePath := filepath.Join(
home,
consts.ConfigDirName.DALightNode,
"config.toml",
)
if len(sequencers.Sequencers) == 0 {
pterm.Info.Println("no sequencers registered for the rollapp")
pterm.Info.Println("using latest height for da-light-client configuration")

pterm.Info.Printf(
"da light client will be initialized at height %s, block hash %s",
height,
blockIdHash,
latestHeight,
latestBlockIdHash,
)
heightInt, err := strconv.Atoi(height)
if err != nil {
return err
}

celestiaConfigFilePath := filepath.Join(
home,
consts.ConfigDirName.DALightNode,
"config.toml",
)

err = UpdateCelestiaConfig(celestiaConfigFilePath, blockIdHash, heightInt)
err = UpdateCelestiaConfig(celestiaConfigFilePath, latestBlockIdHash, heightInt)
if err != nil {
return err
}
Expand All @@ -231,48 +236,50 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
if err != nil {
if strings.Contains(out.String(), "NotFound") {
pterm.Info.Printf(
"no state found for %s, da light client will be initialized with latest height",
"no state found for %s, da light client will be initialized with latest height\n",
raID,
)
err = UpdateCelestiaConfig(celestiaConfigFilePath, latestBlockIdHash, heightInt)
if err != nil {
return err
}
} else {
return err
}
}
} else {
daSpinner.UpdateText("state update found, extracting da height")

daSpinner.UpdateText("state update found, extracting da height")
var result Result
if err := yaml.Unmarshal(out.Bytes(), &result); err != nil {
pterm.Error.Println("failed to extract state update: ", err)
return err
}

var result Result
if err := yaml.Unmarshal(out.Bytes(), &result); err != nil {
return err
}
h, err := ExtractHeightfromDAPath(result.StateInfo.DAPath)
if err != nil {
pterm.Error.Println("failed to extract height from state update da path: ", err)
return err
}

h, err := ExtractHeightfromDAPath(result.StateInfo.DAPath)
if err != nil {
return err
}
height, hash, err := GetDABlockByHeight(h)
if err != nil {
pterm.Error.Println("failed to retrieve DA height: ", err)
return err
}

height, hash, err := GetDABlockByHeight(h)
if err != nil {
return err
}
heightInt, err := strconv.Atoi(height)
if err != nil {
return err
}

heightInt, err := strconv.Atoi(height)
if err != nil {
return err
pterm.Info.Printf("the first %s state update has DA height of %s with hash %s\n", raID, height, hash)
pterm.Info.Printf("updating %s \n", celestiaConfigFilePath)
err = UpdateCelestiaConfig(celestiaConfigFilePath, hash, heightInt)
if err != nil {
return err
}
}

celestiaConfigFilePath := filepath.Join(
home,
consts.ConfigDirName.DALightNode,
"config.toml",
)

pterm.Info.Printf("the first %s state update has DA height of %s with hash %s\n", raID, height, hash)
pterm.Info.Printf("updating %s \n", celestiaConfigFilePath)
err = UpdateCelestiaConfig(celestiaConfigFilePath, hash, heightInt)
if err != nil {
return err
}
}

daAddress, err := damanager.GetDAAccountAddress()
Expand Down
33 changes: 26 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0
github.com/docker/docker v27.0.3+incompatible
github.com/docker/go-connections v0.5.0
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240808102132-04bd9df0eec8
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240816184020-d34233020797
github.com/gizak/termui/v3 v3.1.0
github.com/gogo/protobuf v1.3.3
github.com/manifoldco/promptui v0.9.0
Expand All @@ -36,22 +36,25 @@ require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
cosmossdk.io/api v0.3.1 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/api v0.7.0 // indirect
cosmossdk.io/core v0.10.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/DataDog/zstd v1.5.0 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
Expand All @@ -68,11 +71,14 @@ require (
github.com/containerd/log v0.1.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ibc-go/v7 v7.5.1 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/danwt/gerr v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand All @@ -81,6 +87,7 @@ require (
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/edwards v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
Expand All @@ -102,12 +109,17 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/orderedcode v0.0.1 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
Expand All @@ -119,10 +131,12 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
Expand All @@ -132,6 +146,7 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
Expand All @@ -141,19 +156,22 @@ require (
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/osmosis-labs/osmosis/v15 v15.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pierrec/xxHash v0.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.9.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
Expand Down Expand Up @@ -198,6 +216,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
pgregory.net/rapid v1.1.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Expand Down
Loading

0 comments on commit abc90b4

Please sign in to comment.