-
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: build onRequestCreated #18
Conversation
GRT-81 Implement onRequestCreated
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-2711&t=y06FKcx0NVro4Jml-4 AC:
|
1fe0161
to
4178514
Compare
4178514
to
40f0e03
Compare
|
||
constructor( | ||
private readonly protocolProvider: ProtocolProvider, | ||
private readonly blockNumberService: BlockNumberService, | ||
private readonly requestId: string, | ||
) { | ||
this.requestActivity = []; | ||
this.registry = new EboRegistry(); |
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.
shouldn't the registry be injected as a Dependency here?
also, maybe use an interface IEboRegistry, so if we wanted to later change for a real DB instead of in-memory maps we can easily switch to that. (i understand that the registry is sort of Database/Cache)
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.
You're absolutely 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.
probably not used now but getRequest should exist 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.
We'll probably need that, yep.
Figured we'll add methods in the registry as needed, it'd be easier to know what are we going to use while implementing the EboActor
handlers (probably all the get...
/add...
); there are some edge cases that I want to think about while implemeting the EboActor
.
currentEpoch, | ||
chainId, | ||
epochBlockNumber, | ||
); |
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.
we should handle the case in which proposeResponse fails, if it is an rpc failure or if a propose was already posted for the requestId
public async onRequestCreated(_event: EboEvent<"RequestCreated">): Promise<void> { | ||
// TODO: implement | ||
return; | ||
private alreadyProposed(epoch: bigint, chainId: Caip2ChainId, blockNumber: bigint) { |
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.
would call this activePropose
. We can have a propose on the registry that was already discarded
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.
also , we should add an isActive
field to response object
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.
Does it make sense to have a new propose with the same block? I'd think that if there has already been a proposal with the block N, rejected or not, the agent wouldn't want to propose the same block N again. I might be missing something though.
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.
Left this as alreadyProposed
, this will be the last thing to check on the agent side; it'd save it of trying to propose a response that has already been created. The activePropose
check is done at the beginning of this method.
private requests: Map<string, Request>; | ||
private responses: Map<string, Response>; | ||
private dispute: Map<string, 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.
private requests: Map<string, Request>; | |
private responses: Map<string, Response>; | |
private dispute: Map<string, Dispute>; | |
private requests: Map<string, Request>= new Map(); | |
private responses: Map<string, Response>= new Map(); | |
private dispute: Map<string, Dispute>= new Map(); |
this.requests = new Map(); | ||
this.responses = new Map(); | ||
this.dispute = new Map(); |
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.requests = new Map(); | |
this.responses = new Map(); | |
this.dispute = new Map(); |
: E extends "ResponseCreated" | ||
? ResponseCreated | ||
: E extends "ResponseProposed" | ||
? ResponseProposed |
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.
🤣
|
||
// To be byte-encode when sending it to Prophet | ||
response: { | ||
chainId: Caip2ChainId; // Pending on-chain definition on CAIP-2 usage |
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.
chainId: Caip2ChainId; // Pending on-chain definition on CAIP-2 usage | |
chainId: Caip2ChainId; //FIXME/TODO: Pending on-chain definition on CAIP-2 usage |
@@ -0,0 +1,18 @@ | |||
import { Request, Response } from "../types/prophet.js"; | |||
|
|||
export interface EboRegistry { |
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.
lets add a high level description here
this.dispute = new Map(); | ||
} | ||
|
||
public addRequest(requestId: string, request: Request) { |
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.
public addRequest(requestId: string, request: Request) { | |
/** @inheritdoc */ | |
public addRequest(requestId: string, request: Request) { |
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.
ooaa nice, didn't know that. however, vscode is so magical that doesn't need this tag xd
public addRequest(requestId: string, request: Request) { | ||
this.requests.set(requestId, request); | ||
} | ||
|
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.
/** @inheritdoc */ |
i don't have the business context, if |
Each EboActor is responsible to handle a single and unique requestId, and also each of the EboAgents have its own EboRegistry. Not sure if i got it, but maybe this info answers your question @0xnigir1 |
That's right, by design each I like the idea of adding a check for already having a request though, a nice case for using |
d3dba9d
to
2aba0ac
Compare
if (this.anyActiveProposal()) { | ||
// Skipping new proposal until the actor receives a ResponseDisputed event; | ||
// at that moment, it will be possible to re-propose again. | ||
this.logger.info( | ||
`There is an active proposal for request ${this.requestId}. Skipping...`, | ||
); | ||
|
||
return; | ||
} |
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.
@0xkenj1 included this check prior starting to build the Response
(any response will be ignored if there's an active proposal)
public async onRequestCreated(_event: EboEvent<"RequestCreated">): Promise<void> { | ||
// TODO: implement | ||
return; | ||
private alreadyProposed(epoch: bigint, chainId: Caip2ChainId, blockNumber: bigint) { |
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.
Left this as alreadyProposed
, this will be the last thing to check on the agent side; it'd save it of trying to propose a response that has already been created. The activePropose
check is done at the beginning of this method.
|
||
expect(proposeResponseMock).not.toHaveBeenCalled(); | ||
}); | ||
|
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.
it("throws if request was already handled by the actor", () => { | |
const actor = new EboActor( | |
protocolProvider, | |
blockNumberService, | |
registry, | |
requestId, | |
logger, | |
); | |
vi.spyOn(registry, "getRequest").mockReturnValue(BASE_REQUEST); | |
expect(actor.onRequestCreated(requestCreatedEvent)).rejects.toBeInstanceOf( | |
InvalidActorState, | |
); | |
}); | |
|
||
import { EboActor } from "../src/eboActor.js"; | ||
import { EboMemoryRegistry } from "../src/eboMemoryRegistry.js"; | ||
import { RequestMismatch } from "../src/exceptions/requestMismatch.js"; |
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.
import { RequestMismatch } from "../src/exceptions/requestMismatch.js"; | |
import { RequestMismatch } from "../src/exceptions/requestMismatch.js"; | |
import { InvalidActorState } from "../src/exceptions/invalidActorState.exception.js"; |
this is related to the other comment
🤖 Linear
Closes GRT-81 GRT-77
Description
BigInt
type, to be consistent with viemBlock.timestamp
typeEboActor.onRequestCreated
handler