From 8985f1da24c45fcd3a25328dc449faa69ec8a1b0 Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Wed, 6 Nov 2024 02:57:35 -0300 Subject: [PATCH] feat: add multisend support, fix counts on reinserts. --- packages/subgraph/package.json | 12 ++++------ packages/subgraph/src/helpers.ts | 4 ++++ packages/subgraph/src/mapping.ts | 41 ++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json index 142cb2a1..c0762abf 100644 --- a/packages/subgraph/package.json +++ b/packages/subgraph/package.json @@ -6,12 +6,10 @@ "codegen": "yarn && graph codegen", "test": "yarn && yarn prep:test && yarn codegen && graph test", "build": "yarn && yarn prepare && graph build", - "deploy-mainnet": "yarn && yarn prep:mainnet && yarn codegen && graph build --network mainnet && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/mainnet-epoch-block-oracle", - "deploy-arbitrum": "yarn && yarn prep:arbitrum && yarn codegen && graph build --network arbitrum-one && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arbitrum-epoch-block-oracle", - "deploy-goerli": "yarn && yarn prep:goerli && yarn codegen && graph build --network goerli && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/goerli-epoch-block-oracle", - "deploy-arbitrum-goerli": "yarn && yarn prep:arbitrum-goerli && yarn codegen && graph build --network arbitrum-goerli && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arb-goerli-epoch-block-oracle", - "deploy-sepolia": "yarn && yarn prep:sepolia && yarn codegen && graph build --network sepolia && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/sepolia-epoch-block-oracle", - "deploy-arbitrum-sepolia": "yarn && yarn prep:arbitrum-sepolia && yarn codegen && graph build --network arbitrum-sepolia && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arbitrum-sepolia-ebo", + "deploy-mainnet": "yarn && yarn prep:mainnet && yarn codegen && graph build --network mainnet && graph deploy --studio graph-ebo-ethereum", + "deploy-arbitrum": "yarn && yarn prep:arbitrum && yarn codegen && graph build --network arbitrum-one && graph deploy --studio graph-ebo-arbitrum", + "deploy-sepolia": "yarn && yarn prep:sepolia && yarn codegen && graph build --network sepolia && graph deploy --studio graph-ebo-sepolia", + "deploy-arbitrum-sepolia": "yarn && yarn prep:arbitrum-sepolia && yarn codegen && graph build --network arbitrum-sepolia && graph deploy --studio graph-ebo-arbitrum-sepolia", "create-local": "graph create --node http://127.0.0.1:8020/ edgeandnode/block-oracle", "remove-local": "graph remove --node http://127.0.0.1:8020/ edgeandnode/block-oracle", "deploy-local": "yarn codegen && graph deploy --node http://127.0.0.1:8020/ --ipfs http://localhost:${IPFS_PORT} edgeandnode/block-oracle --version-label 0.1.0", @@ -19,8 +17,6 @@ "prep:test": "mustache ./config/test.json subgraph.template.yaml > subgraph.yaml && mustache ./config/test.json src/constants.template.ts > src/constants.ts", "prep:mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && mustache ./config/mainnet.json src/constants.template.ts > src/constants.ts", "prep:arbitrum": "mustache ./config/arbitrum.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum.json src/constants.template.ts > src/constants.ts", - "prep:goerli": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && mustache ./config/goerli.json src/constants.template.ts > src/constants.ts", - "prep:arbitrum-goerli": "mustache ./config/arbitrum-goerli.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum-goerli.json src/constants.template.ts > src/constants.ts", "prep:sepolia": "mustache ./config/sepolia.json subgraph.template.yaml > subgraph.yaml && mustache ./config/sepolia.json src/constants.template.ts > src/constants.ts", "prep:arbitrum-sepolia": "mustache ./config/arbitrum-sepolia.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum-sepolia.json src/constants.template.ts > src/constants.ts" }, diff --git a/packages/subgraph/src/helpers.ts b/packages/subgraph/src/helpers.ts index aaf0a82c..103baef8 100644 --- a/packages/subgraph/src/helpers.ts +++ b/packages/subgraph/src/helpers.ts @@ -53,6 +53,7 @@ let EVENT_SIGNATURE = "SafeMultiSigTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)"; let EVENT_DATA_TYPES = "(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)"; +let LOG_EVENT_SIGNATURE = "Log(bytes)" // For some reason it's erroring when trying to parse the calldata export class SafeExecutionContext { @@ -270,6 +271,9 @@ export function getEventFromReceipt( // maybe also check that the data contains the selector for the EBO 0xa1dce332 // but we require the parsing of the calldata to work for that desiredLog = logs[i]; + } else if(isEventLog(topics[0], LOG_EVENT_SIGNATURE)) { + // try with a previous value for multisend cases + return getEventFromReceipt(event, eventSignature, logIndex.minus(BIGINT_ONE)) } } } diff --git a/packages/subgraph/src/mapping.ts b/packages/subgraph/src/mapping.ts index 6c8b255d..d1a584d7 100644 --- a/packages/subgraph/src/mapping.ts +++ b/packages/subgraph/src/mapping.ts @@ -40,10 +40,12 @@ export function handleLogCrossChainEpochOracle(event: Log): void { event.transaction.from.toHexString() ]) } + // Support for Multisend type of transactions ONLY for EventfulDataEdge impl + let payloadId = [event.transaction.hash.toHexString(), event.logIndex.toString()].join("-") processPayload( safeExecutionContext != null ? safeExecutionContext.multisigAddress.toHexString() : event.transaction.from.toHexString(), data, - event.transaction.hash.toHexString(), + payloadId, event.block.number ); } @@ -62,19 +64,19 @@ export function handleCrossChainEpochOracle( export function processPayload( submitter: string, payloadBytes: Bytes, - txHash: string, + payloadId: string, blockNumber: BigInt ): void { log.warning( - "Processing payload. Submitter: {}, txHash: {}, blockNumber: {}", - [submitter, txHash, blockNumber.toString()] + "Processing payload. Submitter: {}, payloadId: {}, blockNumber: {}", + [submitter, payloadId, blockNumber.toString()] ); // Start the StoreCache let cache = new StoreCache(); // This is the only thing not handled through the store cache since we want all // Payload entity to persist (to provide context for validity of the payload) - let payload = new Payload(txHash); + let payload = new Payload(payloadId); payload.data = payloadBytes; payload.submitter = submitter; payload.valid = true; @@ -99,7 +101,7 @@ export function processPayload( ]); // Handle message block - let messageBlock = cache.getMessageBlock([txHash, i].join("-")); + let messageBlock = cache.getMessageBlock([payloadId, i].join("-")); messageBlock.payload = payload.id; processMessageBlock(cache, messageBlock, reader, payload.submitter); if (!reader.ok) { @@ -117,8 +119,8 @@ export function processPayload( payload.save(); cache.commitChanges(); log.warning( - "Processed payload. Submitter: {}, txHash: {}, blockNumber: {}", - [submitter, txHash, blockNumber.toString()] + "Processed payload. Submitter: {}, payloadId: {}, blockNumber: {}", + [submitter, payloadId, blockNumber.toString()] ); } @@ -439,6 +441,7 @@ function executeRegisterNetworksMessage( networks = networksMapped.flat(); let numInsertions = decodeU64(reader) as i32; + let numReinsertions = 0; if (!reader.ok) { return; } @@ -453,8 +456,13 @@ function executeRegisterNetworksMessage( if (!cache.isNetworkAlreadyRegistered(chainId)) { let network = cache.getNetwork(chainId); network.alias = PRELOADED_ALIASES.keys().includes(network.id) ? PRELOADED_ALIASES.get(network.id).toString() : "" - network.addedAt = message.id; - network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed + if(network.removedAt == null) { + network.addedAt = message.id; + } else { + numReinsertions += 1; + network.lastUpdatedAt = message.id; + network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed + } networks.push(network); } else { reader.fail("Network {} is already registered.".replace("{}", chainId)); @@ -465,6 +473,7 @@ function executeRegisterNetworksMessage( globalState.activeNetworkCount += numInsertions; globalState.activeNetworkCount -= numRemovals; globalState.networkCount += numInsertions; + globalState.networkCount -= numReinsertions; commitNetworkChanges(removedNetworks, networks, globalState, message.id); @@ -538,6 +547,7 @@ function executeRegisterNetworksAndAliasesMessage( networks = networksMapped.flat(); let numInsertions = decodeU64(reader) as i32; + let numReinsertions = 0; if (!reader.ok) { return; } @@ -552,9 +562,13 @@ function executeRegisterNetworksAndAliasesMessage( if (!cache.isNetworkAlreadyRegistered(chainId)) { let network = cache.getNetwork(chainId); - network.addedAt = message.id; - network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed - + if(network.removedAt == null) { + network.addedAt = message.id; + } else { + numReinsertions += 1; + network.lastUpdatedAt = message.id; + network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed + } // Get manifest alias for that CAIP2 id let alias = decodeString(reader); if (!reader.ok) { @@ -572,6 +586,7 @@ function executeRegisterNetworksAndAliasesMessage( globalState.activeNetworkCount += numInsertions; globalState.activeNetworkCount -= numRemovals; globalState.networkCount += numInsertions; + globalState.networkCount -= numReinsertions; commitNetworkChanges(removedNetworks, networks, globalState, message.id);