Skip to content
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

feat: handle ProposeDisputed event #21

Merged
merged 6 commits into from
Aug 14, 2024
Merged

feat: handle ProposeDisputed event #21

merged 6 commits into from
Aug 14, 2024

Conversation

0xyaco
Copy link
Collaborator

@0xyaco 0xyaco commented Aug 13, 2024

🤖 Linear

Closes GRT-83

Description

Handles the ResposeDisputed event.

Copy link

linear bot commented Aug 13, 2024

GRT-83 Implement onResponseDisputed

We want the actors to handle the event ResponseDisputed from prophet Orcale.

This handler should:

  • Update RequestActivity
  • Validate if the proposal was correct, Leveraging BlockNumberService
  • Bond for disputer or proposer based on validation output

Event: https://github.com/defi-wonderland/prophet-core/blob/d01bc1a0fe39d516ff502a669e80b8eb2fe2df86/solidity/interfaces/IOracle.sol#L40

Follow figma sequence diagram: https://www.figma.com/board/BbciqJb5spg35ZglTsRRBb/Offchain?node-id=239-2749&t=y06FKcx0NVro4Jml-4
AC:

  • Event handler successfully implemented
  • Unit tests

@0xyaco 0xyaco marked this pull request as ready for review August 13, 2024 02:27
@0xyaco 0xyaco requested review from 0xkenj1 and 0xnigir1 August 13, 2024 02:48
@0xyaco 0xyaco changed the title Feat/on propose disputed feat: handle ProposeDisputed event Aug 13, 2024
await this.protocolProvider.pledgeForDispute(request.prophetData, dispute.prophetData);
} catch (err) {
if (err instanceof ContractFunctionRevertedError) {
this.logger.warn(`Pledging for dispute ${dispute.id} was reverted. Skipping...`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we log the error here also ?

Copy link
Collaborator

@0xkenj1 0xkenj1 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe what we want is to have more granular errors thrown from the protocolProvider and handle them here. The actor should be the responsible to decide if errors are recoverable or unrecoverable.

wdyt ?

I will write it down on a linear task

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, the ideal would be a situation in which we are able to handle each revert explicitly if wanted. I didn't want to go deeper with that right now, as I prefer to have the whole base of the EboActor ready and when everything is set, tackle these details.

I'll add some TODOs in those error handling blocks too, with this piece of info, thanks for the Linear task 🫶

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, just wanted to be sure we were on the same page with that :)

);
} catch (err) {
if (err instanceof ContractFunctionRevertedError) {
this.logger.warn(`Pledging on dispute ${dispute.id} was reverted. Skipping...`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

this.logger.warn(`Pledging for dispute ${dispute.id} was reverted. Skipping...`);
} else {
this.logger.error(
`Actor handling request ${this.actorRequest.id} is not able to continue.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

this.logger.warn(`Pledging on dispute ${dispute.id} was reverted. Skipping...`);
} else {
this.logger.error(
`Actor handling request ${this.actorRequest.id} is not able to continue.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dittooo

Comment on lines +31 to +39
/** @inheritdoc */
public getResponse(responseId: string): Response | undefined {
return this.responses.get(responseId);
}

/** @inheritdoc */
public addDispute(disputeId: string, dispute: Dispute): void {
this.disputes.set(disputeId, dispute);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop encapsulation 🤓

* @param event `ResponseDisputed` event.
*/
public async onResponseDisputed(event: EboEvent<"ResponseDisputed">): Promise<void> {
this.shouldHandleRequest(event.metadata.dispute.requestId);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a double check right ? EboActor is selected by the EboProcessor using the requestId right ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating myself with this, between having this check or not.

I guess that we could rely on EboProcessor + EboActorsManager to work as expected, but I like the defensiveness of having this check within EboActor. If something goes wrong in the event → request → actor routing between the other two classes, this check will catch the error before even trying to do anything.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent, would be different if it was a heavy computation , but in this case works perfectly :)

Comment on lines 169 to 226
function scaffoldEboActor(mockedValues: {
requestId: Address;
indexedChainId: Caip2ChainId;
mockActorResponse: { mockBlockNumber: bigint; mockEpoch: bigint };
}) {
const { requestId, indexedChainId, mockActorResponse } = mockedValues;
const { mockBlockNumber, mockEpoch } = mockActorResponse;

const protocolProvider = new ProtocolProvider(
["http://localhost:8538"],
DEFAULT_MOCKED_PROTOCOL_CONTRACTS,
);

const chainRpcUrls = new Map<Caip2ChainId, string[]>();
chainRpcUrls.set(indexedChainId, ["http://localhost:8539"]);

const blockNumberService = new BlockNumberService(chainRpcUrls, logger);
vi.spyOn(blockNumberService, "getEpochBlockNumber").mockResolvedValue(mockBlockNumber);

const registry = new EboMemoryRegistry();
const response: Response = {
id: "0x01",
wasDisputed: false,
prophetData: {
proposer: "0x01",
requestId: requestId,
response: {
chainId: indexedChainId,
block: mockBlockNumber,
epoch: mockEpoch,
},
},
};

vi.spyOn(registry, "getRequest").mockReturnValue(DEFAULT_MOCKED_REQUEST_CREATED_DATA);
vi.spyOn(registry, "getResponse").mockReturnValue(response);

const requestConfig = {
id: requestId,
epoch: mockEpoch,
epochTimestamp: BigInt(Date.UTC(2024, 1, 1, 0, 0, 0, 0)),
};

const actor = new EboActor(
requestConfig,
protocolProvider,
blockNumberService,
registry,
logger,
);

return {
actor,
protocolProvider,
blockNumberService,
registry,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have something similar to this. May we move it to helpers or mocks folder ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a new PR for this! Check it out #22

@0xyaco 0xyaco requested a review from 0xkenj1 August 13, 2024 22:29
0xyaco added 2 commits August 14, 2024 11:04
# 🤖 Linear

Part of GRT-83

## Description

- Create the `mocks.buildEboActor(r: Request, l: ILogger)` that enable
developers to easily build `EboActor` instances, with access to all its
dependencies.
- Create the `mocks.buildResponse(r: Request)` that enable developers to
easily build `Response` instances based on a request, for data
consistency between both entities.
- General cleaning of tests using new mock methods.
@0xyaco
Copy link
Collaborator Author

0xyaco commented Aug 14, 2024

@0xnigir1 @0xkenj1 remember that you've already reviewed tests changes on #22, as that PR branched from this one!

@0xyaco 0xyaco merged commit e1ba843 into dev Aug 14, 2024
5 checks passed
@0xyaco 0xyaco deleted the feat/on-propose-disputed branch August 14, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants