-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add bware linea goerli subgraph * chore: rebuild graph client * fix: thegraph network id for zksync-era * feat: 5069 testnet onboarding lh agents works (#5074) * feat: hh task for claiming linea message * feat: gas cost for linea propagate * test: LH tests for linea * fix: 5069 testnet onboarding lh agents works (#5080) * feat: hh task for claiming linea message * feat: gas cost for linea propagate * test: LH tests for linea * chore: yarn.lock * chore: update yarn.lock * chore: attempt fixing ci/cd for lighthouse * chore: fix broken ci/cd * fix: docker build fix (#5092) * fix: process from root linea (#5084) * feat: claimMessage interface * chore: rebuild * feat: linea process from root * test: linea process from root unit tests * feat: deploy testnet linea hub connector * feat: hub subgraph for linea hub connector * chore: rename --------- Co-authored-by: Liu <57480598+liu-zhipeng@users.noreply.github.com> Co-authored-by: preethamr <preethamr@users.noreply.github.com> Co-authored-by: Carlo Mazzaferro <carlo.mazzaferro@gmail.com>
- Loading branch information
1 parent
18b72f4
commit a4f146a
Showing
23 changed files
with
2,212 additions
and
1,571 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 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
59 changes: 59 additions & 0 deletions
59
packages/agents/lighthouse/src/tasks/processFromRoot/helpers/linea.ts
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,59 @@ | ||
import { createLoggingContext } from "@connext/nxtp-utils"; | ||
import { BigNumber } from "ethers"; | ||
|
||
import { LineaSDK } from "../../../mockable"; | ||
import { AlreadyProcessed, NoRootAvailable } from "../errors"; | ||
import { getContext } from "../processFromRoot"; | ||
|
||
import { GetProcessArgsParams } from "."; | ||
|
||
export const getProcessFromLineaRootArgs = async ({ | ||
spokeChainId, | ||
hubChainId, | ||
hubProvider, | ||
spokeProvider, | ||
message: _message, | ||
sendHash, | ||
_requestContext, | ||
}: GetProcessArgsParams): Promise<[BigNumber, string]> => { | ||
const { logger } = getContext(); | ||
const { requestContext, methodContext } = createLoggingContext(getProcessFromLineaRootArgs.name, _requestContext); | ||
logger.info("Method start", requestContext, methodContext); | ||
|
||
const sdk = new LineaSDK({ | ||
l1RpcUrl: hubProvider, // L1 rpc url | ||
l2RpcUrl: spokeProvider, // L2 rpc url | ||
network: hubChainId === 1 ? "linea-mainnet" : "linea-goerli", // network you want to interact with (either linea-mainnet or linea-goerli) | ||
mode: "read-only", // contract wrapper class mode (read-only or read-write), read-only: only read contracts state, read-write: read contracts state and claim messages | ||
}); | ||
|
||
// get Message Status | ||
const messages = await sdk.getL2Contract().getMessagesByTransactionHash(sendHash); | ||
|
||
if (!messages?.length) { | ||
throw new NoRootAvailable(spokeChainId, hubChainId, requestContext, methodContext, { | ||
error: `${sendHash} has no message sent`, | ||
}); | ||
} | ||
|
||
// returns on-chain message status by message hash | ||
const messageStatus = await sdk.getL1Contract().getMessageStatus(messages[0].messageHash); | ||
logger.info("Got Message status on hub chain from linea", requestContext, methodContext, { | ||
sendHash, | ||
message: messages[0], | ||
messageStatus, | ||
}); | ||
|
||
if (messageStatus === "CLAIMED") { | ||
throw new AlreadyProcessed(spokeChainId, hubChainId, requestContext, methodContext, { | ||
sendHash, | ||
messageStatus, | ||
}); | ||
} else if (messageStatus === "CLAIMABLE") { | ||
return [messages[0].messageNonce, messages[0].calldata]; | ||
} else { | ||
throw new NoRootAvailable(spokeChainId, hubChainId, requestContext, methodContext, { | ||
error: `Linea Unknown message status`, | ||
}); | ||
} | ||
}; |
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
140 changes: 140 additions & 0 deletions
140
packages/agents/lighthouse/test/tasks/processFromRoot/helpers/linea.spec.ts
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,140 @@ | ||
import { createRequestContext, expect, mkAddress, mkHash } from "@connext/nxtp-utils"; | ||
import { stub, SinonStub } from "sinon"; | ||
import { BigNumber } from "ethers"; | ||
|
||
import * as MockableFns from "../../../../src/mockable"; | ||
import { getProcessFromLineaRootArgs } from "../../../../src/tasks/processFromRoot/helpers"; | ||
import { AlreadyProcessed, NoRootAvailable } from "../../../../src/tasks/processFromRoot/errors"; | ||
|
||
let getL1Contract: SinonStub; | ||
let getL2Contract: SinonStub; | ||
|
||
class MockLineaSDK { | ||
public getL1Contract = getL1Contract; | ||
public getL2Contract = getL2Contract; | ||
} | ||
|
||
describe("Helpers: Linea", () => { | ||
beforeEach(() => { | ||
stub(MockableFns, "LineaSDK").value(MockLineaSDK); | ||
}); | ||
|
||
it("should throw error if no messages", async () => { | ||
getL2Contract = stub().returns({ | ||
getMessagesByTransactionHash: stub().resolves([]), | ||
} as any); | ||
await expect( | ||
getProcessFromLineaRootArgs({ | ||
spokeChainId: 1, | ||
spokeDomainId: "1", | ||
spokeProvider: "world", | ||
hubChainId: 2, | ||
hubDomainId: "2", | ||
hubProvider: "hello", | ||
sendHash: mkHash("0xbaa"), | ||
blockNumber: 123, | ||
message: mkHash("0xbbbb"), | ||
_requestContext: createRequestContext("foo"), | ||
}), | ||
).to.be.rejectedWith(NoRootAvailable); | ||
}); | ||
|
||
it("should throw error if already processed", async () => { | ||
getL2Contract = stub().returns({ | ||
getMessagesByTransactionHash: stub().resolves([ | ||
{ | ||
messageSender: mkAddress("a"), | ||
destination: mkAddress("b"), | ||
fee: BigNumber.from(0), | ||
value: BigNumber.from(0), | ||
messageNonce: BigNumber.from(1), | ||
calldata: "0x", | ||
messageHash: mkHash("0xa"), | ||
}, | ||
]), | ||
} as any); | ||
getL1Contract = stub().returns({ | ||
getMessageStatus: stub().resolves("CLAIMED"), | ||
}); | ||
await expect( | ||
getProcessFromLineaRootArgs({ | ||
spokeChainId: 1, | ||
spokeDomainId: "1", | ||
spokeProvider: "world", | ||
hubChainId: 2, | ||
hubDomainId: "2", | ||
hubProvider: "hello", | ||
sendHash: mkHash("0xbaa"), | ||
blockNumber: 123, | ||
message: mkHash("0xbbbb"), | ||
_requestContext: createRequestContext("foo"), | ||
}), | ||
).to.be.rejectedWith(AlreadyProcessed); | ||
}); | ||
|
||
it("should throw error if unknown status", async () => { | ||
getL2Contract = stub().returns({ | ||
getMessagesByTransactionHash: stub().resolves([ | ||
{ | ||
messageSender: mkAddress("a"), | ||
destination: mkAddress("b"), | ||
fee: BigNumber.from(0), | ||
value: BigNumber.from(0), | ||
messageNonce: BigNumber.from(1), | ||
calldata: "0x", | ||
messageHash: mkHash("0xa"), | ||
}, | ||
]), | ||
} as any); | ||
getL1Contract = stub().returns({ | ||
getMessageStatus: stub().resolves("UNKNOWN"), | ||
}); | ||
await expect( | ||
getProcessFromLineaRootArgs({ | ||
spokeChainId: 1, | ||
spokeDomainId: "1", | ||
spokeProvider: "world", | ||
hubChainId: 2, | ||
hubDomainId: "2", | ||
hubProvider: "hello", | ||
sendHash: mkHash("0xbaa"), | ||
blockNumber: 123, | ||
message: mkHash("0xbbbb"), | ||
_requestContext: createRequestContext("foo"), | ||
}), | ||
).to.be.rejectedWith(NoRootAvailable); | ||
}); | ||
|
||
it("should work", async () => { | ||
getL2Contract = stub().returns({ | ||
getMessagesByTransactionHash: stub().resolves([ | ||
{ | ||
messageSender: mkAddress("a"), | ||
destination: mkAddress("b"), | ||
fee: BigNumber.from(0), | ||
value: BigNumber.from(0), | ||
messageNonce: BigNumber.from(1), | ||
calldata: mkHash("0xa"), | ||
messageHash: mkHash("0xb"), | ||
}, | ||
]), | ||
} as any); | ||
getL1Contract = stub().returns({ | ||
getMessageStatus: stub().resolves("CLAIMABLE"), | ||
}); | ||
const args = await getProcessFromLineaRootArgs({ | ||
spokeChainId: 1, | ||
spokeDomainId: "1", | ||
spokeProvider: "world", | ||
hubChainId: 2, | ||
hubDomainId: "2", | ||
hubProvider: "hello", | ||
sendHash: mkHash("0xbaa"), | ||
blockNumber: 123, | ||
message: mkHash("0xbbbb"), | ||
_requestContext: createRequestContext("foo"), | ||
}); | ||
|
||
expect(args).to.deep.eq([BigNumber.from(1), mkHash("0xa")]); | ||
}); | ||
}); |
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
Oops, something went wrong.