Skip to content

Update AssemblyScript to 0.19.2 #2571

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

Merged
merged 32 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
68fabea
runtime: Fix sample `AscType::from_asc_bytes` implementation
evaporei May 10, 2021
7a23467
runtime: AssemblyScript update to version 0.19.2
evaporei May 10, 2021
5a9aae1
integration-tests: Point to graph-{ts, cli} ASC branch w/ update
evaporei Jun 8, 2021
fdeca16
integration-tests: Change from 'as T' to 'changetype<T>'
evaporei Jun 8, 2021
5f6e31f
integration-tests: Fix some mapping code to the new AS version
evaporei Jun 8, 2021
e2d246f
runtime: Behave conditionally on apiVersion for AscPtr::{alloc_obj, r…
evaporei Jun 16, 2021
2156ffa
runtime: Behave conditionally on apiVersion for memory allocation fn
evaporei Jun 16, 2021
38991e7
runtime: Behave conditionally on apiVersion for id_of_type fn
evaporei Jun 16, 2021
b2a7ae1
graph: Add env var for max api version
evaporei Jun 17, 2021
dae0a3c
integration-tests: Upgrade apiVersion to 0.0.5
evaporei Jun 17, 2021
7d4143f
runtime: Class abi versioning
evaporei Jun 17, 2021
d3ef341
runtime: Make wasm_tests work for both apiVersions
evaporei Jun 17, 2021
98a7506
integration-tests: Add one for older apiVersion
evaporei Jun 18, 2021
4e9f3da
integration-tests: Update yarn.lock
evaporei Jun 18, 2021
e28d4fc
runtime/derive: Use < in sanity check
evaporei Jun 18, 2021
9ff7382
runtime/asc_abi: Better documentation
evaporei Jun 18, 2021
39be34a
runtime: Remove unused Makefiles
evaporei Jun 19, 2021
03e7936
runtime: Add _start function for apiVersion v0.0.5
evaporei Jul 1, 2021
a5b467e
integration-tests: Remove unnecessary changetypes
evaporei Jul 2, 2021
38bd25c
runtime: Create common folder for v0.0.5 wasm_tests
evaporei Jul 2, 2021
071d840
runtime: Remove the code duplication in tests
evaporei Jul 12, 2021
753f3b0
runtime: Rename get_aligned_length to padding_to_16
evaporei Jul 12, 2021
fcf2981
runtime: Use fully qualified HEADER_SIZE name in derive
evaporei Jul 12, 2021
c3fdab5
runtime: Remove AS 0.19.2 comment
evaporei Jul 12, 2021
a04cebb
runtime: Remove stray comment
evaporei Jul 12, 2021
45c6cbe
runtime: Add checked_sub on v0.0.5 memory layout subtractions
evaporei Jul 12, 2021
0f30148
runtime: Change unreachable statments from if let to match
evaporei Jul 12, 2021
85385bc
runtime: Add comment to explain memory alignment in AscPtr::alloc_obj
evaporei Jul 12, 2021
cc5ce84
runtime: Explain better in comment about AssemblyScript header genera…
evaporei Jul 13, 2021
7f29b82
runtime: Add explanation on offset of ArrayBufferView memory layout (…
evaporei Jul 13, 2021
36cb6a5
integration-tests: Remove useless TODO
evaporei Jul 15, 2021
aeb0e43
derive: Add comment on why we're using less than size for confidence …
evaporei Jul 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dirs-next = "2.0"
anyhow = "1.0"
tiny-keccak = "1.5.0"
hex = "0.4.3"
semver = "1.0.3"

# master contains changes such as
# https://github.com/paritytech/ethabi/pull/140, which upstream does not want
Expand Down
82 changes: 74 additions & 8 deletions chain/ethereum/src/runtime/abi.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use graph::prelude::BigInt;
use graph::runtime::{asc_get, asc_new, AscPtr, DeterministicHostError, FromAscObj, ToAscObj};
use graph::runtime::{AscHeap, AscType};
use graph::runtime::{AscHeap, AscIndexId, AscType, IndexForAscTypeId};
use graph_runtime_derive::AscType;
use graph_runtime_wasm::asc_abi::class::{
Array, AscAddress, AscBigInt, AscEnum, AscH160, AscString, EthereumValueKind, Uint8Array,
};
use semver::Version;
use std::mem::size_of;

use crate::trigger::{
EthereumBlockData, EthereumCallData, EthereumEventData, EthereumTransactionData,
Expand All @@ -13,7 +15,35 @@ use crate::trigger::{
use super::runtime_adapter::UnresolvedContractCall;

type AscH256 = Uint8Array;
type AscLogParamArray = Array<AscPtr<AscLogParam>>;

pub struct AscLogParamArray(Array<AscPtr<AscLogParam>>);

impl AscType for AscLogParamArray {
fn to_asc_bytes(&self) -> Result<Vec<u8>, DeterministicHostError> {
self.0.to_asc_bytes()
}
fn from_asc_bytes(
asc_obj: &[u8],
api_version: Version,
) -> Result<Self, DeterministicHostError> {
Ok(Self(Array::from_asc_bytes(asc_obj, api_version)?))
}
}

impl ToAscObj<AscLogParamArray> for Vec<ethabi::LogParam> {
fn to_asc_obj<H: AscHeap + ?Sized>(
&self,
heap: &mut H,
) -> Result<AscLogParamArray, DeterministicHostError> {
let content: Result<Vec<_>, _> = self.iter().map(|x| asc_new(heap, x)).collect();
let content = content?;
Ok(AscLogParamArray(Array::new(&*content, heap)?))
}
}

impl AscIndexId for AscLogParamArray {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::ArrayEventParam;
}

#[repr(C)]
#[derive(AscType)]
Expand All @@ -25,6 +55,10 @@ pub struct AscUnresolvedContractCall_0_0_4 {
pub function_args: AscPtr<Array<AscPtr<AscEnum<EthereumValueKind>>>>,
}

impl AscIndexId for AscUnresolvedContractCall_0_0_4 {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::SmartContractCall;
}

impl FromAscObj<AscUnresolvedContractCall_0_0_4> for UnresolvedContractCall {
fn from_asc_obj<H: AscHeap + ?Sized>(
asc_call: AscUnresolvedContractCall_0_0_4,
Expand Down Expand Up @@ -83,6 +117,10 @@ pub(crate) struct AscEthereumBlock {
pub size: AscPtr<AscBigInt>,
}

impl AscIndexId for AscEthereumBlock {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumBlock;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscEthereumTransaction_0_0_1 {
Expand All @@ -95,6 +133,10 @@ pub(crate) struct AscEthereumTransaction_0_0_1 {
pub gas_price: AscPtr<AscBigInt>,
}

impl AscIndexId for AscEthereumTransaction_0_0_1 {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumTransaction;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscEthereumTransaction_0_0_2 {
Expand All @@ -108,6 +150,10 @@ pub(crate) struct AscEthereumTransaction_0_0_2 {
pub input: AscPtr<Uint8Array>,
}

impl AscIndexId for AscEthereumTransaction_0_0_2 {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumTransaction;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscEthereumEvent<T>
Expand All @@ -123,13 +169,25 @@ where
pub params: AscPtr<AscLogParamArray>,
}

impl AscIndexId for AscEthereumEvent<AscEthereumTransaction_0_0_1> {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumEvent;
}

impl AscIndexId for AscEthereumEvent<AscEthereumTransaction_0_0_2> {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumEvent;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscLogParam {
pub name: AscPtr<AscString>,
pub value: AscPtr<AscEnum<EthereumValueKind>>,
}

impl AscIndexId for AscLogParam {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EventParam;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscEthereumCall {
Expand All @@ -140,6 +198,10 @@ pub(crate) struct AscEthereumCall {
pub outputs: AscPtr<AscLogParamArray>,
}

impl AscIndexId for AscEthereumCall {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumCall;
}

#[repr(C)]
#[derive(AscType)]
pub(crate) struct AscEthereumCall_0_0_3 {
Expand All @@ -151,6 +213,10 @@ pub(crate) struct AscEthereumCall_0_0_3 {
pub outputs: AscPtr<AscLogParamArray>,
}

impl AscIndexId for AscEthereumCall_0_0_3 {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::EthereumCall;
}

impl ToAscObj<AscEthereumBlock> for EthereumBlockData {
fn to_asc_obj<H: AscHeap + ?Sized>(
&self,
Expand Down Expand Up @@ -219,7 +285,7 @@ impl ToAscObj<AscEthereumTransaction_0_0_2> for EthereumTransactionData {
}
}

impl<T: AscType> ToAscObj<AscEthereumEvent<T>> for EthereumEventData
impl<T: AscType + AscIndexId> ToAscObj<AscEthereumEvent<T>> for EthereumEventData
where
EthereumTransactionData: ToAscObj<T>,
{
Expand All @@ -241,7 +307,7 @@ where
.unwrap_or(Ok(AscPtr::null()))?,
block: asc_new(heap, &self.block)?,
transaction: asc_new::<T, EthereumTransactionData, _>(heap, &self.transaction)?,
params: asc_new(heap, self.params.as_slice())?,
params: asc_new(heap, &self.params)?,
})
}
}
Expand All @@ -255,8 +321,8 @@ impl ToAscObj<AscEthereumCall> for EthereumCallData {
address: asc_new(heap, &self.to)?,
block: asc_new(heap, &self.block)?,
transaction: asc_new(heap, &self.transaction)?,
inputs: asc_new(heap, self.inputs.as_slice())?,
outputs: asc_new(heap, self.outputs.as_slice())?,
inputs: asc_new(heap, &self.inputs)?,
outputs: asc_new(heap, &self.outputs)?,
})
}
}
Expand All @@ -271,8 +337,8 @@ impl ToAscObj<AscEthereumCall_0_0_3> for EthereumCallData {
from: asc_new(heap, &self.from)?,
block: asc_new(heap, &self.block)?,
transaction: asc_new(heap, &self.transaction)?,
inputs: asc_new(heap, self.inputs.as_slice())?,
outputs: asc_new(heap, self.outputs.as_slice())?,
inputs: asc_new(heap, &self.inputs)?,
outputs: asc_new(heap, &self.outputs)?,
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions chain/ethereum/src/runtime/runtime_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
use anyhow::{Context, Error};
use blockchain::HostFn;
use ethabi::{Address, Token};
use graph::runtime::{AscIndexId, IndexForAscTypeId};
use graph::{
blockchain::{self, BlockPtr, DataSource as _, HostFnCtx},
cheap_clone::CheapClone,
Expand Down Expand Up @@ -204,3 +205,7 @@ pub(crate) struct UnresolvedContractCall {
pub function_signature: Option<String>,
pub function_args: Vec<ethabi::Token>,
}

impl AscIndexId for AscUnresolvedContractCall {
const INDEX_ASC_TYPE_ID: IndexForAscTypeId = IndexForAscTypeId::SmartContractCall;
}
13 changes: 11 additions & 2 deletions graph/src/data/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ lazy_static! {
// doesn't exist. In the future we should not use 0.0.3 as version
// and skip to 0.0.4 to avoid ambiguity.
static ref MAX_SPEC_VERSION: Version = Version::new(0, 0, 3);

static ref MAX_API_VERSION: Version = std::env::var("GRAPH_MAX_API_VERSION")
.ok()
.and_then(|api_version_str| Version::parse(&api_version_str).ok())
.unwrap_or(Version::new(0, 0, 4));
}

/// Rust representation of the GraphQL schema for a `SubgraphManifest`.
Expand Down Expand Up @@ -604,8 +609,12 @@ impl UnresolvedMapping {

let api_version = Version::parse(&api_version)?;

ensure!(VersionReq::parse("<= 0.0.4").unwrap().matches(&api_version),
"The maximum supported mapping API version of this indexer is 0.0.4, but `{}` was found",
ensure!(
VersionReq::parse(&format!("<= {}", *MAX_API_VERSION))
.unwrap()
.matches(&api_version),
"The maximum supported mapping API version of this indexer is {}, but `{}` was found",
*MAX_API_VERSION,
api_version
);

Expand Down
13 changes: 9 additions & 4 deletions graph/src/runtime/asc_heap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use semver::Version;

use super::{AscPtr, AscType, DeterministicHostError};
use super::{AscIndexId, AscPtr, AscType, DeterministicHostError, IndexForAscTypeId};
/// A type that can read and write to the Asc heap. Call `asc_new` and `asc_get`
/// for reading and writing Rust structs from and to Asc.
///
Expand All @@ -12,6 +12,11 @@ pub trait AscHeap {
fn get(&self, offset: u32, size: u32) -> Result<Vec<u8>, DeterministicHostError>;

fn api_version(&self) -> Version;

fn asc_type_id(
&mut self,
type_id_index: IndexForAscTypeId,
) -> Result<u32, DeterministicHostError>;
}

/// Instantiate `rust_obj` as an Asc object of class `C`.
Expand All @@ -24,7 +29,7 @@ pub fn asc_new<C, T: ?Sized, H: AscHeap + ?Sized>(
rust_obj: &T,
) -> Result<AscPtr<C>, DeterministicHostError>
where
C: AscType,
C: AscType + AscIndexId,
T: ToAscObj<C>,
{
let obj = rust_obj.to_asc_obj(heap)?;
Expand All @@ -40,7 +45,7 @@ pub fn asc_get<T, C, H: AscHeap + ?Sized>(
asc_ptr: AscPtr<C>,
) -> Result<T, DeterministicHostError>
where
C: AscType,
C: AscType + AscIndexId,
T: FromAscObj<C>,
{
T::from_asc_obj(asc_ptr.read_ptr(heap)?, heap)
Expand All @@ -51,7 +56,7 @@ pub fn try_asc_get<T, C, H: AscHeap + ?Sized>(
asc_ptr: AscPtr<C>,
) -> Result<T, DeterministicHostError>
where
C: AscType,
C: AscType + AscIndexId,
T: TryFromAscObj<C>,
{
T::try_from_asc_obj(asc_ptr.read_ptr(heap)?, heap)
Expand Down
Loading