diff --git a/.github/workflows/publish-native-binaries.yml b/.github/workflows/publish-native-binaries.yml index 2b05d46fa..8f521a8a1 100644 --- a/.github/workflows/publish-native-binaries.yml +++ b/.github/workflows/publish-native-binaries.yml @@ -23,15 +23,6 @@ jobs: target: x86_64-apple-darwin - os: ubuntu-22.04 target: x86_64-unknown-linux-gnu - include: - - node_version: 17 - system: - os: ubuntu-20.04 - target: x86_64-unknown-linux-gnu - - node_version: 17 - system: - os: macos-11 - target: x86_64-apple-darwin runs-on: ${{ matrix.system.os }} steps: - name: Checkout the repo diff --git a/package.json b/package.json index 102375d61..bce0a94d7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "graphql": "16.8.0" }, "engines": { - "node": ">=12.22.0" + "node": ">=18.0.0" }, "jest": { "transformIgnorePatterns": [ diff --git a/packages/indexer-native/native/Cargo.lock b/packages/indexer-native/native/Cargo.lock index 48fae5487..0732e60df 100644 --- a/packages/indexer-native/native/Cargo.lock +++ b/packages/indexer-native/native/Cargo.lock @@ -349,12 +349,12 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" -version = "0.6.7" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "winapi", + "windows-targets", ] [[package]] @@ -419,45 +419,29 @@ checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" [[package]] name = "neon" -version = "0.10.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e15415261d880aed48122e917a45e87bb82cf0260bb6db48bbab44b7464373" +checksum = "7d75440242411c87dc39847b0e33e961ec1f10326a9d8ecf9c1ea64a3b3c13dc" dependencies = [ - "neon-build", + "libloading", "neon-macros", - "neon-runtime", - "semver 0.9.0", + "once_cell", + "semver", + "send_wrapper", "smallvec", ] -[[package]] -name = "neon-build" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bac98a702e71804af3dacfde41edde4a16076a7bbe889ae61e56e18c5b1c811" - [[package]] name = "neon-macros" -version = "0.10.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7288eac8b54af7913c60e0eb0e2a7683020dffa342ab3fd15e28f035ba897cf" +checksum = "c6813fde79b646e47e7ad75f480aa80ef76a5d9599e2717407961531169ee38b" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.43", "syn-mid", ] -[[package]] -name = "neon-runtime" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4676720fa8bb32c64c3d9f49c47a47289239ec46b4bdb66d0913cc512cb0daca" -dependencies = [ - "cfg-if", - "libloading", - "smallvec", -] - [[package]] name = "num-traits" version = "0.2.16" @@ -468,6 +452,12 @@ dependencies = [ "libm", ] +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "opaque-debug" version = "0.3.0" @@ -492,9 +482,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -614,7 +604,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.18", + "semver", ] [[package]] @@ -662,24 +652,15 @@ dependencies = [ [[package]] name = "semver" -version = "0.9.0" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] -name = "semver-parser" -version = "0.7.0" +name = "send_wrapper" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" @@ -698,7 +679,7 @@ checksum = "dc59dfdcbad1437773485e0367fea4b090a2e0a16d9ffc46af47764536a298ec" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn 2.0.43", ] [[package]] @@ -716,9 +697,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smol_str" @@ -754,9 +735,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", @@ -765,13 +746,13 @@ dependencies = [ [[package]] name = "syn-mid" -version = "0.5.4" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea305d57546cc8cd04feb14b62ec84bf17f50e3f7b12560d7bfa9265f39d9ed" +checksum = "b5dc35bb08dd1ca3dfb09dce91fd2d13294d6711c88897d9a9d60acf39bce049" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.43", ] [[package]] @@ -853,28 +834,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/packages/indexer-native/native/Cargo.toml b/packages/indexer-native/native/Cargo.toml index 4fe94e66d..ef17cd2a5 100644 --- a/packages/indexer-native/native/Cargo.toml +++ b/packages/indexer-native/native/Cargo.toml @@ -6,9 +6,10 @@ authors = [ "Theo Butler ", ] license = "MIT" -edition = "2018" +edition = "2021" [lib] +name = "indexer_native" crate-type = ["cdylib"] [dependencies] @@ -17,5 +18,5 @@ arc-swap = "1.2" eip-712-derive = { git = "https://github.com/graphprotocol/eip-712-derive" } keccak-hash = "0.10.0" lazy_static = "1.4" -neon = { version = "0.10", default-features = false, features = ["napi-6"] } +neon = { version = "1.0.0", default-features = false, features = ["napi-6"] } secp256k1 = { version = "0.27", features = ["recovery"] } diff --git a/packages/indexer-native/native/src/lib.rs b/packages/indexer-native/native/src/lib.rs index 1bd061c1d..0a5c72d19 100644 --- a/packages/indexer-native/native/src/lib.rs +++ b/packages/indexer-native/native/src/lib.rs @@ -13,30 +13,66 @@ use signature_verification::SignatureVerifier; pub struct SignatureVerifierProxy; +// Lifting neon's `or_throw` extension trait pattern here. +trait ResultDbgExt { + fn or_else_throw<'a, C: Context<'a>>(self, cx: &mut C) -> NeonResult; +} +impl ResultDbgExt for Result { + fn or_else_throw<'a, C: Context<'a>>(self, cx: &mut C) -> NeonResult { + self.or_else(|err| cx.throw_error(format!("{err:?}"))) + } +} + fn signature_verifier_new(mut cx: FunctionContext) -> JsResult> { - let address: Address = cx.argument::(0)?.value(&mut cx).parse().unwrap(); + let address: Address = cx + .argument::(0)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; Ok(cx.boxed(SignatureVerifier::new(address))) } fn signature_verifier_verify(mut cx: FunctionContext) -> JsResult { let this = cx.argument::>(0)?; - let message: Bytes = cx.argument::(1)?.value(&mut cx).parse().unwrap(); - let signature: FixedBytes<65> = cx.argument::(2)?.value(&mut cx).parse().unwrap(); + let message: Bytes = cx + .argument::(1)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; + let signature: FixedBytes<65> = cx + .argument::(2)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; let recovery_id = signature[64] as i32; let recovery_id = match recovery_id { - 0 | 1 => RecoveryId::from_i32(recovery_id).unwrap(), - 27 | 28 => RecoveryId::from_i32(recovery_id - 27).unwrap(), + 0 | 1 => RecoveryId::from_i32(recovery_id).or_else_throw(&mut cx)?, + 27 | 28 => RecoveryId::from_i32(recovery_id - 27).or_else_throw(&mut cx)?, _ => panic!("Invalid recovery id"), }; - let signature = RecoverableSignature::from_compact(&signature[..64], recovery_id).unwrap(); - Ok(cx.boolean(this.verify(&message, &signature).unwrap())) + let signature = + RecoverableSignature::from_compact(&signature[..64], recovery_id).or_else_throw(&mut cx)?; + let verified = this.verify(&message, &signature).or_else_throw(&mut cx)?; + Ok(cx.boolean(verified)) } fn attestation_signer_new(mut cx: FunctionContext) -> JsResult> { let chain_id = cx.argument::(0)?.value(&mut cx) as u64; - let dispute_manager: Address = cx.argument::(1)?.value(&mut cx).parse().unwrap(); - let signer: B256 = cx.argument::(2)?.value(&mut cx).parse().unwrap(); - let subgraph_deployment_id: B256 = cx.argument::(3)?.value(&mut cx).parse().unwrap(); + let dispute_manager: Address = cx + .argument::(1)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; + let signer: B256 = cx + .argument::(2)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; + let subgraph_deployment_id: B256 = cx + .argument::(3)? + .value(&mut cx) + .parse() + .or_else_throw(&mut cx)?; Ok(cx.boxed(AttestationSigner::new( U256::from(chain_id), dispute_manager, diff --git a/packages/indexer-native/package.json b/packages/indexer-native/package.json index da53dbd11..cff92cebf 100644 --- a/packages/indexer-native/package.json +++ b/packages/indexer-native/package.json @@ -1,6 +1,6 @@ { "name": "@graphprotocol/indexer-native", - "version": "0.20.11", + "version": "0.21.4", "description": "Performance sensitive indexer code", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -16,13 +16,31 @@ }, "author": "Zac Burns ", "license": "MIT", + "os": [ + "darwin", + "linux" + ], + "cpu": [ + "x64", + "arm", + "arm64" + ], + "engines": { + "node": ">=12.22.0" + }, "scripts": { - "build": "cd native && cargo-cp-artifact -nc ../binary/index.node -- cargo build --release --message-format=json-render-diagnostics", + "build": "cd native && cargo-cp-artifact -a cdylib indexer_native ../binary/index.node -- cargo build --message-format=json-render-diagnostics", + "build-debug": "yarn build --", + "build-release": "yarn build --release", + "pull-or-build": "node-pre-gyp install --fallback-to-build=false --update-binary || yarn build-release", + "package": "node-pre-gyp package", + "publish-github-draft": "node-pre-gyp-github publish", + "publish-github": "node-pre-gyp-github publish --release", + "build-test-pack-publish": "yarn build-release && yarn test && yarn package && yarn publish-github-draft", "format": "prettier --write 'lib/**/*.js'", "lint": "eslint .", "prepare": "yarn format && yarn lint", - "test:ci": "jest --verbose --ci", - "install": "yarn build", + "install": "yarn pull-or-build", "test": "yarn build && jest --colors --verbose --forceExit", "test:ci": "yarn build && jest --verbose --ci", "clean": "rm -rf ./node_modules ./binary ./build ./coverage ./native/target ./native/artifacts.json ./native/index.node" @@ -41,5 +59,12 @@ "jest": "<30.0.0-0", "prettier": "3.0.3" }, + "binary": { + "module_name": "index", + "module_path": "./binary", + "host": "https://github.com/graphprotocol/indexer/releases/download/", + "remote_path": "v{version}", + "package_name": "graphprotocol-indexer-native-v{version}-{node_abi}-{platform}-{arch}.tar.gz" + }, "gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27" } diff --git a/packages/indexer-service/package.json b/packages/indexer-service/package.json index 78c9e6b02..f6ae9f4fa 100644 --- a/packages/indexer-service/package.json +++ b/packages/indexer-service/package.json @@ -34,7 +34,7 @@ "@google-cloud/profiler": "6.0.1", "@graphprotocol/common-ts": "2.0.9", "@graphprotocol/indexer-common": "^0.21.4", - "@graphprotocol/indexer-native": "0.20.11", + "@graphprotocol/indexer-native": "0.21.4", "@graphql-tools/load": "8.0.0", "@graphql-tools/url-loader": "8.0.0", "@graphql-tools/wrap": "10.0.1",