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!: new encoding scheme for logs and encode RawSlice as u8 #1673

Merged
merged 100 commits into from
Feb 7, 2024

Conversation

danielbate
Copy link
Contributor

@danielbate danielbate commented Jan 22, 2024

Closes #1671

This PR adds support for sway's experimental encoding in logs. This is demonstrated via a new test suite, which is a subset of fuel-gauge, which builds another forc workspace using the experimental flag (--experimental-new-encoding).

There are opportunities for refactoring here, however that shall be detailed and implemented as part of #1672 given this PR is already over 2K lines.

Breaking Change

RawSlice data encoded as unpadded u8, also implemented by the RS SDK. Currently we are encoding it as u64 and doing additional arithmetic on encode and decode to compute the byte length. A RawSlice indicates a slice of bytes so we should treat it as so.

This poses a problem either on v0 or v1, one will have to compromise to the other as v1 assumes the data as u8 so we'd have to do additional arithmetic to get the correct len, rather than decoding it from the byte data. I have opted to introduce the breaking change in v0 as it brings us closer to v1.

Type Support

  • u8
  • u16
  • u32
  • u64
  • b256
  • b512
  • Array
  • String Array (str[n])
  • Option
  • Raw Slice
  • Tuple
  • Struct
  • Enum
  • String Dynamic (struct String)
  • Vec
  • Bytes

⚠️ String Slices are currently not supported in the TS SDK by encoding v0. This is possible in v1, however requires contract calls to be encoded as well, so the value can be encoded/decoded, and thus the logs. I have added a StrSlice coder using the specs and partially tested, but I have left it unimplemented within AbiCoder. Therefore it is currently blocked by this Sway issue.

Further changes

Blockers

@danielbate danielbate added the feat Issue is a feature label Jan 22, 2024
@danielbate danielbate added this to the 2 - Beetle milestone Jan 22, 2024
@danielbate danielbate self-assigned this Jan 22, 2024
@danielbate danielbate marked this pull request as draft January 22, 2024 16:34
@danielbate danielbate marked this pull request as ready for review February 6, 2024 12:01
Copy link
Contributor

@Torres-ssf Torres-ssf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Copy link
Contributor

@nedsalk nedsalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@danielbate danielbate enabled auto-merge (squash) February 7, 2024 16:21
Copy link
Contributor

github-actions bot commented Feb 7, 2024

Coverage Report:

Lines Branches Functions Statements
78.95%(+0.5%) 69.08%(+0.56%) 77.37%(+0.72%) 78.91%(+0.49%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/abi-coder/src/abi-coder.ts 89.65%
(+0.18%)
70.37%
(-11.98%)
87.5%
(+0%)
89.83%
(+0.18%)
🔴 packages/abi-coder/src/function-fragment.ts 73.52%
(-0.76%)
70.96%
(-1.76%)
81.81%
(+0%)
74.66%
(-0.66%)
✨ packages/abi-coder/src/coders/v0/array.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/b256.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/b512.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/boolean.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/byte.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/enum.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/number.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/abi-coder/src/coders/v0/option.ts 91.66%
(+91.66%)
87.5%
(+87.5%)
100%
(+100%)
91.66%
(+91.66%)
✨ packages/abi-coder/src/coders/v0/raw-slice.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/stdString.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/string.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/struct.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/tuple.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/u64.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v0/vec.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/boolean.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/byte.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
🔴 ✨ packages/abi-coder/src/coders/v1/enum.ts 92.3%
(+92.3%)
75%
(+75%)
100%
(+100%)
92.3%
(+92.3%)
✨ packages/abi-coder/src/coders/v1/number.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/raw-slice.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/std-string.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/str-slice.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/string.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/struct.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/tuple.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)
✨ packages/abi-coder/src/coders/v1/vec.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)

@danielbate danielbate merged commit 71c052c into master Feb 7, 2024
15 of 17 checks passed
@danielbate danielbate deleted the db/feat/new-log-encoding branch February 7, 2024 16:32
@arboleya
Copy link
Member

arboleya commented Feb 7, 2024

Oh shoot, I didn't have the chance to review it, and it's merged already. 😅

I trust the reviewers. 🤞

@danielbate
Copy link
Contributor Author

danielbate commented Feb 7, 2024

Sorry @arboleya, I enabled auto merge because of the 2 SDK reviews, but also on the basis that a FE review would be the third reviewer. However it doesn't seem to have blocked? It has merged with 2 failing steps (both the FE review steps).

cc @Torres-ssf

@danielbate
Copy link
Contributor Author

Any concerns can also be picked up in #1672

@Torres-ssf
Copy link
Contributor

Yeah, it shouldn't be possible to merge this one without the review from someone in the FE team 🤔 .

@arboleya
Copy link
Member

arboleya commented Feb 7, 2024

@danielbate Perhaps we should avoid using auto-merge in considerably big PRs to gather the maximum reviews possible.

@Torres-ssf Yes, I will take a look at it later on. Maybe I need to change something in the repo settings, but I'm unsure.

@Dhaiwat10
Copy link
Member

I believe in order for that to happen the 'FE conditional review' check should be required if it is enabled.

@Torres-ssf
Copy link
Contributor

@Dhaiwat10 I believe that was the problem. The check didn't pass but the PR got merged anyway.

@arboleya
Copy link
Member

arboleya commented Feb 7, 2024

@Torres-ssf Yes. That's what I'll double check in the repo settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support new encode/decode for __log
5 participants