-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
GRT-83 Implement onResponseDisputed
We want the actors to handle the event This handler should:
Follow figma sequence diagram: https://www.figma.com/board/BbciqJb5spg35ZglTsRRBb/Offchain?node-id=239-2749&t=y06FKcx0NVro4Jml-4
|
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...`); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 TODO
s in those error handling blocks too, with this piece of info, thanks for the Linear task 🫶
There was a problem hiding this comment.
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...`); |
There was a problem hiding this comment.
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.`, |
There was a problem hiding this comment.
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.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dittooo
/** @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); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
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, | ||
}; | ||
} |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
# 🤖 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.
🤖 Linear
Closes GRT-83
Description
Handles the
ResposeDisputed
event.