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(async): dispatcher #1853

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fdd36ff
dispatcher
ocnc2 Aug 6, 2024
9ddb355
reorg
ocnc2 Aug 6, 2024
6d6c6f3
sleep
ocnc2 Aug 7, 2024
1e6ad38
dispatch middleware
ocnc2 Aug 7, 2024
c61d794
wip
ocnc2 Aug 7, 2024
03cf52b
Merge branch 'main' into dispatcherv2
nidhi-singh02 Aug 7, 2024
9df8769
dispatch validator
ocnc2 Aug 7, 2024
b176c5d
Merge branch 'main' into dispatcherv2
ocnc2 Aug 7, 2024
bf8787b
types
ocnc2 Aug 7, 2024
c999d17
dispatcher pruner deposit
ocnc2 Aug 7, 2024
cc7567d
dispatch da service and add more routes
ocnc2 Aug 7, 2024
52f4458
Merge branch 'main' into dispatcherv2
ocnc2 Aug 7, 2024
9066944
mock
ocnc2 Aug 7, 2024
6eb7206
give chainservice a dispatcher
ocnc2 Aug 7, 2024
66d66ee
why was this even here
ocnc2 Aug 7, 2024
cc96b11
goodbye broker
ocnc2 Aug 7, 2024
70c0f36
tidy
ocnc2 Aug 7, 2024
c6a8a43
tmr
ocnc2 Aug 8, 2024
748d712
logger
ocnc2 Aug 8, 2024
e3db47b
Merge branch 'main' into dispatcherv2
ocnc2 Aug 8, 2024
7f2dbfa
checkpoint
ocnc2 Aug 8, 2024
1a4d885
merge main fr this time
ocnc2 Aug 8, 2024
a686a03
Merge remote-tracking branch 'origin/main' into dispatcherv2
ocnc2 Aug 8, 2024
c27ada8
bointer]
ocnc2 Aug 8, 2024
bc43819
cleanup with arch
ocnc2 Aug 8, 2024
a6172ed
Merge branch 'main' into dispatcherv2
ocnc2 Aug 8, 2024
9213b65
rename
ocnc2 Aug 8, 2024
b6cb638
fixes & cleanup
ocnc2 Aug 8, 2024
a0fcd08
checkpoint
ocnc2 Aug 9, 2024
da942ef
bet
ocnc2 Aug 9, 2024
82d08cd
lint
ocnc2 Aug 9, 2024
1792026
comments
ocnc2 Aug 9, 2024
9b4a337
pruner
ocnc2 Aug 9, 2024
125ad29
fixes
ocnc2 Aug 9, 2024
eb9c207
Merge branch 'main' into dispatcherv2
ocnc2 Aug 9, 2024
ac6d1cb
revert pruner change
ocnc2 Aug 9, 2024
6db6b49
Merge branch 'main' into dispatcherv2
ocnc2 Aug 9, 2024
0a0735a
pass dispatcher in deposit service
ocnc2 Aug 9, 2024
c84a80d
registry
ocnc2 Aug 9, 2024
a57efa2
provide
ocnc2 Aug 9, 2024
6806275
nil
ocnc2 Aug 9, 2024
687bf5f
bet
ocnc2 Aug 9, 2024
ec0bf81
merge main
ocnc2 Aug 9, 2024
64212d2
tidy
ocnc2 Aug 9, 2024
82e0a8e
merge main
ocnc2 Aug 9, 2024
fd10d25
tidy
ocnc2 Aug 9, 2024
3bd43d6
future + modular refactor
ocnc2 Aug 12, 2024
3f42ab8
bet
ocnc2 Aug 12, 2024
90e5f12
Merge branch 'main' into dispatcherv2
ocnc2 Aug 12, 2024
ae045ff
nit fixes
ocnc2 Aug 12, 2024
85b9c7b
interface
ocnc2 Aug 12, 2024
d0289d1
Merge remote-tracking branch 'origin/main' into dispatcherv2
ocnc2 Aug 12, 2024
6301814
bet
ocnc2 Aug 12, 2024
4e4440e
Merge branch 'main' into dispatcherv2
ocnc2 Aug 12, 2024
08fff98
nilaway
ocnc2 Aug 12, 2024
cd0b7be
interface
ocnc2 Aug 12, 2024
c77f234
Merge branch 'main' into dispatcherv2
ocnc2 Aug 14, 2024
a66708b
bet
ocnc2 Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions mod/async/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
module github.com/berachain/beacon-kit/mod/async

go 1.22.5

require (
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0
github.com/berachain/beacon-kit/mod/log v0.0.0-20240807213340-5779c7a563cd
)

require (
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
)
72 changes: 72 additions & 0 deletions mod/async/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0 h1:kCSrkb/uVXfMKJPKjf0c7nlJkwn5cNwMxtzRW4zNq2A=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0/go.mod h1:og0jtHZosPDTyhge9tMBlRItoZ4Iv3aZFM9n4QDpcdo=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240807213340-5779c7a563cd h1:DYSjsq80Omqqlt+z2VcYsSxjZpLqCDRz7CvUDBrLDJE=
github.com/berachain/beacon-kit/mod/log v0.0.0-20240807213340-5779c7a563cd/go.mod h1:BilVBmqKhC4GXYCaIs8QnKaR14kpn3YmF5uYBdayF9I=
github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDrbC/I=
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getsentry/sentry-go v0.28.1 h1:zzaSm/vHmGllRM6Tpx1492r0YDzauArdBfkJRtY6P5k=
github.com/getsentry/sentry-go v0.28.1/go.mod h1:1fQZ+7l7eeJ3wYi82q5Hg8GqAPgefRq+FP/QhafYVgg=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
110 changes: 0 additions & 110 deletions mod/async/pkg/broker/broker.go

