Skip to content

Commit

Permalink
fix(da): fixed da path seperator and encoding issue (#731)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Sergi Rene <[email protected]>
  • Loading branch information
3 people committed Apr 28, 2024
1 parent 48ff85f commit 43aece5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# [](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]

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]

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 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]

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]
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

0 comments on commit 43aece5

Please sign in to comment.