From 5c64e0bdcc74bdf2143c70ecf1413951f14ae2ad Mon Sep 17 00:00:00 2001 From: tilacog Date: Thu, 7 Apr 2022 23:18:52 -0300 Subject: [PATCH 1/2] graph: Use reserved discriminant segments for `IndexForAscTypeId` --- graph/src/runtime/mod.rs | 165 ++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/graph/src/runtime/mod.rs b/graph/src/runtime/mod.rs index d23300b891b..7e0940b5d8e 100644 --- a/graph/src/runtime/mod.rs +++ b/graph/src/runtime/mod.rs @@ -139,12 +139,23 @@ macro_rules! impl_asc_type { impl_asc_type!(u8, u16, u32, u64, i8, i32, i64, f32, f64); -// The numbers on each variant could just be comments hence the -// `#[repr(u32)]`, however having them in code enforces each value -// to be the same as the docs. +/// Contains type IDs and their discriminants for every blockchain supported by Graph-Node. +/// +/// Each variant corresponds to the unique ID of an AssemblyScript concrete class used in the +/// [`runtime`]. +/// +/// # Rules for updating this enum +/// +/// 1 .The discriminants must have the same value as their counterparts in `TypeId` enum from +/// graph-ts' `global` module. If not, the runtime will fail to determine the correct class +/// during allocation. +/// 2. Each supported blockchain has a reserved space of 500 contiguous variants. +/// 3. Once defined, items and their discriminants cannot be changed, as this would break running +/// subgraphs compiled in previous versions of this representation. #[repr(u32)] #[derive(Copy, Clone, Debug)] pub enum IndexForAscTypeId { + // Ethereum type IDs String = 0, ArrayBuffer = 1, Int8Array = 2, @@ -199,15 +210,6 @@ pub enum IndexForAscTypeId { ArrayBigDecimal = 51, // Near Type IDs - // - // Generated with the following shell script: - // - // ``` - // cat chain/near/src/runtime/generated.rs | grep IndexForAscTypeId::Near | grep -Eo "Near[a-zA-Z0-9]+" | awk '{for(x=1;x<=NF;x++)sub(/$/,"="++i+51",")}1' | sed 's/=/ = /' - // ``` - // - // The `51` literal at the end in the `awk` should be replaced with the last element - // value in the list above. NearArrayDataReceiver = 52, NearArrayCryptoHash = 53, NearArrayActionEnum = 54, @@ -243,70 +245,93 @@ pub enum IndexForAscTypeId { NearChunkHeader = 84, NearBlock = 85, NearReceiptWithOutcome = 86, - - // Tendermint Type IDs + // Reserved discriminant space for more Near type IDs: [87, 499]: + // Continue to add more Near type IDs here. + // e.g.: + // NextNearType = 87, + // AnotherNearType = 88, + // ... + // LastNearType = 499, + + // Reserved discriminant space for more Ethereum type IDs: [500, 999] + TransactionReceipt = 500, + Log = 501, + ArrayH256 = 502, + ArrayLog = 503, + // Continue to add more Ethereum type IDs here. + // e.g.: + // NextEthereumType = 504, + // AnotherEthereumType = 505, + // ... + // LastEthereumType = 999, + + // Reserved discriminant space for Tendermint type IDs: [1,500, 1,999] + TendermintArrayBytes = 1500, + TendermintArrayCommitSig = 1501, + TendermintArrayEvent = 1502, + TendermintArrayEventAttribute = 1503, + TendermintArrayEventTx = 1504, + TendermintArrayEvidence = 1505, + TendermintArrayValidator = 1506, + TendermintArrayValidatorUpdate = 1507, + TendermintBlock = 1508, + TendermintBlockID = 1509, + TendermintBlockIDFlagEnum = 1510, + TendermintBlockParams = 1511, + TendermintCommit = 1512, + TendermintCommitSig = 1513, + TendermintConsensus = 1514, + TendermintConsensusParams = 1515, + TendermintData = 1516, + TendermintDuplicateVoteEvidence = 1517, + TendermintDuration = 1518, + TendermintEvent = 1519, + TendermintEventAttribute = 1520, + TendermintEventBlock = 1521, + TendermintEventData = 1522, + TendermintEventList = 1523, + TendermintEventTx = 1524, + TendermintEventValidatorSetUpdates = 1525, + TendermintEventVote = 1526, + TendermintEvidence = 1527, + TendermintEvidenceList = 1528, + TendermintEvidenceParams = 1529, + TendermintHeader = 1530, + TendermintLightBlock = 1531, + TendermintLightClientAttackEvidence = 1532, + TendermintPartSetHeader = 1533, + TendermintPublicKey = 1534, + TendermintResponseBeginBlock = 1535, + TendermintResponseDeliverTx = 1536, + TendermintResponseEndBlock = 1537, + TendermintSignedHeader = 1538, + TendermintSignedMsgTypeEnum = 1539, + TendermintTimestamp = 1540, + TendermintTxResult = 1541, + TendermintValidator = 1542, + TendermintValidatorParams = 1543, + TendermintValidatorSet = 1544, + TendermintValidatorUpdate = 1545, + TendermintVersionParams = 1546, + // Continue to add more Tendermint type IDs here. + // e.g.: + // NextTendermintType = 1547, + // AnotherTendermintType = 1547, + // ... + // LastTendermintType = 1999, + + // Reserved discriminant space for a future blockchain type IDs: [2,000, 2,500] // // Generated with the following shell script: // // ``` - // cat chain/tendermint/src/runtime/generated.rs | grep IndexForAscTypeId::Tendermint | grep -Eo "Tendermint[a-zA-Z0-9]+" | awk '{for(x=1;x<=NF;x++)sub(/$/,"="++i+86",")}1' | sed 's/=/ = /' + // grep -Po "(?<=IndexForAscTypeId::)IDENDIFIER_PREFIX.*\b" SRC_FILE | sort |uniq | awk 'BEGIN{count=2000} {sub("$", " = "count",", $1); count++} 1' // ``` // - // The `86` literal at the end in the `awk` should be replaced with the last element - // value in the list above. - TendermintArrayEventTx = 87, - TendermintArrayEvent = 88, - TendermintArrayCommitSig = 89, - TendermintArrayBytes = 90, - TendermintArrayEvidence = 91, - TendermintArrayEventAttribute = 92, - TendermintBlockIDFlagEnum = 93, - TendermintSignedMsgTypeEnum = 94, - TendermintEventList = 95, - TendermintEventBlock = 96, - TendermintResponseBeginBlock = 97, - TendermintResponseEndBlock = 98, - TendermintValidatorUpdate = 99, - TendermintArrayValidatorUpdate = 100, - TendermintConsensusParams = 101, - TendermintBlockParams = 102, - TendermintEvidenceParams = 103, - TendermintValidatorParams = 104, - TendermintVersionParams = 105, - TendermintBlock = 106, - TendermintCommit = 107, - TendermintCommitSig = 108, - TendermintHeader = 109, - TendermintConsensus = 110, - TendermintBlockID = 111, - TendermintPartSetHeader = 112, - TendermintData = 113, - TendermintEvidence = 114, - TendermintDuplicateVoteEvidence = 115, - TendermintEventTx = 116, - TendermintEventVote = 117, - TendermintLightClientAttackEvidence = 118, - TendermintLightBlock = 119, - TendermintValidatorSet = 120, - TendermintSignedHeader = 121, - TendermintEvidenceList = 122, - TendermintValidator = 123, - TendermintArrayValidator = 124, - TendermintPublicKey = 125, - TendermintTxResult = 126, - TendermintResponseDeliverTx = 127, - TendermintEvent = 128, - TendermintEventAttribute = 129, - TendermintEventValidatorSetUpdates = 130, - TendermintDuration = 131, - TendermintTimestamp = 132, - TendermintEventData = 133, - - // More Ethereum tyes - TransactionReceipt = 134, - Log = 135, - ArrayH256 = 136, - ArrayLog = 137, + // INSTRUCTIONS: + // 1. Replace the IDENTIFIER_PREFIX and the SRC_FILE placeholders according to the blockchain + // name and implementation before running this script. + // 2. Insert the output right before the end of this block. } impl ToAscObj for IndexForAscTypeId { From 3a71d7bf833e5a7a8e2768a3c001e594974a7518 Mon Sep 17 00:00:00 2001 From: tilacog Date: Mon, 11 Apr 2022 18:29:23 -0300 Subject: [PATCH 2/2] graph: Increase discriminant space size to a thousand variants --- graph/src/runtime/mod.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/graph/src/runtime/mod.rs b/graph/src/runtime/mod.rs index 7e0940b5d8e..644488072da 100644 --- a/graph/src/runtime/mod.rs +++ b/graph/src/runtime/mod.rs @@ -149,7 +149,7 @@ impl_asc_type!(u8, u16, u32, u64, i8, i32, i64, f32, f64); /// 1 .The discriminants must have the same value as their counterparts in `TypeId` enum from /// graph-ts' `global` module. If not, the runtime will fail to determine the correct class /// during allocation. -/// 2. Each supported blockchain has a reserved space of 500 contiguous variants. +/// 2. Each supported blockchain has a reserved space of 1,000 contiguous variants. /// 3. Once defined, items and their discriminants cannot be changed, as this would break running /// subgraphs compiled in previous versions of this representation. #[repr(u32)] @@ -245,27 +245,27 @@ pub enum IndexForAscTypeId { NearChunkHeader = 84, NearBlock = 85, NearReceiptWithOutcome = 86, - // Reserved discriminant space for more Near type IDs: [87, 499]: + // Reserved discriminant space for more Near type IDs: [87, 999]: // Continue to add more Near type IDs here. // e.g.: // NextNearType = 87, // AnotherNearType = 88, // ... - // LastNearType = 499, + // LastNearType = 999, - // Reserved discriminant space for more Ethereum type IDs: [500, 999] - TransactionReceipt = 500, - Log = 501, - ArrayH256 = 502, - ArrayLog = 503, + // Reserved discriminant space for more Ethereum type IDs: [1000, 1499] + TransactionReceipt = 1000, + Log = 1001, + ArrayH256 = 1002, + ArrayLog = 1003, // Continue to add more Ethereum type IDs here. // e.g.: - // NextEthereumType = 504, - // AnotherEthereumType = 505, + // NextEthereumType = 1004, + // AnotherEthereumType = 1005, // ... - // LastEthereumType = 999, + // LastEthereumType = 1499, - // Reserved discriminant space for Tendermint type IDs: [1,500, 1,999] + // Reserved discriminant space for Tendermint type IDs: [1,500, 2,499] TendermintArrayBytes = 1500, TendermintArrayCommitSig = 1501, TendermintArrayEvent = 1502, @@ -318,20 +318,21 @@ pub enum IndexForAscTypeId { // NextTendermintType = 1547, // AnotherTendermintType = 1547, // ... - // LastTendermintType = 1999, + // LastTendermintType = 2499, - // Reserved discriminant space for a future blockchain type IDs: [2,000, 2,500] + // Reserved discriminant space for a future blockchain type IDs: [2,500, 3,499] // // Generated with the following shell script: // // ``` - // grep -Po "(?<=IndexForAscTypeId::)IDENDIFIER_PREFIX.*\b" SRC_FILE | sort |uniq | awk 'BEGIN{count=2000} {sub("$", " = "count",", $1); count++} 1' + // grep -Po "(?<=IndexForAscTypeId::)IDENDIFIER_PREFIX.*\b" SRC_FILE | sort |uniq | awk 'BEGIN{count=2500} {sub("$", " = "count",", $1); count++} 1' // ``` // // INSTRUCTIONS: // 1. Replace the IDENTIFIER_PREFIX and the SRC_FILE placeholders according to the blockchain // name and implementation before running this script. - // 2. Insert the output right before the end of this block. + // 2. Replace `2500` part with the first number of that blockchain's reserved discriminant space. + // 3. Insert the output right before the end of this block. } impl ToAscObj for IndexForAscTypeId {