This file was deleted.

137 changes: 137 additions & 0 deletions mod/async/pkg/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package dispatcher

import (
"context"

"github.com/berachain/beacon-kit/mod/async/pkg/types"
"github.com/berachain/beacon-kit/mod/log"
)

// Dispatcher faciliates asynchronous communication between components,
// typically services. It acts as an API facade to the underlying event and
// message servers.
type Dispatcher struct {
eventServer EventServer
msgServer MessageServer
logger log.Logger[any]
}

// NewDispatcher creates a new dispatcher.
func NewDispatcher(
ocnc2 marked this conversation as resolved.
Show resolved Hide resolved
eventServer EventServer,
msgServer MessageServer,
logger log.Logger[any],
) *Dispatcher {
eventServer.SetLogger(logger)
msgServer.SetLogger(logger)
return &Dispatcher{
eventServer: eventServer,
msgServer: msgServer,
logger: logger,
}
ocnc2 marked this conversation as resolved.
Show resolved Hide resolved
}

// Start starts the dispatcher.
func (d *Dispatcher) Start(ctx context.Context) error {
d.eventServer.Start(ctx)
return nil
}
ocnc2 marked this conversation as resolved.
Show resolved Hide resolved

// PublishEvent dispatches the given event to the event server.
// It will error if the <event> type is inconsistent with the publisher
// registered for the given eventID.
func (d *Dispatcher) PublishEvent(event types.BaseMessage) error {
return d.eventServer.Publish(event)
}

// SendRequest dispatches the given request to the message server.
// It will error if the <req> and <resp> types are inconsistent with the
// route registered for the given messageID.
func (d *Dispatcher) SendRequest(req types.BaseMessage, future any) error {
return d.msgServer.Request(req, future)
}

// SendResponse dispatches the given response to the message server.
// It will error if the <resp> type is inconsistent with the route registered
// for the given messageID.
func (d *Dispatcher) SendResponse(resp types.BaseMessage) error {
return d.msgServer.Respond(resp)
}

// ============================== Events ===================================

// RegisterPublishers registers the given publisher with the given eventID.
// Any subsequent events with <eventID> dispatched to this Dispatcher must be
// consistent with the type expected by <publisher>.
func (d *Dispatcher) RegisterPublishers(
publishers ...types.Publisher,
) error {
var err error
for _, publisher := range publishers {
d.logger.Info("Publisher registered", "eventID", publisher.EventID())
err = d.eventServer.RegisterPublisher(publisher.EventID(), publisher)
if err != nil {
return err
}
}
return nil
}
ocnc2 marked this conversation as resolved.
Show resolved Hide resolved

// Subscribe subscribes the given channel to the event with the given <eventID>.
// It will error if the channel type does not match the event type corresponding
// to the <eventID>.
func (d *Dispatcher) Subscribe(eventID types.MessageID, ch any) error {
return d.eventServer.Subscribe(eventID, ch)
}

// ================================ Messages ================================

// RegisterMsgRecipient registers the given channel to the message with the
// given <messageID>.
func (d *Dispatcher) RegisterMsgReceiver(
messageID types.MessageID, ch any,
) error {
d.logger.Info("Message receiver registered", "messageID", messageID)
return d.msgServer.RegisterReceiver(messageID, ch)
}

// RegisterRoutes registers the given route with the given messageID.
// Any subsequent messages with <messageID> sent to this Dispatcher must be
// consistent with the type expected by <route>.
func (d *Dispatcher) RegisterRoutes(
routes ...types.MessageRoute,
) error {
var err error
for _, route := range routes {
d.logger.Info("Route registered", "messageID", route.MessageID())
err = d.msgServer.RegisterRoute(route.MessageID(), route)
if err != nil {
return err
}
}
return nil
}
ocnc2 marked this conversation as resolved.
Show resolved Hide resolved

func (d *Dispatcher) Name() string {
return "dispatcher"
}
44 changes: 44 additions & 0 deletions mod/async/pkg/dispatcher/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package dispatcher

import (
"context"

"github.com/berachain/beacon-kit/mod/async/pkg/types"
"github.com/berachain/beacon-kit/mod/log"
)

type MessageServer interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

add some comments / can we make API surface smaller?

RegisterReceiver(mID types.MessageID, ch any) error
Request(req types.BaseMessage, future any) error
Respond(resp types.BaseMessage) error
RegisterRoute(mID types.MessageID, route types.MessageRoute) error
SetLogger(logger log.Logger[any])
}

type EventServer interface {
Start(ctx context.Context)
RegisterPublisher(mID types.EventID, publisher types.Publisher) error
Subscribe(mID types.EventID, ch any) error
Publish(event types.BaseMessage) error
SetLogger(logger log.Logger[any])
}
Loading
Loading