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

fix(da): fixed da path seperator and encoding issue. #731

Merged
merged 4 commits into from
Apr 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# [](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc02...v) (2024-04-27)
# [](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc02...v) (2024-04-28)


Check failure on line 3 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]
### Bug Fixes

Check failure on line 4 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading levels should only increment by one level at a time [Expected: h2; Actual: h3]

* **p2p:** validate block before applying and not before caching in p2p gossiping ([#723](https://github.com/dymensionxyz/dymint/issues/723)) ([98371b5](https://github.com/dymensionxyz/dymint/commit/98371b5220613e70f3274fab5593e02ba532f7db))
* **produce loop:** handle unauthenticated error in settlement layer ([#726](https://github.com/dymensionxyz/dymint/issues/726)) ([33e78d1](https://github.com/dymensionxyz/dymint/commit/33e78d116b5f14b91b8b3bda2b6cbfee9040e2d3))


Check failure on line 9 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 10 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 3]
# [1.1.0-rc02](https://github.com/dymensionxyz/dymint/compare/v1.1.0-rc01...v1.1.0-rc02) (2024-04-26)

Check failure on line 11 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple top-level headings in the same document [Context: "# [1.1.0-rc02](https://github...."]


Check failure on line 13 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]

Check failure on line 14 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 3]
# [1.1.0-rc01](https://github.com/dymensionxyz/dymint/compare/v1.0.1-alpha...v1.1.0-rc01) (2024-04-25)

Check failure on line 15 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple top-level headings in the same document [Context: "# [1.1.0-rc01](https://github...."]


Check failure on line 17 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Multiple consecutive blank lines [Expected: 1; Actual: 2]
### Bug Fixes

Check failure on line 18 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading levels should only increment by one level at a time [Expected: h2; Actual: h3]

* **block production:** apply block before gossiping ([#695](https://github.com/dymensionxyz/dymint/issues/695)) ([5c496b4](https://github.com/dymensionxyz/dymint/commit/5c496b453e98bbcc67feb6df3a2d4ad340586816))
* **block:** Only register `nodeHealthStatusHandler` for sequencer ([#683](https://github.com/dymensionxyz/dymint/issues/683)) ([da2ff94](https://github.com/dymensionxyz/dymint/commit/da2ff94bcdd064109da703fa885609846a94e180))
Expand Down
30 changes: 23 additions & 7 deletions da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,36 @@ type DASubmitMetaData struct {
Root []byte
}

const PathSeparator = "|"

// ToPath converts a DAMetaData to a path.
func (d *DASubmitMetaData) ToPath() string {
// convert uint64 to string
if d.Commitment != nil {
commitment := hex.EncodeToString(d.Commitment)
dataroot := hex.EncodeToString(d.Root)
path := []string{string(d.Client), ".", strconv.FormatUint(d.Height, 10), ".", strconv.Itoa(d.Index), ".", strconv.Itoa(d.Length), ".", commitment, ".", string(d.Namespace), ".", dataroot}
return strings.Join(path, "")
path := []string{
string((d.Client)),
strconv.FormatUint(d.Height, 10),
strconv.Itoa(d.Index),
strconv.Itoa(d.Length),
commitment,
hex.EncodeToString(d.Namespace),
dataroot,
}
for i, part := range path {
path[i] = strings.Trim(part, PathSeparator)
}
return strings.Join(path, PathSeparator)
} else {
path := []string{string(d.Client), ".", strconv.FormatUint(d.Height, 10)}
return strings.Join(path, "")
path := []string{string(d.Client), PathSeparator, strconv.FormatUint(d.Height, 10)}
return strings.Join(path, PathSeparator)
}
}

// FromPath parses a path to a DAMetaData.
func (d *DASubmitMetaData) FromPath(path string) (*DASubmitMetaData, error) {
pathParts := strings.FieldsFunc(path, func(r rune) bool { return r == '.' })
pathParts := strings.FieldsFunc(path, func(r rune) bool { return r == rune(PathSeparator[0]) })
if len(pathParts) < 2 {
return nil, fmt.Errorf("invalid DA path")
}
Expand All @@ -103,7 +116,7 @@ func (d *DASubmitMetaData) FromPath(path string) (*DASubmitMetaData, error) {
Height: height,
Client: Client(pathParts[0]),
}

// TODO: check per DA and panic if not enough parts
if len(pathParts) == 7 {
submitData.Index, err = strconv.Atoi(pathParts[2])
if err != nil {
Expand All @@ -117,7 +130,10 @@ func (d *DASubmitMetaData) FromPath(path string) (*DASubmitMetaData, error) {
if err != nil {
return nil, err
}
submitData.Namespace = []byte(pathParts[5])
submitData.Namespace, err = hex.DecodeString(pathParts[5])
if err != nil {
return nil, err
}
submitData.Root, err = hex.DecodeString(pathParts[6])
if err != nil {
return nil, err
Expand Down
Loading