From 43aece5bb0431de0147bf95c8d5f3ec0d6d9cbcc Mon Sep 17 00:00:00 2001 From: Omri Date: Sun, 28 Apr 2024 20:31:51 +0200 Subject: [PATCH] fix(da): fixed da path seperator and encoding issue (#731) Co-authored-by: github-actions Co-authored-by: Sergi Rene --- CHANGELOG.md | 3 ++- da/da.go | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b4624001..678a11728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ### Bug Fixes * **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)) diff --git a/da/da.go b/da/da.go index 744277a18..565bdcb98 100644 --- a/da/da.go +++ b/da/da.go @@ -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") } @@ -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 { @@ -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