-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load runtime version on runtime build (#300)
In summary: - add functionality to first try to parse the runtime version directly from the wasm blob's custom sections and if this fails (sections not present), fall back to calling `Core_version` on the built runtime. In this, fix the previously existing parsing from custom sections; - move the essence of shared memory reading into the `Runtime` class (i.e. the method `getDataFromMemory`), was previously in `HostApi` - use the state version field of the runtime version for the genesis trie - add tests (actually, only a single working one, since the runtime builder tests turned out more complicated than expected) Detailed log: * fix!: rename two imports runtime is expecting them with those names, so it wasn't building * feat!: fetch runtime version on runtime build - add functionality to first try to parse the runtime version directly from the wasm blob and if this fails, fall back to calling `Core_version` on the built runtime (in this, fix the previously existing parsing from custom sections) - move the essence of memory reading into the `Runtime` class (i.e. the method `getDataFromMemory`) - use the state version field of the runtime version for the genesis trie - add tests (actually, only a single working one, since the runtime builder tests turned out more complicated than expected) * chore: add `toString()` in `ApiVersion` * chore: remove dysfunctional test and introduce a TODO.md instead - `TODO.md` is planned to grow into a backlog for future out-of-scope necessities stumbled upon during development * chore: add past concern to `TODO.md` * chore: remove testability concern TODO * chore: improving comment pointing to Smoldot * chore: add javadoc and improve exception handling in `ApiVersions.decodeNoLength` - to better handle and emphasize the peculiarity of the missing list length in the scale encoded input * chore(sonarlint): add a `toString()` to `WasmCustomSection` record simply for reliability and consistency purposes with Java's requirements, not that anyone would have significant use of its presence (perhaps in rare debugging cases, printing opaque byte sections from the wasm blob) * refactor: change method name currently unused (was used), but makes sense to exist nonetheless, so no breaking changes introduced
- Loading branch information
1 parent
240ace1
commit 3115554
Showing
26 changed files
with
626 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/main/java/com/limechain/runtime/WasmCustomSection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.limechain.runtime; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Identifies a wasm custom section | ||
* | ||
* @param name - the name of the section (in the wasm sense, as a tag above the byte content) | ||
* @param content - the byte content of the section | ||
*/ | ||
public record WasmCustomSection(byte[] name, byte[] content) { | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
WasmCustomSection that = (WasmCustomSection) o; | ||
return Arrays.equals(name, that.name) && Arrays.equals(content, that.content); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Arrays.hashCode(name); | ||
result = 31 * result + Arrays.hashCode(content); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "WasmCustomSection{" + | ||
"name=" + Arrays.toString(name) + | ||
", content=" + Arrays.toString(content) + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.