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

Support arbitrary-sized bytes in Ceres #258

Merged
merged 4 commits into from
Feb 5, 2024
Merged

Support arbitrary-sized bytes in Ceres #258

merged 4 commits into from
Feb 5, 2024

Conversation

davidyuk
Copy link
Member

related to aeternity/aesophia#456

This PR is supported by the Æternity Crypto Foundation

bin/aesophia_cli includes changed from aeternity/aesophia#495

@davidyuk davidyuk force-pushed the bytes_any_size branch 7 times, most recently from 1310d40 to 105f9f9 Compare January 22, 2024 20:47
@davidyuk davidyuk requested a review from dincho January 22, 2024 20:49
@davidyuk davidyuk marked this pull request as ready for review January 22, 2024 20:51
Copy link
Member

@dincho dincho left a comment

Choose a reason for hiding this comment

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

Blocking mainly because of unofficial compiler CLI and OTP version. Should be released soon

sudo apt install --allow-downgrades ./esl-erlang_21.3.8.17-1~ubuntu~bionic_amd64.deb || true
sudo apt --fix-broken install
wget -q https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_25.2.3-1~ubuntu~jammy_amd64.deb
sudo apt install --allow-downgrades ./esl-erlang_25.2.3-1~ubuntu~jammy_amd64.deb
Copy link
Member

Choose a reason for hiding this comment

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

OTP 24 is usually used around the environments, I checked with @hanssv and CLI CI and OTP 24 should sufficient

@@ -35,9 +35,9 @@ class FateBytes extends FateData {
constructor(value, size, name = 'bytes') {
super(name)

this._value = toByteArray(value, size)
this._value = toByteArray(value, size === 'any' ? undefined : size)
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer Infinity, undefined or null instead of new string symbol

@dincho
Copy link
Member

dincho commented Jan 23, 2024

Testing the changes locally and trying to grasp in my head the new changes I realised the FateBytes already supports variable size data? Why did you added the new any symbol?

removing most of the changes still pass the tests:

iff --git a/src/types/FateBytes.js b/src/types/FateBytes.js
index c7eefac..12902db 100644
--- a/src/types/FateBytes.js
+++ b/src/types/FateBytes.js
@@ -35,9 +35,9 @@ class FateBytes extends FateData {
     constructor(value, size, name = 'bytes') {
         super(name)
 
-        this._value = toByteArray(value, size === 'any' ? undefined : size)
+        this._value = toByteArray(value, size)
 
-        if (size && size !== 'any' && this._value.byteLength !== size) {
+        if (size && this._value.byteLength !== size) {
             throw new FateTypeError(
                 name,
                 `Invalid length: got ${this._value.byteLength} bytes instead of ${size} bytes`
diff --git a/tests/Serializers/BytesSerializer.js b/tests/Serializers/BytesSerializer.js
index 0eaf120..6a504dd 100644
--- a/tests/Serializers/BytesSerializer.js
+++ b/tests/Serializers/BytesSerializer.js
@@ -17,7 +17,7 @@ test('Serialize', t => {
     )
 
     t.deepEqual(
-        s.serialize(new FateBytes(0xbeef, 'any')),
+        s.serialize(new FateBytes(0xbeef)),
         [159,1,9,190,239]
     )
 
diff --git a/tests/TypeResolver.js b/tests/TypeResolver.js
index 1ee4a29..6991de3 100644
--- a/tests/TypeResolver.js
+++ b/tests/TypeResolver.js
@@ -140,8 +140,8 @@ test('Resolve bytes', t => {
 test('Resolve bytes any size', t => {
     t.plan(1)
     t.deepEqual(
-        resolver.resolveType({bytes: 'any'}),
-        FateTypeBytes('any')
+        resolver.resolveType({bytes: 0}),
+        FateTypeBytes(0)
     )
 })

@dincho
Copy link
Member

dincho commented Jan 23, 2024

Perhaps, the 0 size used to denote variable sized data is not the best choice, I would accept improvements (Infinity, undefined) if you think it would be more readable.

@dincho
Copy link
Member

dincho commented Jan 24, 2024

new CLI version has been released: https://github.com/aeternity/aesophia_cli/releases/tag/v7.4.1

@davidyuk
Copy link
Member Author

shouldn't we wait till 8.0.0-rc1? As I understand 7.4.1 won't include bytes() and AENSv2

@davidyuk
Copy link
Member Author

resolver.resolveType({bytes: 'any'})

in this case any comes from contract ACI

@@ -152,7 +152,7 @@ class TypeResolver {
}

if (key === 'bytes') {
return FateTypeBytes(valueTypes)
return FateTypeBytes(valueTypes === 'any' ? undefined : valueTypes)
Copy link
Member Author

Choose a reason for hiding this comment

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

@dincho How do you like this? I would use undefined instead 'any' because it works this way and FateTypeBytes, FateBytes are internal.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with undefined

@dincho
Copy link
Member

dincho commented Jan 25, 2024

shouldn't we wait till 8.0.0-rc1? As I understand 7.4.1 won't include bytes() and AENSv2

ah, yes I didn't noticed the version

@davidyuk davidyuk force-pushed the bytes_any_size branch 3 times, most recently from 08f5c19 to 366149f Compare February 2, 2024 09:16
@dincho
Copy link
Member

dincho commented Feb 2, 2024

@davidyuk could you please change the implementation to get rid of any as we discussed above ?

@davidyuk
Copy link
Member Author

davidyuk commented Feb 3, 2024

As I understand src/TypeResolver.js is used to get internal FATE type based on ACI. Internal FateTypeBytes accepts the actual size or undefined if it has no fixed size. Bytes with arbitrary size are defined in ACI as

"type": {
  "bytes": "any"
}

So, the only any remaining is ternary in TypeResolver.js which pass undefined size of FateTypeBytes in case of "any" in ACI. I don't think I can get rid of it 🙃

Copy link
Member

@dincho dincho left a comment

Choose a reason for hiding this comment

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

thanks

@dincho
Copy link
Member

dincho commented Feb 5, 2024

As I understand src/TypeResolver.js is used to get internal FATE type based on ACI. Internal FateTypeBytes accepts the actual size or undefined if it has no fixed size. Bytes with arbitrary size are defined in ACI as

"type": {
  "bytes": "any"
}

So, the only any remaining is ternary in TypeResolver.js which pass undefined size of FateTypeBytes in case of "any" in ACI. I don't think I can get rid of it 🙃

You're right, I overseen the location of any ;)

@dincho dincho merged commit 6722be2 into master Feb 5, 2024
2 checks passed
@dincho dincho deleted the bytes_any_size branch February 5, 2024 10:51
@dincho dincho added the feature Introduces new feature label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Introduces new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants