Replies: 2 comments 10 replies
-
Thank you aaron! The approach looks good to me. But I was wondering, can't we, even in this case, leverage ADR-033? Pseudo code: func (r ADR033Router) Invoke(ctx context.Context, request, response, interface{}, ...options) {
preExecHooks := r.getPreExecHooksFor(request)
for _, preHook := range preExecHooks {
err := preHook(ctx, request)
if err != nil {
return err // rollback
}
}
handler := r.getHandlerFor(request)
resp, err := handler(ctx, request)
if err != nil { blablabla }
copyToResponse(resp, response)
postExecHooks := r.getPostExecHooksFor(request)
for _, postHook := range postExecHooks {
err := postHook(ctx, request, response)
if err != nil { blablabla }
}
} I think the infrastructure we're setting up for ADR-033 can solve this issues, and it might be a good excuse to start core modules migration towards it (staking, gov for example).
Yes this is what in our PoC we called "admission handlers", they can read state only and allow modules to extend rejection behaviour of messages of other modules. Also we could define admission handlers, pre exec hooks, post exec hooks as protobuf services and mark them with protobuf service options as "admission handlers/pre exec hooks..." and facilitate wiring too. example: package vesting.v1;
import "somewhere/cosmos.proto"
import "somewhere/bank./tx.proto"
service AdmissionService {
option (cosmos_proto.msgserver_extension) = {
type: cosmos_proto.admission_handler,
}
rpc AdmitSendCoins(bank.v1.MsgSendCoins) returns (protobuf.EmptyResponse) {};
} something like this approximately... |
Beta Was this translation helpful? Give feedback.
-
Observation: if we fire the hooks immediately, then the event based hooks shouldn't do any off-chain action - because events will be cancelled if the transaction will fail. |
Beta Was this translation helpful? Give feedback.
-
Hooks have been added to many modules as a way to observe state changes and sometimes allow/disallow them (ex. #9133 #9571). This is likely a composable way of extending a module's functionality that we want to generalize.
One observation is that hooks are almost always injected at the same place where an event is emitted. With ADR 032 Typed Events, events would essentially be struct types defined in protobuf files. We could create a framework for event listener hooks that allow modules to listen to any event emitted by another module and possibly cancel the state change with an error.
There are specifics that would need to be worked out as to how event listeners are registered (in the context of #9182), but this would basically involve a module registering functions like this:
where
EventTransfer
might be:It is even possible, that complex things like vesting and staking encumbrances could be managed with event hooks (basically restricting transfers if coins are locked or delegated). This is something that would need to be explored, but it seems like the utility of hooks has been demonstrated in many use cases and we should generalize this rather than doing it one by one for every case.
/cc @robert-zaremba @fdymylja @jgimeno @sunnya97
Beta Was this translation helpful? Give feedback.
All reactions